pub fn fit<const N: usize, P>(
    problem: &P,
    params: &mut [f64; N],
    params_config: [ParamConfig; N],
    config: Config,
) -> Result<Status<N>>
where
    P: Problem<N>,
{
    let mut fit = Fit::new(problem, params, config)?;
    fit.check_config()?;
    fit.parse_params(params_config)?;
    fit.init_lm()?;
    loop {
        fit.fill_xnew();
        fit.fdjac2()?;
        fit.check_limits();
        fit.qrfac();
        fit.scale();
        fit.transpose();
        if !fit.check_is_finite() {
            return Err(Error::Nan);
        }
        let gnorm = fit.gnorm();
        if gnorm <= config.gtol {
            fit.info = Success::Dir;
        }
        if fit.info != Success::NotDone {
            return fit.terminate(&params_config);
        }
        if config.max_iter == 0 {
            fit.info = Success::MaxIter;
            return fit.terminate(&params_config);
        }
        fit.rescale();
        loop {
            fit.lmpar();
            let res = fit.iterate(gnorm)?;
            match res {
                MPDone::Exit => return fit.terminate(&params_config),
                MPDone::Inner => continue,
                MPDone::Outer => break,
            }
        }
    }
}
/// Main function to refine the parameters.
/// # Arguments
/// * `problem` - A user defind struct implementing the [`Problem`] trait
/// * `params` - A mutable array with starting fit parameters
/// * `params_config` - An array with parameter configurations
/// * `config` - [`Config`] to configure the fit
Main function to refine the parameters.
Main function to refine the parameters .
pub fn fit<const N: usize, P>(
    problem: &P,
    params: &mut [f64; N],
    params_config: [ParamConfig; N],
    config: Config,
) -> Result<Status<N>>
where
    P: Problem<N>,
{
    let mut fit = Fit::new(problem, params, config)?;
    fit.check_config()?;
    fit.parse_params(params_config)?;
    fit.init_lm()?;
    loop {
        fit.fill_xnew();
        fit.fdjac2()?;
        fit.check_limits();
        fit.qrfac();
        fit.scale();
        fit.transpose();
        if !fit.check_is_finite() {
            return Err(Error::Nan);
        }
        let gnorm = fit.gnorm();
        if gnorm <= config.gtol {
            fit.info = Success::Dir;
        }
        if fit.info != Success::NotDone {
            return fit.terminate(&params_config);
        }
        if config.max_iter == 0 {
            fit.info = Success::MaxIter;
            return fit.terminate(&params_config);
        }
        fit.rescale();
        loop {
            fit.lmpar();
            let res = fit.iterate(gnorm)?;
            match res {
                MPDone::Exit => return fit.terminate(&params_config),
                MPDone::Inner => continue,
                MPDone::Outer => break,
            }
        }
    }
}
pub fn fit < const N : usize , P > ( problem : & P , params : & mut [ f64 ; N ] , params_config : [ ParamConfig ; N ] , config : Config , ) -> Result < Status < N > > where P : Problem < N > , { let mut fit = Fit :: new ( problem , params , config ) ? ; fit . check_config ( ) ? ; fit . parse_params ( params_config ) ? ; fit . init_lm ( ) ? ; loop { fit . fill_xnew ( ) ; fit . fdjac2 ( ) ? ; fit . check_limits ( ) ; fit . qrfac ( ) ; fit . scale ( ) ; fit . transpose ( ) ; if ! fit . check_is_finite ( ) { return Err ( Error :: Nan ) ; } let gnorm = fit . gnorm ( ) ; if gnorm <= config . gtol { fit . info = Success :: Dir ; } if fit . info != Success :: NotDone { return fit . terminate ( & params_config ) ; } if config . max_iter == 0 { fit . info = Success :: MaxIter ; return fit . terminate ( & params_config ) ; } fit . rescale ( ) ; loop { fit . lmpar ( ) ; let res = fit . iterate ( gnorm ) ? ; match res { MPDone :: Exit => return fit . terminate ( & params_config ) , MPDone :: Inner => continue , MPDone :: Outer => break , } } } }
Main function to refine the parameters.
Main function to refine the parameters .
problem
&P
params
&mut [f64; N]
params_config
[ParamConfig; N]
config
Config
problem
&P
params
&mut [f64; N]
params_config
[ParamConfig; N]
config
Config