mixle.task.refine module

Diagnosis-directed correction versus blind structure search.

diagnose turns failing cases into a FaultReport naming a structural element and a suggested fix. This module compares acting on that diagnosis with blind search over the same edit space. Every candidate edge, whether diagnosed or blindly tried, is refit from the same training data and verified against held-out data before acceptance. A candidate that does not clear the held-out bar is recorded as a failed trial rather than silently kept.

The comparison is intentionally conservative: if diagnosis-directed correction does not reach the held-out target in fewer trials than blind search on the planted-fault benchmark, the recorded result shows that the diagnosis did not justify using the directed refinement path for that case.

fit_independent_baseline(train_data)[source]

Fit an independent network with one marginal Gaussian per field.

Parameters:

train_data (Sequence[tuple])

Return type:

HeterogeneousBayesianNetwork

apply_edge(model, edge, train_data)[source]

Refit the named child factor as a linear-Gaussian conditional.

Every other factor is kept unchanged, so the returned model represents only the proposed edge edit.

Parameters:
Return type:

HeterogeneousBayesianNetwork

class EditTrial(edge, held_out_score, verified)[source]

Bases: object

Held-out result for one proposed graph edit.

Parameters:
class SearchOutcome(trials, found_edge, final_model, history=<factory>)[source]

Bases: object

Final refinement state plus the verified edit-search history.

Parameters:
  • trials (int)

  • found_edge (tuple[int, int] | None)

  • final_model (HeterogeneousBayesianNetwork)

  • history (list[EditTrial])

diagnosis_directed_correction(model, train_data, failing_cases, held_out, *, background=None, target)[source]

Diagnose the fault from failing_cases, apply only its suggested edge (trying both parent-child orientations of the named pair, since diagnose reports an undirected co-anomaly), and verify held-out improvement before accepting – one trial if the diagnosis names the right pair and orientation, honestly more (or a refusal) if it does not.

Parameters:
Return type:

SearchOutcome

blind_structure_search(model, train_data, held_out, edit_space, *, target)[source]

Try candidate edges in order and accept only verified held-out gains.

Parameters:
Return type:

SearchOutcome