kups.core.utils.random
¶
Random sampling utilities.
sample_like(sampler, key, tree)
¶
Generate random arrays matching the structure and shapes of a PyTree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampler
|
Sampler
|
Function |
required |
key
|
Key
|
JAX PRNG key (split internally for each leaf). |
required |
tree
|
PyTree
|
Template PyTree; each leaf's shape and dtype are matched. |
required |
Returns:
| Type | Description |
|---|---|
PyTree
|
PyTree with the same structure as |
Example
Source code in src/kups/core/utils/random.py
segment_chi_squared(key, segment, dof, slots_per_row=3)
¶
Per-segment χ²(dof) samples, exact and without loops.
Draws slots_per_row standard normals per row and sums the squares of the
first dof[s] slots of segment s. jax.random.chisquare samples by
rejection in data-dependent while loops, a host round trip per iteration on GPU.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Key
|
PRNG key. |
required |
segment
|
Index[Any]
|
Segment of each row. |
required |
dof
|
Array
|
Degrees of freedom per segment, at most |
required |
slots_per_row
|
int
|
Normals per row (3 for momenta). |
3
|
Returns:
| Type | Description |
|---|---|
Array
|
One sample per segment, shape |