mixle.inference.reproduce module

Reproducibility receipts – record a fit so it can be replayed and checked bit-for-bit (N2).

A fitted model is only trustworthy if someone else can re-derive it. record_fit() captures the minimal recipe – a fingerprint of the training data, the seed, the estimator, and a fingerprint of the fitted parameters – into a ReproReceipt. verify_reproducible() refits from that recipe and confirms the parameters come out identical: replay-based reproducibility, the same discipline the certificate applies to how a model was estimated, applied to whether the exact fit can be recovered.

Fingerprints are canonical: data and parameters are serialized with floats rounded to a fixed precision before hashing, so last-bit platform noise doesn’t make an otherwise-identical fit look different, while any real change to the data or the fitted parameters flips the hash. A model is fingerprinted through its own to_json (its complete state), so this works for any serializable mixle distribution.

data_fingerprint(data, *, ndigits=_NDIGITS)[source]

A stable hash of a training dataset (order-sensitive; floats rounded) – identifies the exact input.

Parameters:
Return type:

str

param_fingerprint(model, *, ndigits=_NDIGITS)[source]

A stable hash of a fitted model’s parameters, via its to_json state (floats rounded).

Parameters:
Return type:

str

class ReproReceipt(data_fingerprint, n, seed, estimator, param_fingerprint)[source]

Bases: object

The recipe to re-derive a fit: data + seed + estimator, plus the parameter fingerprint to check.

Parameters:
  • data_fingerprint (str)

  • n (int)

  • seed (int)

  • estimator (str)

  • param_fingerprint (str)

data_fingerprint: str
n: int
seed: int
estimator: str
param_fingerprint: str
as_dict()[source]
Return type:

dict[str, Any]

matches_data(data)[source]

Whether data is the exact dataset this fit was recorded on.

Parameters:

data (Any)

Return type:

bool

matches_model(model)[source]

Whether model has the exact parameters this receipt fingerprinted.

Parameters:

model (Any)

Return type:

bool

record_fit(model, data, *, seed, estimator=None)[source]

Record a ReproReceipt for a model fitted on data with seed (see module docstring).

Parameters:
Return type:

ReproReceipt

verify_reproducible(estimator, data, receipt, *, seed=None, max_its=25)[source]

Refit estimator on data and check the fit reproduces receipt (data + parameters).

Returns {reproducible, data_matches, params_match, refit_fingerprint}. reproducible is True iff BOTH the data fingerprint and the refit’s parameter fingerprint match the receipt – i.e. the exact fit can be recovered from the recorded recipe. seed defaults to the receipt’s seed.

Parameters:
  • estimator (Any)

  • data (Any)

  • receipt (ReproReceipt)

  • seed (int | None)

  • max_its (int)

Return type:

dict[str, Any]