(self, obs, action, reward_scores)
return reward * self.reward_scaler
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.
Calls whatever reward function is indicated in the reward_mode field.
Calls whatever reward function is indicated in the reward_mode field .
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
def collect_reward ( self , obs , action , reward_scores ) : # 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