TensorTonic
Study Plans
Study Plan
Apply a Dihedral Go Symmetry
Reinforcement LearningData Processing
Medium

Augment one Go training record with a symmetry of its square board. Transform IDs 0, 1, 2, and 3 mean counterclockwise rotations of 0, 90, 180, and 270 degrees. IDs 4 through 7 mean a left-right reflection followed by those same rotations.

state_planes is a NumPy array of shape (C, n, n), where C is the plane count and n is the board size. policy is a floating-point NumPy array of length n squared plus one: board entries in row-major order, followed by pass. Its nonnegative weights need not sum to one; do not normalize them. Apply the same symmetry to every plane and the board entries, leaving pass and value unchanged.

Return a three-item tuple: the transformed state array, transformed policy array, and unchanged scalar value. Both arrays must retain their input shapes and dtypes and use newly allocated storage.

Loading visualization...

Examples

Input: state_planes=[[[1, 2], [3, 4]]], policy=[0.1, 0.2, 0.3, 0.4, 0.5], value=0.25, transform_id=1

Output: ([[[2, 4], [1, 3]]], [0.2, 0.4, 0.1, 0.3, 0.5], 0.25)

Explanation: The state and board-action probabilities receive the same 90 degree counterclockwise rotation, while the pass entry remains last.

Input: state_planes=[[[1, 2], [3, 4]]], policy=[0.1, 0.2, 0.3, 0.4, 0.5], value=-0.5, transform_id=4

Output: ([[[2, 1], [4, 3]]], [0.2, 0.1, 0.4, 0.3, 0.5], -0.5)

Input: state_planes=[[[7]]], policy=[0.6, 0.4], value=1.0, transform_id=7

Output: ([[[7]]], [0.6, 0.4], 1.0)

Hint 1

np.rot90 accepts axes=(-2, -1) to rotate every plane together.

Hint 2

np.flip with axis=-1 reflects the board from left to right.

Hint 3

Array.copy prevents transformed views from sharing the input storage.

Requirements

  • Use NumPy and preserve each input array's dtype.
  • Leave all input values unchanged.
  • Returned arrays must not share storage with either input array.

Constraints

  • state_planes has shape (C, n, n), with nonnegative C and positive n.
  • policy is a finite, nonnegative floating-point array of shape (n squared plus one,).
  • value is a finite numeric scalar.
  • transform_id is an integer from 0 through 7.
Try Similar Problems
Sample a Recent Self-Play Replay BatchEasyScore a Terminal Position with Tromp-Taylor RulesMediumEncode AlphaGo Zero Board HistoryMediumFind a Go Group and Its LibertiesEasyApply a Go Action with Captures and RepetitionHardBuild the Legal Go Action MaskHardCanonicalize Pairwise Preference DataMediumApply One Policy-Value Head Training StepHardExperience Replay BufferEasyTile and DiffMediumBox Encode and DecodeMediumDrop DuplicatesMedium

Accepts: array

Accepts: array

Accepts: number

Accepts: number

You must run your code first.

Apply a Dihedral Go Symmetry

Reinforcement LearningData Processing
Medium

Augment one Go training record with a symmetry of its square board. Transform IDs 0, 1, 2, and 3 mean counterclockwise rotations of 0, 90, 180, and 270 degrees. IDs 4 through 7 mean a left-right reflection followed by those same rotations.

state_planes is a NumPy array of shape (C, n, n), where C is the plane count and n is the board size. policy is a floating-point NumPy array of length n squared plus one: board entries in row-major order, followed by pass. Its nonnegative weights need not sum to one; do not normalize them. Apply the same symmetry to every plane and the board entries, leaving pass and value unchanged.

Return a three-item tuple: the transformed state array, transformed policy array, and unchanged scalar value. Both arrays must retain their input shapes and dtypes and use newly allocated storage.

Loading visualization...

Examples

Input: state_planes=[[[1, 2], [3, 4]]], policy=[0.1, 0.2, 0.3, 0.4, 0.5], value=0.25, transform_id=1

Output: ([[[2, 4], [1, 3]]], [0.2, 0.4, 0.1, 0.3, 0.5], 0.25)

Explanation: The state and board-action probabilities receive the same 90 degree counterclockwise rotation, while the pass entry remains last.

Input: state_planes=[[[1, 2], [3, 4]]], policy=[0.1, 0.2, 0.3, 0.4, 0.5], value=-0.5, transform_id=4

Output: ([[[2, 1], [4, 3]]], [0.2, 0.1, 0.4, 0.3, 0.5], -0.5)

Input: state_planes=[[[7]]], policy=[0.6, 0.4], value=1.0, transform_id=7

Output: ([[[7]]], [0.6, 0.4], 1.0)

Hint 1

np.rot90 accepts axes=(-2, -1) to rotate every plane together.

Hint 2

np.flip with axis=-1 reflects the board from left to right.

Hint 3

Array.copy prevents transformed views from sharing the input storage.

Requirements

  • Use NumPy and preserve each input array's dtype.
  • Leave all input values unchanged.
  • Returned arrays must not share storage with either input array.

Constraints

  • state_planes has shape (C, n, n), with nonnegative C and positive n.
  • policy is a finite, nonnegative floating-point array of shape (n squared plus one,).
  • value is a finite numeric scalar.
  • transform_id is an integer from 0 through 7.
Try Similar Problems
Sample a Recent Self-Play Replay BatchEasyScore a Terminal Position with Tromp-Taylor RulesMediumEncode AlphaGo Zero Board HistoryMediumFind a Go Group and Its LibertiesEasyApply a Go Action with Captures and RepetitionHardBuild the Legal Go Action MaskHardCanonicalize Pairwise Preference DataMediumApply One Policy-Value Head Training StepHardExperience Replay BufferEasyTile and DiffMediumBox Encode and DecodeMediumDrop DuplicatesMedium

Accepts: array

Accepts: array

Accepts: number

Accepts: number

You must run your code first.