-
Notifications
You must be signed in to change notification settings - Fork 1
/
amd_cf_worker-1.2.1.min.js
15 lines (13 loc) · 3.02 KB
/
amd_cf_worker-1.2.1.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*!
* @overview amd_cf_worker.
* @license Licensed under MIT license
* See https://raw.githubusercontent.com/adussaq/amd_cf/gh-pages/LICENSE
* @version 1.2.1
* @Compressed with: https://closure-compiler.appspot.com/home
*/
(function(){var p,t,u;p=function(){var e,b;e=function(b,g,f,c){var a=0,d,e=g.length;for(d=0;d<e;d+=1)a+=Math.pow(b(g[d],c)-f[d],2);return a};b=function(b){var e,f,c,a;e=f=0;c=b.length;for(a=0;a<c;a+=1)e+=b[a];e/=c;for(a=0;a<c;a+=1)f+=Math.pow(b[a]-e,2);return f};return function(h,g,f,c,a){var d,m,r,k,l;a="object"===typeof a?a:{};a.step=a.step||g.map(function(a){return a/100});a.maxItt=a.maxItt||1E3;a.minPer=a.minPer||1E-6;a.checkItt=Math.floor(a.checkItt)||3;a.converge=a.converge||1.2;a.diverge=a.diverge||
-.5;r=Infinity;l=JSON.parse(JSON.stringify(g));for(m=0;m<a.maxItt;m+=1){for(k in l)l.hasOwnProperty(k)&&(l[k]+=a.step[k],e(h,f,c,l)<e(h,f,c,g)?(g[k]=l[k],a.step[k]*=a.converge):(l[k]=g[k],a.step[k]*=a.diverge));if(0===m%a.checkItt){d=e(h,f,c,g);if(Math.abs(1-d/r)<a.minPer)break;r=d}}d=b(c);k=e(h,f,c,g);d=1-k/d;l=m;m===a.maxItt&&Math.abs(1-k/r)>a.minPer&&(l=0);return{ops:JSON.parse(JSON.stringify(a)),success:l,parameters:g,totalSqrErrors:k,R2:d,WWtest:u(h,f,c,g)}}}();t=function(e){var b,h,g,f,c,a,
d,m;a=eval("equationObj="+e.equation);h=e.x_values;g=[];f=[];c=h.length;d=!0;e.hasOwnProperty("bool")||(d=!1,e.bool=[]);for(b=0;b<c;b+=1)d?e.bool[b]&&(g.push([h[b]]),f.push(e.y_values[b])):(e.bool.push(1),g.push([h[b]]),f.push(e.y_values[b]));b=a.func_fit_params||{};e=e.fit_params||{};for(m in e)e.hasOwnProperty(m)&&(b[m]=e[m]);m=a.setInitial(g,f);b.hasOwnProperty("step")&&("function"===typeof b.step?b.step=b.step(m):delete b.step);return{fit_params:b,params:a.setInitial(g,f),X:g,y:f,func:a.func}};
u=function(){var e,b,h,g,f;b=function(c,a,d){return 2>d?0:d%2?(f(c-1,(d-1)/2)*f(a-1,(d-3)/2)+f(c-1,(d-3)/2)*f(a-1,(d-1)/2))/f(c+a,c):2*f(c-1,d/2-1)*f(a-1,d/2-1)/f(c+a,c)};f=function(c,a){var d;a>c?d=0:e.hasOwnProperty(c)?e[c].hasOwnProperty(a)&&(d=e[c][a]):d=g(c,Math.max(c-a,a))/h(Math.min(c-a,a));return d};h=function(c){var a=1;if(1<=c)for(;1<c;--c)a*=c;return a};g=function(c,a){var d,b=1;for(d=c;d>a;d+=-1)b*=d;return b};e={1:{0:1,1:1},2:{0:1,1:2,2:1},3:{0:1,1:3,2:3,3:1},4:{0:1,1:4,2:6,3:4,4:1},
5:{0:1,1:5,2:10,3:10,4:5,5:1},6:{0:1,1:6,2:15,3:20,4:15,5:6,6:1},7:{0:1,1:7,2:21,3:35,4:35,5:21,6:7,7:1},8:{0:1,1:8,2:28,3:56,4:70,5:56,6:28,7:8,8:1},9:{0:1,1:9,2:36,3:84,4:126,5:126,6:84,7:36,8:9,9:1},10:{0:1,1:10,2:45,3:120,4:210,5:252,6:210,7:120,8:45,9:10,10:1},11:{0:1,1:11,2:55,3:165,4:330,5:462,6:462,7:330,8:165,9:55,10:11,11:1},12:{0:1,1:12,2:66,3:220,4:495,5:792,6:924,7:792,8:495,9:220,10:66,11:12,12:1},13:{0:1,1:13,2:78,3:286,4:715,5:1287,6:1716,7:1716,8:1287,9:715,10:286,11:78,12:13,13:1}};
return function(c,a,d,e){var f,g,l,h,q,n,p;h=[1,0];q=[1,0];n=0;p=a.length;l=d[0]-c(a[0],e);for(f=1;f<p;f+=1)g=d[f]-c(a[f],e),0>=g*l&&(n=(n+1)%2,q[n]+=1),h[n]+=1,l=g;return b(h[0],h[1],q[0]+q[1])}}();self.onmessage=function(e){var b;b=t(e.data);b=p(b.func,b.params,b.X,b.y,b.fit_params);self.postMessage([e.data,b])}})();