mixle.inference.refine module¶
Diagnosis-directed correction compared with blind structure search.
If diagnosis-directed correction does not reach the same held-out target in
fewer trials than blind structure search (learn_bayesian_network run with no
diagnosis, over growing prefixes of data) on the planted-fault benchmark, keep
blind search as the baseline.
Only the add_edge fix is translated to a concrete structural edit here, because that is the only fix mixle.inference.explain.diagnose actually detects today (upgrade_leaf/split_region/add_factor are recognized vocabulary with no detector wired yet – see that module’s docstring). A FaultReport naming any other fix is reported as “not actionable,” never guessed at.
- held_out_log_likelihood(model, data)[source]
Total log-density of a fitted network (or anything exposing
dist_to_encoder/seq_log_density) over held-outdata– the metric both paths below are compared on.
- apply_add_edge_fix(model, fault, data)[source]
Apply only the fix
diagnoseactually named: add a linear-Gaussian edge between the two fields infault.dominant(parsed from its"field[i]|...field[j]|..."shape), refit that one factor ondata, and return the corrected network – every other factor is left untouched.Returns
None(never guesses) whenfault.suggested_fixis not"add_edge", ordominantdoes not name exactly two fields (nothing dominant, or a shape this translation doesn’t understand).
- class TrialsToTarget(n_trials, final_model, history=<factory>)[source]
Bases:
objectHow many trials a path needed to reach its target (
None= never reached), plus its score history.
- directed_correction(model, cases, data, held_out, *, background=None)[source]
One diagnosis, one targeted edit, one verification.
Costs exactly 1 trial if
diagnosenames an actionable fix and it verifiably improves held-out score over the original model; costs 0 (unreached) if the fix isn’t actionable or doesn’t verify – a correction that does not improve held-out is a failed diagnosis, logged as such, never silently kept anyway.
- blind_search_trials_to_target(data, held_out, target_score, *, round_size=10, max_rounds=20, max_parents=1, seed=0)[source]
The blind baseline: NO diagnosis. Re-run
learn_bayesian_networkfrom scratch on growing prefixes ofdata(round_sizemore examples each round, shuffled once up front) until the discovered structure’s held-out score reachestarget_score(typicallydirected_correction()’s own held-out score) ormax_roundsis exhausted.