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 an immutable registered identity rather than passed as a raw callable. Every identity pins a name, version, output dimension, and code/schema digest in the serialized leaf. Duplicate registration cannot silently replace an artifact’s semantics.
- class FeatureIdentity(name, version, feature_dim, digest)[source]
Bases:
objectImmutable identity of a deterministic raw-item feature transform.
- register_feature_fn(name, fn, *, version, feature_dim)[source]
Register one immutable, versioned raw-item feature transform.
Repeating the exact registration is idempotent. Reusing
(name, version)for different code or output schema raises; callers must publish a new version instead.
- feature_fn(name, *, version=None, digest=None, feature_dim=None)[source]
Resolve a feature function and optionally verify its complete pinned identity.
- class FeatureMapDensity(feature_name, inner, name=None, *, feature_version=None, feature_digest=None, feature_dim=None)[source]
Bases:
SequenceEncodableProbabilityDistributionp(feature_fn(x))for a registered, deterministicfeature_fnand inner distribution.- Parameters:
- 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]
Raw-item sampling is undefined because the feature map has no inverse.
- Parameters:
seed (int | None)
- Return type:
DistributionSampler
- feature_sampler(seed=None)[source]
Return the sampler of the explicitly separate inner feature-space distribution.
- Parameters:
seed (int | None)
- Return type:
DistributionSampler
- 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 FeatureMapEncoder(feature_name, *, feature_version=None, feature_digest=None, feature_dim=None)[source]
Bases:
DataSequenceEncoderEncode raw items by applying a registered deterministic feature function.
- Parameters:
- class FeatureMapAccumulator(identity, inner_acc)[source]
Bases:
SequenceEncodableStatisticAccumulatorDelegate accumulation to the inner estimator after feature extraction.
- Parameters:
identity (FeatureIdentity)
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(identity, inner_factory)[source]
Bases:
StatisticAccumulatorFactoryFactory for feature-map accumulators wrapping an inner accumulator factory.
- Parameters:
identity (FeatureIdentity)
inner_factory (Any)
- make()[source]
Create a fresh feature-map accumulator.
- Return type:
FeatureMapAccumulator
- class FeatureMapEstimator(feature_name, inner, name=None, *, feature_version=None, feature_digest=None, feature_dim=None)[source]
Bases:
ParameterEstimatorFits
inneronfeature_fn(x)for raw itemsx– the estimator side ofFeatureMapDensity.- Parameters:
- accumulator_factory()[source]
Return an accumulator factory that feature-maps raw inputs before inner accumulation.
- Return type:
FeatureMapAccumulatorFactory