PositionSplitManager#
- class liesel.optim.PositionSplitManager(splits, *, passthrough=<factory>)[source]#
Bases:
objectCoordinates multiple
PositionSplitobjects as one split interface.PositionSplitManageris the split-side counterpart toBatchManager. It is useful when a model has observed branches with different axis sizes. Each childPositionSplitstores the split data for one branch, while the manager exposes mergedtrain,validate, andtestpositions.- Parameters:
splits (
Sequence[PositionSplit]) – Non-empty sequence ofPositionSplitobjects. TheirPositionSplit.position_keysmust not overlap. Either all children must contain validation data or none may contain validation data; the same rule applies to test data.passthrough (
Position(dict[str,Any]), default:<factory>) – Keyword-only shared position entries included unchanged in the manager’s mergedtrain,validate, andtestpositions. They are not split or batched automatically. Use this for shared lookup tables or constants, not per-observation data.
- Raises:
ValueError – If
splitsis empty, if position keys overlap, or if validation/test availability differs across children.
Notes
Branch-specific sizes are available as
axis_sizes,train_axis_sizes,validate_axis_sizes, andtest_axis_sizes. Branch-specific likelihood sizes are available assample_sizes,train_sample_sizes,validate_sample_sizes, andtest_sample_sizes. Scalar aliases such astrain_axis_size,validate_axis_share, andvalidate_sample_scaleare available only when all children have the same value. Usesample_size()for the total likelihood sample size of a split part across all branches.Examples
Merge two branches with different axis sizes:
>>> import jax.numpy as jnp >>> from liesel.optim import PositionSplitManager, Split >>> position = {"x": jnp.arange(10), "y": jnp.arange(6)} >>> split_x = Split( ... ["x"], axis_size=10, validate_axis_size=2, shuffle=False ... ).split_position(position) >>> split_y = Split( ... ["y"], axis_size=6, validate_axis_size=1, shuffle=False ... ).split_position(position) >>> manager = PositionSplitManager([split_x, split_y]) >>> manager.position_keys ['x', 'y'] >>> manager.train_axis_sizes (8, 5) >>> manager.train["x"].shape, manager.train["y"].shape ((8,), (5,))
Unequal scalar aliases raise and direct users to the plural property:
>>> try: ... manager.train_axis_size ... except ValueError as error: ... print("train_axis_sizes" in str(error)) True
Build a manager directly from a model with two observation sizes:
>>> import liesel.model as lsl >>> y1 = lsl.Var.new_obs(jnp.arange(10.0), name="y1") >>> y2 = lsl.Var.new_obs(jnp.arange(6.0), name="y2") >>> model = lsl.Model([y1, y2]) >>> managed = PositionSplitManager.from_model( ... model, ... position_keys=[["y1"], ["y2"]], ... validate_axis_share=0.2, ... shuffle=True, ... seed=42, ... ) >>> managed.validate_axis_sizes (2, 1)
Methods
from_model(model[, position_keys, ...])Builds grouped position splits from a model.
sample_scale(part)Common sample scale, available only when all branches agree.
sample_scales(part)Sample scaling factors for each contained split.
sample_size(part)Total effective likelihood sample size for one split part.
scaled_log_lik(model, model_state[, part])Returns the log likelihood with branch-specific split scaling.
Attributes
Common total axis size, available only when all branches agree.
Total axis sizes for each contained split.
Whether all child splits contain test data.
Whether all child splits contain validation data.
Position keys claimed by all contained split objects.
Raw effective sample-size mappings for each contained split.
Position keys that are partitioned rather than passed through.
Merged test position.
Common test share, available only when all branches agree.
Test shares for each contained split.
Common test axis size, available only when all branches agree.
Test axis sizes for each contained split.
Common test sample size, available only when all branches agree.
Test sample sizes for each contained split.
Merged training position.
Common training axis size, available only when all branches agree.
Training axis sizes for each contained split.
Common training sample size, available only when all branches agree.
Training sample sizes for each contained split.
Merged validation position.
Common validation share, available only when all branches agree.
Validation shares for each contained split.
Common validation axis size, available only when all branches agree.
Validation axis sizes for each contained split.
Common validation likelihood scale.
Validation likelihood scales for each contained split.
Common validation sample size, available only when all branches agree.
Validation sample sizes for each contained split.
Non-empty sequence of
PositionSplitobjects.Keyword-only shared position entries included unchanged in the manager's merged
train,validate, andtestpositions.