mixle.models.feature_map module¶
Frozen deterministic feature maps composed with inner densities.
A deterministic, non-invertible feature function (for example
mixle.represent.modality.image_features()) reduces a raw item – an image array, a signal, any
shape a plain scalar/vector family cannot represent – to a fixed-length vector, and an inner
distribution/estimator (any five-piece mixle family, including a neural density) is fit on the
induced feature-space distribution.
Stated plainly: this is a genuine, well-defined density over the feature representation, not a claim
about the density of the raw item – there is no Jacobian correction because the map is not invertible.
Anywhere this leaf is chosen, the reasoning is recorded so that distinction stays visible (see
mixle.utils.automatic’s modality routing).
Feature functions are looked up by a registered name, not passed as a raw callable, so the leaf
serializes: the same closed-registry pattern mixle.models.neural_density uses for its hoisted
nn.Module classes. Register a feature function once (register_feature_fn); the leaf then
carries only the name.
- register_feature_fn(name, fn)[source]
Register
fn(raw item -> fixed-length vector) undernameso a leaf can carry just the name.
- feature_fn(name)[source]
Look up a registered feature function by name; raises if it was never registered.
- class FeatureMapDensity(feature_name, inner, name=None)[source]
Bases:
SequenceEncodableProbabilityDistributionp(feature_fn(x))for a registered, deterministicfeature_fnand inner distribution.- density(x)[source]
Return the induced feature-space density at raw item
x.
- log_density(x)[source]
Return
log p(feature_fn(x))under the inner distribution.
- seq_log_density(x)[source]
Return inner log densities for an already-featurized batch.
- sampler(seed=None)[source]
Return a sampler for the inner feature-space distribution.
- Parameters:
seed (int | None)
- Return type:
FeatureMapSampler
- estimator(pseudo_count=None)[source]
Return an estimator that fits the inner estimator on registered features.
- Parameters:
pseudo_count (float | None)
- Return type:
FeatureMapEstimator
- dist_to_encoder()[source]
Return the encoder that maps raw items to feature vectors.
- Return type:
FeatureMapEncoder
- class FeatureMapSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSampler for the feature-space distribution induced by a feature-map leaf.
- Parameters:
dist (FeatureMapDensity)
seed (int | None)
- class FeatureMapEncoder(feature_name)[source]
Bases:
DataSequenceEncoderEncode raw items by applying a registered deterministic feature function.
- Parameters:
feature_name (str)
- class FeatureMapAccumulator(feature_name, inner_acc)[source]
Bases:
SequenceEncodableStatisticAccumulatorDelegate accumulation to the inner estimator after feature extraction.
- Parameters:
feature_name (str)
inner_acc (Any)
- update(x, weight, estimate)[source]
Feature-map one raw item and add it to the inner accumulator.
- seq_update(enc, weights, estimate)[source]
Pass an already-featurized batch through to the inner accumulator.
- initialize(x, weight, rng)[source]
Initialize the inner accumulator from one feature-mapped item.
- seq_initialize(enc, weights, rng)[source]
Initialize the inner accumulator from an encoded feature batch.
- combine(other)[source]
Merge sufficient statistics into the inner accumulator.
- Parameters:
other (Any)
- Return type:
FeatureMapAccumulator
- from_value(v)[source]
Restore the inner accumulator from its value representation.
- Parameters:
v (Any)
- Return type:
FeatureMapAccumulator
- acc_to_encoder()[source]
Return the feature-map encoder expected by this accumulator.
- Return type:
FeatureMapEncoder
- class FeatureMapAccumulatorFactory(feature_name, inner_factory)[source]
Bases:
StatisticAccumulatorFactoryFactory for feature-map accumulators wrapping an inner accumulator factory.
- Parameters:
feature_name (str)
inner_factory (Any)
- make()[source]
Create a fresh feature-map accumulator.
- Return type:
FeatureMapAccumulator
- class FeatureMapEstimator(feature_name, inner, name=None)[source]
Bases:
ParameterEstimatorFits
inneronfeature_fn(x)for raw itemsx– the estimator side ofFeatureMapDensity.- accumulator_factory()[source]
Return an accumulator factory that feature-maps raw inputs before inner accumulation.
- Return type:
FeatureMapAccumulatorFactory