diff --git a/build/dann.js b/build/dann.js index b24e1e9a..7654e9de 100644 --- a/build/dann.js +++ b/build/dann.js @@ -206,38 +206,38 @@ let activations = { let x1 = 1 / (1 + Math.exp(-x)); return x1 * (1 - x1); }, - siLU(x) { + silu(x) { return x / (1 + Math.exp(-x)); }, - siLU_d(x) { + silu_d(x) { let top = 1 + Math.exp(-x) + x * Math.exp(-x); let down = Math.pow(1 + Math.exp(-x), 2); return top / down; }, - tanH(x) { + tanh(x) { let top = Math.exp(x) - Math.exp(-x); let down = Math.exp(x) + Math.exp(-x); return top / down; }, - tanH_d(x) { + tanh_d(x) { let numer = Math.pow(Math.exp(2 * x) - 1, 2); let denom = Math.pow(Math.exp(2 * x) + 1, 2); return 1 - numer / denom; }, - leakyReLU(x) { + leakyrelu(x) { return Math.max(x, x * 0.01); }, - leakyReLU_d(x) { + leakyrelu_d(x) { if (x >= 0) { return 1; } else { return 0.01; } }, - reLU(x) { + relu(x) { return Math.max(x, 0); }, - reLU_d(x) { + relu_d(x) { if (x >= 0) { return 1; } else { @@ -282,7 +282,7 @@ let activations = { return 1 / (1 + Math.exp(-x)); }, // Experimental - leakyReLUCapped(x) { + leakyrelucapped(x) { if (x >= 0 && x <= 6) { return x; } else if (x < 0) { @@ -291,7 +291,7 @@ let activations = { return 6; } }, - leakyReLUCapped_d(x) { + leakyrelucapped_d(x) { if (x >= 0 && x <= 6) { return 1; } else if (x < 0) { @@ -300,10 +300,10 @@ let activations = { return 0; } }, - leakySigmoid(x) { + leakysigmoid(x) { return 1 / (1 + Math.exp(-x)) + x / 100; }, - leakySigmoid_d(x) { + leakysigmoid_d(x) { return Math.exp(-x) / Math.pow(Math.exp(-x) + 1, 2) + 1 / 100; }, }; @@ -1574,7 +1574,8 @@ Layer.selectPools = function selectPools(arr, f, s, w, h) { * @param {String} act The activation function name */ Layer.prototype.setFunc = function setFunc(act) { - let obj = Layer.stringTofunc(act); + const lowerCaseAct = act.toLocaleLowerCase(); + let obj = Layer.stringTofunc(lowerCaseAct); if (obj !== undefined) { this.actname = obj.name; this.actname_d = obj.name_d; @@ -1594,7 +1595,7 @@ Layer.prototype.setFunc = function setFunc(act) { * @return {Object} Object containing information about an activation function. */ Layer.stringTofunc = function stringTofunc(str) { - let act = str; + let act = str.toLocaleLowerCase(); let der = act + '_d'; let func; let func_d; @@ -1933,7 +1934,8 @@ Dann.prototype.addDropout = function addDropout(rate) { */ Dann.prototype.addHiddenLayer = function addHiddenLayer(size, act) { if (act !== undefined) { - if (activations[act] === undefined) { + const lowerCaseAct = act.toLocaleLowerCase(); + if (activations[lowerCaseAct] === undefined) { if (typeof act === 'string') { DannError.error( "'" + @@ -1947,6 +1949,7 @@ Dann.prototype.addHiddenLayer = function addHiddenLayer(size, act) { } else { act = 'sigmoid'; } + this.arch.splice(this.arch.length - 1, 0, size); let layer = new Layer('hidden', size, act); this.Layers.splice(this.Layers.length - 1, 0, layer); @@ -2076,7 +2079,8 @@ Dann.prototype.makeWeights = function makeWeights(arg1, arg2) { * */ Dann.prototype.outputActivation = function outputActivation(act) { - if (activations[act] === undefined && !isBrowser) { + const lowerCaseAct = act.toLocaleLowerCase(); + if (activations[lowerCaseAct] === undefined && !isBrowser) { if (typeof act === 'string') { DannError.error( "'" + @@ -2093,6 +2097,7 @@ Dann.prototype.outputActivation = function outputActivation(act) { return; } } + this.Layers[this.Layers.length - 1].setFunc(act); }; @@ -3271,8 +3276,9 @@ Add.activation = function (name, activation, derivative) { ); return; } else { - activations[name] = activation; - activations[name + '_d'] = derivative; + const lowerCaseAct = name.toLocaleLowerCase(); + activations[lowerCaseAct] = activation; + activations[lowerCaseAct + '_d'] = derivative; return; } }; diff --git a/build/dann.min.js b/build/dann.min.js index a96a6c9c..38f3949f 100644 --- a/build/dann.min.js +++ b/build/dann.min.js @@ -1,2 +1,2 @@ /*! Dann.js */ -const isBrowser="object"!=typeof process,VERSION="v2.4.0";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}const XOR=makeXOR(2);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:t=>1/(1+Math.exp(-t)),sigmoid_d(t){let e=1/(1+Math.exp(-t));return e*(1-e)},siLU:t=>t/(1+Math.exp(-t)),siLU_d:t=>(1+Math.exp(-t)+t*Math.exp(-t))/Math.pow(1+Math.exp(-t),2),tanH:t=>(Math.exp(t)-Math.exp(-t))/(Math.exp(t)+Math.exp(-t)),tanH_d:t=>1-Math.pow(Math.exp(2*t)-1,2)/Math.pow(Math.exp(2*t)+1,2),leakyReLU:t=>Math.max(t,.01*t),leakyReLU_d:t=>t>=0?1:.01,reLU:t=>Math.max(t,0),reLU_d:t=>t>=0?1:0,sinc:t=>0===t?1:Math.sin(t)/t,sinc_d:t=>0===t?0:Math.cos(t)/t-Math.sin(t)/(t*t),softsign:t=>t/(1+Math.abs(t)),softsign_d(t){let e=1+Math.abs(t);return 1/(e*e)},binary:t=>t<=0?0:1,binary_d:t=>0,softplus:t=>Math.log(1+Math.exp(t)),softplus_d:t=>1/(1+Math.exp(-t)),leakyReLUCapped:t=>t>=0&&t<=6?t:t<0?.1*t:6,leakyReLUCapped_d:t=>t>=0&&t<=6?1:t<0?.1:0,leakySigmoid:t=>1/(1+Math.exp(-t))+t/100,leakySigmoid_d:t=>Math.exp(-t)/Math.pow(Math.exp(-t)+1,2)+.01},lossfuncs={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}};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;r21?(DannError.warn("Maximum number of decimals is 21.","Matrix.prototype.log"),r=pow(10,21)):r=pow(10,t.decimals)||r,e.map((t=>round(t*r)/r))}t.table?console.table(e.matrix):console.log(e)},Matrix.make=function(t=0,e=0){let r=[[]];for(let i=0;i=1)||(DannError.error("The learning rate specified is greater or equal to 1","Dann.prototype.backpropagate"),!1)},Dann.prototype.checkDropoutRate=function(t){return t>=1?(DannError.error("The probability value can not be bigger or equal to 1","Dann.prototype.backpropagate"),!1):!(t<=0)||(DannError.error("The probability value can not be smaller or equal to 0","Dann.prototype.backpropagate"),!1)},Dann.prototype.addDropout=function addDropout(rate){if(0===this.weights.length)return void DannError.error("You need to initialize weights before using this function, use Dann.prototype.makeWeights();","Dann.prototype.addDropout");let func=(t=>{let e=1-rate;return Math.floor(Math.random()+e)}).toString().replace(/rate/gm,rate),randomMap=eval(func),inactive=[];for(let t=0;tround(t*i)/i))),!0===e.log&&(Dann.print("Prediction: "),Dann.print(o,e.table)),o},Dann.prototype.feed=function(){return this.feedForward.apply(this,arguments)},Dann.prototype.log=function(t=Dann.logDefaults()){let e=1e3;if(t.decimals>21?(DannError.error("Maximum number of decimals is 21.","Dann.prototype.log"),e=pow(10,21)):e=pow(10,t.decimals)||e,t.details){let e=t.details;t.gradients=e,t.weights=e,t.errors=e,t.biases=e,t.struct=e,t.misc=e,t.layers=e}if(0===this.weights.length&&this.makeWeights(),t.struct){console.log("Dann Model:"),console.log("Layers:");for(let e=0;e0;t--){let e=Matrix.mult(this.gradients[t],Matrix.transpose(this.Layers[t].layer));void 0!==r.dropout&&(e=e.mult(this.dropout[t])),this.weights[t].add(e),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).mult(this.errors[t-1]).mult(this.lr)}let o=Matrix.transpose(this.Layers[0].layer),s=Matrix.mult(this.gradients[0],o);void 0!==r.dropout&&(s=s.mult(this.dropout[0])),this.weights[0].add(s),this.biases[0].add(this.gradients[0]),this.loss=this.lossfunc(this.outs,e,this.percentile),!0===r.saveLoss&&this.losses.push(this.loss),!0===r.log&&(Dann.print("Prediction: "),Dann.print(this.outs,r.table),Dann.print("target: "),Dann.print(e,r.table),Dann.print(`Loss: ${this.loss}`))},Dann.prototype.train=function(){return this.backpropagate.apply(this,arguments)},Dann.prototype.mapWeights=function(t){if("function"==typeof t)for(let e=0;e=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}const XOR=makeXOR(2);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:t=>1/(1+Math.exp(-t)),sigmoid_d(t){let e=1/(1+Math.exp(-t));return e*(1-e)},silu:t=>t/(1+Math.exp(-t)),silu_d:t=>(1+Math.exp(-t)+t*Math.exp(-t))/Math.pow(1+Math.exp(-t),2),tanh:t=>(Math.exp(t)-Math.exp(-t))/(Math.exp(t)+Math.exp(-t)),tanh_d:t=>1-Math.pow(Math.exp(2*t)-1,2)/Math.pow(Math.exp(2*t)+1,2),leakyrelu:t=>Math.max(t,.01*t),leakyrelu_d:t=>t>=0?1:.01,relu:t=>Math.max(t,0),relu_d:t=>t>=0?1:0,sinc:t=>0===t?1:Math.sin(t)/t,sinc_d:t=>0===t?0:Math.cos(t)/t-Math.sin(t)/(t*t),softsign:t=>t/(1+Math.abs(t)),softsign_d(t){let e=1+Math.abs(t);return 1/(e*e)},binary:t=>t<=0?0:1,binary_d:t=>0,softplus:t=>Math.log(1+Math.exp(t)),softplus_d:t=>1/(1+Math.exp(-t)),leakyrelucapped:t=>t>=0&&t<=6?t:t<0?.1*t:6,leakyrelucapped_d:t=>t>=0&&t<=6?1:t<0?.1:0,leakysigmoid:t=>1/(1+Math.exp(-t))+t/100,leakysigmoid_d:t=>Math.exp(-t)/Math.pow(Math.exp(-t)+1,2)+.01},lossfuncs={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}};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;r21?(DannError.warn("Maximum number of decimals is 21.","Matrix.prototype.log"),r=pow(10,21)):r=pow(10,t.decimals)||r,e.map((t=>round(t*r)/r))}t.table?console.table(e.matrix):console.log(e)},Matrix.make=function(t=0,e=0){let r=[[]];for(let i=0;i=1)||(DannError.error("The learning rate specified is greater or equal to 1","Dann.prototype.backpropagate"),!1)},Dann.prototype.checkDropoutRate=function(t){return t>=1?(DannError.error("The probability value can not be bigger or equal to 1","Dann.prototype.backpropagate"),!1):!(t<=0)||(DannError.error("The probability value can not be smaller or equal to 0","Dann.prototype.backpropagate"),!1)},Dann.prototype.addDropout=function addDropout(rate){if(0===this.weights.length)return void DannError.error("You need to initialize weights before using this function, use Dann.prototype.makeWeights();","Dann.prototype.addDropout");let func=(t=>{let e=1-rate;return Math.floor(Math.random()+e)}).toString().replace(/rate/gm,rate),randomMap=eval(func),inactive=[];for(let t=0;tround(t*i)/i))),!0===e.log&&(Dann.print("Prediction: "),Dann.print(o,e.table)),o},Dann.prototype.feed=function(){return this.feedForward.apply(this,arguments)},Dann.prototype.log=function(t=Dann.logDefaults()){let e=1e3;if(t.decimals>21?(DannError.error("Maximum number of decimals is 21.","Dann.prototype.log"),e=pow(10,21)):e=pow(10,t.decimals)||e,t.details){let e=t.details;t.gradients=e,t.weights=e,t.errors=e,t.biases=e,t.struct=e,t.misc=e,t.layers=e}if(0===this.weights.length&&this.makeWeights(),t.struct){console.log("Dann Model:"),console.log("Layers:");for(let e=0;e0;t--){let e=Matrix.mult(this.gradients[t],Matrix.transpose(this.Layers[t].layer));void 0!==r.dropout&&(e=e.mult(this.dropout[t])),this.weights[t].add(e),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).mult(this.errors[t-1]).mult(this.lr)}let o=Matrix.transpose(this.Layers[0].layer),s=Matrix.mult(this.gradients[0],o);void 0!==r.dropout&&(s=s.mult(this.dropout[0])),this.weights[0].add(s),this.biases[0].add(this.gradients[0]),this.loss=this.lossfunc(this.outs,e,this.percentile),!0===r.saveLoss&&this.losses.push(this.loss),!0===r.log&&(Dann.print("Prediction: "),Dann.print(this.outs,r.table),Dann.print("target: "),Dann.print(e,r.table),Dann.print(`Loss: ${this.loss}`))},Dann.prototype.train=function(){return this.backpropagate.apply(this,arguments)},Dann.prototype.mapWeights=function(t){if("function"==typeof t)for(let e=0;e */ Dann.prototype.outputActivation = function outputActivation(act) { - if (activations[act] === undefined && !isBrowser) { + const lowerCaseAct = act.toLocaleLowerCase(); + if (activations[lowerCaseAct] === undefined && !isBrowser) { if (typeof act === 'string') { DannError.error( "'" + @@ -83,5 +84,6 @@ Dann.prototype.outputActivation = function outputActivation(act) { return; } } + this.Layers[this.Layers.length - 1].setFunc(act); }; diff --git a/src/classes/layer/methods/setFunc.js b/src/classes/layer/methods/setFunc.js index 2edfe417..b1bb71fb 100644 --- a/src/classes/layer/methods/setFunc.js +++ b/src/classes/layer/methods/setFunc.js @@ -5,7 +5,8 @@ * @param {String} act The activation function name */ Layer.prototype.setFunc = function setFunc(act) { - let obj = Layer.stringTofunc(act); + const lowerCaseAct = act.toLocaleLowerCase(); + let obj = Layer.stringTofunc(lowerCaseAct); if (obj !== undefined) { this.actname = obj.name; this.actname_d = obj.name_d; diff --git a/src/classes/layer/methods/stringTofunc.js b/src/classes/layer/methods/stringTofunc.js index fab95e7f..0962398b 100644 --- a/src/classes/layer/methods/stringTofunc.js +++ b/src/classes/layer/methods/stringTofunc.js @@ -6,7 +6,7 @@ * @return {Object} Object containing information about an activation function. */ Layer.stringTofunc = function stringTofunc(str) { - let act = str; + let act = str.toLocaleLowerCase(); let der = act + '_d'; let func; let func_d; diff --git a/src/core/functions/actfuncs.js b/src/core/functions/actfuncs.js index 24079c13..28f1e4bb 100644 --- a/src/core/functions/actfuncs.js +++ b/src/core/functions/actfuncs.js @@ -10,38 +10,38 @@ let activations = { let x1 = 1 / (1 + Math.exp(-x)); return x1 * (1 - x1); }, - siLU(x) { + silu(x) { return x / (1 + Math.exp(-x)); }, - siLU_d(x) { + silu_d(x) { let top = 1 + Math.exp(-x) + x * Math.exp(-x); let down = Math.pow(1 + Math.exp(-x), 2); return top / down; }, - tanH(x) { + tanh(x) { let top = Math.exp(x) - Math.exp(-x); let down = Math.exp(x) + Math.exp(-x); return top / down; }, - tanH_d(x) { + tanh_d(x) { let numer = Math.pow(Math.exp(2 * x) - 1, 2); let denom = Math.pow(Math.exp(2 * x) + 1, 2); return 1 - numer / denom; }, - leakyReLU(x) { + leakyrelu(x) { return Math.max(x, x * 0.01); }, - leakyReLU_d(x) { + leakyrelu_d(x) { if (x >= 0) { return 1; } else { return 0.01; } }, - reLU(x) { + relu(x) { return Math.max(x, 0); }, - reLU_d(x) { + relu_d(x) { if (x >= 0) { return 1; } else { @@ -86,7 +86,7 @@ let activations = { return 1 / (1 + Math.exp(-x)); }, // Experimental - leakyReLUCapped(x) { + leakyrelucapped(x) { if (x >= 0 && x <= 6) { return x; } else if (x < 0) { @@ -95,7 +95,7 @@ let activations = { return 6; } }, - leakyReLUCapped_d(x) { + leakyrelucapped_d(x) { if (x >= 0 && x <= 6) { return 1; } else if (x < 0) { @@ -104,10 +104,10 @@ let activations = { return 0; } }, - leakySigmoid(x) { + leakysigmoid(x) { return 1 / (1 + Math.exp(-x)) + x / 100; }, - leakySigmoid_d(x) { + leakysigmoid_d(x) { return Math.exp(-x) / Math.pow(Math.exp(-x) + 1, 2) + 1 / 100; }, }; diff --git a/test/unit/classes/dann.js b/test/unit/classes/dann.js index 629524c6..aa16664a 100644 --- a/test/unit/classes/dann.js +++ b/test/unit/classes/dann.js @@ -179,7 +179,7 @@ suite('Dann Object', function () { } }); test('Should have initiated an output layer with sigmoid', function () { - let acts = ['leakyReLU', 'leakyReLU', 'leakyReLU', 'tanH']; + let acts = ['leakyrelu', 'leakyrelu', 'leakyrelu', 'tanh']; //starts at one to ignore input for (let i = 1; i < acts.length; i++) { let name = acts[i - 1]; @@ -317,10 +317,10 @@ suite('Dann Object', function () { assert.equal(nn.Layers[1].size, 16); }); test('Should have initiated a tanH activation', function () { - assert.equal('tanH', nn.Layers[1].actname); - assert.equal('tanH_d', nn.Layers[1].actname_d); - assert.equal(activations.tanH, nn.Layers[1].actfunc); - assert.equal(activations.tanH_d, nn.Layers[1].actfunc_d); + assert.equal('tanh', nn.Layers[1].actname); + assert.equal('tanh_d', nn.Layers[1].actname_d); + assert.equal(activations.tanh, nn.Layers[1].actfunc); + assert.equal(activations.tanh_d, nn.Layers[1].actfunc_d); }); test('Should have initiated matrix', function () { assert.instanceOf(nn.Layers[1].layer, Matrix); @@ -436,7 +436,7 @@ suite('Dann Object', function () { nn.outputActivation('reLU'); }); test('Should have initiated a reLU activation function for the output', function () { - let name = 'reLU'; + let name = 'relu'; let derivative = name + '_d'; assert.equal(name, nn.Layers[2].actname); assert.equal(derivative, nn.Layers[2].actname_d); @@ -531,7 +531,7 @@ suite('Dann Object', function () { assert.typeOf(nn.epoch, 'Number'); }); test('Should have loaded layers activations', function () { - let acts = ['siLU', 'tanH']; + let acts = ['silu', 'tanh']; //starts at one to ignore input for (let i = 1; i < acts.length; i++) { let name = acts[i - 1]; @@ -689,7 +689,7 @@ suite('Dann Object', function () { assert.typeOf(nn.epoch, 'Number'); }); test('Should have loaded layers activations', function () { - let acts = ['leakyReLU', 'tanH']; + let acts = ['leakyrelu', 'tanh']; //starts at one to ignore input for (let i = 1; i < acts.length; i++) { let name = acts[i - 1]; diff --git a/test/unit/core/functions/actfuncs.js b/test/unit/core/functions/actfuncs.js index 539b5a83..1a1fd6a1 100644 --- a/test/unit/core/functions/actfuncs.js +++ b/test/unit/core/functions/actfuncs.js @@ -29,7 +29,7 @@ suite('', function () { let pointsX = [-4, -2, 0, 2, 4]; let ans_hardcoded = [-0.999, -0.964, 0, 0.964, 0.999]; for (let i = 0; i < pointsX.length; i++) { - assert.closeTo(activations.tanH(pointsX[i]), ans_hardcoded[i], 0.01); + assert.closeTo(activations.tanh(pointsX[i]), ans_hardcoded[i], 0.01); } }); test("Testing 'tanH_d' activation function", function () { @@ -37,7 +37,7 @@ suite('', function () { let ans_hardcoded = [0.001, 0.071, 1, 0.071, 0.001]; for (let i = 0; i < pointsX.length; i++) { assert.closeTo( - activations.tanH_d(pointsX[i]), + activations.tanh_d(pointsX[i]), ans_hardcoded[i], 0.01 ); @@ -49,7 +49,7 @@ suite('', function () { let pointsX = [-4, -2, 0, 2, 4]; let ans_hardcoded = [-0.072, -0.238, 0, 1.762, 3.928]; for (let i = 0; i < pointsX.length; i++) { - assert.closeTo(activations.siLU(pointsX[i]), ans_hardcoded[i], 0.01); + assert.closeTo(activations.silu(pointsX[i]), ans_hardcoded[i], 0.01); } }); test("Testing 'siLU_d' activation function", function () { @@ -57,7 +57,7 @@ suite('', function () { let ans_hardcoded = [-0.053, -0.091, 0.5, 1.091, 1.053]; for (let i = 0; i < pointsX.length; i++) { assert.closeTo( - activations.siLU_d(pointsX[i]), + activations.silu_d(pointsX[i]), ans_hardcoded[i], 0.01 ); @@ -70,7 +70,7 @@ suite('', function () { let ans_hardcoded = [-0.04, -0.02, 0, 2, 4]; for (let i = 0; i < pointsX.length; i++) { assert.closeTo( - activations.leakyReLU(pointsX[i]), + activations.leakyrelu(pointsX[i]), ans_hardcoded[i], 0.01 ); @@ -81,7 +81,7 @@ suite('', function () { let ans_hardcoded = [0.01, 0.01, 1, 1, 1]; for (let i = 0; i < pointsX.length; i++) { assert.closeTo( - activations.leakyReLU_d(pointsX[i]), + activations.leakyrelu_d(pointsX[i]), ans_hardcoded[i], 0.01 ); @@ -93,7 +93,7 @@ suite('', function () { let pointsX = [-4, -2, 0, 2, 4]; let ans_hardcoded = [0, 0, 0, 2, 4]; for (let i = 0; i < pointsX.length; i++) { - assert.closeTo(activations.reLU(pointsX[i]), ans_hardcoded[i], 0.01); + assert.closeTo(activations.relu(pointsX[i]), ans_hardcoded[i], 0.01); } }); test("Testing 'reLU_d' activation function", function () { @@ -101,7 +101,7 @@ suite('', function () { let ans_hardcoded = [0, 0, 1, 1, 1]; for (let i = 0; i < pointsX.length; i++) { assert.closeTo( - activations.reLU_d(pointsX[i]), + activations.relu_d(pointsX[i]), ans_hardcoded[i], 0.01 ); diff --git a/test/unit/core/functions/add.js b/test/unit/core/functions/add.js index 30084f88..5baebf85 100644 --- a/test/unit/core/functions/add.js +++ b/test/unit/core/functions/add.js @@ -7,7 +7,14 @@ suite('', function () { func = (x) => x * x; func_d = (x) => 2 * x; }); - test('Sould have added an activation', function () { + test('Should have added case insensitive activation', function () { + Add.activation('myNewFunc', func, func_d); + assert.exists(activations.mynewfunc); + assert.exists(activations.mynewfunc_d); + assert.equal(activations.mynewfunc(3), func(3)); + assert.equal(activations.mynewfunc_d(3), func_d(3)); + }); + test('Should have added an activation', function () { Add.activation('mynewfunc', func, func_d); assert.exists(activations.mynewfunc); assert.exists(activations.mynewfunc_d); @@ -35,7 +42,7 @@ suite('', function () { setup(function () { func = (x, y) => x[0] - y[0]; }); - test('Sould have added a loss function', function () { + test('Should have added a loss function', function () { Add.loss('mynewfunc', func); assert.exists(lossfuncs.mynewfunc); assert.equal(lossfuncs.mynewfunc([4], [2]), func([4], [2]));