Guide

Getting started

Install the package, fit a small distribution, and see how the same API extends to task models and structured latent models.

Packagemixle
Python3.10+
Base depsNumPy, SciPy, mpmath
Extrasoptional by backend

Installation

Install from PyPI.

Start with the base package. Install extras only when you need acceleration, task learning, data connectors, or distributed execution.

Baselocal distributions and estimators
All extrasengines, data, tasks, distributed backends
Developeditable checkout for examples and docs
pip install mixle

Base installs every distribution and local estimation path.

First fit

Fit a two-component Gaussian mixture.

Define a prototype distribution and pass it to optimize. The fitted object keeps the same distribution interface for density evaluation, sampling, and inspection.

1Describe the family shape.
2Fit with optimize.
3Score, sample, inspect, or save the result.

Minimal mixture example

from mixle.inference import *
from mixle.stats import *

data = [-1.2, -0.9, -1.1, 0.8, 1.2, 1.1]

model = optimize(data, MixtureDistribution(
    [
        GaussianDistribution(-1.0, 1.0),
        GaussianDistribution(1.0, 1.0),
    ],
    [0.5, 0.5],
))

model.log_density(0.0)
model.sampler().sample(size=3)

Task model

Use an LLM as the teacher for a local model.

The task layer treats an LLM, human, or rule as a teacher. Active distillation spends a limited label budget, then a calibrated cascade answers locally when the student is confident. The endpoint shown below can be any OpenAI-compatible local or hosted model.

LLM teacher and active labeling

from mixle.task import *

# pool = ["free prize today", ...]
# calibration = ["cheap loan offer", ...]
# requests = ["winner click now", ...]
teacher = llm_labeler(
    OpenAICompatLLM(
        "http://localhost:11434/v1",
        "llama3.1",
    ),
    ["spam", "ham"],
)

cascade = Cascade(
    CalibratedTaskModel(
        active_distill(
            teacher,
            pool,
            budget=60,
        ).model,
    ).calibrate(calibration, teacher(calibration)),
    teacher,
    cost=CostModel(c_frontier=0.01),
)
cascade.serve(requests)
cascade.report()

Heterogeneous latent model

from mixle.inference import *
from mixle.stats import *

# data is a list of numeric sequences:
# data[:2] == [
#     [-1.2, -0.9, -1.0, 0.8, 1.1],
#     [1.0, 1.3, 0.9, -0.8, -1.1],
# ]

fit = optimize(data, HiddenMarkovEstimator([
    GaussianEstimator(),
    GaussianEstimator(),
]))

fit.log_density(data[0])
Open the examples page