class_docstr: Class for RNN event sequence generation models.
  
  Currently this class only supports generation, of both event sequences and
  note sequences (via event sequences). Support for model training will be added
  at a later time.
class_docstr_tok: ["Class","for","RNN","event","sequence","generation","models",".","Currently","this","class","only","supports","generation",",","of","both","event","sequences","and","note","sequences","(","via","event","sequences",")",".","Support","for","model","training","will","be","added","at","a","later","time","."]
docstr: Evaluate log likelihood for a list of event sequences of the same length.
  
  Args:
    event_sequences: A list of event sequences for which to evaluate the log
        likelihood.
    control_events: A sequence of control events upon which to condition the
        event sequences. If not None, the encoder/decoder should be a
        ConditionalEventSequenceEncoderDecoder, and the log likelihood of each
        event sequence will be computed conditional on the control sequence.
  
  Returns:
    The log likelihood of each sequence in `event_sequences`.
  
  Raises:
    EventSequenceRnnModelError: If the event sequences are not all the
        same length, or if the control sequence is shorter than the event
        sequences.
docstr_tok: ["Evaluate","log","likelihood","for","a","list","of","event","sequences","of","the","same","length",".","Args",":","event_sequences",":","A","list","of","event","sequences","for","which","to","evaluate","the","log","likelihood",".","control_events",":","A","sequence","of","control","events","upon","which","to","condition","the","event","sequences",".","If","not","None",",","the","encoder\/decoder","should","be","a","ConditionalEventSequenceEncoderDecoder",",","and","the","log","likelihood","of","each","event","sequence","will","be","computed","conditional","on","the","control","sequence",".","Returns",":","The","log","likelihood","of","each","sequence","in","`","event_sequences","`",".","Raises",":","EventSequenceRnnModelError",":","If","the","event","sequences","are","not","all","the","same","length",",","or","if","the","control","sequence","is","shorter","than","the","event","sequences","."]
code: def _evaluate_log_likelihood(
      self, event_sequences, control_events=None
  ):
      """Evaluate log likelihood for a list of event sequences of the same length.
  
      Args:
        event_sequences: A list of event sequences for which to evaluate the log
            likelihood.
        control_events: A sequence of control events upon which to condition the
            event sequences. If not None, the encoder/decoder should be a
            ConditionalEventSequenceEncoderDecoder, and the log likelihood of each
            event sequence will be computed conditional on the control sequence.
  
      Returns:
        The log likelihood of each sequence in `event_sequences`.
  
      Raises:
        EventSequenceRnnModelError: If the event sequences are not all the
            same length, or if the control sequence is shorter than the event
            sequences.
      """
      num_steps = len(event_sequences[0])
      for events in event_sequences[1:]:
          if len(events) != num_steps:
              raise EventSequenceRnnModelError(
                  "log likelihood evaluation requires all event sequences to have "
                  "the same length"
              )
      if control_events is not None and len(control_events) < num_steps:
          raise EventSequenceRnnModelError(
              "control sequence must be at least as long as the event sequences"
          )
  
      batch_size = self._batch_size()
      num_full_batches = len(event_sequences) // batch_size
  
      loglik = np.empty(len(event_sequences))
  
      # Since we're computing log-likelihood and not generating, the inputs batch
      # doesn't need to include the final event in each sequence.
      if control_events is not None:
          # We are conditioning on a control sequence.
          inputs = self._config.encoder_decoder.get_inputs_batch(
              [control_events] * len(event_sequences),
              [events[:-1] for events in event_sequences],
              full_length=True,
          )
      else:
          inputs = self._config.encoder_decoder.get_inputs_batch(
              [events[:-1] for events in event_sequences],
              full_length=True,
          )
  
      graph_initial_state = self._session.graph.get_collection(
          "initial_state"
      )
      initial_state = self._session.run(graph_initial_state)
      offset = 0
      for _ in range(num_full_batches):
          # Evaluate a single step for one batch of event sequences.
          batch_indices = range(offset, offset + batch_size)
          batch_loglik = self._evaluate_batch_log_likelihood(
              [event_sequences[i] for i in batch_indices],
              [inputs[i] for i in batch_indices],
              [initial_state] * len(batch_indices),
          )
          loglik[batch_indices] = batch_loglik
          offset += batch_size
  
      if offset < len(event_sequences):
          # There's an extra non-full batch. Pad it with a bunch of copies of the
          # final sequence.
          num_extra = len(event_sequences) - offset
          pad_size = batch_size - num_extra
          batch_indices = range(offset, len(event_sequences))
          batch_loglik = self._evaluate_batch_log_likelihood(
              [event_sequences[i] for i in batch_indices]
              + [
                  copy.deepcopy(event_sequences[-1])
                  for _ in range(pad_size)
              ],
              [inputs[i] for i in batch_indices]
              + inputs[-1] * pad_size,
              np.append(
                  [initial_state] * len(batch_indices),
                  np.tile(inputs[-1, :], (pad_size, 1)),
                  axis=0,
              ),
          )
          loglik[batch_indices] = batch_loglik[0:num_extra]
  
      return loglik
  
imports: import collections
  import copy
  import functools
  from magenta.common import beam_search
  from magenta.common import state_util
  from magenta.contrib import training
  from magenta.models.shared import events_rnn_graph
  from magenta.models.shared import model
  import note_seq
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 8 for calling the EventSequenceRnnModel obj's underlying member method code with example usage: obj._evaluate_log_likelihood(event_sequences, control_events) and returns: loglik