-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
89 lines (82 loc) · 2.96 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<html>
<head>
<!-- Note that the below script loads:
'workersPackage.js'
'fitCurves.js'
'jquery-2.1.4.min.js'
ES6 Promise if they do not already exist
In no particular order.
-->
<script src="amd_core-1.0.1.min.js"></script>
<script>
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];
</script>
</head>
<body>
<h2>Open the console to test curve fitting with web workers!</h2>
<b>The following is the set up, this has already been done for you!</b>
<pre style="margin-left: 25px; margin-top: -10px;"><code>
/* 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];
</code></pre>
<b>The following is the minimum contents of simpleCubic.json</b> <br />Actual parameters set (all possible) can be seen at: <a href="https://github.com/adussaq/amd_cf/blob/gh-pages/simpleCubic.jseo">https://github.com/adussaq/amd_cf/blob/gh-pages/simpleCubic.jseo</a>
<pre style="margin-left: 25px; margin-top: -10px;"><code>
{
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];
}
}
</code></pre>
<b>Copy and paste this into your console to run this functions.</b>
<pre style="margin-left: 25px; margin-top: -10px;"><code>
//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);
});
</code></pre>
</body>
</html>