class_docstr: Implements a recurrent DQN designed to produce melody sequences.
class_docstr_tok: ["Implements","a","recurrent","DQN","designed","to","produce","melody","sequences","."]
docstr: Calls whatever reward function is indicated in the reward_mode field.
  
  New reward functions can be written and called from here. Note that the
  reward functions can make use of the musical composition that has been
  played so far, which is stored in self.composition. Some reward functions
  are made up of many smaller functions, such as those related to music
  theory.
  
  Args:
    obs: A one-hot encoding of the observed note.
    action: A one-hot encoding of the chosen action.
    reward_scores: The value for each note output by the reward_rnn.
  Returns:
    Float reward value.
docstr_tok: ["Calls","whatever","reward","function","is","indicated","in","the","reward_mode","field",".","New","reward","functions","can","be","written","and","called","from","here",".","Note","that","the","reward","functions","can","make","use","of","the","musical","composition","that","has","been","played","so","far",",","which","is","stored","in","self.composition",".","Some","reward","functions","are","made","up","of","many","smaller","functions",",","such","as","those","related","to","music","theory",".","Args",":","obs",":","A","one-hot","encoding","of","the","observed","note",".","action",":","A","one-hot","encoding","of","the","chosen","action",".","reward_scores",":","The","value","for","each","note","output","by","the","reward_rnn",".","Returns",":","Float","reward","value","."]
code: def collect_reward(self, obs, action, reward_scores):
      """Calls whatever reward function is indicated in the reward_mode field.
  
      New reward functions can be written and called from here. Note that the
      reward functions can make use of the musical composition that has been
      played so far, which is stored in self.composition. Some reward functions
      are made up of many smaller functions, such as those related to music
      theory.
  
      Args:
        obs: A one-hot encoding of the observed note.
        action: A one-hot encoding of the chosen action.
        reward_scores: The value for each note output by the reward_rnn.
      Returns:
        Float reward value.
      """
      # Gets and saves log p(a|s) as output by reward_rnn.
      note_rnn_reward = self.reward_from_reward_rnn_scores(
          action, reward_scores
      )
      self.note_rnn_reward_last_n += note_rnn_reward
  
      if self.reward_mode == "scale":
          # Makes the model play a scale (defaults to c major).
          reward = self.reward_scale(obs, action)
      elif self.reward_mode == "key":
          # Makes the model play within a key.
          reward = self.reward_key_distribute_prob(action)
      elif self.reward_mode == "key_and_tonic":
          # Makes the model play within a key, while starting and ending on the
          # tonic note.
          reward = self.reward_key(action)
          reward += self.reward_tonic(action)
      elif self.reward_mode == "non_repeating":
          # The model can play any composition it wants, but receives a large
          # negative reward for playing the same note repeatedly.
          reward = self.reward_non_repeating(action)
      elif self.reward_mode == "music_theory_random":
          # The model receives reward for playing in key, playing tonic notes,
          # and not playing repeated notes. However the rewards it receives are
          # uniformly distributed over all notes that do not violate these rules.
          reward = self.reward_key(action)
          reward += self.reward_tonic(action)
          reward += self.reward_penalize_repeating(action)
      elif self.reward_mode == "music_theory_basic":
          # As above, the model receives reward for playing in key, tonic notes
          # at the appropriate times, and not playing repeated notes. However, the
          # rewards it receives are based on the note probabilities learned from
          # data in the original model.
          reward = self.reward_key(action)
          reward += self.reward_tonic(action)
          reward += self.reward_penalize_repeating(action)
  
          return reward * self.reward_scaler + note_rnn_reward
      elif self.reward_mode == "music_theory_basic_plus_variety":
          # Uses the same reward function as above, but adds a penalty for
          # compositions with a high autocorrelation (aka those that don't have
          # sufficient variety).
          reward = self.reward_key(action)
          reward += self.reward_tonic(action)
          reward += self.reward_penalize_repeating(action)
          reward += self.reward_penalize_autocorrelation(action)
  
          return reward * self.reward_scaler + note_rnn_reward
      elif self.reward_mode == "preferred_intervals":
          reward = self.reward_preferred_intervals(action)
      elif self.reward_mode == "music_theory_all":
          tf.logging.debug("Note RNN reward: %s", note_rnn_reward)
  
          reward = self.reward_music_theory(action)
  
          tf.logging.debug(
              "Total music theory reward: %s",
              self.reward_scaler * reward,
          )
          tf.logging.debug("Total note rnn reward: %s", note_rnn_reward)
  
          self.music_theory_reward_last_n += reward * self.reward_scaler
          return reward * self.reward_scaler + note_rnn_reward
      elif self.reward_mode == "music_theory_only":
          reward = self.reward_music_theory(action)
      else:
          tf.logging.fatal(
              "ERROR! Not a valid reward mode. Cannot compute reward"
          )
  
      self.music_theory_reward_last_n += reward * self.reward_scaler
      return reward * self.reward_scaler
  
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 13 for calling the RLTuner obj's underlying member method code with example usage: obj.collect_reward(obs, action, reward_scores) and returns: unknown, unknown, unknown, unknown