class_docstr: Implements a recurrent DQN designed to produce melody sequences.
class_docstr_tok: ["Implements","a","recurrent","DQN","designed","to","produce","melody","sequences","."]
docstr: Dispenses reward based on the melodic interval just played.
  
  Args:
    action: One-hot encoding of the chosen action.
    scaler: This value will be multiplied by all rewards in this function.
    key: The numeric values of notes belonging to this key. Defaults to
      C-major if not provided.
  Returns:
    Float reward value.
docstr_tok: ["Dispenses","reward","based","on","the","melodic","interval","just","played",".","Args",":","action",":","One-hot","encoding","of","the","chosen","action",".","scaler",":","This","value","will","be","multiplied","by","all","rewards","in","this","function",".","key",":","The","numeric","values","of","notes","belonging","to","this","key",".","Defaults","to","C-major","if","not","provided",".","Returns",":","Float","reward","value","."]
code: def reward_preferred_intervals(self, action, scaler=5.0, key=None):
      """Dispenses reward based on the melodic interval just played.
  
      Args:
        action: One-hot encoding of the chosen action.
        scaler: This value will be multiplied by all rewards in this function.
        key: The numeric values of notes belonging to this key. Defaults to
          C-major if not provided.
      Returns:
        Float reward value.
      """
      interval, _, _ = self.detect_sequential_interval(action, key)
      tf.logging.debug("Interval:", interval)
  
      if (
          interval == 0
      ):  # either no interval or involving uninteresting rests
          tf.logging.debug("No interval or uninteresting.")
          return 0.0
  
      reward = 0.0
  
      # rests can be good
      if interval == rl_tuner_ops.REST_INTERVAL:
          reward = 0.05
          tf.logging.debug("Rest interval.")
      if interval == rl_tuner_ops.HOLD_INTERVAL:
          reward = 0.075
      if interval == rl_tuner_ops.REST_INTERVAL_AFTER_THIRD_OR_FIFTH:
          reward = 0.15
          tf.logging.debug("Rest interval after 1st or 5th.")
      if interval == rl_tuner_ops.HOLD_INTERVAL_AFTER_THIRD_OR_FIFTH:
          reward = 0.3
  
      # large leaps and awkward intervals bad
      if interval == rl_tuner_ops.SEVENTH:
          reward = -0.3
          tf.logging.debug("7th")
      if interval > rl_tuner_ops.OCTAVE:
          reward = -1.0
          tf.logging.debug("More than octave.")
  
      # common major intervals are good
      if interval == rl_tuner_ops.IN_KEY_FIFTH:
          reward = 0.1
          tf.logging.debug("In key 5th")
      if interval == rl_tuner_ops.IN_KEY_THIRD:
          reward = 0.15
          tf.logging.debug("In key 3rd")
  
      # smaller steps are generally preferred
      if interval == rl_tuner_ops.THIRD:
          reward = 0.09
          tf.logging.debug("3rd")
      if interval == rl_tuner_ops.SECOND:
          reward = 0.08
          tf.logging.debug("2nd")
      if interval == rl_tuner_ops.FOURTH:
          reward = 0.07
          tf.logging.debug("4th")
  
      # larger leaps not as good, especially if not in key
      if interval == rl_tuner_ops.SIXTH:
          reward = 0.05
          tf.logging.debug("6th")
      if interval == rl_tuner_ops.FIFTH:
          reward = 0.02
          tf.logging.debug("5th")
  
      tf.logging.debug("Interval reward", reward * scaler)
      return 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 31 for calling the RLTuner obj's underlying member method code with example usage: obj.reward_preferred_intervals(action, scaler, key) and returns: unknown, int