code: def test_adder(self):
      stats_adder = TestStatisticsAdder()
      demonstration_ratio = 0.2
      initial_insert_count = 50
      adder = lfd_adder.LfdAdder(
          stats_adder,
          self.generate_demonstration(),
          initial_insert_count=initial_insert_count,
          demonstration_ratio=demonstration_ratio,
      )
  
      num_episodes = 100
      for episode_index in range(num_episodes):
          episode = self.generate_episode(
              self._collected_episode_type,
              episode_index,
              self._collected_episode_length,
          )
          for k, (action, timestep) in enumerate(episode):
              if k == 0:
                  adder.add_first(timestep)
                  if episode_index == 0:
                      self.assertGreaterEqual(
                          stats_adder.counts[
                              self._demonstration_episode_type
                          ],
                          initial_insert_count
                          - self._demonstration_episode_length,
                      )
                      self.assertLessEqual(
                          stats_adder.counts[
                              self._demonstration_episode_type
                          ],
                          initial_insert_count
                          + self._demonstration_episode_length,
                      )
              else:
                  adder.add(action, timestep)
  
      # Only 2 types of episodes.
      self.assertLen(stats_adder.counts, 2)
  
      total_count = (
          stats_adder.counts[self._demonstration_episode_type]
          + stats_adder.counts[self._collected_episode_type]
      )
      # The demonstration ratio does not account for the initial demonstration
      # insertion. Computes a ratio that takes it into account.
      target_ratio = (
          demonstration_ratio
          * (float)(total_count - initial_insert_count)
          + initial_insert_count
      ) / (float)(total_count)
      # Effective ratio of demonstrations.
      effective_ratio = float(
          stats_adder.counts[self._demonstration_episode_type]
      ) / float(total_count)
      # Only full episodes can be fed to the adder so the effective ratio
      # might be slightly different from the requested demonstration ratio.
      min_ratio = (
          target_ratio
          - self._demonstration_episode_length / float(total_count)
      )
      max_ratio = (
          target_ratio
          + self._demonstration_episode_length / float(total_count)
      )
      self.assertGreaterEqual(effective_ratio, min_ratio)
      self.assertLessEqual(effective_ratio, max_ratio)
  
file_path: acme/acme/agents/jax/lfd/lfd_adder_test.py
imports: import collections
  from acme import adders
  from acme import types
  from acme.agents.jax.lfd import lfd_adder
  import dm_env
  import numpy
  from absl.testing import absltest
label_desc: Use image node_id 4 for calling the LfdAdderTest obj's underlying member method code with example usage: obj.test_adder() without return types