code: def test_normalize_by_max(self):
      rbuf = replay_buffers.PrioritizedReplayBuffer(
          self.capacity,
          normalize_by_max=self.normalize_by_max,
          error_max=1000,
          num_steps=self.num_steps,
      )
  
      # Add 100 transitions
      for i in range(100):
          trans = dict(
              state=i,
              action=1,
              reward=2,
              next_state=i + 1,
              next_action=1,
              is_state_terminal=False,
          )
          rbuf.append(**trans)
      assert len(rbuf) == 100
  
      def set_errors_based_on_state(rbuf, samples):
          # Use the value of 'state' as an error, so that state 0 will have
          # the smallest error, thus the largest weight
          errors = [s[0]["state"] for s in samples]
          rbuf.update_errors(errors)
  
      # Assign different errors to all the transitions first
      samples = rbuf.sample(100)
      set_errors_based_on_state(rbuf, samples)
  
      # Repeatedly check how weights are normalized
      for i in range(100):
          samples = rbuf.sample(i + 1)
          # All the weights must be unique
          assert len(set(s[0]["weight"] for s in samples)) == len(
              samples
          )
          # Now check the maximum weight in a minibatch
          max_w = max([s[0]["weight"] for s in samples])
          if self.normalize_by_max == "batch":
              # Maximum weight in a minibatch must be 1
              np.testing.assert_allclose(max_w, 1)
          elif self.normalize_by_max == "memory":
              # Maximum weight in a minibatch must be less than 1 unless
              # the minibatch contains the transition of least error.
              if any(s[0]["state"] == 0 for s in samples):
                  np.testing.assert_allclose(max_w, 1)
              else:
                  assert max_w < 1
          set_errors_based_on_state(rbuf, samples)
  
imports: import collections
  import copy
  import os
  import tempfile
  import unittest
  import numpy
  import pytest
  import torch
  from pfrl import replay_buffer, replay_buffers
label_desc: Use image node_id 3 for calling the TestPrioritizedReplayBuffer obj's underlying member method code with example usage: obj.test_normalize_by_max() without return types