assert_robust_r_squared

Macro assert_robust_r_squared 

Source
macro_rules! assert_robust_r_squared {
    ($fit:expr $(, msg = $msg:literal $(, $($args:tt),*)?)?) => { ... };
    ($fit:expr, $r2:expr $(, msg = $msg:literal $(, $($args:tt),*)?)?) => { ... };
}
Expand description

Macro for asserting that a fitted curve meets a minimum R² threshold in tests. This is a measure of how well the curve explains how wiggly the data is.

See crate::CurveFit::robust_r_squared for more details.

Will generate a failure plot in <target/test_output> if the assertion fails.

§Syntax

assert_r_squared!(<CurveFit>, <threshold> [, msg = <custom message>])

  • CurveFit: The fitted curve to test.
  • threshold: Minimum acceptable R² value (between 0.0 and 1.0). Defaults to 0.9 if omitted.
  • msg: (optional) Custom message to include on failure, supports formatting arguments.

§Notes

  • Automatically handles test labeling and failure plotting.
  • Panics if the R² is below the threshold, ending the test.

§Example

function!(test(x) = 20.0 + 3.0 x^1 + 2.0 x^2 + 4.0 x^3);
let data = test.solve_range(0.0..=1000.0, 1.0).apply_normal_noise(Strength::Relative(1.5), None);

let fit = ChebyshevFit::new_auto(&data, DegreeBound::Relaxed, &Aic).expect("Failed to create model");
assert_robust_r_squared!(fit, 0.6);