use numra_core::Scalar;
#[derive(Clone, Debug)]
pub struct FitResult<S: Scalar> {
pub params: Vec<S>,
pub covariance: Option<Vec<S>>,
pub std_errors: Option<Vec<S>>,
pub residuals: Vec<S>,
pub chi_squared: S,
pub reduced_chi_squared: S,
pub r_squared: S,
pub dof: usize,
pub n_evaluations: usize,
pub converged: bool,
}
#[derive(Clone, Debug)]
pub struct FitOptions<S: Scalar> {
pub max_iter: usize,
pub ftol: S,
pub gtol: S,
pub xtol: S,
}
impl<S: Scalar> Default for FitOptions<S> {
fn default() -> Self {
Self {
max_iter: 200,
ftol: S::from_f64(1e-12),
gtol: S::from_f64(1e-10),
xtol: S::from_f64(1e-10),
}
}
}
impl<S: Scalar> FitOptions<S> {
pub fn max_iter(mut self, n: usize) -> Self {
self.max_iter = n;
self
}
pub fn ftol(mut self, v: S) -> Self {
self.ftol = v;
self
}
pub fn gtol(mut self, v: S) -> Self {
self.gtol = v;
self
}
pub fn xtol(mut self, v: S) -> Self {
self.xtol = v;
self
}
}