diff --git a/README.md b/README.md index b7ded476..b01cdcde 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ ## Installation ### CDN : ```html - + ``` ### Node : ``` diff --git a/build/dann.js b/build/dann.js index 2824a1b3..fed24fd9 100644 --- a/build/dann.js +++ b/build/dann.js @@ -1,6 +1,6 @@ /*! Dann.js */ const isBrowser = typeof process !== 'object'; -const VERSION = 'v2.4.1c'; +const VERSION = 'v2.4.1d'; /* * Undisplayed documentation @@ -2836,48 +2836,6 @@ Dann.prototype.fromJSON = function fromJSON(data) { * @param {String} name The name of the saved directory that holds the dann model. * @param {Function} arg2 A function to be called when the model finished loading. */ -// Dann.prototype.load = function load(name, arg2, arg3) { -// if (isBrowser) { -// upload(name, arg2, arg3); -// } else { -// let path = './savedDanns/' + name + '/dannData.json'; -// if (fs.existsSync(path)) { -// let text = fs.readFileSync(path, 'utf8'); -// let xdata = JSON.parse(text); - -// let newNN = xdata; -// this.applyToModel(newNN); -// if (typeof arg2 === 'function') { -// arg2(false); -// } else { -// let type = typeof arg2; -// DannError.error( -// "callback specified is not a function, the function recieved a '" + -// type + -// "' instead", -// 'Dann.prototype.load' -// ); -// return; -// } -// } else { -// if (typeof arg2 === 'function') { -// arg2(true); -// } else if (typeof arg2 !== 'function') { -// let type = typeof arg2; -// DannError.error( -// 'Callback specified is not a function, the function recieved a ' + -// type + -// ' instead', -// 'Dann.prototype.load' -// ); -// return; -// } else { -// DannError.error('File not found', 'Dann.prototype.load'); -// return; -// } -// } -// } -// }; /* * (Browser) @@ -2896,94 +2854,6 @@ Dann.prototype.fromJSON = function fromJSON(data) { * @param {String} name The name of the json file. * @param {Object} [options] An object containing options on the save process. */ -// Dann.prototype.save = function save(name, options) { -// let path; -// let overwritten = false; -// let report = false; -// let result = 0; -// let rstr = 'none'; -// //options -// if (options !== undefined) { -// if (options.report !== undefined) { -// report = options.report; -// } -// if (options.test !== undefined) { -// if (typeof options.test === 'function') { -// let testfunc = options.test; -// result = testfunc() * 100; -// rstr = result + '%'; -// } else { -// console.error('Dann Error: the test option can only be a function.'); -// console.trace(); -// } -// } -// } -// let dataOBJ = this.dataObject(); - -// if (isBrowser) { -// downloadSTR(dataOBJ, name); -// } else { -// path = './savedDanns/' + name + '/dannData.json'; -// if (fs.existsSync(path)) { -// overwritten = true; -// } -// if (!fs.existsSync('./savedDanns')) { -// fs.mkdirSync('./savedDanns'); -// } -// if (!fs.existsSync('./savedDanns/' + name)) { -// fs.mkdirSync('./savedDanns/' + name); -// } -// if (report === true) { -// let acts = []; -// for (let i = 1; i < this.arch.length; i++) { -// acts[i - 1] = this.Layers[i].actname; -// } -// let csvFile = []; -// csvFile.push(['Dann', 'train report']); -// csvFile.push(['Arch: ', this.arch]); -// csvFile.push(['Acts: ', acts]); -// csvFile.push(['Lr: ', this.lr]); -// csvFile.push(['Epoch:', this.epoch]); - -// if (typeof options.test === 'function') { -// csvFile.push(['Accuracy:', rstr]); -// } -// csvFile.push(['Index', 'AvgLoss']); -// for (let i = 0; i < this.losses.length; i++) { -// csvFile.push([i + 1, this.losses[i]]); -// } - -// w.writeToPath('./savedDanns/' + name + '/report.csv', csvFile) -// .on('error', (err) => console.error(err)) -// .on('finish', () => -// console.log( -// 'saved training report at ' + './savedDanns/' + name + '/report.csv' -// ) -// ); -// } - -// fs.writeFileSync(path, JSON.stringify(dataOBJ)); -// if (overwritten === true) { -// console.log('\x1b[32m', ''); -// this.log(); -// console.log( -// 'Succesfully overwritten the Dann Model at ./savedDanns/' + -// name + -// '/dannData.json ' -// ); -// console.log('\x1b[0m', ''); -// } else { -// console.log('\x1b[32m', ''); -// this.log(); -// console.log( -// 'Succesfully saved the Dann Model at ./savedDanns/' + -// name + -// '/dannData.json ' -// ); -// console.log('\x1b[0m', ''); -// } -// } -// }; /** * @module Dann @@ -2999,9 +2869,9 @@ Dann.prototype.fromJSON = function fromJSON(data) { * const nn = new Dann(4, 4); * nn.addHiddenLayer(8); * nn.makeWeights(); - * let stringFunction = nn.toFunction(); + * * // Copy & paste the string function! - * console.log(stringFunction); + * console.log(nn.toFunction()); * */ Dann.prototype.toFunction = function toFunction(name = 'myDannFunction') { @@ -3146,7 +3016,7 @@ function minify(string) { * Detect if a function is an ES6 function. */ function isES6(fn) { - let s = fn.match(/([a-z]=>).*/gm); + let s = fn.match(/([a-z] {0,1}=> {0,1}).*/gm); if (s !== null) return true; return false; } @@ -3158,7 +3028,7 @@ function toES6(fn) { if (isES6(fn)) return fn; let args = fn.match(/\(.*?\)/gm)[0]; - let matches = fn.split('\n').join('').match(/{.*?}/); + let matches = fn.match(/{.*?}/); let implementation = ''; if (matches !== null) { diff --git a/build/dann.min.js b/build/dann.min.js index 6f3a2f92..054189f3 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.1c";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{t=t.replace(e,r)})),t}function minify(t){return t=matchReplace(t,/ = /g,"="),t=matchReplace(t,/ \+ /g,"+"),t=matchReplace(t,/ - /g,"-"),t=matchReplace(t,/ \* /g,"*"),t=matchReplace(t,/ \/ /g,"/"),t=matchReplace(t,/for \(/g,"for("),t=matchReplace(t,/; /g,";"),t=matchReplace(t,/\) {/g,"){"),t=matchReplace(t,/ < /g,"<"),t=matchReplace(t,/ > /g,">"),t=matchReplace(t,/ \+= /g,"+="),t=matchReplace(t,/;\}/g,"}"),t=matchReplace(t,/\{ /g,"{"),t=matchReplace(t,/ \{/g,"{"),t=matchReplace(t,/\} /g,"}"),t=matchReplace(t,/\t/g,""),t=matchReplace(t,/\n/g,""),t=matchReplace(t,/; /g,";"),t=matchReplace(t,/[ ]{2,}/g," ")}function isES6(t){return null!==t.match(/([a-z]=>).*/gm)}function toES6(t){if(isES6(t))return t;let e=t.match(/\(.*?\)/gm)[0],r=t.split("\n").join("").match(/{.*?}/),i="";return null!==r?i=r[0].trimEnd().trimStart():DannError.error("Something went wrong, we couldn't find the function definition. ","toFunction call to toES6"),i=matchReplace(i,/{ /g,"{"),i=matchReplace(i,/ }/g,"}"),`${e}=>${i}`}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),n=Matrix.mult(this.gradients[0],o);void 0!==r.dropout&&(n=n.mult(this.dropout[0])),this.weights[0].add(n),this.biases[0].add(this.gradients[0]),this.loss=this.lossfunc(this.outs,e,this.percentile),!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{t=t.replace(e,r)})),t}function minify(t){return t=matchReplace(t,/ = /g,"="),t=matchReplace(t,/ \+ /g,"+"),t=matchReplace(t,/ - /g,"-"),t=matchReplace(t,/ \* /g,"*"),t=matchReplace(t,/ \/ /g,"/"),t=matchReplace(t,/for \(/g,"for("),t=matchReplace(t,/; /g,";"),t=matchReplace(t,/\) {/g,"){"),t=matchReplace(t,/ < /g,"<"),t=matchReplace(t,/ > /g,">"),t=matchReplace(t,/ \+= /g,"+="),t=matchReplace(t,/;\}/g,"}"),t=matchReplace(t,/\{ /g,"{"),t=matchReplace(t,/ \{/g,"{"),t=matchReplace(t,/\} /g,"}"),t=matchReplace(t,/\t/g,""),t=matchReplace(t,/\n/g,""),t=matchReplace(t,/; /g,";"),t=matchReplace(t,/[ ]{2,}/g," ")}function isES6(t){return null!==t.match(/([a-z] {0,1}=> {0,1}).*/gm)}function toES6(t){if(isES6(t))return t;let e=t.match(/\(.*?\)/gm)[0],r=t.match(/{.*?}/),i="";return null!==r?i=r[0].trimEnd().trimStart():DannError.error("Something went wrong, we couldn't find the function definition. ","toFunction call to toES6"),i=matchReplace(i,/{ /g,"{"),i=matchReplace(i,/ }/g,"}"),`${e}=>${i}`}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),n=Matrix.mult(this.gradients[0],o);void 0!==r.dropout&&(n=n.mult(this.dropout[0])),this.weights[0].add(n),this.biases[0].add(this.gradients[0]),this.loss=this.lossfunc(this.outs,e,this.percentile),!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;eInstallation

CDN :

-
<script src="https://cdn.jsdelivr.net/gh/matiasvlevi/dann@v2.4.1c/build/dann.min.js"></script>
+
<script src="https://cdn.jsdelivr.net/gh/matiasvlevi/dann@v2.4.1d/build/dann.min.js"></script>

Node :

npm i dannjs

dannjs on npmjs.com

diff --git a/gruntfile.js b/gruntfile.js index c0264442..3c34f326 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -58,10 +58,12 @@ module.exports = (grunt) => { }, terser: { src: { - files: [{ - src: 'build/dann.js', - dest: 'build/dann.min.js', - }, ], + files: [ + { + src: 'build/dann.js', + dest: 'build/dann.min.js', + }, + ], }, }, clean: { @@ -87,8 +89,8 @@ module.exports = (grunt) => { }, makechangelog: { targets: { - path: 'CHANGES.md' - } + path: 'CHANGES.md', + }, }, yuidoc: { compile: { @@ -113,10 +115,12 @@ module.exports = (grunt) => { }, rename: { main: { - files: [{ - src: ['docs/documentation/markdown/README.html'], - dest: 'docs/' + theme + '/partials/readme.handlebars', - }, ], + files: [ + { + src: ['docs/documentation/markdown/README.html'], + dest: 'docs/' + theme + '/partials/readme.handlebars', + }, + ], }, }, sampleTest: { @@ -138,15 +142,18 @@ module.exports = (grunt) => { 'docs/documentation/classes/*.html', ], overwrite: true, - replacements: [{ - from: /
  • Add<\/a><\/li>/gm, - to: '', - }, ], + replacements: [ + { + from: /
  • Add<\/a><\/li>/gm, + to: '', + }, + ], }, index: { src: ['docs/documentation/*.html'], overwrite: true, - replacements: [{ + replacements: [ + { from: /\.\.\/index\.html/gm, to: '/', }, @@ -159,15 +166,18 @@ module.exports = (grunt) => { constant: { src: ['src/io/head.js'], overwrite: true, - replacements: [{ - from: /VERSION = '.*'/gm, - to: "VERSION = 'v<%= grunt.option('ver') %>'", - }, ], + replacements: [ + { + from: /VERSION = '.*'/gm, + to: "VERSION = 'v<%= grunt.option('ver') %>'", + }, + ], }, version: { src: ['package.json'], overwrite: true, - replacements: [{ + replacements: [ + { from: /"_id": "dannjs@.*"/gm, to: '"_id": "dannjs@<%= grunt.option("ver") %>"', }, @@ -180,31 +190,38 @@ module.exports = (grunt) => { testversion: { src: ['test/manual-tests/browser/*/*.html'], overwrite: true, - replacements: [{ - from: /.*<\/span>/gm, - to: '<%= grunt.option("ver")%>', - }, ], + replacements: [ + { + from: /.*<\/span>/gm, + to: '<%= grunt.option("ver")%>', + }, + ], }, readmeversion: { src: ['README.md'], overwrite: true, - replacements: [{ - from: /dann@v.*\/build/gm, - to: 'dann@v<%= grunt.option("ver") %>/build', - }, ], + replacements: [ + { + from: /dann@v.*\/build/gm, + to: 'dann@v<%= grunt.option("ver") %>/build', + }, + ], }, hljsdocs: { src: ['docs/documentation/classes/*.html'], overwrite: true, - replacements: [{ - from: /\.\.\/highlight\/hljs\.min\.js/gm, - to: '../../highlight/hljs.min.js', - }, ], + replacements: [ + { + from: /\.\.\/highlight\/hljs\.min\.js/gm, + to: '../../highlight/hljs.min.js', + }, + ], }, hljsdocsIndex: { src: ['docs/documentation/index.html'], overwrite: true, - replacements: [{ + replacements: [ + { from: /\.\.\/assets\//gm, to: './assets/', }, @@ -245,20 +262,20 @@ module.exports = (grunt) => { 'formatExamples', 'clean:unused', 'replace:addClass', - 'replace:hljsdocsIndex' + 'replace:hljsdocsIndex', ]); grunt.registerTask('tag', [ 'replace:version', 'replace:testversion', 'replace:readmeversion', 'replace:constant', - 'build-fix' + 'build-fix', ]); grunt.registerTask('test', [ 'doc-compile', 'build-unit', 'sampleTest:samples', - 'mochaTest:test' + 'mochaTest:test', ]); grunt.registerTask('prod', ['build-fix', 'doc-compile', 'test']); -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 4d37b11a..7a77d0a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "_from": "dannjs", - "_id": "dannjs@2.4.1c", + "_id": "dannjs@2.4.1d", "_inBundle": false, "_integrity": "sha512-+Do7tE1EtLn/UMqyIy0V6dgLo43Wq6tj2vAY8oZTMHAY+ysYLJ2sT32H9DgZViL/B59XTIKN6BO8WEbn5pv8XA==", "_location": "/dannjs", @@ -56,7 +56,7 @@ "doc-server": "node docs/serve.js", "makechangelog": "grunt makechangelog" }, - "version": "2.4.1c", + "version": "2.4.1d", "keywords": [ "dann", "dannjs", diff --git a/src/classes/dann/methods/Share/load.js b/src/classes/dann/methods/Share/load.js index 2bb09c55..b1036688 100644 --- a/src/classes/dann/methods/Share/load.js +++ b/src/classes/dann/methods/Share/load.js @@ -15,45 +15,3 @@ * @param {String} name The name of the saved directory that holds the dann model. * @param {Function} arg2 A function to be called when the model finished loading. */ -// Dann.prototype.load = function load(name, arg2, arg3) { -// if (isBrowser) { -// upload(name, arg2, arg3); -// } else { -// let path = './savedDanns/' + name + '/dannData.json'; -// if (fs.existsSync(path)) { -// let text = fs.readFileSync(path, 'utf8'); -// let xdata = JSON.parse(text); - -// let newNN = xdata; -// this.applyToModel(newNN); -// if (typeof arg2 === 'function') { -// arg2(false); -// } else { -// let type = typeof arg2; -// DannError.error( -// "callback specified is not a function, the function recieved a '" + -// type + -// "' instead", -// 'Dann.prototype.load' -// ); -// return; -// } -// } else { -// if (typeof arg2 === 'function') { -// arg2(true); -// } else if (typeof arg2 !== 'function') { -// let type = typeof arg2; -// DannError.error( -// 'Callback specified is not a function, the function recieved a ' + -// type + -// ' instead', -// 'Dann.prototype.load' -// ); -// return; -// } else { -// DannError.error('File not found', 'Dann.prototype.load'); -// return; -// } -// } -// } -// }; diff --git a/src/classes/dann/methods/Share/save.js b/src/classes/dann/methods/Share/save.js index 98fa72cb..ccad87f3 100644 --- a/src/classes/dann/methods/Share/save.js +++ b/src/classes/dann/methods/Share/save.js @@ -15,91 +15,3 @@ * @param {String} name The name of the json file. * @param {Object} [options] An object containing options on the save process. */ -// Dann.prototype.save = function save(name, options) { -// let path; -// let overwritten = false; -// let report = false; -// let result = 0; -// let rstr = 'none'; -// //options -// if (options !== undefined) { -// if (options.report !== undefined) { -// report = options.report; -// } -// if (options.test !== undefined) { -// if (typeof options.test === 'function') { -// let testfunc = options.test; -// result = testfunc() * 100; -// rstr = result + '%'; -// } else { -// console.error('Dann Error: the test option can only be a function.'); -// console.trace(); -// } -// } -// } -// let dataOBJ = this.dataObject(); - -// if (isBrowser) { -// downloadSTR(dataOBJ, name); -// } else { -// path = './savedDanns/' + name + '/dannData.json'; -// if (fs.existsSync(path)) { -// overwritten = true; -// } -// if (!fs.existsSync('./savedDanns')) { -// fs.mkdirSync('./savedDanns'); -// } -// if (!fs.existsSync('./savedDanns/' + name)) { -// fs.mkdirSync('./savedDanns/' + name); -// } -// if (report === true) { -// let acts = []; -// for (let i = 1; i < this.arch.length; i++) { -// acts[i - 1] = this.Layers[i].actname; -// } -// let csvFile = []; -// csvFile.push(['Dann', 'train report']); -// csvFile.push(['Arch: ', this.arch]); -// csvFile.push(['Acts: ', acts]); -// csvFile.push(['Lr: ', this.lr]); -// csvFile.push(['Epoch:', this.epoch]); - -// if (typeof options.test === 'function') { -// csvFile.push(['Accuracy:', rstr]); -// } -// csvFile.push(['Index', 'AvgLoss']); -// for (let i = 0; i < this.losses.length; i++) { -// csvFile.push([i + 1, this.losses[i]]); -// } - -// w.writeToPath('./savedDanns/' + name + '/report.csv', csvFile) -// .on('error', (err) => console.error(err)) -// .on('finish', () => -// console.log( -// 'saved training report at ' + './savedDanns/' + name + '/report.csv' -// ) -// ); -// } - -// fs.writeFileSync(path, JSON.stringify(dataOBJ)); -// if (overwritten === true) { -// console.log('\x1b[32m', ''); -// this.log(); -// console.log( -// 'Succesfully overwritten the Dann Model at ./savedDanns/' + -// name + -// '/dannData.json ' -// ); -// console.log('\x1b[0m', ''); -// } else { -// console.log('\x1b[32m', ''); -// this.log(); -// console.log( -// 'Succesfully saved the Dann Model at ./savedDanns/' + -// name + -// '/dannData.json ' -// ); -// console.log('\x1b[0m', ''); -// } -// } -// }; diff --git a/src/classes/dann/methods/Share/toFunction.js b/src/classes/dann/methods/Share/toFunction.js index e4d15185..43381930 100644 --- a/src/classes/dann/methods/Share/toFunction.js +++ b/src/classes/dann/methods/Share/toFunction.js @@ -12,9 +12,9 @@ * const nn = new Dann(4, 4); * nn.addHiddenLayer(8); * nn.makeWeights(); - * let stringFunction = nn.toFunction(); + * * // Copy & paste the string function! - * console.log(stringFunction); + * console.log(nn.toFunction()); * */ Dann.prototype.toFunction = function toFunction(name = 'myDannFunction') { @@ -159,7 +159,7 @@ function minify(string) { * Detect if a function is an ES6 function. */ function isES6(fn) { - let s = fn.match(/([a-z]=>).*/gm); + let s = fn.match(/([a-z] {0,1}=> {0,1}).*/gm); if (s !== null) return true; return false; } @@ -171,7 +171,7 @@ function toES6(fn) { if (isES6(fn)) return fn; let args = fn.match(/\(.*?\)/gm)[0]; - let matches = fn.split('\n').join('').match(/{.*?}/); + let matches = fn.match(/{.*?}/); let implementation = ''; if (matches !== null) { diff --git a/src/io/head.js b/src/io/head.js index 8b07bbb1..283f830f 100644 --- a/src/io/head.js +++ b/src/io/head.js @@ -1,3 +1,3 @@ /*! Dann.js */ const isBrowser = typeof process !== 'object'; -const VERSION = 'v2.4.1c'; +const VERSION = 'v2.4.1d'; diff --git a/test/manual-tests/browser/binarycount-example/browser.html b/test/manual-tests/browser/binarycount-example/browser.html index 1d24409d..10fe2c77 100644 --- a/test/manual-tests/browser/binarycount-example/browser.html +++ b/test/manual-tests/browser/binarycount-example/browser.html @@ -9,7 +9,7 @@
    -

    Dannjs

    2.4.1c +

    Dannjs

    2.4.1d

    Browser Test

    diff --git a/test/manual-tests/browser/empty-example/browser.html b/test/manual-tests/browser/empty-example/browser.html index b97c52f1..e52b19ed 100644 --- a/test/manual-tests/browser/empty-example/browser.html +++ b/test/manual-tests/browser/empty-example/browser.html @@ -9,7 +9,7 @@
    -

    Dannjs

    2.4.1c +

    Dannjs

    2.4.1d

    Browser Test

    diff --git a/test/manual-tests/browser/xor-example/browser.html b/test/manual-tests/browser/xor-example/browser.html index 1d24409d..10fe2c77 100644 --- a/test/manual-tests/browser/xor-example/browser.html +++ b/test/manual-tests/browser/xor-example/browser.html @@ -9,7 +9,7 @@
    -

    Dannjs

    2.4.1c +

    Dannjs

    2.4.1d

    Browser Test