TensorTonic
Study Plans
Study Plan
Sample a Recent Self-Play Replay Batch
Reinforcement LearningData ProcessingProbability and Statistics
Easy

Sample training records from the most recent window_size self-play games. Games are ordered oldest to newest, with positions ordered within each game. Each record is a dictionary containing state, policy, and value; preserve these contents without interpreting them.

The eligible pool contains positions from the last window_size games, or all games if fewer are available, in game and position order. Supplied zero-based position_indices select from that pool in their given order, including repeated draws. Do not generate new indices. Return a tuple containing a list of independent deep copies of the selected records and the eligible position count as a Python integer.

Loading visualization...

Examples

Input: games=[[{"state": "s0", "policy": [1, 0], "value": 1}, {"state": "s1", "policy": [0, 1], "value": -1}], [{"state": "s2", "policy": [0.5, 0.5], "value": 0}]], window_size=2, position_indices=[0, 2, 0]

Output: ([{"state": "s0", "policy": [1, 0], "value": 1}, {"state": "s2", "policy": [0.5, 0.5], "value": 0}, {"state": "s0", "policy": [1, 0], "value": 1}], 3)

Explanation: All three positions are eligible, and the repeated index creates a second independent copy of the first record.

Input: games=[[{"state": "old", "policy": [1], "value": -1}], [{"state": "new", "policy": [1], "value": 1}]], window_size=1, position_indices=[0]

Output: ([{"state": "new", "policy": [1], "value": 1}], 1)

Input: games=[[], [{"state": [], "policy": [], "value": 0}, {"state": [1], "policy": [1], "value": 1}]], window_size=5, position_indices=[]

Output: ([], 2)

Hint 1

Negative slicing can select the recent game window.

Hint 2

A nested loop keeps game order and position order intact.

Hint 3

copy.deepcopy each selected record separately to isolate repeated draws.

Requirements

  • Accept Python lists or tuples for games, each game, and position_indices; no NumPy conversion is needed.
  • Preserve input records and the order and multiplicity of requested draws.
  • Returned records must be independent of replay storage and of one another.

Constraints

  • window_size is a positive integer.
  • Each record has exactly state, policy, and value, containing finite JSON-compatible values.
  • Every position index is a valid nonnegative integer for the eligible pool.
  • Empty games, an empty replay buffer, and an empty sample are supported.
Try Similar Problems
Apply a Dihedral Go SymmetryMediumFind a Go Group and Its LibertiesEasyMix Dirichlet Noise into Root PriorsEasyScore a Terminal Position with Tromp-Taylor RulesMediumEncode AlphaGo Zero Board HistoryMediumApply a Go Action with Captures and RepetitionHardBuild the Legal Go Action MaskHardCanonicalize Pairwise Preference DataMediumSoftmax (Boltzmann) ExplorationEasyUCB1 for Multi-Armed BanditsEasyExperience Replay BufferEasyRandom Array GenerationEasy

Accepts: array

Accepts: number

Accepts: array

You must run your code first.

Sample a Recent Self-Play Replay Batch

Reinforcement LearningData ProcessingProbability and Statistics
Easy

Sample training records from the most recent window_size self-play games. Games are ordered oldest to newest, with positions ordered within each game. Each record is a dictionary containing state, policy, and value; preserve these contents without interpreting them.

The eligible pool contains positions from the last window_size games, or all games if fewer are available, in game and position order. Supplied zero-based position_indices select from that pool in their given order, including repeated draws. Do not generate new indices. Return a tuple containing a list of independent deep copies of the selected records and the eligible position count as a Python integer.

Loading visualization...

Examples

Input: games=[[{"state": "s0", "policy": [1, 0], "value": 1}, {"state": "s1", "policy": [0, 1], "value": -1}], [{"state": "s2", "policy": [0.5, 0.5], "value": 0}]], window_size=2, position_indices=[0, 2, 0]

Output: ([{"state": "s0", "policy": [1, 0], "value": 1}, {"state": "s2", "policy": [0.5, 0.5], "value": 0}, {"state": "s0", "policy": [1, 0], "value": 1}], 3)

Explanation: All three positions are eligible, and the repeated index creates a second independent copy of the first record.

Input: games=[[{"state": "old", "policy": [1], "value": -1}], [{"state": "new", "policy": [1], "value": 1}]], window_size=1, position_indices=[0]

Output: ([{"state": "new", "policy": [1], "value": 1}], 1)

Input: games=[[], [{"state": [], "policy": [], "value": 0}, {"state": [1], "policy": [1], "value": 1}]], window_size=5, position_indices=[]

Output: ([], 2)

Hint 1

Negative slicing can select the recent game window.

Hint 2

A nested loop keeps game order and position order intact.

Hint 3

copy.deepcopy each selected record separately to isolate repeated draws.

Requirements

  • Accept Python lists or tuples for games, each game, and position_indices; no NumPy conversion is needed.
  • Preserve input records and the order and multiplicity of requested draws.
  • Returned records must be independent of replay storage and of one another.

Constraints

  • window_size is a positive integer.
  • Each record has exactly state, policy, and value, containing finite JSON-compatible values.
  • Every position index is a valid nonnegative integer for the eligible pool.
  • Empty games, an empty replay buffer, and an empty sample are supported.
Try Similar Problems
Apply a Dihedral Go SymmetryMediumFind a Go Group and Its LibertiesEasyMix Dirichlet Noise into Root PriorsEasyScore a Terminal Position with Tromp-Taylor RulesMediumEncode AlphaGo Zero Board HistoryMediumApply a Go Action with Captures and RepetitionHardBuild the Legal Go Action MaskHardCanonicalize Pairwise Preference DataMediumSoftmax (Boltzmann) ExplorationEasyUCB1 for Multi-Armed BanditsEasyExperience Replay BufferEasyRandom Array GenerationEasy

Accepts: array

Accepts: number

Accepts: array

You must run your code first.