Neutral Political Machine
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

ml-levenberg-marquardt

1.0.3 • Public • Published

levenberg-marquardt

NPM version build status Test coverage David deps npm download

Curve fitting method in javascript

Installation

$ npm install ml-levenberg-marquardt

API Documentation

This algorithm is based on the article Brown, Kenneth M., and J. E. Dennis. "Derivative free analogues of the Levenberg-Marquardt and Gauss algorithms for nonlinear least squares approximation." Numerische Mathematik 18.4 (1971): 289-297.

In order to get a general idea of the problem you could also check the Wikipedia article.

Example

// import library
import LM from 'ml-levenberg-marquardt';
// const LM = require('ml-levenberg-marquardt').default;
 
// function that receives the parameters and returns
// a function with the independent variable as a parameter
function sinFunction([a, b]) {
  return (t) => a * Math.sin(* t);
}
 
// array of points to fit
let data = {
  x: [
    /* x1, x2, ... */
  ],
  y: [
    /* y1, y2, ... */
  ]
};
 
// array of initial parameter values
let initialValues = [
  /* a, b, c, ... */
];
 
const options = {
  damping: 1.5,
  initialValues: initialValues,
  gradientDifference: 10e-2,
  maxIterations: 100,
  errorTolerance: 10e-3
};
 
let fittedParams = LM(data, sinFunction, options);

Or test it in Runkit

License

MIT

install

npm i ml-levenberg-marquardt

Downloadsweekly downloads

308

version

1.0.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar