Open the console to test curve fitting with web workers!
The following is the set up, this has already been done for you!
/* This has already been defined */
var X = [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]];
var y1 = [1.12, 7.78, 27.09, 63.83, 124.93, 215.86, 343.22, 511.86, 729.06, 1000.19];
var y2 = [4.86, 19.14, 57.18, 131.12, 252.92, 435.2, 688.79, 1027.15, 1461.02, 2003.1];
The following is the minimum contents of simpleCubic.json
Actual parameters set (all possible) can be seen at: https://github.com/adussaq/amd_cf/blob/gh-pages/simpleCubic.jseo
{
func: function (xVector, P) {
return P[0] * Math.pow(xVector[0],3) + P[1];
},
setInitial: function (x_mat, y_vec) {
// For other data, this must be made more intelligent
var A = ( y_vec[1] - y_vec[0] ) / (Math.pow(x_mat[1][0], 3) - Math.pow(x_mat[0][0], 3));
var B = y_vec[0] - A * Math.pow(x_mat[0][0], 3);
return [A, B];
}
}
Copy and paste this into your console to run this functions.
//Grab you equation object
var eq_obj = amd_cf.getEquation('simpleCubic.jseo');
//This can be done to insure the equation was properly downloaded,
//But is not neccisarry (error message will be generated with
//or without this line)
eq_obj.catch(function (err) {
console.error('Something is wrong with the equation:', err);
});
/* Set up your data */
var data1 = {
x_values: X,
y_values: y1
};
var data2 = {
x_values: X,
y_values: y2,
fit_params: { // These are optional and will overwrite the func_fit_params found in the .jseo file
checkItt: 3,
maxItt: 100
}
};
//Fits the data asynchronously
eq_obj.fit(data1).then(function(res) {
console.log('Done With 1', res);
}).catch(function(err) {
console.error('1 did not work:', err);
});
//Fits the data asynchronously
eq_obj.fit(data2).then(function(res) {
console.log('Done With 2', res);
}).catch(function(err) {
console.error('1 did not work:', err);
});;
// If a lot of fits are called, this will be called once all fitting is completed
eq_obj.all().then(function(resArr) {
//Note when used like this any fits that failed return undefined rather than an error
console.log('Done With All!', resArr);
});