sakuya/node_modules/neataptic/mkdocs/theme/cdn/1.2.24/neataptic.min.js
2022-04-10 00:37:53 +08:00

27 lines
42 KiB
JavaScript

/*!
* The MIT License (MIT)
*
* Copyright 2017 Thomas Wagenaar <wagenaartje@protonmail.com>. Copyright for
* portions of Neataptic are held by Copyright 2017 Juan Cazala - cazala.com, as a
* part of project Synaptic.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE
*
*/
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.neataptic=n():t.neataptic=n()}(this,function(){return function(t){function n(e){if(o[e])return o[e].exports;var i=o[e]={i:e,l:!1,exports:{}};return t[e].call(i.exports,i,i.exports,n),i.l=!0,i.exports}var o={};return n.m=t,n.c=o,n.i=function(t){return t},n.d=function(t,o,e){n.o(t,o)||Object.defineProperty(t,o,{configurable:!1,enumerable:!0,get:e})},n.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(o,"a",o),o},n.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},n.p="",n(n.s=18)}([function(t,n){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,n,o){var e,i,s={Activation:o(10),Mutation:o(15),Selection:o(17),Crossover:o(13),Cost:o(12),Gating:o(14),Connection:o(11),Rate:o(16)};e=[],void 0!==(i=function(){return s}.apply(n,e))&&(t.exports=i),void 0!==t&&t.exports&&(t.exports=s),"object"==typeof window&&(!function(){var t=window.methods;s.ninja=function(){return window.methods=t,s}}(),window.methods=s)},function(t,n,o){(function(t){function n(t){this.bias="input"==t?0:.2*Math.random()-.1,this.squash=r.LOGISTIC,this.type=t||"hidden",this.activation=0,this.state=0,this.old=0,this.mask=1,this.previousDeltaBias=0,this.connections={in:[],out:[],gated:[],self:new e(this,this,0)},this.error={responsibility:0,projected:0,gated:0}}t&&(t.exports=n);var e=o(4),i=o(1),s=(o(5),o(3)),r=i.Activation,a=i.Mutation;n.prototype={activate:function(t){if(void 0!==t)return this.activation=t,this.activation;this.old=this.state,this.state=this.connections.self.gain*this.connections.self.weight*this.state+this.bias;for(var n=0;n<this.connections.in.length;n++){var o=this.connections.in[n];this.state+=o.from.activation*o.weight*o.gain}this.activation=this.squash(this.state)*this.mask,this.derivative=this.squash(this.state,!0);for(var e=[],i=[],n=0;n<this.connections.gated.length;n++){var s=this.connections.gated[n],r=s.to,a=e.indexOf(r);a>-1?i[a]+=s.weight*s.from.activation:(e.push(r),i.push(s.weight*s.from.activation+(r.connections.self.gater==this?r.old:0))),s.gain=this.activation}for(var n=0;n<this.connections.in.length;n++){var o=this.connections.in[n];o.elegibility=this.connections.self.gain*this.connections.self.weight*o.elegibility+o.from.activation*o.gain;for(var c=0;c<e.length;c++){var r=e[c],h=i[c],a=o.xtrace.nodes.indexOf(r);a>-1?o.xtrace.values[a]=r.connections.self.gain*r.connections.self.weight*o.xtrace.values[a]+this.derivative*o.elegibility*h:(o.xtrace.nodes.push(r),o.xtrace.values.push(this.derivative*o.elegibility*h))}}return this.activation},propagate:function(t,n,o){n=n||0,t=t||.3;var e=0;if("output"==this.type)this.error.responsibility=this.error.projected=o-this.activation;else{for(var i=0;i<this.connections.out.length;i++){var s=this.connections.out[i],r=s.to;e+=r.error.responsibility*s.weight*s.gain}this.error.projected=this.derivative*e,e=0;for(var i=0;i<this.connections.gated.length;i++){var a=this.connections.gated[i],r=a.to,c=r.connections.self.gater==this?r.old:0;c+=a.weight*a.from.activation,e+=r.error.responsibility*c}this.error.gated=this.derivative*e,this.error.responsibility=this.error.projected+this.error.gated}if("constant"!=this.type){for(var i=0;i<this.connections.in.length;i++){for(var s=this.connections.in[i],h=this.error.projected*s.elegibility,u=0;u<s.xtrace.nodes.length;u++){var r=s.xtrace.nodes[u],f=s.xtrace.values[u];h+=r.error.responsibility*f}var l=t*h*this.mask+n*s.previousDeltaWeight;s.weight+=l,s.previousDeltaWeight=l}var p=t*this.error.responsibility+n*this.previousDeltaBias;this.bias+=p,this.previousDeltabias=p}},connect:function(t,n){var o=[];if(void 0!==t.bias)if(t==this)0!=this.connections.self.weight?s.warnings&&console.warn("This connection already exists!"):this.connections.self.weight=n||1,o.push(this.connections.self);else{if(this.isProjectingTo(t))throw new Error("Already projecting a connection to this node!");var i=new e(this,t,n);t.connections.in.push(i),this.connections.out.push(i),o.push(i)}else for(var r=0;r<t.nodes.length;r++){var i=new e(this,t.nodes[r],n);t.nodes[r].connections.in.push(i),this.connections.out.push(i),t.connections.in.push(i),o.push(i)}return o},disconnect:function(t,n){if(this==t)return void(this.connections.self.weight=0);for(var o=0;o<this.connections.out.length;o++){var e=this.connections.out[o];if(e.to==t){this.connections.out.splice(o,1);var i=e.to.connections.in.indexOf(e);e.to.connections.in.splice(i,1),null!=e.gater&&this.ungate(e);break}}n&&t.disconnect(this)},gate:function(t){Array.isArray(t)||(t=[t]);for(var n=0;n<t.length;n++){var o=t[n];this.connections.gated.push(o),o.gater=this}},ungate:function(t){Array.isArray(t)||(t=[t]);for(var n=t.length-1;n>=0;n--){var o=t[n],e=this.connections.gated.indexOf(o);this.connections.gated.splice(e,1),o.gater=null}},clear:function(){for(var t=0;t<this.connections.in.length;t++){var n=this.connections.in[t];n.elegibility=0,n.xtrace={nodes:[],values:[]}}this.error.responsibility=this.error.projected=this.error.gated=0,this.old=this.state=this.activation=0},mutate:function(t){if(void 0===t)throw new Error("No mutate method given!");if(!t.name in i.Mutation)throw new Error("This method does not exist!");switch(t){case a.MOD_ACTIVATION:var n=t.allowed[(t.allowed.indexOf(this.squash)+Math.floor(Math.random()*(t.allowed.length-1))+1)%t.allowed.length];this.squash=n;break;case a.MOD_BIAS:var o=Math.random()*(t.max-t.min)+t.min;this.bias+=o}},isProjectingTo:function(t){for(var n=0;n<this.connections.out.length;n++){if(this.connections.out[n].to==t)return!0}return t==this&&0!=this.connections.self.weight},isProjectedBy:function(t){for(var n=0;n<this.connections.in.length;n++){if(this.connections.in[n].from==t)return!0}return t==this&&0!=this.connections.self.weight},toJSON:function(){return{bias:this.bias,type:this.type,squash:this.squash.name,mask:this.mask}}},n.fromJSON=function(t){var o=new n;o.bias=t.bias,o.type=t.type,o.mask=t.mask;for(squash in r)if(r[squash].name==t.squash){o.squash=r[squash];break}return o}}).call(n,o(0)(t))},function(t,n,o){(function(t){var n={warnings:!0};t&&(t.exports=n)}).call(n,o(0)(t))},function(t,n,o){(function(t){function n(t,n,o){this.from=t,this.to=n,this.gain=1,this.weight=void 0===o?.2*Math.random()-.1:o,this.gater=null,this.elegibility=0,this.previousDeltaWeight=0,this.xtrace={nodes:[],values:[]}}t&&(t.exports=n),n.prototype={toJSON:function(){return{weight:this.weight}}},n.innovationID=function(t,n){return.5*(t+n)*(t+n+1)+n}}).call(n,o(0)(t))},function(t,n,o){(function(t){function n(t){this.nodes=[],this.connections={in:[],out:[],self:[]};for(var n=0;n<t;n++)this.nodes.push(new i)}t&&(t.exports=n);var e=o(1),i=(o(4),o(2)),s=o(3),r=o(6);e.Activation,e.Mutation;n.prototype={activate:function(t){var n=[];if(void 0!==t&&t.length!=this.nodes.length)throw new Error("Array with values should be same as the amount of nodes!");for(var o=0;o<this.nodes.length;o++){if(void 0===t)var e=this.nodes[o].activate();else var e=this.nodes[o].activate(t[o]);n.push(e)}return n},propagate:function(t,n,o){if(void 0!==o&&o.length!=this.nodes.length)throw new Error("Array with values should be same as the amount of nodes!");for(var e=this.nodes.length-1;e>=0;e--)void 0===o?this.nodes[e].propagate(t,n):this.nodes[e].propagate(t,n,o[e])},connect:function(t,o,a){var c=[];if(t instanceof n){if(void 0===o&&(this!=t?(s.warnings&&console.warn("No group connection specified, using ALL_TO_ALL"),o=e.Connection.ALL_TO_ALL):(s.warnings&&console.warn("No group connection specified, using ONE_TO_ONE"),o=e.Connection.ONE_TO_ONE)),o==e.Connection.ALL_TO_ALL||o==e.Connection.ALL_TO_ELSE){for(var h=0;h<this.nodes.length;h++)for(var u=0;u<t.nodes.length;u++)if(o!=e.Connection.ALL_TO_ELSE||this.nodes[h]!=t.nodes[u]){var f=this.nodes[h].connect(t.nodes[u],a);this.connections.out.push(f[0]),t.connections.in.push(f[0]),c.push(f[0])}}else if(o==e.Connection.ONE_TO_ONE){if(this.nodes.length!=t.nodes.length)throw new Error("From and To group must be the same size!");for(var h=0;h<this.nodes.length;h++){var f=this.nodes[h].connect(t.nodes[h],a);this.connections.self.push(f[0]),c.push(f[0])}}}else if(t instanceof r)var c=t.input(this,o,a);else if(t instanceof i)for(var h=0;h<this.nodes.length;h++){var f=this.nodes[h].connect(t,a);this.connections.out.push(f[0]),c.push(f[0])}return c},gate:function(t,n){if(void 0===n)throw new Error("Please specify Gating.INPUT, Gating.OUTPUT");Array.isArray(t)||(t=[t]);var o=[],i=[];for(var s in t)s=t[s],o.includes(s.from)||o.push(s.from),i.includes(s.to)||i.push(s.to);switch(n){case e.Gating.INPUT:for(var r=0;r<i.length;r++){var a=i[r],c=this.nodes[r%this.nodes.length];for(var h in a.connections.in)h=a.connections.in[h],t.includes(h)&&c.gate(h)}break;case e.Gating.OUTPUT:for(var r=0;r<o.length;r++){var a=o[r],c=this.nodes[r%this.nodes.length];for(var h in a.connections.out)h=a.connections.out[h],t.includes(h)&&c.gate(h)}break;case e.Gating.SELF:for(var r=0;r<o.length;r++){var a=o[r],c=this.nodes[r%this.nodes.length];t.includes(a.connections.self)&&c.gate(a.connections.self)}}},set:function(t){for(var n in this.nodes)void 0!==t.bias&&(this.nodes[n].bias=t.bias),this.nodes[n].squash=t.squash||this.nodes[n].squash,this.nodes[n].type=t.type||this.nodes[n].type},disconnect:function(t,o){if(o=o||!1,t instanceof n)for(var e=0;e<this.nodes.length;e++)for(var s=0;s<t.nodes.length;s++){this.nodes[e].disconnect(t.nodes[s],o);for(index in this.connections.out){var r=this.connections.out[index];if(r.from==this.nodes[e]&&r.to==t.nodes[s]){this.connections.out.splice(index,1);break}}if(o)for(index in this.connections.in){var r=this.connections.in[index];if(r.from==t.nodes[s]&&r.to==this.nodes[e]){this.connections.in.splice(index,1);break}}}else if(t instanceof i)for(var e=0;e<this.nodes.length;e++){this.nodes[e].disconnect(t,o);for(index in this.connections.out){var r=this.connections.out[index];if(r.from==this.nodes[e]&&r.to==t){this.connections.out.splice(index,1);break}}if(o)for(index in this.connections.in){var r=this.connections.in[index];if(r.from==t&&r.to==this.nodes[e]){this.connections.in.splice(index,1);break}}}},clear:function(){for(var t in this.nodes)this.nodes[t].clear()}}}).call(n,o(0)(t))},function(t,n,o){(function(t){function n(){this.output=null,this.nodes=[],this.connections={in:[],out:[],self:[]}}t&&(t.exports=n);var e=o(1),i=(o(4),o(2)),s=(o(3),o(8),o(5));e.Activation,e.Mutation;n.prototype={activate:function(t){var n=[];if(void 0!==t&&t.length!=this.nodes.length)throw new Error("Array with values should be same as the amount of nodes!");for(var o=0;o<this.nodes.length;o++){if(void 0===t)var e=this.nodes[o].activate();else var e=this.nodes[o].activate(t[o]);n.push(e)}return n},propagate:function(t,n,o){if(void 0!==o&&o.length!=this.nodes.length)throw new Error("Array with values should be same as the amount of nodes!");for(var e=this.nodes.length-1;e>=0;e--)void 0===o?this.nodes[e].propagate(t,n):this.nodes[e].propagate(t,n,o[e])},connect:function(t,o,e){if(t instanceof s||t instanceof i)var r=this.output.connect(t,o,e);else if(t instanceof n)var r=t.input(this,o,e);return r},gate:function(t,n){this.output.gate(t,n)},set:function(t){for(var n in this.nodes)n=this.nodes[n],n instanceof i?(void 0!==t.bias&&(n.bias=t.bias),n.squash=t.squash||n.squash,n.type=t.type||n.type):n instanceof s&&n.set(t)},disconnect:function(t,n){if(n=n||!1,t instanceof s)for(var o=0;o<this.nodes.length;o++)for(var e=0;e<t.nodes.length;e++){this.nodes[o].disconnect(t.nodes[e],n);for(index in this.connections.out){var r=this.connections.out[index];if(r.from==this.nodes[o]&&r.to==t.nodes[e]){this.connections.out.splice(index,1);break}}if(n)for(index in this.connections.in){var r=this.connections.in[index];if(r.from==t.nodes[e]&&r.to==this.nodes[o]){this.connections.in.splice(index,1);break}}}else if(t instanceof i)for(var o=0;o<this.nodes.length;o++){this.nodes[o].disconnect(t,n);for(index in this.connections.out){var r=this.connections.out[index];if(r.from==this.nodes[o]&&r.to==t){this.connections.out.splice(index,1);break}}if(n)for(index in this.connections.in){var r=this.connections.in[index];if(r.from==t&&r.to==this.nodes[o]){this.connections.in.splice(index,1);break}}}},clear:function(){for(var t in this.nodes)this.nodes[t].clear()}},n.Dense=function(t){var o=new n,i=new s(t);return o.nodes.push(i),o.output=i,o.input=function(t,o,s){return t instanceof n&&(t=t.output),o=o||e.Connection.ALL_TO_ALL,t.connect(i,o,s)},o},n.LSTM=function(t){var o=new n,i=new s(t),r=new s(t),a=new s(t),c=new s(t),h=new s(t);i.set({bias:1}),r.set({bias:1}),c.set({bias:1}),a.connect(i,e.Connection.ALL_TO_ALL),a.connect(r,e.Connection.ALL_TO_ALL),a.connect(c,e.Connection.ALL_TO_ALL);var u=a.connect(a,e.Connection.ONE_TO_ONE),f=a.connect(h,e.Connection.ALL_TO_ALL);return r.gate(u,e.Gating.SELF),c.gate(f,e.Gating.OUTPUT),o.nodes=[i,r,a,c,h],o.output=h,o.input=function(t,o,s){t instanceof n&&(t=t.output),o=o||e.Connection.ALL_TO_ALL;var h=[],u=t.connect(a,o,s);return h=h.concat(u),h=h.concat(t.connect(i,o,s)),h=h.concat(t.connect(c,o,s)),h=h.concat(t.connect(r,o,s)),i.gate(u,e.Gating.INPUT),h},o},n.GRU=function(t){var o=new n,i=new s(t),r=new s(t),a=new s(t),c=new s(t),h=new s(t),u=new s(t);u.set({bias:0,squash:e.Activation.IDENTITY,type:"constant"}),c.set({squash:e.Activation.TANH}),r.set({bias:0,squash:e.Activation.INVERSE,type:"constant"}),i.set({bias:1}),a.set({bias:0}),u.connect(i,e.Connection.ALL_TO_ALL),i.connect(r,e.Connection.ONE_TO_ONE,1),u.connect(a,e.Connection.ALL_TO_ALL);var f=u.connect(c,e.Connection.ALL_TO_ALL);a.gate(f,e.Gating.OUTPUT);var l=u.connect(h,e.Connection.ALL_TO_ALL),p=c.connect(h,e.Connection.ALL_TO_ALL);return i.gate(l,e.Gating.OUTPUT),r.gate(p,e.Gating.OUTPUT),h.connect(u,e.Connection.ONE_TO_ONE,1),o.nodes=[i,r,a,c,h,u],o.output=h,o.input=function(t,o,s){t instanceof n&&(t=t.output),o=o||e.Connection.ALL_TO_ALL;var r=[];return r=r.concat(t.connect(i,o,s)),r=r.concat(t.connect(a,o,s)),r=r.concat(t.connect(c,o,s))},o},n.Memory=function(t,o){for(var i=new n,r=null,a=0;a<o;a++){var c=new s(t);c.set({squash:e.Activation.IDENTITY,bias:0,type:"constant"}),null!=r&&r.connect(c,e.Connection.ONE_TO_ONE,1),i.nodes.push(c),r=c}i.nodes.reverse();for(var h in i.nodes)i.nodes[h].nodes.reverse();var u=new s(0);for(var h in i.nodes)u.nodes=u.nodes.concat(i.nodes[h].nodes);return i.output=u,i.input=function(t,o,s){if(t instanceof n&&(t=t.output),o=o||e.Connection.ALL_TO_ALL,t.nodes.length!=i.nodes[i.nodes.length-1].nodes.length)throw new Error("Previous layer size must be same as memory size");return t.connect(i.nodes[i.nodes.length-1],e.Connection.ONE_TO_ONE,1)},i}}).call(n,o(0)(t))},function(t,n,o){(function(t){function n(t,n){if(void 0===t||void 0===n)throw new Error("No input or output size given");this.input=t,this.output=n,this.nodes=[],this.connections=[],this.gates=[],this.selfconns=[],this.dropout=0;for(var o=0;o<this.input+this.output;o++){var i=o<this.input?"input":"output";this.nodes.push(new e(i,this.nodes.length))}for(var o=0;o<this.input;o++)for(var s=this.input;s<this.output+this.input;s++){var r=Math.random()*this.input*Math.sqrt(2/this.input);this.connect(this.nodes[o],this.nodes[s],r)}}t&&(t.exports=n);var e=o(2),i=o(4),s=o(1),r=o(3),a=o(9),c=(s.Activation,s.Mutation);n.prototype={activate:function(t,n){for(var o=[],e=0;e<this.nodes.length;e++)if("input"==this.nodes[e].type)this.nodes[e].activate(t[e]);else if("output"==this.nodes[e].type){var i=this.nodes[e].activate();o.push(i)}else n&&(this.nodes[e].mask=Math.random()<this.dropout?0:1),this.nodes[e].activate();return o},propagate:function(t,n,o){if(void 0!==o&&o.length!=this.output)throw new Error("Output target length should match network output length");for(var e=o.length,i=this.nodes.length-1;i>=this.nodes.length-this.output;i--)this.nodes[i].propagate(t,n,o[--e]);for(var i=this.nodes.length-this.output-1;i>=this.input;i--)this.nodes[i].propagate(t,n)},clear:function(){for(var t=0;t<this.nodes.length;t++)this.nodes[t].clear()},connect:function(t,n,o){for(var e=t.connect(n,o),i=0;i<e.length;i++){var s=e[i];t!=n?this.connections.push(s):this.selfconns.push(s)}return e},disconnect:function(t,n){for(var o=t==n?this.selfconns:this.connections,e=0;e<o.length;e++){var i=o[e];if(i.from==t&&i.to==n){null!=i.gater&&this.ungate(i),o.splice(e,1);break}}t.disconnect(n)},gate:function(t,n){if(-1==this.nodes.indexOf(t))throw new Error("This node is not part of the network!");if(null!=n.gater)return void(r.warnings&&console.warn("This connection is already gated!"));t.gate(n),this.gates.push(n)},ungate:function(t){var n=this.gates.indexOf(t);if(-1==n)throw new Error("This connection is not gated!");this.gates.splice(n,1),t.gater.ungate(t)},remove:function(t){var n=this.nodes.indexOf(t);if(-1==n)throw new Error("This node does not exist in the network!");var o=[];this.disconnect(t,t);for(var e=[],i=t.connections.in.length-1;i>=0;i--){var r=t.connections.in[i];s.Mutation.SUB_NODE.keep_gates&&null!=r.gater&&r.gater!=t&&o.push(r.gater),e.push(r.from),this.disconnect(r.from,t)}for(var a=[],i=t.connections.out.length-1;i>=0;i--){var r=t.connections.out[i];s.Mutation.SUB_NODE.keep_gates&&null!=r.gater&&r.gater!=t&&o.push(r.gater),a.push(r.to),this.disconnect(t,r.to)}var c=[];for(var h in e){h=e[h];for(var u in a)if(u=a[u],!h.isProjectingTo(u)){var f=this.connect(h,u);c.push(f[0])}}for(var l in o){if(0==c.length)break;l=o[l];var p=Math.floor(Math.random()*c.length),f=c[p];this.gate(l,c[p]),c.splice(p,1)}for(var i=t.connections.gated.length-1;i>=0;i--){var f=t.connections.gated[i];this.ungate(f)}this.disconnect(t,t),this.nodes.splice(n,1)},mutate:function(t){if(void 0===t)throw new Error("No (correct) mutate method given!");switch(t){case c.ADD_NODE:var n=this.connections[Math.floor(Math.random()*this.connections.length)],o=n.gater;this.disconnect(n.from,n.to);var i=this.nodes.indexOf(n.to),s=new e("hidden",this.nodes.length);s.mutate(c.MOD_ACTIVATION);var a=Math.min(i,this.nodes.length-this.output);this.nodes.splice(a,0,s);var h=this.connect(n.from,s)[0],u=this.connect(s,n.to)[0];null!=o&&this.gate(o,Math.random()>=.5?h:u);break;case c.SUB_NODE:if(this.nodes.length==this.input+this.output){r.warnings&&console.warn("No more nodes left to remove!");break}var f=Math.floor(Math.random()*(this.nodes.length-this.output-this.input)+this.input);this.remove(this.nodes[f]);break;case c.ADD_CONN:for(var l=[],p=0;p<this.nodes.length-this.output;p++)for(var d=this.nodes[p],g=Math.max(p+1,this.input);g<this.nodes.length;g++){var v=this.nodes[g];d.isProjectingTo(v)||l.push([d,v])}if(0==l.length){r.warnings&&console.warn("No more connections to be made!");break}var m=l[Math.floor(Math.random()*l.length)];this.connect(m[0],m[1]);break;case c.SUB_CONN:var O=[];for(A in this.connections)A=this.connections[A],A.from.connections.out.length>1&&A.to.connections.in.length>1&&this.nodes.indexOf(A.to)>this.nodes.indexOf(A.from)&&O.push(A);if(0==O.length){r.warnings&&console.warn("No connections to remove!");break}var w=O[Math.floor(Math.random()*O.length)];this.disconnect(w.from,w.to);break;case c.MOD_WEIGHT:var n=this.connections[Math.floor(Math.random()*this.connections.length)],_=Math.random()*(t.max-t.min)+t.min;n.weight+=_;break;case c.MOD_BIAS:var f=Math.floor(Math.random()*(this.nodes.length-this.input)+this.input),s=this.nodes[f];s.mutate(t);break;case c.MOD_ACTIVATION:if(!t.mutateOutput&&this.input+this.output==this.nodes.length){r.warnings&&console.warn("No nodes that allow mutation of activation function");break}var f=Math.floor(Math.random()*(this.nodes.length-(t.mutateOutput?0:this.output)-this.input)+this.input),s=this.nodes[f];s.mutate(t);break;case c.ADD_SELF_CONN:for(var O=[],p=this.input;p<this.nodes.length;p++){var s=this.nodes[p];-1==this.selfconns.indexOf(s.connections.self)&&O.push(s)}if(0==O.length){r.warnings&&console.warn("No more self-connections to add!");break}var s=O[Math.floor(Math.random()*O.length)];this.connect(s,s);break;case c.SUB_SELF_CONN:if(0==this.selfconns.length){r.warnings&&console.warn("No more self-connections to remove!");break}var A=this.selfconns[Math.floor(Math.random()*this.selfconns.length)];this.disconnect(A.from,A.to);break;case c.ADD_GATE:var N=this.connections.concat(this.selfconns),O=[];for(var A in N)A=N[A],null==A.gater&&O.push(A);if(0==O.length){r.warnings&&console.warn("No more connections to gate!");break}var s=this.nodes[Math.floor(Math.random()*this.nodes.length)],A=O[Math.floor(Math.random()*O.length)];this.gate(s,A);break;case c.SUB_GATE:if(0==this.gates.length){r.warnings&&console.warn("No more connections to ungate!");break}var f=Math.floor(Math.random()*this.gates.length),T=this.gates[f];this.ungate(T);break;case c.ADD_BACK_CONN:for(var l=[],p=this.input;p<this.nodes.length;p++)for(var d=this.nodes[p],g=this.input;g<p;g++){var v=this.nodes[g];d.isProjectingTo(v)||l.push([d,v])}if(0==l.length){r.warnings&&console.warn("No more connections to be made!");break}var m=l[Math.floor(Math.random()*l.length)];this.connect(m[0],m[1]);break;case c.SUB_BACK_CONN:var O=[];for(A in this.connections)A=this.connections[A],A.from.connections.out.length>1&&A.to.connections.in.length>1&&this.nodes.indexOf(A.from)>this.nodes.indexOf(A.to)&&O.push(A);if(0==O.length){r.warnings&&console.warn("No connections to remove!");break}var w=O[Math.floor(Math.random()*O.length)];this.disconnect(w.from,w.to);break;case c.SWAP_NODES:var f=Math.floor(Math.random()*(this.nodes.length-this.input)+this.input),d=this.nodes[f],f=Math.floor(Math.random()*(this.nodes.length-this.input)+this.input),v=this.nodes[f],L=d.bias,M=d.squash;d.bias=v.bias,d.squash=v.squash,v.bias=L,v.squash=M}},train:function(t,n){n=n||{},void 0===n.rate&&r.warnings&&console.warn("Using default learning rate, please define a rate!"),void 0===n.iterations&&r.warnings&&console.warn("No target iterations given, running until error is reached!");var o=Date.now(),e=n.log||!1,i=n.error||.05,a=n.cost||s.Cost.MSE,c=n.rate||.3,h=n.shuffle||!1,u=n.iterations||0,f=n.crossValidate||!1,l=n.clear||!1,p=n.dropout||0,d=n.momentum||0,g=n.batchSize||1,v=n.ratePolicy||s.Rate.FIXED(),m=n.schedule;if(void 0===n.iterations&&void 0===n.error?r.warnings&&console.warn("At least one of the following options must be specified: error, iterations"):void 0===n.error&&(i=-1),this.dropout=p,f)var O=n.crossValidate.testSize,w=n.crossValidate.testError,_=Math.ceil((1-O)*t.length),A=t.slice(0,_),N=t.slice(_);for(var T=c,L=0,M=1;M>i&&(0==u||L<u)&&!(f&&M<=w);){if(L++,T=v(c,L),M=0,f?(this._trainSet(A,g,T,d,a),l&&this.clear(),M+=this.test(N,a).error,l&&this.clear()):(M+=this._trainSet(t,g,T,d,a),l&&this.clear()),h)for(var E,x,b=t.length;b;E=Math.floor(Math.random()*b),x=t[--b],t[b]=t[E],t[E]=x);e&&L%e==0&&console.log("iteration",L,"error",M,"rate",T),m&&L%m.iterations==0&&m.function({error:M,iteration:L})}if(l&&this.clear(),p)for(var b=0;b<this.nodes.length;b++)"hidden"!=this.nodes[b].type&&"constant"!=this.nodes[b].type||(this.nodes[b].mask=1-this.dropout);return{error:M,iterations:L,time:Date.now()-o}},_trainSet:function(t,n,o,e,i){for(var s=0,r=0;r<t.length;r++){var a=t[r].input,c=t[r].output,h=this.activate(a,!0);this.propagate(o,e,c),s+=i(c,h)}return s/r},test:function(t,n){if(this.dropout)for(var o=0;o<this.nodes.length;o++)"hidden"!=this.nodes[o].type&&"constant"!=this.nodes[o].type||(this.nodes[o].mask=1-this.dropout);n=n||s.Cost.MSE;for(var e,i,r,a=0,c=Date.now(),o=0;o<t.length;o++)e=t[o].input,r=t[o].output,i=this.activate(e),a+=n(r,i);return a/=t.length,{error:a,time:Date.now()-c}},graph:function(t,n){for(var o=0,e=0,i={nodes:[],links:[],constraints:[{type:"alignment",axis:"x",offsets:[]},{type:"alignment",axis:"y",offsets:[]}]},s=0;s<this.nodes.length;s++){var r=this.nodes[s];"input"==r.type?(1==this.input?i.constraints[0].offsets.push({node:s,offset:0}):i.constraints[0].offsets.push({node:s,offset:.8*t/(this.input-1)*o++}),i.constraints[1].offsets.push({node:s,offset:0})):"output"==r.type&&(1==this.output?i.constraints[0].offsets.push({node:s,offset:0}):i.constraints[0].offsets.push({node:s,offset:.8*t/(this.output-1)*e++}),i.constraints[1].offsets.push({node:s,offset:-.8*n})),i.nodes.push({id:s,name:"hidden"==r.type?r.squash.name:r.type.toUpperCase(),activation:r.activation,bias:r.bias})}var a=this.connections.concat(this.selfconns);for(connection in a)if(connection=a[connection],null==connection.gater)i.links.push({source:this.nodes.indexOf(connection.from),target:this.nodes.indexOf(connection.to),weight:connection.weight});else{var c=i.nodes.length;i.nodes.push({id:c,activation:connection.gater.activation,name:"GATE"}),i.links.push({source:this.nodes.indexOf(connection.from),target:c,weight:.5*connection.weight}),i.links.push({source:c,target:this.nodes.indexOf(connection.to),weight:.5*connection.weight}),i.links.push({source:this.nodes.indexOf(connection.gater),target:c,weight:connection.gater.activation,gate:!0})}return i},toJSON:function(){var t={nodes:[],connections:[],input:this.input,output:this.output,dropout:this.dropout};for(index in this.nodes){var n=this.nodes[index],o=n.toJSON();if(o.index=index,t.nodes.push(o),0!=n.connections.self.weight){var o=n.connections.self.toJSON();o.from=index,o.to=index,o.gater=null!=n.connections.self.gater?this.nodes.indexOf(n.connections.self.gater):null,t.connections.push(o)}}for(e in this.connections){var e=this.connections[e],o=e.toJSON();o.from=this.nodes.indexOf(e.from),o.to=this.nodes.indexOf(e.to),o.gater=null!=e.gater?this.nodes.indexOf(e.gater):null,t.connections.push(o)}return t},set:function(t){for(var n=0;n<this.nodes.length;n++)this.nodes[n].bias=t.bias||this.nodes[n].bias,this.nodes[n].squash=t.squash||this.nodes[n].squash},evolve:function(t,n){function o(n){for(var o=0,s=0;s<i;s++)f&&n.clear(),o-=n.test(t,e).error;return o-=(n.nodes.length+n.connections.length+n.gates.length)*r,(o=isNaN(o)?-1/0:o)/i}var e=n.cost||s.Cost.MSE,i=n.amount||1,r=void 0!==n.growth?n.growth:1e-4,c=n.iterations||0,h=n.error||.005,u=n.log||0,f=n.clear||!1,l=n.schedule,p=Date.now();n.network=this;for(var d=new a(0,0,o,n),g=-1/0,v=-1/0,m=null;g<-h&&(0==c||d.generation<c);){d.evolve();var O=d.getFittest();f&&O.clear(),g=-O.test(t).error-(O.nodes.length+O.connections.length+O.gates.length)*r,g>v&&(v=g,m=O),u&&d.generation%u==0&&console.log("generation",d.generation,"error",O.score,"cost error",g),l&&iteration%l.iterations==0&&l.function({error:g,iteration:d.generation})}f&&m.clear();var w={error:v,generations:d.generation,time:Date.now()-p};return this.nodes=m.nodes,this.connections=m.connections,this.gates=m.gates,this.selfconns=m.selfconns,w}},n.fromJSON=function(t){var o=new n(t.input,t.output);o.dropout=t.dropout,o.nodes=[],o.connections=[];for(node in t.nodes)o.nodes.push(e.fromJSON(t.nodes[node]));for(i in t.connections){var i=t.connections[i],s=o.connect(o.nodes[i.from],o.nodes[i.to])[0];s.weight=i.weight,null!=i.gater&&o.gate(o.nodes[i.gater],s)}return o},n.merge=function(t,o){if(t=n.fromJSON(t.toJSON()),o=n.fromJSON(o.toJSON()),t.output!=o.input)throw new Error("Output size of network1 should be the same as the input size of network2!");for(conn in o.connections)if(conn=o.connections[conn],"input"==conn.from.type){var e=o.nodes.indexOf(conn.from);o.nodes[e];conn.from=t.nodes[t.nodes.length-1-e]}for(var i=o.input-1;i>=0;i--)o.nodes.splice(i,1);for(var i=t.nodes.length-t.output;i<t.nodes.length;i++)t.nodes[i].type="hidden";return t.connections=t.connections.concat(o.connections),t.nodes=t.nodes.concat(o.nodes),t},n.crossOver=function(t,o,s){if(t.input!=o.input||t.output!=o.output)throw new Error("Networks don't have the same input/output size!");var r=new n(t.input,t.output);r.connections=[],r.nodes=[];var a=t.score||0,c=o.score||0;if(a==c)var h=Math.max(t.nodes.length,o.nodes.length),u=Math.min(t.nodes.length,o.nodes.length),f=Math.floor(Math.random()*(h-u+1)+u);else if(a>c)var f=t.nodes.length;else var f=o.nodes.length;for(var l=t.output,p=0;p<f;p++){if(p<f-l){var d=Math.random(),g=d>=.5?t.nodes[p]:o.nodes[p],v=d<.5?t.nodes[p]:o.nodes[p];void 0!==g&&"output"!=g.type||(g=v)}else if(Math.random()>=.5)var g=t.nodes[t.nodes.length+p-f];else var g=o.nodes[o.nodes.length+p-f];var m=new e;m.bias=g.bias,m.squash=g.squash,m.type=g.type,r.nodes.push(m)}for(var O=[],w=[],p=0;p<t.connections.length;p++){var _=t.connections[p],A={weight:_.weight,from:t.nodes.indexOf(_.from),to:t.nodes.indexOf(_.to),gater:t.nodes.indexOf(_.gater)};i.innovationID(A.from,A.to);O.push(A)}for(var p=0;p<t.selfconns.length;p++){var _=t.selfconns[p],A={weight:_.weight,from:t.nodes.indexOf(_.from),to:t.nodes.indexOf(_.to),gater:t.nodes.indexOf(_.gater)};i.innovationID(A.from,A.to);O.push(A)}for(var p=0;p<o.connections.length;p++){var _=o.connections[p],A={weight:_.weight,from:o.nodes.indexOf(_.from),to:o.nodes.indexOf(_.to),gater:o.nodes.indexOf(_.gater)};i.innovationID(A.from,A.to);w.push(A)}for(var p=0;p<o.selfconns.length;p++){var _=o.selfconns[p],A={weight:_.weight,from:o.nodes.indexOf(_.from),to:o.nodes.indexOf(_.to),gater:o.nodes.indexOf(_.gater)};i.innovationID(A.from,A.to);w.push(A)}for(var N=[],p=O.length-1;p>=0;p--){for(var T=!1,L=w.length-1;L>=0;L--)if(O[p].from==w[L].from&&O[p].to==w[L].to){var _=Math.random()>=.5?O[p]:w[L];N.push(_),w[L]=[-1,-1];var T=!0;break}!T&&a>=c&&N.push(O[p])}if(c>=a)for(var p=0;p<w.length;p++)-1!=w[p][0]&&-1!=w[p][1]&&N.push(w[p]);for(var p=0;p<N.length;p++){var M=N[p];if(M.to<f&&M.from<f){var E=r.nodes[M.from],x=r.nodes[M.to],_=r.connect(E,x)[0];_.weight=M.weight,-1!=M.gater&&M.gater<f&&r.gate(r.nodes[M.gater],_)}}return r}}).call(n,o(0)(t))},function(t,n,o){(function(t){var n=o(7),e=o(1),i=o(2),s=o(5),r=o(6),a={Construct:function(t){for(var o=new n(0,0),e=[],a=0;a<t.length;a++)if(t[a]instanceof s)for(var c=0;c<t[a].nodes.length;c++)e.push(t[a].nodes[c]);else if(t[a]instanceof r)for(var c=0;c<t[a].nodes.length;c++)for(var h=0;h<t[a].nodes[c].nodes.length;h++)e.push(t[a].nodes[c].nodes[h]);else t[a]instanceof i&&e.push(t[a]);for(var u=[],f=[],a=e.length-1;a>=0;a--)"output"==e[a].type||e[a].connections.out.length+e[a].connections.gated.length==0?(e[a].type="output",o.output++,f.push(e[a]),e.splice(a,1)):"input"!=e[a].type&&e[a].connections.in.length||(e[a].type="input",o.input++,u.push(e[a]),e.splice(a,1));if(e=u.concat(e).concat(f),0==o.input||0==o.output)throw new Error("Given nodes have no clear input/output node!");for(var a=0;a<e.length;a++){for(var c=0;c<e[a].connections.out.length;c++)o.connections.push(e[a].connections.out[c]);for(var c=0;c<e[a].connections.gated.length;c++)o.gates.push(e[a].connections.gated[c]);0!=e[a].connections.self.weight&&o.selfconns.push(e[a].connections.self)}return o.nodes=e,o},Perceptron:function(){var t=Array.prototype.slice.call(arguments);if(t.length<3)throw new Error("not enough layers (minimum 3) !!");var n=[];n.push(new s(t[0]));for(var o=1;o<t.length;o++){var e=t[o],e=new s(e);n.push(e),n[o-1].connect(n[o])}return a.Construct(n)},Random:function(t,o,i,s){s=s||{};for(var r=s.connections||2*o,a=s.backconnections||0,c=s.selfconnections||0,h=s.gates||0,u=new n(t,i),f=0;f<o;f++)u.mutate(e.Mutation.ADD_NODE);for(var f=0;f<r-o;f++)u.mutate(e.Mutation.ADD_CONN);for(var f=0;f<a;f++)u.mutate(e.Mutation.ADD_BACK_CONN);for(var f=0;f<c;f++)u.mutate(e.Mutation.ADD_SELF_CONN);for(var f=0;f<h;f++)u.mutate(e.Mutation.ADD_GATE);return u},LSTM:function(){var t=Array.prototype.slice.call(arguments);if(t.length<3)throw new Error("not enough layers (minimum 3) !!");var n=t.pop();if("number"==typeof n){var o=new s(n);n={}}else var o=new s(t.pop());o.set({type:"output"});var i={};i.memoryToMemory=n.memoryToMemory||!1,i.outputToMemory=n.outputToMemory||!1,i.outputToGates=n.outputToGates||!1,i.inputToOutput=void 0==n.inputToOutput||n.inputToOutput,i.inputToDeep=void 0==n.inputToDeep||n.inputToDeep;var r=new s(t.shift());r.set({type:"input"});var c=t,h=[];h.push(r);for(var u=r,f=0;f<c.length;f++){var l=c[f],p=new s(l),d=new s(l),g=new s(l),v=new s(l),m=f==c.length-1?o:new s(l);p.set({bias:1}),d.set({bias:1}),v.set({bias:1});var O=u.connect(g,e.Connection.ALL_TO_ALL);u.connect(p,e.Connection.ALL_TO_ALL),u.connect(v,e.Connection.ALL_TO_ALL),u.connect(d,e.Connection.ALL_TO_ALL),g.connect(p,e.Connection.ALL_TO_ALL),g.connect(d,e.Connection.ALL_TO_ALL),g.connect(v,e.Connection.ALL_TO_ALL);var w=g.connect(g,e.Connection.ONE_TO_ONE),_=g.connect(m,e.Connection.ALL_TO_ALL);if(p.gate(O,e.Gating.INPUT),d.gate(w,e.Gating.SELF),v.gate(_,e.Gating.OUTPUT),i.inputToDeep&&f>0){var O=r.connect(g,e.Connection.ALL_TO_ALL);p.gate(O,e.Gating.INPUT)}if(i.memoryToMemory){var O=g.connect(g,e.Connection.ALL_TO_ELSE);p.gate(O,e.Gating.INPUT)}if(i.outputToMemory){var O=o.connect(g,e.Connection.ALL_TO_ALL);p.gate(O,e.Gating.INPUT)}i.outputToGates&&(o.connect(p,e.Connection.ALL_TO_ALL),o.connect(d,e.Connection.ALL_TO_ALL),o.connect(v,e.Connection.ALL_TO_ALL)),h.push(p),h.push(d),h.push(g),h.push(v),f!=c.length-1&&h.push(m),u=m}return i.inputToOutput&&r.connect(o,e.Connection.ALL_TO_ALL),h.push(o),a.Construct(h)},GRU:function(){var t=Array.prototype.slice.call(arguments);if(t.length<3)throw new Error("not enough layers (minimum 3) !!");var n=new s(t.shift()),o=new s(t.pop()),e=t,i=[];i.push(n);for(var c=n,h=0;h<e.length;h++){var u=new r.GRU(e[h]);c.connect(u),c=u,i.push(u)}return c.connect(o),i.push(o),a.Construct(i)},Hopfield:function(t){var n=new s(t),o=new s(t);return n.connect(o,e.Connection.ALL_TO_ALL),n.set({type:"input"}),o.set({squash:e.Activation.STEP,type:"output"}),new a.Construct([n,o])},NARX:function(t,n,o,i,s){Array.isArray(n)||(n=[n]);var c=[],h=new r.Dense(t),u=new r.Memory(t,i),f=[],l=new r.Dense(o),p=new r.Memory(o,s);c.push(h),c.push(p);for(var d=0;d<n.length;d++){var g=new r.Dense(n[d]);f.push(g),c.push(g),void 0!==f[d-1]&&f[d-1].connect(g,e.Connection.ALL_TO_ALL)}return c.push(u),c.push(l),h.connect(f[0],e.Connection.ALL_TO_ALL),h.connect(u,e.Connection.ONE_TO_ONE,1),u.connect(f[0],e.Connection.ALL_TO_ALL),f[f.length-1].connect(l,e.Connection.ALL_TO_ALL),l.connect(p,e.Connection.ONE_TO_ONE,1),p.connect(f[0],e.Connection.ALL_TO_ALL),h.set({type:"input"}),l.set({type:"output"}),a.Construct(c)}};t&&(t.exports=a)}).call(n,o(0)(t))},function(t,n,o){(function(t){function n(t,n,o,s){this.input=t,this.output=n,this.fitness=o,s=s||{},this.equal=s.equal||!1,this.popsize=s.popsize||50,this.elitism=s.elitism||0,this.mutationRate=s.mutationRate||.3,this.mutationAmount=s.mutationAmount||1,this.selection=s.selection||i.Selection.POWER,this.crossover=s.crossover||[i.Crossover.SINGLE_POINT,i.Crossover.TWO_POINT,i.Crossover.UNIFORM,i.Crossover.AVERAGE],this.mutation=s.mutation||i.Mutation.FFW,this.generation=0,this.createPool(s.network||new e(this.input,this.output))}t&&(t.exports=n);var e=(o(2),o(7)),i=o(1),s=(i.Activation,i.Mutation,i.Selection);i.Crossover;n.prototype={createPool:function(t){this.population=[];for(var n=0;n<this.popsize;n++){var o=e.fromJSON(t.toJSON());o.score=null,this.population.push(o)}},evolve:function(){null==this.population[this.population.length-1].score&&this.evaluate(),this.sort();for(var t=[],n=0;n<this.elitism;n++)t.push(this.population[n]);for(var n=0;n<this.popsize-this.elitism;n++)t.push(this.getOffspring());this.population=t,this.mutate();for(var n=0;n<this.popsize;n++)this.population[n].score=null;this.generation++},getOffspring:function(){var t=this.getParent(),n=this.getParent();return this.equal&&(t.score=0,n.score=0),e.crossOver(t,n)},mutate:function(){for(var t=this.elitism;t<this.popsize;t++)if(Math.random()<=this.mutationRate)for(var n=0;n<this.mutationAmount;n++){var o=this.mutation[Math.floor(Math.random()*this.mutation.length)];this.population[t].mutate(o)}},evaluate:function(){for(var t=0;t<this.popsize;t++){var n=this.fitness(this.population[t]);this.population[t].score=n}},sort:function(){this.population.sort(function(t,n){return n.score-t.score})},getFittest:function(){return null==this.population[this.popsize-1].score&&this.evaluate(),this.sort(),this.population[0]},getAverage:function(){null==this.population[tthis.popsize-1].score&&this.evaluate();for(var t=0,n=0;n<this.popsize;n++)t+=this.population[n].score;return t/this.popsize},getParent:function(){switch(this.selection){case s.POWER:this.population[0].score<this.population[1].score&&this.sort();var t=Math.floor(Math.pow(Math.random(),this.selection.power)*this.popsize);return this.population[t];case s.FITNESS_PROPORTIONATE:for(var n=0,o=0,e=0;e<this.popsize;e++){var i=this.population[e].score;o=i<o?i:o,n+=i}o=Math.abs(o),n+=o*this.popsize;for(var r=Math.random()*n,a=0,e=0;e<this.popsize;e++){var c=this.population[e];if(a+=c.score+o,r<a)return c}return this.population[Math.floor(Math.random()*this.population.length)];case s.TOURNAMENT:if(this.selection.size>this.popsize)throw new Error("Your tournament size should be lower than the population size, please change Methods.Selection.TOURNAMENT.size");for(var h=[],e=0;e<this.selection.size;e++){var r=this.population[Math.floor(Math.random()*this.popsize)];h.push(r)}h.sort(function(t,n){return n.score-t.score});for(var e=0;e<this.selection.size;e++)if(Math.random()<this.selection.probability||e==this.selection.size-1)return h[e]}},export:function(){for(var t=[],n=0;n<this.popsize;n++){var o=this.population[o];t.push(o.toJSON())}return t},import:function(t){for(var n=[],o=0;o<t.length;o++){var i=t[o];n.push(e.fromJSON(i))}this.population=n,this.popsize=n.length}}}).call(n,o(0)(t))},function(t,n,o){(function(t){var n={LOGISTIC:function(t,n){var o=1/(1+Math.exp(-t));return n?o*(1-o):o},TANH:function(t,n){return n?1-Math.pow(Math.tanh(t),2):Math.tanh(t)},IDENTITY:function(t,n){return n?1:t},STEP:function(t,n){return n?0:t>0?1:0},RELU:function(t,n){return n?t>0?1:0:t>0?t:0},SOFTSIGN:function(t,n){var o=1+Math.abs(t);return n?t/Math.pow(o,2):t/o},SINUSOID:function(t,n){return n?Math.cos(t):Math.sin(t)},GAUSSIAN:function(t,n){var o=Math.exp(-Math.pow(t,2));return n?-2*t*o:o},BENT_IDENTITY:function(t,n){var o=Math.sqrt(Math.pow(t,2)+1);return n?t/(2*o)+1:(o-1)/2+t},BIPOLAR:function(t,n){return n?0:t>0?1:-1},BIPOLAR_SIGMOID:function(t,n){var o=2/(1+Math.exp(-t))-1;return n?.5*(1+o)*(1-o):o},HARD_TANH:function(t,n){return n?t>-1&&t<1?1:0:Math.max(-1,Math.min(1,t))},ABSOLUTE:function(t,n){return n?t<0?-1:1:Math.abs(t)},INVERSE:function(t,n){return n?-1:1-t},SELU:function(t,n){var o=1.6732632423543772,e=1.0507009873554805,i=(t>0?t:o*Math.exp(t)-o)*e;return n?t>0?e:i+o:i}};t&&(t.exports=n)}).call(n,o(0)(t))},function(t,n,o){(function(t){var n={ALL_TO_ALL:{name:"OUTPUT"},ALL_TO_ELSE:{name:"INPUT"},ONE_TO_ONE:{name:"SELF"}};t&&(t.exports=n)}).call(n,o(0)(t))},function(t,n,o){(function(t){var n={CROSS_ENTROPY:function(t,n){for(var o=0,e=0;e<n.length;e++)o-=t[e]*Math.log(Math.max(n[e],1e-15))+(1-t[e])*Math.log(1-Math.max(n[e],1e-15));return o},MSE:function(t,n){for(var o=0,e=0;e<n.length;e++)o+=Math.pow(t[e]-n[e],2);return o/n.length},BINARY:function(t,n){for(var o=0,e=0;e<n.length;e++)o+=Math.round(2*t[e])!=Math.round(2*n[e]);return o},MAE:function(t,n){for(var o=0,e=0;e<n.length;e++)o+=Math.abs(t[e]-n[e]);return o/n.length},MAPE:function(t,n){for(var o=0,e=0;e<n.length;e++)o+=Math.abs((n[e]-t[e])/Math.max(t[e],1e-15));return o/n.length},MSLE:function(t,n){for(var o=0,e=0;e<n.length;e++)o+=Math.log(Math.max(t[e],1e-15))-Math.log(Math.max(n[e],1e-15));return o},HINGE:function(t,n){for(var o=0,e=0;e<n.length;e++)o+=Math.max(0,1-t[e]*n[e]);return o}};t&&(t.exports=n)}).call(n,o(0)(t))},function(t,n,o){(function(t){var n={SINGLE_POINT:{name:"SINGLE_POINT",config:[.4]},TWO_POINT:{name:"TWO_POINT",config:[.4,.9]},UNIFORM:{name:"UNIFORM"},AVERAGE:{name:"AVERAGE"}};t&&(t.exports=n)}).call(n,o(0)(t))},function(t,n,o){(function(t){var n={OUTPUT:{name:"OUTPUT"},INPUT:{name:"INPUT"},SELF:{name:"SELF"}};t&&(t.exports=n)}).call(n,o(0)(t))},function(t,n,o){(function(t){var n=o(10),e={ADD_NODE:{name:"ADD_NODE"},SUB_NODE:{name:"SUB_NODE",keep_gates:!0},ADD_CONN:{name:"ADD_CONN"},SUB_CONN:{name:"REMOVE_CONN"},MOD_WEIGHT:{name:"MOD_WEIGHT",min:-1,max:1},MOD_BIAS:{name:"MOD_BIAS",min:-1,max:1},MOD_ACTIVATION:{name:"MOD_ACTIVATION",mutateOutput:!0,allowed:[n.LOGISTIC,n.TANH,n.RELU,n.IDENTITY,n.STEP,n.SOFTSIGN,n.SINUSOID,n.GAUSSIAN,n.BENT_IDENTITY,n.BIPOLAR,n.BIPOLAR_SIGMOID,n.HARD_TANH,n.ABSOLUTE,n.INVERSE,n.SELU]},ADD_SELF_CONN:{name:"ADD_SELF_CONN"},SUB_SELF_CONN:{name:"SUB_SELF_CONN"},ADD_GATE:{name:"ADD_GATE"},SUB_GATE:{name:"SUB_GATE"},ADD_BACK_CONN:{name:"ADD_BACK_CONN"},SUB_BACK_CONN:{name:"SUB_BACK_CONN"},SWAP_NODES:{name:"SWAP_NODES"}};e.ALL=[e.ADD_NODE,e.SUB_NODE,e.ADD_CONN,e.SUB_CONN,e.MOD_WEIGHT,e.MOD_BIAS,e.MOD_ACTIVATION,e.ADD_GATE,e.SUB_GATE,e.ADD_SELF_CONN,e.SUB_SELF_CONN,e.ADD_BACK_CONN,e.SUB_BACK_CONN],e.FFW=[e.ADD_NODE,e.SUB_NODE,e.ADD_CONN,e.SUB_CONN,e.MOD_WEIGHT,e.MOD_BIAS,e.MOD_ACTIVATION],t&&(t.exports=e)}).call(n,o(0)(t))},function(t,n,o){(function(t){var n={FIXED:function(){return function(t,n){return t}},STEP:function(t,n){return t=t||.9,n=n||100,function(o,e){return o*Math.pow(t,Math.floor(e/n))}},EXP:function(t){return t=t||.999,function(n,o){return n*Math.pow(t,o)}},INV:function(t,n){return t=t||.001,n=n||2,function(o,e){return o*Math.pow(1+t*e,-n)}}};t&&(t.exports=n)}).call(n,o(0)(t))},function(t,n,o){(function(t){var n={FITNESS_PROPORTIONATE:{name:"FITNESS_PROPORTIONATE"},POWER:{name:"POWER",power:4},TOURNAMENT:{name:"TOURNAMENT",size:5,probability:.5}};t&&(t.exports=n)}).call(n,o(0)(t))},function(t,n,o){var e,i,s={Node:o(2),Neat:o(9),Network:o(7),Methods:o(1),Architect:o(8),Group:o(5),Connection:o(4),Config:o(3),Layer:o(6)};e=[],void 0!==(i=function(){return s}.apply(n,e))&&(t.exports=i),void 0!==t&&t.exports&&(t.exports=s),"object"==typeof window&&(!function(){var t=window.neataptic;s.ninja=function(){return window.neataptic=t,s}}(),window.neataptic=s)}])});