forked from jeffheaton/encog-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestlib.min.js
executable file
·1 lines (1 loc) · 1.28 KB
/
testlib.min.js
1
var TESTLIB=TESTLIB||{};TESTLIB.namespace=function(a){"use strict";var b=a.split("."),c=TESTLIB,d;if(b[0]==="TESTLIB"){b=b.slice(1)}for(d=0;d<b.length;d+=1){if(typeof c[b[d]]==="undefined"){c[b[d]]={}}c=c[b[d]]}return c};TESTLIB.namespace("TESTLIB.Vector");TESTLIB.namespace("TESTLIB.VectorUtil");TESTLIB.Vector=function(){"use strict"};TESTLIB.Vector.prototype={data:{},sum:function(){"use strict";var a=0,b;for(b=0;b<this.data.length;b+=1){a+=this.data[b]}return a},count:function(){"use strict";return this.data.length},length:function(){"use strict";var a,b;b=0;for(a=0;a<this.data.length;a+=1){b+=Math.pow(this.data[a],2)}return Math.sqrt(b)},clear:function(a){"use strict";var b,c;this.data=[];c=a||this.data.length;for(b=0;b<c;b+=1){this.data[b]=0}},toString:function(){return"["+this.data.join(",")+"]"}};TESTLIB.Vector.create=function(a){"use strict";var b=new TESTLIB.Vector;if(a instanceof Array){b.data=a.splice(0)}else{b.clear(a||0)}return b};TESTLIB.VectorUtil=function(){"use strict"};TESTLIB.VectorUtil.distance=function(a,b){"use strict";var c=0,d,e;for(d=0;d<a.data.length;d+=1){e=a.data[d]-b.data[d];c+=e*e}return Math.sqrt(c)};TESTLIB.VectorUtil.add=function(a,b){"use strict";var c,d;c=TESTLIB.Vector.create(a.count());for(d=0;d<a.data.length;d+=1){c.data[d]=a.data[d]+b.data[d]}return c}