gam_models/binomial_multi.rs
1//! Penalized multi-output binomial-logit fitter at fixed λ.
2//!
3//! This is the row-diagonal sibling of [`crate::multinomial`]: the
4//! same shared design `X ∈ ℝ^{N×P}` and shared penalty `S ∈ ℝ^{P×P}` are
5//! reused across `K` independent binomial-logit response columns. Per-column
6//! smoothing parameters `λ_a` (length `K`) scale `S` independently for each
7//! response. Because the Fisher information has no cross-column coupling
8//! (`H_{n,a,b} = δ_{ab} · w_n · μ_{n,a} (1 − μ_{n,a})`), the joint penalized
9//! Hessian is block-diagonal in the `K` `P × P` per-response systems; the
10//! shared [`crate::penalized_vector_glm`] engine factors that
11//! block-diagonal Hessian in a single coupled damped-Newton loop, which is
12//! mathematically identical to `K` independent per-column solves.
13//!
14//! # Fit problem
15//!
16//! Minimise the penalized negative log-likelihood
17//!
18//! ```text
19//! F(β) = − Σ_n Σ_a w_n [ y_{n,a} log μ_{n,a} + (1 − y_{n,a}) log(1 − μ_{n,a}) ]
20//! + ½ Σ_a λ_a · β_aᵀ S β_a
21//! ```
22//!
23//! with `μ_{n,a} = σ(η_{n,a})`, `η_{n,a} = (X β_a)_n`. The per-column Newton
24//! step solves
25//!
26//! ```text
27//! (Xᵀ diag(w_n μ_{n,a}(1 − μ_{n,a})) X + λ_a S) δ_a = − [Xᵀ diag(w_n)(μ_{·,a} − y_{·,a}) + λ_a S β_a]
28//! ```
29//!
30//! followed by a backtracking line search on `F` (full step first, halve up
31//! to 8 times) so monotone descent is enforced even when the quadratic
32//! model overshoots near saturation. This is precisely the shared
33//! [`crate::penalized_vector_glm`] scaffold; this module supplies
34//! only the row-diagonal binomial Fisher block, residual, and log-likelihood
35//! via [`BinomialMultiLikelihood`].
36//!
37//! # Relation to the multi-class softmax driver
38//!
39//! [`crate::multinomial::fit_penalized_multinomial`] handles the
40//! coupled softmax Fisher block `H_{n,a,b} = w_n μ_{n,a} (δ_{ab} − μ_{n,b})`
41//! and is the right entry when the user wants a single normalized
42//! probability vector per row. This driver is the right entry when the
43//! user has `K` independent binary marginals sharing a smooth basis (e.g.
44//! multi-label classification, multi-trait penalised logistic regression
45//! on a Duchon latent design). Both families are thin Fisher-block adapters
46//! over the same `penalized_vector_glm` engine: the only difference is that
47//! the softmax block is dense across outputs while these binomial columns are
48//! row-diagonal.
49//!
50//! The function-boundary contract mirrors `fit_penalized_multinomial` so
51//! the two are interchangeable at the FFI layer: same input arity, same
52//! convergence semantics, same `(N, K)` fitted-probability output.
53
54use crate::model_types::EstimationError;
55use crate::penalized_vector_glm::{
56 PenalizedVectorGlmInputs, VectorGlmSolve, fit_penalized_vector_glm,
57};
58use crate::vector_response::VectorLikelihood;
59use gam_problem::FixedLambdaSolverStage;
60use ndarray::{Array1, Array2, Array3, ArrayView1, ArrayView2, ArrayView3};
61
62/// Inputs for [`fit_penalized_binomial_multi`].
63#[derive(Debug, Clone)]
64pub struct BinomialMultiFitInputs<'a> {
65 /// Design matrix `X ∈ ℝ^{N×P}` (one row per observation, shared across
66 /// all response columns).
67 pub design: ArrayView2<'a, f64>,
68 /// Multi-column binomial response `Y ∈ ℝ^{N×K}`. Each column is treated
69 /// as an independent binomial-logit response, so every entry must be a
70 /// binomial proportion in `[0, 1]` (hard `{0, 1}` Bernoulli labels and soft
71 /// proportions / probabilities alike). Entries outside `[0, 1]` are
72 /// rejected because the per-entry log-likelihood is then unbounded in `η`.
73 pub y: ArrayView2<'a, f64>,
74 /// Shared smoothing penalty `S ∈ ℝ^{P×P}` (symmetric, PSD).
75 pub penalty: ArrayView2<'a, f64>,
76 /// Per-response smoothing parameter `λ_a` (length `K`).
77 pub lambdas: ArrayView1<'a, f64>,
78 /// Optional per-row weights (length `N`); `None` ⇒ uniform 1.0.
79 pub row_weights: Option<ArrayView1<'a, f64>>,
80 /// Optional per-row Fisher-block override, shape `(N, K, K)`. The `K`
81 /// binomial-logit columns are fit independently, so only the per-column
82 /// diagonal `[n, a, a]` is consumed as the curvature `w_n μ_a(1 − μ_a)`;
83 /// off-diagonals must be zero (enforced at the FFI boundary) since a
84 /// non-zero cross term cannot be represented by the separable per-column
85 /// solve. The gradient/residual path stays analytic — this is a
86 /// curvature-only override (issue #349). Diagonal entries must be finite
87 /// and non-negative.
88 pub fisher_w_override: Option<ArrayView3<'a, f64>>,
89 /// Maximum Newton iterations per response column; recommend 50.
90 pub max_iter: usize,
91 /// Relative-step convergence tolerance; recommend 1e-7.
92 pub tol: f64,
93}
94
95/// Outputs of [`fit_penalized_binomial_multi`].
96#[derive(Debug, Clone)]
97pub struct BinomialMultiFitOutputs {
98 /// Coefficient matrix, shape `(P, K)` (column `a` is `β_a`).
99 pub coefficients: Array2<f64>,
100 /// Fitted probabilities `μ_{n,a} = σ((X β_a)_n)`, shape `(N, K)`.
101 pub fitted_probabilities: Array2<f64>,
102 /// Number of joint Newton iterations executed (including the final step
103 /// that satisfied the tolerance). The `K` columns share the design and
104 /// are fitted by a single coupled damped-Newton loop over the
105 /// block-diagonal penalized Hessian, so there is one iteration count for
106 /// the whole solve.
107 pub iterations: usize,
108 /// Penalized negative log-likelihood at the returned `β̂`:
109 /// `−log L(β̂) + ½ Σ_a λ_a · β̂_aᵀ S β̂_a`.
110 pub penalized_neg_log_likelihood: f64,
111 /// Unpenalized deviance `−2 log L(β̂)` for diagnostic reporting.
112 pub deviance: f64,
113}
114
115/// Numerically stable logistic CDF used by the Newton driver. Mirrors the
116/// inline helper that previously lived in `crates/gam-pyffi/src/lib.rs`.
117#[inline]
118fn sigmoid_stable(eta: f64) -> f64 {
119 if eta >= 0.0 {
120 let e = (-eta).exp();
121 1.0 / (1.0 + e)
122 } else {
123 let e = eta.exp();
124 e / (1.0 + e)
125 }
126}
127
128/// Row-diagonal multi-output binomial-logit likelihood adapter for the shared
129/// [`crate::penalized_vector_glm`] engine.
130///
131/// The `K` response columns are mutually independent binomial-logit marginals
132/// sharing the design `X`, so the per-row Fisher block is **diagonal across
133/// outputs**: `H_{n,a,b} = δ_{ab} · w_n · μ_{n,a} (1 − μ_{n,a})`. The engine
134/// works in `η = X β` space with `μ_{n,a} = σ(η_{n,a})`; this adapter supplies
135/// the log-likelihood, the residual gradient `w_n (y_a − μ_a)`, and that
136/// row-diagonal block.
137struct BinomialMultiLikelihood {
138 /// Optional per-row weights (length N), or `None` for uniform 1.0.
139 row_weights: Option<Array1<f64>>,
140}
141
142impl BinomialMultiLikelihood {
143 #[inline]
144 fn row_weight(&self, n: usize) -> f64 {
145 self.row_weights.as_ref().map_or(1.0, |w| w[n])
146 }
147}
148
149impl VectorLikelihood for BinomialMultiLikelihood {
150 /// `Σ_n Σ_a w_n [ y_{n,a} log μ_{n,a} + (1 − y_{n,a}) log(1 − μ_{n,a}) ]`,
151 /// evaluated in log-space via `log μ = −softplus(−η)`,
152 /// `log(1 − μ) = −softplus(η)` — exact and finite for every η, with no
153 /// probability clamp. The former `μ.clamp(1e-12, 1−1e-12)` made this value
154 /// FLAT beyond |η| ≈ 27.6 while [`Self::grad_eta`]/[`Self::hess_diag`]
155 /// kept reporting the unclamped derivatives, so the line search scored a
156 /// surface the Newton direction was not the derivative of: on a
157 /// misclassified saturated row the gradient pushed full-strength while
158 /// the objective registered no improvement. The softplus form keeps the
159 /// true slope (≈ |η| per unit) at any saturation, so value, gradient, and
160 /// curvature are exact surfaces of ONE function.
161 fn log_lik(&self, eta: ArrayView2<'_, f64>, y: ArrayView2<'_, f64>) -> f64 {
162 let (n, k) = eta.dim();
163 let mut acc = 0.0_f64;
164 for row in 0..n {
165 let w = self.row_weight(row);
166 for a in 0..k {
167 let e = eta[[row, a]];
168 let yv = y[[row, a]];
169 acc -= w
170 * (yv * gam_linalg::utils::stable_softplus(-e)
171 + (1.0 - yv) * gam_linalg::utils::stable_softplus(e));
172 }
173 }
174 acc
175 }
176
177 /// `∂ log L / ∂η_{n,a} = w_n (y_{n,a} − μ_{n,a})`.
178 fn grad_eta(&self, eta: ArrayView2<'_, f64>, y: ArrayView2<'_, f64>) -> Array2<f64> {
179 let (n, k) = eta.dim();
180 let mut out = Array2::<f64>::zeros((n, k));
181 for row in 0..n {
182 let w = self.row_weight(row);
183 for a in 0..k {
184 let mu = sigmoid_stable(eta[[row, a]]);
185 out[[row, a]] = w * (y[[row, a]] - mu);
186 }
187 }
188 out
189 }
190
191 /// Per-output diagonal curvature `w_n μ_{n,a} (1 − μ_{n,a})`. The Fisher
192 /// information of independent Bernoulli outputs is `y`-independent; `y` is
193 /// read only to assert the target shape matches `eta`, as in the sibling
194 /// [`VectorLikelihood`] implementations.
195 fn hess_diag(&self, eta: ArrayView2<'_, f64>, y: ArrayView2<'_, f64>) -> Array2<f64> {
196 assert_eq!(eta.dim(), y.dim(), "y must match eta shape (N, K)");
197 let (n, k) = eta.dim();
198 let mut out = Array2::<f64>::zeros((n, k));
199 for row in 0..n {
200 let w = self.row_weight(row);
201 for a in 0..k {
202 let mu = sigmoid_stable(eta[[row, a]]);
203 out[[row, a]] = w * mu * (1.0 - mu);
204 }
205 }
206 out
207 }
208
209 /// Row-diagonal Fisher block `H_{n,a,b} = δ_{ab} · w_n μ_{n,a}(1 − μ_{n,a})`.
210 /// The independent columns have no cross-output coupling, so the off-diagonal
211 /// entries are identically zero; lifting [`Self::hess_diag`] onto the per-row
212 /// diagonal (the [`VectorLikelihood`] default) is exact here.
213 fn hess_block(&self, eta: ArrayView2<'_, f64>, y: ArrayView2<'_, f64>) -> Array3<f64> {
214 let diag = self.hess_diag(eta, y);
215 let (n, k) = diag.dim();
216 let mut out = Array3::<f64>::zeros((n, k, k));
217 for row in 0..n {
218 for a in 0..k {
219 out[[row, a, a]] = diag[[row, a]];
220 }
221 }
222 out
223 }
224}
225
226/// Fit `K` independent penalized binomial-logit GLMs sharing the design `X`
227/// and penalty `S`. See the module docs for the optimization problem.
228pub fn fit_penalized_binomial_multi(
229 inputs: BinomialMultiFitInputs<'_>,
230) -> Result<BinomialMultiFitOutputs, EstimationError> {
231 let BinomialMultiFitInputs {
232 design,
233 y,
234 penalty,
235 lambdas,
236 row_weights,
237 fisher_w_override,
238 max_iter,
239 tol,
240 } = inputs;
241
242 // ──────────────────────── family-specific validation ───────────────────
243 // The engine re-validates the shared geometry (nonempty design, penalty
244 // shape, λ finiteness/non-negativity, override `(N, M, M)` shape, finite
245 // design), but the binomial family owns three preconditions the generic
246 // scaffold cannot know: the response must be a `[0, 1]` proportion, the
247 // optional row weights must be finite and non-negative, and the optional
248 // curvature override must be **row-diagonal** (independent columns carry no
249 // cross-output coupling, so a non-zero off-diagonal cannot be represented).
250 let n_obs = design.nrows();
251 let (y_rows, k) = y.dim();
252 if y_rows != n_obs {
253 crate::bail_invalid_estim!(
254 "fit_penalized_binomial_multi: y rows {y_rows} ≠ design rows {n_obs}"
255 );
256 }
257 if k == 0 {
258 crate::bail_invalid_estim!(
259 "fit_penalized_binomial_multi: y must have at least one column (got K=0)"
260 );
261 }
262 if lambdas.len() != k {
263 crate::bail_invalid_estim!(
264 "fit_penalized_binomial_multi: lambdas length {} ≠ K = {k}",
265 lambdas.len()
266 );
267 }
268 if let Some(fw) = fisher_w_override.as_ref() {
269 if fw.dim() != (n_obs, k, k) {
270 crate::bail_invalid_estim!(
271 "fit_penalized_binomial_multi: fisher_w_override shape {:?} ≠ (N, K, K) = ({n_obs}, {k}, {k})",
272 fw.dim()
273 );
274 }
275 // Independent binomial columns have a strictly row-diagonal Fisher
276 // block; a non-zero cross term `[n, a, b]` (a ≠ b) cannot be the
277 // curvature of a separable per-column objective, so reject it rather
278 // than silently couple the columns through the shared dense solve.
279 for ((n_idx, a, b), &v) in fw.indexed_iter() {
280 if a != b && v != 0.0 {
281 crate::bail_invalid_estim!(
282 "fit_penalized_binomial_multi: fisher_w_override[{n_idx},{a},{b}] must be zero \
283 (independent columns have a row-diagonal Fisher block); got {v}"
284 );
285 }
286 }
287 }
288 if let Some(w) = row_weights.as_ref() {
289 if w.len() != n_obs {
290 crate::bail_invalid_estim!(
291 "fit_penalized_binomial_multi: row_weights length {} ≠ N = {n_obs}",
292 w.len()
293 );
294 }
295 for (i, &v) in w.iter().enumerate() {
296 if !(v.is_finite() && v >= 0.0) {
297 crate::bail_invalid_estim!(
298 "fit_penalized_binomial_multi: row_weights[{i}] must be finite and ≥ 0 (got {v})"
299 );
300 }
301 }
302 }
303 for ((i, j), &v) in y.indexed_iter() {
304 // The per-entry objective y log μ + (1 − y) log(1 − μ) is the binomial
305 // (Bernoulli / proportion) log-likelihood only when 0 ≤ y ≤ 1. Outside
306 // that range it is unbounded above in η (e.g. y = 2 gives
307 // 2η − log(1 + e^η) → ∞), so a finite-but-invalid entry would make the
308 // stated likelihood not a binomial likelihood at all. Reject it here.
309 if !(v.is_finite() && (0.0..=1.0).contains(&v)) {
310 crate::bail_invalid_estim!(
311 "fit_penalized_binomial_multi: y[{i},{j}] must be a binomial proportion in [0,1] (got {v})"
312 );
313 }
314 }
315
316 // ─────────────────── shared penalized vector-GLM solve ─────────────────
317 let likelihood = BinomialMultiLikelihood {
318 row_weights: row_weights.map(|w| w.to_owned()),
319 };
320 let solve = fit_penalized_vector_glm(
321 PenalizedVectorGlmInputs {
322 design,
323 y,
324 penalty,
325 lambdas,
326 fisher_w_override,
327 max_iter,
328 tol,
329 // Independent-binomial columns ARE genuinely independent outputs, so
330 // the per-output Diagonal penalty is correct here (the #1587 Centered
331 // metric is softmax-specific — there is no shared reference class).
332 class_penalty_metric: crate::penalized_vector_glm::ClassPenaltyMetric::Diagonal,
333 resume_from: None,
334 },
335 &likelihood,
336 "fit_penalized_binomial_multi",
337 )?;
338
339 let fit = match solve {
340 VectorGlmSolve::Converged(fit) => fit,
341 VectorGlmSolve::Stalled(stall) => {
342 // SPEC: a fit object must only ever come from a converged
343 // optimization. Exhausting `max_iter` is a typed error carrying
344 // evidence from the checkpoint, never an `Ok` with a flag.
345 return Err(stall.into_nonconvergence_error(
346 FixedLambdaSolverStage::BinomialMultiNewton,
347 "fit_penalized_binomial_multi (fixed-λ vector-GLM damped Newton)",
348 )?);
349 }
350 };
351
352 // η → μ = σ(η) is the binomial inverse link applied column-wise.
353 let fitted = fit.eta.mapv(sigmoid_stable);
354
355 Ok(BinomialMultiFitOutputs {
356 coefficients: fit.coefficients,
357 fitted_probabilities: fitted,
358 iterations: fit.iterations,
359 penalized_neg_log_likelihood: -fit.log_likelihood + fit.penalty_term,
360 deviance: -2.0 * fit.log_likelihood,
361 })
362}
363
364#[cfg(test)]
365mod tests {
366 use super::*;
367 use ndarray::Array3;
368
369 fn toy_inputs() -> (Array2<f64>, Array2<f64>, Array2<f64>, Array1<f64>) {
370 let n = 12;
371 let p = 2;
372 let k = 2;
373 let design =
374 Array2::<f64>::from_shape_fn(
375 (n, p),
376 |(i, j)| {
377 if j == 0 { 1.0 } else { ((i + 1) as f64).sin() }
378 },
379 );
380 let y =
381 Array2::<f64>::from_shape_fn((n, k), |(i, a)| if (i + a) % 2 == 0 { 1.0 } else { 0.0 });
382 let penalty = Array2::<f64>::eye(p);
383 let lambdas = Array1::<f64>::from_elem(k, 0.5);
384 (design, y, penalty, lambdas)
385 }
386
387 #[test]
388 fn fisher_override_none_reproduces_analytic_bit_for_bit() {
389 // Issue #349: a None override must give exactly the analytic result.
390 let (design, y, penalty, lambdas) = toy_inputs();
391 let base = fit_penalized_binomial_multi(BinomialMultiFitInputs {
392 design: design.view(),
393 y: y.view(),
394 penalty: penalty.view(),
395 lambdas: lambdas.view(),
396 row_weights: None,
397 fisher_w_override: None,
398 max_iter: 50,
399 tol: 1.0e-9,
400 })
401 .expect("analytic fit must succeed");
402 // Explicit None again — identical result.
403 let again = fit_penalized_binomial_multi(BinomialMultiFitInputs {
404 design: design.view(),
405 y: y.view(),
406 penalty: penalty.view(),
407 lambdas: lambdas.view(),
408 row_weights: None,
409 fisher_w_override: None,
410 max_iter: 50,
411 tol: 1.0e-9,
412 })
413 .expect("analytic fit must succeed");
414 for (a, b) in base.coefficients.iter().zip(again.coefficients.iter()) {
415 assert_eq!(a, b, "None override must be deterministic");
416 }
417 }
418
419 #[test]
420 fn exhausted_fixed_lambda_budget_is_typed_error_not_fit() {
421 let (design, y, penalty, lambdas) = toy_inputs();
422 let error = fit_penalized_binomial_multi(BinomialMultiFitInputs {
423 design: design.view(),
424 y: y.view(),
425 penalty: penalty.view(),
426 lambdas: lambdas.view(),
427 row_weights: None,
428 fisher_w_override: None,
429 max_iter: 0,
430 tol: 1.0e-9,
431 })
432 .expect_err("a zero-budget Newton solve must not mint a binomial fit");
433 assert!(matches!(
434 error,
435 EstimationError::FixedLambdaNewtonDidNotConverge {
436 objective_value,
437 checkpoint,
438 ..
439 } if objective_value.is_finite()
440 && checkpoint.stage() == FixedLambdaSolverStage::BinomialMultiNewton
441 && checkpoint.completed_iterations() == 0
442 ));
443 }
444
445 #[test]
446 fn out_of_range_response_is_rejected() {
447 // Issue #452: a finite but invalid entry (y = 2) makes the per-entry
448 // binomial log-likelihood unbounded in η, so it must be rejected rather
449 // than silently fit. The same guard covers negative entries.
450 let (design, y, penalty, lambdas) = toy_inputs();
451 let mut bad = y.clone();
452 bad[[0, 0]] = 2.0;
453 let err = fit_penalized_binomial_multi(BinomialMultiFitInputs {
454 design: design.view(),
455 y: bad.view(),
456 penalty: penalty.view(),
457 lambdas: lambdas.view(),
458 row_weights: None,
459 fisher_w_override: None,
460 max_iter: 50,
461 tol: 1.0e-9,
462 })
463 .expect_err("out-of-range response must error");
464 assert!(format!("{err}").contains("binomial proportion in [0,1]"));
465
466 let mut neg = y.clone();
467 neg[[1, 1]] = -0.5;
468 let err = fit_penalized_binomial_multi(BinomialMultiFitInputs {
469 design: design.view(),
470 y: neg.view(),
471 penalty: penalty.view(),
472 lambdas: lambdas.view(),
473 row_weights: None,
474 fisher_w_override: None,
475 max_iter: 50,
476 tol: 1.0e-9,
477 })
478 .expect_err("negative response must error");
479 assert!(format!("{err}").contains("binomial proportion in [0,1]"));
480 }
481
482 #[test]
483 fn fisher_override_shape_mismatch_is_rejected() {
484 let (design, y, penalty, lambdas) = toy_inputs();
485 let n = design.nrows();
486 let k = y.ncols();
487 let bad = Array3::<f64>::zeros((n, k + 1, k + 1));
488 let err = fit_penalized_binomial_multi(BinomialMultiFitInputs {
489 design: design.view(),
490 y: y.view(),
491 penalty: penalty.view(),
492 lambdas: lambdas.view(),
493 row_weights: None,
494 fisher_w_override: Some(bad.view()),
495 max_iter: 50,
496 tol: 1.0e-9,
497 })
498 .expect_err("mismatched override shape must error");
499 assert!(format!("{err}").contains("fisher_w_override shape"));
500 }
501
502 #[test]
503 fn fisher_override_replaces_curvature_diagonal() {
504 // A scaled curvature override changes the Newton step from β = 0:
505 // with curvature scaled by α the first step is 1/α of the analytic
506 // step (gradient unchanged), so the fitted β must differ from analytic.
507 let (design, y, penalty, lambdas) = toy_inputs();
508 let n = design.nrows();
509 let k = y.ncols();
510 // Analytic diagonal at β = 0 is μ(1−μ) = 0.25 for every column.
511 let mut over = Array3::<f64>::zeros((n, k, k));
512 for row in 0..n {
513 for a in 0..k {
514 over[[row, a, a]] = 0.25 * 4.0; // 4× the analytic curvature
515 }
516 }
517 let likelihood = BinomialMultiLikelihood { row_weights: None };
518 let scaled = fit_penalized_vector_glm(
519 PenalizedVectorGlmInputs {
520 design: design.view(),
521 y: y.view(),
522 penalty: penalty.view(),
523 lambdas: lambdas.view(),
524 fisher_w_override: Some(over.view()),
525 max_iter: 1,
526 tol: 1.0e-9,
527 class_penalty_metric: crate::penalized_vector_glm::ClassPenaltyMetric::Diagonal,
528 resume_from: None,
529 },
530 &likelihood,
531 "binomial scaled-curvature first-step test",
532 )
533 .expect("scaled-curvature engine step must be finite");
534 let analytic = fit_penalized_vector_glm(
535 PenalizedVectorGlmInputs {
536 design: design.view(),
537 y: y.view(),
538 penalty: penalty.view(),
539 lambdas: lambdas.view(),
540 fisher_w_override: None,
541 max_iter: 1,
542 tol: 1.0e-9,
543 class_penalty_metric: crate::penalized_vector_glm::ClassPenaltyMetric::Diagonal,
544 resume_from: None,
545 },
546 &likelihood,
547 "binomial analytic-curvature first-step test",
548 )
549 .expect("analytic-curvature engine step must be finite");
550 let checkpoint_coefficients = |solve| match solve {
551 VectorGlmSolve::Converged(fit) => fit.coefficients,
552 VectorGlmSolve::Stalled(stall) => stall.coefficients,
553 };
554 let scaled = checkpoint_coefficients(scaled);
555 let analytic = checkpoint_coefficients(analytic);
556 let differs = scaled
557 .iter()
558 .zip(analytic.iter())
559 .any(|(a, b)| (a - b).abs() > 1.0e-6);
560 assert!(differs, "scaled curvature override must change the step");
561 }
562}