mixle.task.design module¶
LLM-designed models: let an LLM propose the mixle structure from data – and make mixle validate it.
The hardcoded auto-estimator (mixle.task.recommend.recommend_model()) is a fine fallback, but the
differentiator is flexibility: an LLM can read a data profile and propose a structure no fixed heuristic encodes
– a mixture here, a heavy-tailed leaf there, a composite of mixed families. The risk with “LLM picks the model”
is hallucination; the answer is grounding. The LLM emits a small, allowlisted JSON spec (no code, no eval);
spec_to_estimator() validates and builds a real mixle estimator; design_model() checks its
shape against the observations, fits it without the holdout, and compares independent held-out density
with a separately fitted heuristic baseline before trusting it.
So the LLM proposes and mixle disposes. design_model(data, llm) returns the chosen estimator,
the accepted spec/source, an acceptance receipt, and structured evidence about a rejected proposal.
- spec_to_estimator(spec)[source]
Build a mixle estimator from an allowlisted spec dict (recursively); raise on anything off the allowlist.
- Specs:
{"family": "<name>"}– a scalar leaf (seeALLOWED_FAMILIES);{"type": "composite", "fields": [spec, ...]}– a tuple record of sub-models;{"type": "mixture", "k": K, "component": spec}– a K-component mixture of the component model.
- data_profile(data, *, max_rows=500)[source]
A compact, family-agnostic description of
datafor the LLM: per-field kind and a few sample values.
- class DesignAcceptanceReceipt(accepted, schema_compatible, n_train, n_holdout, train_mean_log_density, holdout_mean_log_density, baseline_holdout_mean_log_density, holdout_regret, max_holdout_regret, reason)[source]
Bases:
objectIndependent train/holdout evidence for one proposed or fallback estimator.
- class DesignFailureReceipt(stage, error_type, message, proposed_spec, reply_excerpt, acceptance=None)[source]
Bases:
objectStructured evidence retained when an LLM proposal is rejected.
- class DesignedModel(estimator, spec, source, note='', acceptance=None, failure=None)[source]
Bases:
objectChosen estimator, provenance, and independent acceptance/rejection evidence.
- Parameters:
- design_model(data, llm, *, fallback=True, validate_rows=200, holdout_frac=0.25, validation_seed=17, validation_max_its=10, max_holdout_regret=1.0)[source]
Accept an LLM design only on schema-compatible independent predictive evidence.
Roles are fixed once, in this order, and never re-drawn (MXR-080-1891): the deterministic subset is split into train and holdout FIRST; everything that influences the choice of model – the data profile the LLM designs from and the heuristic recommendation used both as the acceptance baseline and as the fallback structure – is derived from train only; the holdout is then read exactly once per candidate, to score it. So the LLM estimator sees only the training part and must produce finite holdout density no more than
max_holdout_regretnats/observation below an independently fitted heuristic estimator. A fallback is returned only after it passes the same fit/holdout validity checks. Rejected proposals remain available inDesignedModel.failure.