xxxxxxxxxx
38
//NOTE: The intent of this sketch is to test if I can get the
//ml-levenberg-marquardt library to run in the browser.
//Here's the library's home:
//https://github.com/mljs/levenberg-marquardt
//Here it is on npmjs:
//https://www.npmjs.com/package/ml-levenberg-marquardt
/**** TEST CODE ****/
//The test code below is a simplified version of the test code provided
//in the library documentation.
// function that receives the parameters and returns
// a function with the independent variable as a parameter
function f([a]) {
return (t) => a * t ** 2;
}
// array of points to fit
let data = {
x: [-1, 0, 1],
y: [3, 0, 3]
};
// array of initial parameter values
let initialParams = [1];
let options = {
initialValues: initialParams,
};
let fittedParams = levenbergMarquardt(data, f, options);
//expected approximate value of fitted parameter is 3,
//since f(t) = 3t^2 would fit the data exactly.
console.log(fittedParams);