The model function for curve fitting.
The entire dataset, as an array of points.
The initial guess for function parameters, which defaults to an array filled with zeroes.
The number of parameter sets to generate.
The relative standard parameter deviation. This is a number [0.0-1.0] and affects the standard deviation on the first iteration. Every subsequent iteration has a decayed standard deviation until the final iteration.
The set of parameters and error for the best fit.
// Define model function
function f(x: number, a2: number = -0.5, a1: number = 3.9, a0: number = -1.2): number {
return a2 * x ** 2 + a1 * x + a0;
}
// Construct a data set
const data: Datum<number>[] = [0, 2, 4].map(x => ({ x: x, y: f(x) }));
// Compute best-fit summary
const summary = fit(f, data);
Minimize the sum of squared errors to fit a set of data points to a curve with a set of unknown parameters.