mixle.stats.compute.gradient moduleΒΆ
Gradient-fitting state objects owned by distribution-layer hooks.
- exception GradientFitError[source]
Bases:
NotImplementedErrorRaised when generic gradient fitting cannot handle a model family.
- prior_zero(torch, engine, ref=None)[source]
Return a scalar zero on the active Torch/device context.
- prior_family(prior)[source]
Return the normalized prior family name, if
prioris mapping-like.
- prior_sequence(values, n)[source]
Pad or truncate a sequence of child priors to length
n.- Parameters:
n (int)
- composite_child_priors(priors, n)[source]
Return child priors for a composite-style product distribution.
- Parameters:
n (int)
- conditional_priors(priors, keys)[source]
Return per-condition, default, and given priors for conditional models.
- record_child_priors(priors, fields, n)[source]
Return field-aligned child priors for a named record model.
- Parameters:
n (int)
- transform_prior(priors)[source]
Return the base-child prior for a transform wrapper.
- select_child_priors(priors, n)[source]
Return choice-child priors for a select/routed model.
- Parameters:
n (int)
- mixture_priors(priors, n)[source]
Return component priors plus an optional weight prior for mixtures.
- Parameters:
n (int)
- sequence_priors(priors)[source]
Return element and length priors for an iid sequence model.
- markov_chain_priors(priors, row_keys)[source]
Return initial, transition-row, and length priors for Markov chains.
- dirichlet_alpha_tensor(alpha, labels, logits, engine, torch)[source]
Broadcast Dirichlet concentration values to a logits tensor.
- normal_gamma_log_prior(mu, sigma2, priors, torch)[source]
Return a Normal-Gamma log prior over a Gaussian-style mean/variance.
- class CategoricalGradientFitState(template, labels, logits)[source]
Bases:
objectAutograd state for finite categorical simplex maps.
- Parameters:
template (Any)
labels (Sequence[Any])
logits (Any)
- shadow(torch, shadow_child)[source]
Build a temporary distribution object backed by live Torch logits.
- score(enc, engine, torch, score_child)[source]
Score encoded categorical observations through the shadow object.
- build(torch, build_child, detach_value)[source]
Reconstruct a fitted categorical distribution from optimized logits.
- class OptionalGradientFitState(template, child, logit_p)[source]
Bases:
objectAutograd state for optional/missing-value wrappers.
- Parameters:
template (Any)
child (Any)
logit_p (Any)
- shadow(torch, shadow_child)[source]
Build a temporary optional wrapper backed by live child/raw p state.
- score(enc, engine, torch, score_child)[source]
Score encoded optional observations, including missing values.
- build(torch, build_child, detach_value)[source]
Reconstruct a fitted optional distribution from optimized state.
- class CompositeGradientFitState(template, children)[source]
Bases:
objectAutograd state for product distributions over tuple-like observations.
- Parameters:
template (Any)
children (Sequence[Any])
- shadow(torch, shadow_child)[source]
Build a temporary composite with live child shadows.
- score(enc, engine, torch, score_child)[source]
Return summed child log densities for encoded tuple fields.
- build(torch, build_child, detach_value)[source]
Reconstruct a fitted composite from fitted children.
- class ConditionalGradientFitState(template, dmap, default_child, given_child)[source]
Bases:
objectAutograd state for conditional keyed children.
- Parameters:
template (Any)
dmap (Mapping[Any, Any])
default_child (Any)
given_child (Any)
- shadow(torch, shadow_child)[source]
Build a temporary conditional model with live child shadows.
- score(enc, engine, torch, score_child)[source]
Score grouped conditional encodings by condition key.
- build(torch, build_child, detach_value)[source]
Reconstruct a fitted conditional distribution from children.
- class RecordGradientFitState(template, children)[source]
Bases:
CompositeGradientFitStateAutograd state for named record distributions.
- Parameters:
template (Any)
children (Sequence[Any])
- score(enc, engine, torch, score_child)[source]
Score named-record encodings using product-distribution logic.
- build(torch, build_child, detach_value)[source]
Reconstruct a fitted record distribution preserving field sources.
- class SelectGradientFitState(template, children)[source]
Bases:
CompositeGradientFitStateAutograd state for choice-routed child distributions.
- Parameters:
template (Any)
children (Sequence[Any])
- score(enc, engine, torch, score_child)[source]
Score each routed subset with the selected child model.
- build(torch, build_child, detach_value)[source]
Reconstruct a fitted select distribution preserving the router.
- class TransformGradientFitState(template, child)[source]
Bases:
objectAutograd state for fixed transforms with differentiable children.
- Parameters:
template (Any)
child (Any)
- shadow(torch, shadow_child)[source]
Build a temporary transform wrapper with a live base child.
- score(enc, engine, torch, score_child)[source]
Score transformed encodings with optional Jacobian correction.
- build(torch, build_child, detach_value)[source]
Reconstruct a transform wrapper around the fitted base child.
- class SequenceGradientFitState(template, child, len_child)[source]
Bases:
objectAutograd state for iid sequence distributions.
- Parameters:
template (Any)
child (Any)
len_child (Any)
- shadow(torch, shadow_child)[source]
Build a temporary sequence model with live element/length children.
- score(enc, engine, torch, score_child)[source]
Score flattened sequence elements plus optional length model.
- build(torch, build_child, detach_value)[source]
Reconstruct a fitted sequence distribution from child fits.
- class MixtureGradientFitState(template, components, w_logits)[source]
Bases:
objectAutograd state for mixture components and simplex weights.
- Parameters:
template (Any)
components (Sequence[Any])
w_logits (Any)
- shadow(torch, shadow_child)[source]
Build a temporary mixture backed by live component/weight tensors.
- score(enc, engine, torch, score_child)[source]
Return mixture log densities via log-sum-exp over components.
- build(torch, build_child, detach_value)[source]
Reconstruct a fitted mixture from optimized components and weights.