Skip to main content

Module reference

Module reference 

Source
Expand description

End-to-end quality comparison against mature, standard statistical tools.

The harness lets a cargo test integration test fit the same data with a trusted reference implementation and assert that gam’s fitted function, coefficients, effective degrees of freedom, predictions, or uncertainty agree with what practitioners already trust. It is deliberately tool-agnostic: a test supplies an arbitrary R or Python body and the harness handles all of the data plumbing and result parsing.

Reference toolchains supported today:

  • R via Rscriptmgcv, gamlss, survival, and any package the body chooses to library().
  • Python via python3scikit-learn, scipy, statsmodels, lifelines, scikit-survival, and anything else importable.

There is no skip path. If the interpreter or a required package is not installed, run_r/run_python fail loudly and the test fails — a missing reference dependency is a real failure, not a silent pass. CI is expected to provision the reference stack. (Only genuine hardware gates, e.g. CUDA, are allowed to skip; that lives in tests/common/gpu_gate.rs, not here.)

Wire protocol (kept dependency-free on purpose — no JSON crate on the R/ Python side): the test body calls emit("key", numeric_vector) for every quantity it wants to return. The harness reads these back as key: v1 v2 v3 ... lines and exposes them as f64 scalars / vectors.

Structs§

Column
A named numeric column handed to the reference body as a data.frame column (R) or a NumPy array df["name"] (Python).
DesignDiagnostics
DmlPartialLinearReference
A Double Machine Learning (DML) reference estimate of the average linear effect θ = E[∂E(Y|D,X)/∂D] of a treatment/dose D on outcome Y after partialling out confounders X, computed by a mature Python DML library (DoubleML’s partially-linear model, with EconML’s LinearDML as fallback).
PenaltyDiagnostics
PredictionFingerprint
QualityDiagnostics
Compact, reusable diagnostics for truth/reference quality tests.
ReferenceResult
Parsed results emitted by a reference-tool body via emit(key, values).

Functions§

design_diagnostics
dml_partial_linear_reference
Fit a partially-linear DML model Y = θ·D + g(X) + ε, D = m(X) + ν with a mature Python DML library and return its orthogonal estimate of θ.
held_out_r2
Out-of-sample coefficient of determination against the held-out mean.
max_abs_diff
Maximum absolute difference between two equal-length vectors.
pad_to
Right-pad a vector with its last value, or 0.0 when empty.
pearson
Pearson correlation between two equal-length vectors.
penalty_diagnostics
prediction_fingerprint
r2
Coefficient of determination against the mean predictor.
r_package_available
Probe whether an R package can actually be loaded (namespace + any native dyn.load) in the reference interpreter, without raising. Returns true only when requireNamespace reports the package is usable.
relative_l2
Relative L2 distance ||a - b|| / max(||b||, eps) — the natural scale-free measure of how closely a fitted function tracks a reference function evaluated on the same grid.
rmse
Root-mean-square difference between two equal-length vectors.
run_python
Run a Python reference body. The columns are exposed as a pandas df (or, when pandas is unavailable, a dict of NumPy arrays). The body calls emit("key", iterable) to return results. Fails the test with captured stderr when Python exits non-zero (missing python3, missing module, or a raised exception).
run_r
Run an R reference body. The columns are exposed as a data.frame named df; the body calls emit("key", numeric_vector) to return results. The harness prepends the df, output path, and emit helper. Fails the test with the captured stderr when R exits non-zero — a broken or unavailable reference run (missing Rscript, missing package, R error) is a hard test failure, never a silent skip.