class_docstr: Tests insertion and (weighted) sampling of the PrioritizedReplayBuffer.
class_docstr_tok: ["Tests","insertion","and","(","weighted",")","sampling","of","the","PrioritizedReplayBuffer","."]
code: def test_alpha_parameter(self):
      # Test sampling from a PR with a very small alpha (should behave just
      # like a regular ReplayBuffer).
      buffer = PrioritizedReplayBuffer(self.capacity, alpha=0.01)
  
      # Insert n samples.
      num_records = 5
      for i in range(num_records):
          data = self._generate_data()
          buffer.add(data, weight=float(np.random.rand()))
          self.assertTrue(len(buffer) == i + 1)
          self.assertTrue(buffer._next_idx == i + 1)
      # Test get_state/set_state.
      state = buffer.get_state()
      new_memory = PrioritizedReplayBuffer(self.capacity, alpha=0.01)
      new_memory.set_state(state)
      self.assertTrue(len(new_memory) == num_records)
      self.assertTrue(new_memory._next_idx == num_records)
  
      # Fetch records, their indices and weights.
      batch = buffer.sample(1000, beta=self.beta)
      indices = batch["batch_indexes"]
      counts = Counter()
      for i in indices:
          counts[i] += 1
  
      # Expect an approximately uniform distribution of indices.
      self.assertTrue(any(100 < i < 300 for i in counts.values()))
      # Test get_state/set_state.
      state = buffer.get_state()
      new_memory = PrioritizedReplayBuffer(self.capacity, alpha=0.01)
      new_memory.set_state(state)
      batch = new_memory.sample(1000, beta=self.beta)
      indices = batch["batch_indexes"]
      counts = Counter()
      for i in indices:
          counts[i] += 1
      self.assertTrue(any(100 < i < 300 for i in counts.values()))
  
file_path: ray/python/ray/rllib/utils/replay_buffers/tests/test_prioritized_replay_buffer_replay_buffer_api.py
imports: from collections import Counter
  import numpy
  import unittest
  from ray.rllib.utils.replay_buffers.prioritized_replay_buffer import PrioritizedReplayBuffer
  from ray.rllib.policy.sample_batch import SampleBatch, MultiAgentBatch, concat_samples
  from ray.rllib.utils.test_utils import check
label_desc: Use image node_id 6 for calling the TestPrioritizedReplayBuffer obj's underlying member method code with example usage: obj.test_alpha_parameter() without return types