Core idea
One model object should do the work.
In many projects the modeling code, scoring code, sampler, serializer, and inspection
tools drift apart. mixle keeps those operations attached to the fitted distribution.
Fit
Use direct estimates, EM, MAP, conjugate updates, or registered routes from the declared model shape.
Use
Call density, sampling, encoding, enumeration, explanation, and persistence on the fitted object.
Extend
Keep task models, companion packages, and specialized solvers outside the core until you need them.
Structured latent model
from mixle.inference import *
from mixle.models import *
from mixle.stats import *
# records is a list of sessions.
# each observation is (tone, token_pair, event_name)
# token_pair is (context_token_ids, next_token_id)
# records[:1] == [[
# (-1.64, ([0, 1, 2, 3], 1), "browse"),
# (0.82, ([4, 5, 6, 7], 7), "checkout"),
# ]]
model = optimize(
records,
HiddenMarkovEstimator([
CompositeEstimator((
MixtureEstimator([
GaussianEstimator(),
GaussianEstimator(),
]),
TransformerLMEstimator(vocab=8),
CategoricalEstimator(),
))
] * 2),
)
model.log_density(records[0])