Skip to content
Jonas Almeida edited this page Dec 13, 2024 · 8 revisions

Multiparametric nonlinear regression in javascript.

The purpose of fminsearch is to provide a simple heuristic for non-linear regression that makes the most of javascript's simple functional style.

Core algorithm

The core algorithm is a variation on the golden rule of speeding changes in the values of the parameters that decrease the objective function (cost function), while reversing and slowing it down otherwiese. Accordingly, the core algorithm only really has two lines

var funParm=function(P){
    return Opt.objFun(y,fun(x,P)) // Objective function will compare y with the predicted fun(x), default to SSD
}
	              // silly multi-univariate screening
for(var j=0;j<n;j++){ // take a step for each parameter, js will otherwise pass by reference
	P1=[...P0]; // clone array
	P1[j]+=step[j];
	if(funParm(P1)<funParm(P0)){ // if parm value going in the righ direction
		step[j]=1.2*step[j]; // go a little faster
		P0=[...P1];
	}
	else{ // if not
		step[j]=-(0.5*step[j]); // reverse and go slower
	}	
} 

Logistic regression

A simple illustrative example could be logistic regression:

function logistic(x,P){
    return x.map(
        xi => 1 / (1 + Math.exp(-(P[0] + (P[1] * xi))))
    )
}

What

fminSearch is an original Matlab-inspired implementation of a steepest stochastic descent algorithm for non-linear regression.