From 584a967868d8f1d505d593d2c7c4b4794fb6af9b Mon Sep 17 00:00:00 2001 From: Matias Vazquez-Levi Date: Mon, 30 Aug 2021 12:34:28 -0400 Subject: [PATCH] builds --- build/dann.js | 19 ++++++++++--------- build/dann.min.js | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/build/dann.js b/build/dann.js index e5a5f9f0..c0f7fa91 100644 --- a/build/dann.js +++ b/build/dann.js @@ -1,5 +1,5 @@ const isBrowser = typeof process !== 'object'; -const VERSION = 'v2.3.11'; +const VERSION = 'v2.3.12'; /** * Add a new custom function to Dannjs. @@ -2024,17 +2024,17 @@ Dann.prototype.backpropagate = function backpropagate( if (target.length === this.o) { targets = Matrix.fromArray(target); } else { - console.error( - 'Dann Error: The target array length does not match the number of ouputs the dannjs model has.' + DannError.error( + 'The target array length does not match the number of ouputs the dannjs model has.', + 'Dann.prototype.backpropagate' ); - console.trace(); return; } if (typeof this.lr !== 'number') { - console.error( - 'Dann Error: The learning rate specified (Dann.lr property) is not a number.' + DannError.error( + 'The learning rate specified (Dann.lr property) is not a number.', + 'Dann.prototype.backpropagate' ); - console.trace(); return; } @@ -2534,9 +2534,10 @@ Dann.prototype.log = function log( // Limit decimals to maximum of 21 if (options.decimals > 21) { DannError.error('Maximum number of decimals is 21.', 'Dann.prototype.log'); - options.decimals = 21; + decimals = pow(10, 21); + } else { + decimals = pow(10, options.decimals) || decimals; } - decimals = pow(10, options.decimals); // Details sets all values to true. if (options.details) { diff --git a/build/dann.min.js b/build/dann.min.js index 5480b2be..7b16bc87 100644 --- a/build/dann.min.js +++ b/build/dann.min.js @@ -1 +1 @@ -const isBrowser="object"!=typeof process,VERSION="v2.3.11";function bitLength(t){return t<1?1:Math.floor(Math.log(t)/Math.log(2))+1}function numberToBinary(t,e){let r=t.toString(2),i=[],o=bitLength(t)-1;for(let t=e-1;t>=0;t--){let e=r.charAt(o);i[t]=""===e?0:JSON.parse(e),o--}return i}function makeBinary(t,e){let r;r=void 0!==e?e:function(t){return t+1};let i=[];for(let e=0;e{delete t.output,t.output=[t.input.reduce(((t,e)=>t+e),0)%2]})),e}Add=function(){},Add.activation=function(t,e,r){if("string"==typeof t)return 1!==e.length||1!==r.length?void DannError.error("One of the functions specified does not have only 1 argument.","Add.activation"):(activations[t]=e,void(activations[t+"_d"]=r));DannError.error("The name argument is not a string.","Add.activation")},Add.loss=function(t,e){"string"==typeof t?2===e.length?lossfuncs[t]=e:DannError.error("The loss function specified can only have 2 argument.","newActivation"):DannError.error("The name argument is not a string.","Add.loss")};const XOR=makeXOR(2);function sigmoid(t){return 1/(1+Math.exp(-t))}function sigmoid_d(t){let e=sigmoid(t);return e*(1-e)}function leakySigmoid(t){return 1/(1+Math.exp(-t))+t/100}function leakySigmoid_d(t){let e=leakySigmoid(t);return e*(1-e)}function siLU(t){return t/(1+Math.exp(-t))}function siLU_d(t){return(1+Math.exp(-t)+t*Math.exp(-t))/Math.pow(1+Math.exp(-t),2)}function tanH(t){return(Math.exp(t)-Math.exp(-t))/(Math.exp(t)+Math.exp(-t))}function tanH_d(t){return 1-Math.pow(tanH(t),2)}function leakyReLUCapped(t){return t>=0&&t<=6?t:t<0?.1*t:6}function leakyReLUCapped_d(t){return t>=0&&t<=6?1:t<0?.1:0}function leakyReLU(t){return t>=0?1*t:.01*t}function leakyReLU_d(t){return t>=0?1:.01}function reLU(t){return t>=0?1*t:0}function reLU_d(t){return t>=0?1:0}function sinc(t){return 0===t?1:Math.sin(t)/t}function sinc_d(t){return 0===t?0:Math.cos(t)/t-Math.sin(t)/(t*t)}function softsign(t){return t/(1+Math.abs(t))}function softsign_d(t){let e=1+Math.abs(t);return 1/(e*e)}function binary(t){return t<=0?0:1}function binary_d(t){return 0}function softplus(t){return Math.log(1+Math.exp(t))}function softplus_d(t){return sigmoid(t)}DannError=function(t,e){this.msg=t,this.method=e},DannError.prototype.warn=function(){isBrowser?(console.error("DannWarning: "+this.msg),console.error("> "+this.method)):(console.error("DannWarning: "+this.msg+""),console.error("> "+this.method+"")),console.trace()},DannError.prototype.error=function(){isBrowser?(console.warn("DannError: "+this.msg),console.warn("> "+this.method)):(console.warn("DannError: "+this.msg+""),console.warn("> "+this.method+"")),console.trace()},DannError.warn=function(t,e){isBrowser?(console.warn("DannWarning: "+t),console.warn("> "+e)):(console.warn("DannWarning: "+t+""),console.warn("> "+e+"")),console.trace()},DannError.error=function(t,e){isBrowser?(console.error("DannError: "+t),console.error("> "+e)):(console.error("DannError: "+t+""),console.error("> "+e+"")),console.trace()};let activations={sigmoid:sigmoid,sigmoid_d:sigmoid_d,tanH:tanH,tanH_d:tanH_d,siLU:siLU,siLU_d:siLU_d,reLU:reLU,reLU_d:reLU_d,leakyReLU:leakyReLU,leakyReLU_d:leakyReLU_d,sinc:sinc,sinc_d:sinc_d,softsign:softsign,softsign_d:softsign_d,binary:binary,binary_d:binary_d,softplus:softplus,softplus_d:softplus_d,leakySigmoid:leakySigmoid,leakySigmoid_d:leakySigmoid_d,leakyReLUCapped:leakyReLUCapped,leakyReLUCapped_d:leakyReLUCapped_d};function mae(t,e){let r=0,i=0,o=e.length;for(let i=0;i=0?o+=i*(e[r]-t[r]):o+=(i-1)*(e[r]-t[r]);return o/e.length}let lossfuncs={mae:mae,bce:bce,lcl:lcl,mbe:mbe,mce:mce,mse:mse,rmse:rmse,mael:mael,quantile:quantile};const random=(t,e)=>Math.random(1)*(e-t)+t,exp=t=>Math.exp(t),abs=t=>Math.abs(t),log=t=>Math.log(t),pow=(t,e)=>Math.pow(t,e),round=t=>Math.round(t),sqrt=t=>Math.sqrt(t),cosh=t=>(exp(t)+exp(-t))/2;let poolfuncs={max:function(t){let e=0,r=t.length;for(let i=0;ie&&(e=t[i]);return e},min:function(t){let e=1/0,r=t.length;for(let i=0;i /g,">")).replace(/ \+= /g,"+=")).replace(/;\}/g,"}");for(let e=0;e<5;e++)t=(t=(t=(t=(t=t.replace(/\{ /g,"{")).replace(/ \{/g,"{")).replace(/\} /g,"}")).replace(/\t/g,"")).replace(/\n/g,"");for(let e=0;e<5;e++)t=t.replace(/; /g,";");return t}function slicestring(t,e){return[t.slice(0,e+1),t.slice(e+1,t.length)]}function toEs6(t){let e=t.toString(),r=e.indexOf("("),i=slicestring(e,r)[1];r=i.indexOf(")");let o=slicestring(i,r-1),s=o[0];return r=o[1].indexOf(")"),minify("("+s+")=>"+slicestring(o[1],r)[1])}Matrix=function(t=0,e=0){this.rows=t,this.cols=e;let r=[[]];for(let i=0;i1)DannError.error("Probability argument must be between 0 and 1","Matrix.prototype.addRandom");else for(let i=0;i=this.cols)){for(let r=0;r=this.rows))return this.matrix[t].fill(e),this;DannError.error("The row index specified is too large for this matrix.","Matrix.prototype.fillRow")},Matrix.fromArray=function(t){let e=new Matrix(t.length,1);for(let r=0;r{let e=1-rate;return Math.floor(Math.random()+e)}).toString().replace(/rate/gm,rate),randomMap=eval(func),inactive=[];for(let t=0;t=1)return void DannError.error("The probability value can not be bigger or equal to 1","Dann.prototype.backpropagate");if(a<=0)return void DannError.error("The probability value can not be smaller or equal to 0","Dann.prototype.backpropagate");this.addDropout(a)}for(let t=this.weights.length-1;t>0;t--){let e=Matrix.transpose(this.Layers[t].layer),r=Matrix.mult(this.gradients[t],e);void 0!==a&&(r=r.mult(this.dropout[t])),this.weights[t].add(r),this.biases[t].add(this.gradients[t]);let i=Matrix.transpose(this.weights[t]);this.errors[t-1]=Matrix.mult(i,this.errors[t]),this.gradients[t-1]=Matrix.map(this.Layers[t].layer,this.Layers[t].actfunc_d),this.gradients[t-1].mult(this.errors[t-1]),this.gradients[t-1].mult(this.lr)}let h=Matrix.transpose(this.Layers[0].layer),u=Matrix.mult(this.gradients[0],h);void 0!==a&&(u=u.mult(this.dropout[0])),this.weights[0].add(u),this.biases[0].add(this.gradients[0]),this.loss=this.lossfunc(this.outs,e,this.percentile),!0===s&&this.losses.push(this.loss),!0===i&&(console.log("Prediction: "),n?console.table(this.outs):console.log(this.outs),console.log("target: "),n?console.table(e):console.log(e),console.log("Loss: ",this.loss))},Dann.prototype.train=function(t,e,r){return this.backpropagate(t,e,r)},Dann.createFromJSON=function(t){const e=new Dann;return e.fromJSON(t),e},Dann.prototype.feedForward=function(t,e={}){let r=e.log||!1,i=e.table||!1,o=!1,s=pow(10,e.decimals)||1e3;if(void 0!==e.decimals&&(o=!0),t.length!==this.i){for(let t=0;tround(t*s)/s))),!0===i?(console.log("Prediction: "),console.table(n)):(console.log("Prediction: "),console.log(n))),n},Dann.prototype.feed=function(t,e){return this.feedForward(t,e)},Dann.prototype.fromJSON=function(t){this.i=t.arch[0],this.inputs=new Matrix(this.i,1),this.o=t.arch[t.arch.length-1],this.outputs=new Matrix(this.o,1);let e=JSON.parse(t.lstr);for(let t=0;t21&&(DannError.error("Maximum number of decimals is 21.","Dann.prototype.log"),t.decimals=21),h=pow(10,t.decimals),t.details){let l=t.details;r=l,e=l,i=l,o=l,s=l,n=l,a=l}if(0===this.weights.length&&this.makeWeights(),!0===s&&console.log("Dann Model:"),s){console.log("Layers:");for(let t=0;t=0;t--){let e=r.charAt(o);i[t]=""===e?0:JSON.parse(e),o--}return i}function makeBinary(t,e){let r;r=void 0!==e?e:function(t){return t+1};let i=[];for(let e=0;e{delete t.output,t.output=[t.input.reduce(((t,e)=>t+e),0)%2]})),e}Add=function(){},Add.activation=function(t,e,r){if("string"==typeof t)return 1!==e.length||1!==r.length?void DannError.error("One of the functions specified does not have only 1 argument.","Add.activation"):(activations[t]=e,void(activations[t+"_d"]=r));DannError.error("The name argument is not a string.","Add.activation")},Add.loss=function(t,e){"string"==typeof t?2===e.length?lossfuncs[t]=e:DannError.error("The loss function specified can only have 2 argument.","newActivation"):DannError.error("The name argument is not a string.","Add.loss")};const XOR=makeXOR(2);function sigmoid(t){return 1/(1+Math.exp(-t))}function sigmoid_d(t){let e=sigmoid(t);return e*(1-e)}function leakySigmoid(t){return 1/(1+Math.exp(-t))+t/100}function leakySigmoid_d(t){let e=leakySigmoid(t);return e*(1-e)}function siLU(t){return t/(1+Math.exp(-t))}function siLU_d(t){return(1+Math.exp(-t)+t*Math.exp(-t))/Math.pow(1+Math.exp(-t),2)}function tanH(t){return(Math.exp(t)-Math.exp(-t))/(Math.exp(t)+Math.exp(-t))}function tanH_d(t){return 1-Math.pow(tanH(t),2)}function leakyReLUCapped(t){return t>=0&&t<=6?t:t<0?.1*t:6}function leakyReLUCapped_d(t){return t>=0&&t<=6?1:t<0?.1:0}function leakyReLU(t){return t>=0?1*t:.01*t}function leakyReLU_d(t){return t>=0?1:.01}function reLU(t){return t>=0?1*t:0}function reLU_d(t){return t>=0?1:0}function sinc(t){return 0===t?1:Math.sin(t)/t}function sinc_d(t){return 0===t?0:Math.cos(t)/t-Math.sin(t)/(t*t)}function softsign(t){return t/(1+Math.abs(t))}function softsign_d(t){let e=1+Math.abs(t);return 1/(e*e)}function binary(t){return t<=0?0:1}function binary_d(t){return 0}function softplus(t){return Math.log(1+Math.exp(t))}function softplus_d(t){return sigmoid(t)}DannError=function(t,e){this.msg=t,this.method=e},DannError.prototype.warn=function(){isBrowser?(console.error("DannWarning: "+this.msg),console.error("> "+this.method)):(console.error("DannWarning: "+this.msg+""),console.error("> "+this.method+"")),console.trace()},DannError.prototype.error=function(){isBrowser?(console.warn("DannError: "+this.msg),console.warn("> "+this.method)):(console.warn("DannError: "+this.msg+""),console.warn("> "+this.method+"")),console.trace()},DannError.warn=function(t,e){isBrowser?(console.warn("DannWarning: "+t),console.warn("> "+e)):(console.warn("DannWarning: "+t+""),console.warn("> "+e+"")),console.trace()},DannError.error=function(t,e){isBrowser?(console.error("DannError: "+t),console.error("> "+e)):(console.error("DannError: "+t+""),console.error("> "+e+"")),console.trace()};let activations={sigmoid:sigmoid,sigmoid_d:sigmoid_d,tanH:tanH,tanH_d:tanH_d,siLU:siLU,siLU_d:siLU_d,reLU:reLU,reLU_d:reLU_d,leakyReLU:leakyReLU,leakyReLU_d:leakyReLU_d,sinc:sinc,sinc_d:sinc_d,softsign:softsign,softsign_d:softsign_d,binary:binary,binary_d:binary_d,softplus:softplus,softplus_d:softplus_d,leakySigmoid:leakySigmoid,leakySigmoid_d:leakySigmoid_d,leakyReLUCapped:leakyReLUCapped,leakyReLUCapped_d:leakyReLUCapped_d};function mae(t,e){let r=0,i=0,o=e.length;for(let i=0;i=0?o+=i*(e[r]-t[r]):o+=(i-1)*(e[r]-t[r]);return o/e.length}let lossfuncs={mae:mae,bce:bce,lcl:lcl,mbe:mbe,mce:mce,mse:mse,rmse:rmse,mael:mael,quantile:quantile};const random=(t,e)=>Math.random(1)*(e-t)+t,exp=t=>Math.exp(t),abs=t=>Math.abs(t),log=t=>Math.log(t),pow=(t,e)=>Math.pow(t,e),round=t=>Math.round(t),sqrt=t=>Math.sqrt(t),cosh=t=>(exp(t)+exp(-t))/2;let poolfuncs={max:function(t){let e=0,r=t.length;for(let i=0;ie&&(e=t[i]);return e},min:function(t){let e=1/0,r=t.length;for(let i=0;i /g,">")).replace(/ \+= /g,"+=")).replace(/;\}/g,"}");for(let e=0;e<5;e++)t=(t=(t=(t=(t=t.replace(/\{ /g,"{")).replace(/ \{/g,"{")).replace(/\} /g,"}")).replace(/\t/g,"")).replace(/\n/g,"");for(let e=0;e<5;e++)t=t.replace(/; /g,";");return t}function slicestring(t,e){return[t.slice(0,e+1),t.slice(e+1,t.length)]}function toEs6(t){let e=t.toString(),r=e.indexOf("("),i=slicestring(e,r)[1];r=i.indexOf(")");let o=slicestring(i,r-1),s=o[0];return r=o[1].indexOf(")"),minify("("+s+")=>"+slicestring(o[1],r)[1])}Matrix=function(t=0,e=0){this.rows=t,this.cols=e;let r=[[]];for(let i=0;i1)DannError.error("Probability argument must be between 0 and 1","Matrix.prototype.addRandom");else for(let i=0;i=this.cols)){for(let r=0;r=this.rows))return this.matrix[t].fill(e),this;DannError.error("The row index specified is too large for this matrix.","Matrix.prototype.fillRow")},Matrix.fromArray=function(t){let e=new Matrix(t.length,1);for(let r=0;r{let e=1-rate;return Math.floor(Math.random()+e)}).toString().replace(/rate/gm,rate),randomMap=eval(func),inactive=[];for(let t=0;t=1)return void DannError.error("The probability value can not be bigger or equal to 1","Dann.prototype.backpropagate");if(a<=0)return void DannError.error("The probability value can not be smaller or equal to 0","Dann.prototype.backpropagate");this.addDropout(a)}for(let t=this.weights.length-1;t>0;t--){let e=Matrix.transpose(this.Layers[t].layer),r=Matrix.mult(this.gradients[t],e);void 0!==a&&(r=r.mult(this.dropout[t])),this.weights[t].add(r),this.biases[t].add(this.gradients[t]);let i=Matrix.transpose(this.weights[t]);this.errors[t-1]=Matrix.mult(i,this.errors[t]),this.gradients[t-1]=Matrix.map(this.Layers[t].layer,this.Layers[t].actfunc_d),this.gradients[t-1].mult(this.errors[t-1]),this.gradients[t-1].mult(this.lr)}let h=Matrix.transpose(this.Layers[0].layer),u=Matrix.mult(this.gradients[0],h);void 0!==a&&(u=u.mult(this.dropout[0])),this.weights[0].add(u),this.biases[0].add(this.gradients[0]),this.loss=this.lossfunc(this.outs,e,this.percentile),!0===s&&this.losses.push(this.loss),!0===i&&(console.log("Prediction: "),n?console.table(this.outs):console.log(this.outs),console.log("target: "),n?console.table(e):console.log(e),console.log("Loss: ",this.loss))},Dann.prototype.train=function(t,e,r){return this.backpropagate(t,e,r)},Dann.createFromJSON=function(t){const e=new Dann;return e.fromJSON(t),e},Dann.prototype.feedForward=function(t,e={}){let r=e.log||!1,i=e.table||!1,o=!1,s=pow(10,e.decimals)||1e3;if(void 0!==e.decimals&&(o=!0),t.length!==this.i){for(let t=0;tround(t*s)/s))),!0===i?(console.log("Prediction: "),console.table(n)):(console.log("Prediction: "),console.log(n))),n},Dann.prototype.feed=function(t,e){return this.feedForward(t,e)},Dann.prototype.fromJSON=function(t){this.i=t.arch[0],this.inputs=new Matrix(this.i,1),this.o=t.arch[t.arch.length-1],this.outputs=new Matrix(this.o,1);let e=JSON.parse(t.lstr);for(let t=0;t21?(DannError.error("Maximum number of decimals is 21.","Dann.prototype.log"),h=pow(10,21)):h=pow(10,t.decimals)||h,t.details){let l=t.details;r=l,e=l,i=l,o=l,s=l,n=l,a=l}if(0===this.weights.length&&this.makeWeights(),!0===s&&console.log("Dann Model:"),s){console.log("Layers:");for(let t=0;t