Files
zeekay 026ac25fcf hanzo-learn: fitting is a transformation, a model is a value, predicting is a query
A crate whose whole interface is two verbs. `Config` holds hyperparameters and has no
`predict`. `Fit` maps `Config -> Data -> Model`. `Model` is immutable, has private fields
and no public constructor, so an unfitted model is not a state to be checked for — it is
a value that cannot be spoken, and `check_is_fitted` has no job to do. `Predict::Answer`
is `f64` for a regressor and `Class` for a classifier: the two do not unify, so a
regressor and a classifier are different types rather than one type with a mode flag.
There is no `get_params`, no `BaseEstimator`, no clone protocol and no `Pipeline` — those
exist in Python because a config and a fitted model are the same object there.

Every fitted model is named by `Address`, a content address over its shape, its
hyperparameters and its learned parameters, hashing floats as IEEE-754 bits and
length-prefixing every sequence so the encoding is injective. Same construction and same
reasoning as the risk plane's published model values, so a fit can be stored, cited by a
decision, compared against a challenger and rolled back to without a registry.

Three estimators: least squares by Householder QR on centred data (QR not the normal
equations, which square the condition number; centring not a ones column, so the
intercept never enters the factorisation), binary logistic regression by Newton steps on
a strictly convex penalised objective, and gradient boosted CART regression trees.

A TREE READS FEATURES AT IEEE-754 BINARY32, and that is the algorithm rather than a
detail. scikit-learn casts X to float32 before its splitter sees it, XGBoost and LightGBM
do the same, and ai.onnx.ml's TreeEnsembleRegressor stores nodes_values as floats. A tree
never does arithmetic on a feature value — it only orders values and places thresholds
between them — so precision decides only which side of a boundary a sample falls on.
Placing the threshold at single(a)/2 + single(b)/2 instead of a/2 + b/2 moves it by 2e-8,
which is enough to send a sample down the other branch. Measured over the 40 depth-1
trees of the stumps fixture, whose roots all see the full sample set: the single-precision
midpoint reproduces scikit-learn's threshold bit-for-bit 40 times out of 40, the
double-precision midpoint 0 times out of 40.

Correctness is asserted against scikit-learn itself. Fixtures generated by 1.9.0 are
committed and read as data, so `cargo test` needs no Python and the oracle's version is a
recorded fact. 195 boosted trees / 1,977 split nodes agree node for node — split feature,
threshold and both children all exact — with leaf values to 1.3e-15 and predictions to
8.9e-16 against a 1e-10 bound; least squares agrees to 1.1e-15 against 1e-10 and logistic
to 1.2e-8 against 1e-7, with hard labels exact. Each tolerance is derived from the
mathematics and every assertion prints the deviation it observed, so a regression that
stays inside a bound is still visible. The generator refuses to record an oracle that is
not a function of its data: at scikit-learn's default min_samples_leaf a tree's structure
varies with random_state (20 structures over 40 seeds, prediction spread 3.9), so every
case pins the tie away and proves determinism over 12 seeds before writing a number. This
crate breaks split ties by lowest feature index instead, because a content address over a
model an RNG helped choose would name one draw rather than one fit.

The exhaustive split search is not lowered to hanzo-kernel, and the obstacle is specific:
a launch geometry must be stated before the launch, and across all 69 launch sites in
that crate Grid::Static is the only variant used, every geometry computed on the host from
a count it already knows. A CART node's sample count is not such a number. The histogram
formulation dissolves this — bin count is a hyperparameter, so the per-level geometry is
host-knowable — but it quantises thresholds and so cannot hold the node-for-node bar. It
is named, not built.

scikit-learn is a test oracle only. No code or docstring is taken from it, and NOTICE
records that, along with the obligation to add BSD-3 attribution if that ever changes.

The crate also carries, unchanged and unclaimed, the anomaly-detection and preprocessing
modules written concurrently on another track (isolation, neighbour, transform, scale,
impute, encode, metric, moment, split, twister, plus benches and the perf oracle). They
share lib.rs and tests/sklearn.rs with the estimator seam, so the crate cannot be
committed in halves. Their `Transform` and `Outlier` traits extend this seam without
changing `Fit` or `Predict`. One of their fixture tests,
`the_imbalanced_metrics_match_scikit_learn`, is red on a fixture key that measure.json
does not yet carry — which is why this is a branch and not main.
2026-08-04 17:03:22 -07:00

95 lines
3.6 KiB
JSON

{
"cases": {
"encode": {
"label_codes/100k_x_20": 0.01056627498473972,
"label_codes/10k_x_20": 0.0011004190309904516,
"label_codes/1m_x_20": 0.14454302500234917,
"label_fit/100k_x_20": 0.007774859026540071,
"label_fit/10k_x_20": 0.0008825070108287036,
"label_fit/1m_x_20": 0.0924407999846153,
"onehot_apply/100k_x_20": 0.03537072002654895,
"onehot_apply/10k_x_20": 0.002277905005030334,
"onehot_apply/1m_x_20": 0.4145732690230943
},
"impute": {
"apply/100k_x_20": 0.006432119989767671,
"apply/10k_x_20": 0.0005997279658913612,
"apply/1m_x_20": 0.11708059901138768,
"mean_fit/100k_x_20": 0.008052168996073306,
"mean_fit/10k_x_20": 0.0008144199964590371,
"mean_fit/1m_x_20": 0.15118607395561412,
"median_fit/100k_x_20": 0.07420819898834452,
"median_fit/10k_x_20": 0.004077056946698576,
"median_fit/1m_x_20": 1.3447457519941963
},
"isolation": {
"fit_100_trees/100k_x_20": 0.08138395397691056,
"fit_100_trees/10k_x_20": 0.05108210502658039,
"fit_100_trees/1m_x_20": 0.21957056899555027,
"fit_100_trees_njobs-1/100k_x_20": 0.10407102800672874,
"fit_100_trees_njobs-1/10k_x_20": 0.07757636602036655,
"fit_100_trees_njobs-1/1m_x_20": 0.21426053903996944,
"outlier/100k_x_20": 0.2921833400032483,
"outlier/10k_x_20": 0.03543389798142016,
"outlier/1m_x_20": 2.82248100603465
},
"metric": {
"average_precision/100k_x_20": 0.01318009797250852,
"average_precision/10k_x_20": 0.0011855459888465703,
"average_precision/1m_x_20": 0.15703444997780025,
"curve_of/100k_x_20": 0.011235220998059958,
"curve_of/10k_x_20": 0.0009170660050585866,
"curve_of/1m_x_20": 0.13176543300505728,
"log_loss/100k_x_20": 0.008080368977971375,
"log_loss/10k_x_20": 0.0010106429690495133,
"log_loss/1m_x_20": 0.08099480898818001,
"precision_recall/100k_x_20": 0.011015949014108628,
"precision_recall/10k_x_20": 0.0009011559886857867,
"precision_recall/1m_x_20": 0.13052895001601428,
"roc_auc/100k_x_20": 0.01768974994774908,
"roc_auc/10k_x_20": 0.0017699140007607639,
"roc_auc/1m_x_20": 0.19434807798825204
},
"neighbour": {
"fit_k20/20k_x_20": 0.10112037102226168,
"fit_k20/2k_x_20": 0.008448175038211048,
"fit_k20_njobs-1/20k_x_20": 0.08565506699960679,
"fit_k20_njobs-1/2k_x_20": 0.008724655024707317,
"outlier_1k_queries/20k_x_20": 0.008705504995305091,
"outlier_1k_queries/2k_x_20": 0.003699101973325014
},
"scale": {
"range_apply/100k_x_20": 0.0029478189535439014,
"range_apply/10k_x_20": 0.000240070978179574,
"range_apply/1m_x_20": 0.07147024996811524,
"range_fit/100k_x_20": 0.005451856995932758,
"range_fit/10k_x_20": 0.0005757180042564869,
"range_fit/1m_x_20": 0.05361890798667446,
"standard_apply/100k_x_20": 0.00302677700528875,
"standard_apply/10k_x_20": 0.00025024102069437504,
"standard_apply/1m_x_20": 0.06965868803672493,
"standard_fit/100k_x_20": 0.008297249965835363,
"standard_fit/10k_x_20": 0.0008060900145210326,
"standard_fit/1m_x_20": 0.14708380599040538
},
"split": {
"kfold_5/100k_x_20": 0.0036208450328558683,
"kfold_5/10k_x_20": 0.0004158439696766436,
"kfold_5/1m_x_20": 0.04902919998858124,
"stratified_5/100k_x_20": 0.006464549049269408,
"stratified_5/10k_x_20": 0.0009727340075187385,
"stratified_5/1m_x_20": 0.07811353501165286,
"train_test/100k_x_20": 0.0012631929712370038,
"train_test/10k_x_20": 0.00025012000696733594,
"train_test/1m_x_20": 0.014784158964175731
}
},
"oracle": {
"machine": "x86_64",
"numpy": "2.5.1",
"processor": "x86_64",
"python": "3.12.12",
"sklearn": "1.9.0"
},
"repeats": 5
}