Errors with m-levenberg in Runkit


I tried estimating parameters a and b through the levenberg optimization plugin in Runkit. Comparing the results with what Excel gave me, there’s much difference: Excel values are 11469 and -29.714 respectively. Any assistance will be appreciated.

const LM = require(‘ml-levenberg-marquardt’);
// Using Levenberg-Marquardt Optimization Method for Linearfit
function LinearFunction ([a,b]) {
return (t) => (a-b*t);
// Loading Raw Interval Transit-Time/Sonic Velocity Data

                    const DELTBL = [];
                    const TVDL = [];
                    const VP = [8333.33,8196,8264,8547,7874,7633,7462];
                    const DELTB = [117,116,115,114,113,112,111];
                    const TVD = [8000,8020,8040,8080,8120,8140,8160];
                    let k=0;
                    while (VP[k]!=undefined || DELTB[k]!=undefined){

                        if (DELTB[k]==undefined && (VP[k+1]>VP[k])){                            
                                DELTBL[k] = Math.pow(10,6)/VP[k];
                                TVDL[k] = TVD[k];   

                    } else if (TVD[k]!=undefined && DELTB[k+1]< DELTB[k]) {

                        //Normal Trendline
                            TVDL[k] =TVD[k];                                

                    let datapointsLin = {
                        x: DELTBL,
                        y: TVDL
                    // array of initial parameter values 
                    let initialValuesLin = [4.4567,10.8168];
                    const optionsLin = {
                      damping: 1.5,
                      initialValues: initialValuesLin,
                      gradientDifference: 10e-2,
                      maxIterations: 100,
                      errorTolerance: 10e-6
                    let fittedParamsLin = LM(datapointsLin, LinearFunction, optionsLin);

                    // Extracting the Interval Transit time gradient
                    const DELTNG = fittedParamsLin.parameterValues[1];


Hi feml,

I believe you’re asking why “ml-levenberg-marquardt” is producing a different result than Excel. This is not a plugin we’ve written, the way RunKit works is by connecting you to every package that exists in the npm registry. I would recommend asking this question on their GitHub: . For future reference, you can find this information on npm: (or our npm pages: ). Let me know if we can do anything else to help!