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 the model for playing any motif.
  
  Motif must have at least three distinct notes in the course of one bar.
  There is a bonus for playing more complex motifs; that is, ones that involve
  a greater number of notes.
  
  Args:
    action: One-hot encoding of the chosen action.
    reward_amount: The amount that will be returned if the last note belongs
      to a motif.
  Returns:
    Float reward value.
docstr_tok: ["Rewards","the","model","for","playing","any","motif",".","Motif","must","have","at","least","three","distinct","notes","in","the","course","of","one","bar",".","There","is","a","bonus","for","playing","more","complex","motifs",";","that","is",",","ones","that","involve","a","greater","number","of","notes",".","Args",":","action",":","One-hot","encoding","of","the","chosen","action",".","reward_amount",":","The","amount","that","will","be","returned","if","the","last","note","belongs","to","a","motif",".","Returns",":","Float","reward","value","."]
code: def reward_motif(self, action, reward_amount=3.0):
      """Rewards the model for playing any motif.
  
      Motif must have at least three distinct notes in the course of one bar.
      There is a bonus for playing more complex motifs; that is, ones that involve
      a greater number of notes.
  
      Args:
        action: One-hot encoding of the chosen action.
        reward_amount: The amount that will be returned if the last note belongs
          to a motif.
      Returns:
        Float reward value.
      """
  
      composition = self.composition + [np.argmax(action)]
      motif, num_notes_in_motif = self.detect_last_motif(
          composition=composition
      )
      if motif is not None:
          motif_complexity_bonus = max(
              (num_notes_in_motif - 3) * 0.3, 0
          )
          return reward_amount + motif_complexity_bonus
      else:
          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 27 for calling the RLTuner obj's underlying member method code with example usage: obj.reward_motif(action, reward_amount) and returns: unknown, int