class_docstr: Implements a recurrent DQN designed to produce melody sequences.
class_docstr_tok: ["Implements","a","recurrent","DQN","designed","to","produce","melody","sequences","."]
docstr: Reward function that trains the model to play a scale.
  
  Gives rewards for increasing notes, notes within the desired scale, and two
  consecutive notes from the scale.
  
  Args:
    obs: A one-hot encoding of the observed note.
    action: A one-hot encoding of the chosen action.
    scale: The scale the model should learn. Defaults to C Major if not
      provided.
  Returns:
    Float reward value.
docstr_tok: ["Reward","function","that","trains","the","model","to","play","a","scale",".","Gives","rewards","for","increasing","notes",",","notes","within","the","desired","scale",",","and","two","consecutive","notes","from","the","scale",".","Args",":","obs",":","A","one-hot","encoding","of","the","observed","note",".","action",":","A","one-hot","encoding","of","the","chosen","action",".","scale",":","The","scale","the","model","should","learn",".","Defaults","to","C","Major","if","not","provided",".","Returns",":","Float","reward","value","."]
code: def reward_scale(self, obs, action, scale=None):
      """Reward function that trains the model to play a scale.
  
      Gives rewards for increasing notes, notes within the desired scale, and two
      consecutive notes from the scale.
  
      Args:
        obs: A one-hot encoding of the observed note.
        action: A one-hot encoding of the chosen action.
        scale: The scale the model should learn. Defaults to C Major if not
          provided.
      Returns:
        Float reward value.
      """
  
      if scale is None:
          scale = rl_tuner_ops.C_MAJOR_SCALE
  
      obs = np.argmax(obs)
      action = np.argmax(action)
      reward = 0
      if action == 1:
          reward += 0.1
      if obs < action < obs + 3:
          reward += 0.05
  
      if action in scale:
          reward += 0.01
          if obs in scale:
              action_pos = scale.index(action)
              obs_pos = scale.index(obs)
              if obs_pos == len(scale) - 1 and action_pos == 0:
                  reward += 0.8
              elif action_pos == obs_pos + 1:
                  reward += 0.8
  
      return reward
  
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 18 for calling the RLTuner obj's underlying member method code with example usage: obj.reward_scale(obs, action, scale) and returns: reward