code: def testTrainMaskingPartialEpisodeMultipleEpisodesRewardOnFirst(self):
      # Test that train reacts correctly to experience when there are:
      #   * Multiple MDP episodes
      #   * Rewards on the tf.StepType.FIRST transitions
      #   * Partial episode at end of experience
      #
      # F, L, M = ts.StepType.{FIRST, MID, LAST} in the chart below.
      #
      # Experience looks like this:
      # Trajectories: (F, L) -> (L, F) -> (F, M) -> (M, M)
      # observation : [1, 2]    [1, 2]    [1, 2]    [1, 2]
      # action      :   [0]       [1]       [2]       [3]
      # reward      :    3         0         4         0
      # ~is_boundary:    1         0         1         1
      # is_last     :    1         0         0         0
      # valid reward:   3*1       0*0       4*0       0*0
      #
      # The second action & reward should be masked out due to being on a
      # boundary (step_type=(L, F)) transition.  The third & fourth transitions
      # should get masked out for everything due to it being an incomplete episode
      # (notice there is no trailing step_type=(F,L)).
      #
      # The expected_loss is > 0.0 in this case, matching the expected_loss of the
      # testMaskingRewardSingleEpisodeRewardOnFirst policy_gradient_loss test,
      # because the partial second episode should be masked out.
      agent = reinforce_agent.ReinforceAgent(
          self._time_step_spec,
          self._action_spec,
          actor_network=DummyActorNet(
              self._obs_spec, self._action_spec, unbounded_actions=True
          ),
          optimizer=tf.compat.v1.train.AdamOptimizer(0.001),
          use_advantage_loss=False,
          normalize_returns=False,
      )
  
      step_type = tf.constant(
          [
              ts.StepType.FIRST,
              ts.StepType.LAST,
              ts.StepType.FIRST,
              ts.StepType.MID,
          ]
      )
      next_step_type = tf.constant(
          [
              ts.StepType.LAST,
              ts.StepType.FIRST,
              ts.StepType.MID,
              ts.StepType.MID,
          ]
      )
      reward = tf.constant([3, 0, 4, 0], dtype=tf.float32)
      discount = tf.constant([1, 0, 1, 0], dtype=tf.float32)
      observations = tf.constant(
          [[1, 2], [1, 2], [1, 2], [1, 2]], dtype=tf.float32
      )
      actions = tf.constant([[0], [1], [2], [3]], dtype=tf.float32)
  
      experience = nest_utils.batch_nested_tensors(
          trajectory.Trajectory(
              step_type,
              observations,
              actions,
              (),
              next_step_type,
              reward,
              discount,
          )
      )
  
      # Rewards on the StepType.FIRST should be counted.
      expected_loss = 10.8935775757
  
      if tf.executing_eagerly():
          loss = lambda: agent.train(experience)
      else:
          loss = agent.train(experience)
  
      self.evaluate(tf.compat.v1.global_variables_initializer())
      loss_info = self.evaluate(loss)
      self.assertAllClose(loss_info.loss, expected_loss)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  from absl.testing.absltest import mock
  import tensorflow
  import tensorflow_probability
  from tf_agents.agents.reinforce import reinforce_agent
  from tf_agents.networks import actor_distribution_rnn_network
  from tf_agents.networks import network
  from tf_agents.networks import utils
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import policy_step
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.utils import common
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 17 for calling the ReinforceAgentTest obj's underlying member method code with example usage: obj.testTrainMaskingPartialEpisodeMultipleEpisodesRewardOnFirst() without return types