class_docstr: Implements a recurrent DQN designed to produce melody sequences.
class_docstr_tok: ["Implements","a","recurrent","DQN","designed","to","produce","melody","sequences","."]
docstr: Rewards for playing the tonic note at the right times.
  
  Rewards for playing the tonic as the first note of the first bar, and the
  first note of the final bar.
  
  Args:
    action: One-hot encoding of the chosen action.
    tonic_note: The tonic/1st note of the desired key.
    reward_amount: The amount the model will be awarded if it plays the
      tonic note at the right time.
  Returns:
    Float reward value.
docstr_tok: ["Rewards","for","playing","the","tonic","note","at","the","right","times",".","Rewards","for","playing","the","tonic","as","the","first","note","of","the","first","bar",",","and","the","first","note","of","the","final","bar",".","Args",":","action",":","One-hot","encoding","of","the","chosen","action",".","tonic_note",":","The","tonic\/1st","note","of","the","desired","key",".","reward_amount",":","The","amount","the","model","will","be","awarded","if","it","plays","the","tonic","note","at","the","right","time",".","Returns",":","Float","reward","value","."]
code: def reward_tonic(
      self,
      action,
      tonic_note=rl_tuner_ops.C_MAJOR_TONIC,
      reward_amount=3.0,
  ):
      """Rewards for playing the tonic note at the right times.
  
      Rewards for playing the tonic as the first note of the first bar, and the
      first note of the final bar.
  
      Args:
        action: One-hot encoding of the chosen action.
        tonic_note: The tonic/1st note of the desired key.
        reward_amount: The amount the model will be awarded if it plays the
          tonic note at the right time.
      Returns:
        Float reward value.
      """
      action_note = np.argmax(action)
      first_note_of_final_bar = self.num_notes_in_melody - 4
  
      if self.beat == 0 or self.beat == first_note_of_final_bar:
          if action_note == tonic_note:
              return reward_amount
      elif self.beat == first_note_of_final_bar + 1:
          if action_note == NO_EVENT:
              return reward_amount
      elif self.beat > first_note_of_final_bar + 1:
          if action_note in (NO_EVENT, NOTE_OFF):
              return reward_amount
      return 0.0
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import os
  import random
  import urllib
  from magenta.models.rl_tuner import note_rnn_loader
  from magenta.models.rl_tuner import rl_tuner_eval_metrics
  from magenta.models.rl_tuner import rl_tuner_ops
  import matplotlib.pyplot
  from note_seq import melodies_lib
  from note_seq import midi_io
  import numpy
  import scipy.special
  from six.moves import range
  from six.moves import reload_module
  from six.moves import urllib
  import tensorflow.compat.v1
label_desc: Use image node_id 21 for calling the RLTuner obj's underlying member method code with example usage: obj.reward_tonic(action, tonic_note, reward_amount) and returns: int, reward_amount, reward_amount, reward_amount