#ifndef LMMIN_FIT_H
#define LMMIN_FIT_H
// begin_html
// Curve fitting with Levenburg-Marquardt minimization.
//
Up: Index
//
// end_html
#include "qubfast.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*lmmin_CurveFunc)(void *obj, double *params, float *ff);
typedef int (*lmmin_IterFunc)(void *obj, double *params, int iter);
QUBFAST_API int qub_lmmin_fit(lmmin_CurveFunc curve, int Nparam, double *params, double *lo, double *hi, int *can_fit,
int Ndata, float *yy, float *ww, lmmin_IterFunc on_iter, callbk_reportfun on_report, void *obj,
int max_iter, double toler, float *ff, double *ssr);
/*
Finds param values which minimize the sum-squared residual between curve and yy data;
optionally weighted by multiplying the residuals by ww.
@param curve: void curve(void *obj, double *params, float *ff)
evaluates curve at params into ff
@param Nparam: number of curve params
@param params: starting/final value of params
@param lo: low bound on params, or UNSET_VALUE
@param hi: high bound on params, or UNSET_VALUE
@param can_fit: nonzero if param should be fit
@param Ndata: number of data points
@param yy: data y values
@param ww: data weights to multiply by residuals (1.0 for even weighting)
@param on_iter: int on_iter(void *obj, double *params, float *ff)
returns zero to stop immediately
@param on_report: int on_report(const char *msg, void *obj)
@param obj: for callback functions
@param max_iter: max iterations
@param toler: stop when it gets this close
@param ff: output array for fit samples
@param ssr: pointer to output sum-squared-residual
@returns: number of iterations
*/
#ifdef __cplusplus
}
#endif
#endif