class_docstr: Implements a recurrent DQN designed to produce melody sequences.
class_docstr_tok: ["Implements","a","recurrent","DQN","designed","to","produce","melody","sequences","."]
docstr: Reduces the previous reward if the composition is highly autocorrelated.
  
  Penalizes the model for creating a composition that is highly correlated
  with itself at lags of 1, 2, and 3 beats previous. This is meant to
  encourage variety in compositions.
  
  Args:
    action: One-hot encoding of the chosen action.
    penalty_weight: The default weight which will be multiplied by the sum
      of the autocorrelation coefficients, and subtracted from prev_reward.
  Returns:
    Float reward value.
docstr_tok: ["Reduces","the","previous","reward","if","the","composition","is","highly","autocorrelated",".","Penalizes","the","model","for","creating","a","composition","that","is","highly","correlated","with","itself","at","lags","of","1",",","2",",","and","3","beats","previous",".","This","is","meant","to","encourage","variety","in","compositions",".","Args",":","action",":","One-hot","encoding","of","the","chosen","action",".","penalty_weight",":","The","default","weight","which","will","be","multiplied","by","the","sum","of","the","autocorrelation","coefficients",",","and","subtracted","from","prev_reward",".","Returns",":","Float","reward","value","."]
code: def reward_penalize_autocorrelation(self, action, penalty_weight=3.0):
      """Reduces the previous reward if the composition is highly autocorrelated.
  
      Penalizes the model for creating a composition that is highly correlated
      with itself at lags of 1, 2, and 3 beats previous. This is meant to
      encourage variety in compositions.
  
      Args:
        action: One-hot encoding of the chosen action.
        penalty_weight: The default weight which will be multiplied by the sum
          of the autocorrelation coefficients, and subtracted from prev_reward.
      Returns:
        Float reward value.
      """
      composition = self.composition + [np.argmax(action)]
      lags = [1, 2, 3]
      sum_penalty = 0
      for lag in lags:
          coeff = rl_tuner_ops.autocorrelate(composition, lag=lag)
          if not np.isnan(coeff):
              if np.abs(coeff) > 0.15:
                  sum_penalty += np.abs(coeff) * penalty_weight
      return -sum_penalty
  
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 25 for calling the RLTuner obj's underlying member method code with example usage: obj.reward_penalize_autocorrelation(action, penalty_weight) and returns: unknown