sakuya/node_modules/neataptic/mkdocs/theme/cdn/1.2.16/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(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.neataptic=t():n.neataptic=t()}(this,function(){return function(n){function t(e){if(o[e])return o[e].exports;var i=o[e]={i:e,l:!1,exports:{}};return n[e].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var o={};return t.m=n,t.c=o,t.i=function(n){return n},t.d=function(n,o,e){t.o(n,o)||Object.defineProperty(n,o,{configurable:!1,enumerable:!0,get:e})},t.n=function(n){var o=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(o,"a",o),o},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.p="",t(t.s=18)}([function(n,t){n.exports=function(n){return n.webpackPolyfill||(n.deprecate=function(){},n.paths=[],n.children||(n.children=[]),Object.defineProperty(n,"loaded",{enumerable:!0,get:function(){return n.l}}),Object.defineProperty(n,"id",{enumerable:!0,get:function(){return n.i}}),n.webpackPolyfill=1),n}},function(n,t,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(t,e))&&(n.exports=i),void 0!==n&&n.exports&&(n.exports=s),"object"==typeof window&&(!function(){var n=window.methods;s.ninja=function(){return window.methods=n,s}}(),window.methods=s)},function(n,t,o){(function(n){function t(n){this.bias="input"==n?0:.2*Math.random()-.1,this.squash=a.LOGISTIC,this.type=n||"hidden",this.activation=0,this.state=0,this.old=0,this.mask=1,this.connections={in:[],out:[],gated:[],self:new e(this,this,0)},this.error={responsibility:0,projected:0,gated:0}}n&&(n.exports=t);var e=o(4),i=o(1),s=o(5),r=o(3),a=i.Activation,c=i.Mutation;t.prototype={activate:function(n){if(void 0!==n)return this.activation=n,this.derivative=0,this.bias=0,this.activation;this.old=this.state,this.state=this.connections.self.gain*this.connections.self.weight*this.state+this.bias;for(var t in this.connections.in)t=this.connections.in[t],this.state+=t.from.activation*t.weight*t.gain;this.activation=this.squash(this.state)*this.mask,this.derivative=this.squash(this.state,!0);var o=[],e=[];for(var i in this.connections.gated){i=this.connections.gated[i];var s=i.to,r=o.indexOf(s);r>-1?e[r]+=i.weight*i.from.activation:(o.push(s),e.push(s.connections.self.gater==this?s.old:0),e[e.length-1]+=i.weight*i.from.activation)}for(var t in this.connections.in){t=this.connections.in[t],t.elegibility=this.connections.self.gain*this.connections.self.weight*t.elegibility+t.from.activation*t.gain;for(var a=0;a<o.length;a++){var s=o[a],c=e[a],r=t.xtrace.nodes.indexOf(s);r>-1?t.xtrace.values[r]=s.connections.self.gain*s.connections.self.weight*t.xtrace.values[r]+this.derivative*t.elegibility*c:(t.xtrace.nodes.push(s),t.xtrace.values.push(this.derivative*t.elegibility*c))}}for(var t in this.connections.gated)this.connections.gated[t].gain=this.activation;return this.activation},propagate:function(n,t,o){var e=0;if(t=t||0,"output"==this.type)this.error.responsibility=this.error.projected=o-this.activation;else{for(var i in this.connections.out){var i=this.connections.out[i],s=i.to;e+=s.error.responsibility*i.weight*i.gain}this.error.projected=this.derivative*e,e=0;for(var r in this.connections.gated){r=this.connections.gated[r];var s=r.to,a=s.connections.self.gater==this?s.old:0;a+=r.weight*r.from.activation,e+=s.error.responsibility*a}this.error.gated=this.derivative*e,this.error.responsibility=this.error.projected+this.error.gated}if("constant"!=this.type){n=n||.3;for(var i in this.connections.in){for(var i=this.connections.in[i],c=this.error.projected*i.elegibility,h=0;h<i.xtrace.nodes.length;h++){var s=i.xtrace.nodes[h],u=i.xtrace.values[h];c+=s.error.responsibility*u}var f=n*c*this.mask+t*i.previousDeltaWeight;i.weight+=f,i.previousDeltaWeight=f}this.bias+=n*this.error.responsibility}},connect:function(n,o){var i=[];if(n instanceof s)for(var a=0;a<n.nodes.length;a++){var c=new e(this,n.nodes[a],o);n.nodes[a].connections.in.push(c),this.connections.out.push(c),n.connections.in.push(c),i.push(c)}else if(n instanceof t)if(n==this)0!=this.connections.self.weight?r.warnings&&console.warn("This connection already exists!"):this.connections.self.weight=o||1,i.push(this.connections.self);else{if(this.isProjectingTo(n))throw new Error("Already projecting a connection to this node!");var c=new e(this,n,o);n.connections.in.push(c),this.connections.out.push(c),i.push(c)}return i},disconnect:function(n,t){if(this==n)return void(this.connections.self.weight=0);for(var o in this.connections.out){var e=this.connections.out[o];if(e.to==n){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}}t&&n.disconnect(this)},gate:function(n){Array.isArray(n)||(n=[n]);for(var t in n)t=n[t],this.connections.gated.push(t),t.gater=this},ungate:function(n){Array.isArray(n)||(n=[n]);for(var t=n.length-1;t>=0;t--){var o=n[t],e=this.connections.gated.indexOf(o);this.connections.gated.splice(e,1),o.gater=null}},clear:function(){for(var n in this.connections.in)n=this.connections.in[n],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(n){if(void 0===n)throw new Error("No mutate method given!");if(!n.name in i.Mutation)throw new Error("This method does not exist!");switch(n){case c.MOD_ACTIVATION:var t=n.allowed[(n.allowed.indexOf(this.squash)+Math.floor(Math.random()*(n.allowed.length-1))+1)%n.allowed.length];this.squash=t;break;case c.MOD_BIAS:var o=Math.random()*(n.max-n.min)+n.min;this.bias+=o}},isProjectingTo:function(n){for(conn in this.connections.out)if(conn=this.connections.out[conn],conn.to==n)return!0;return!1},isProjectedBy:function(n){for(conn in this.connections.in)if(conn=this.connections.in[conn],conn.from==n)return!0;return!1},toJSON:function(){return{bias:this.bias,type:this.type,squash:this.squash.name,mask:this.mask}}},t.fromJSON=function(n){var o=new t;o.bias=n.bias,o.type=n.type,o.mask=n.mask;for(squash in a)if(a[squash].name==n.squash){o.squash=a[squash];break}return o}}).call(t,o(0)(n))},function(n,t,o){(function(n){var t={warnings:!0};n&&(n.exports=t)}).call(t,o(0)(n))},function(n,t,o){(function(n){function t(n,t,o){this.from=n,this.to=t,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:[]}}n&&(n.exports=t),t.prototype={toJSON:function(){return{weight:this.weight}}},t.innovationID=function(n,t){return.5*(n+t)*(n+t+1)+t}}).call(t,o(0)(n))},function(n,t,o){(function(n){function t(n){this.nodes=[],this.connections={in:[],out:[],self:[]};for(var t=0;t<n;t++)this.nodes.push(new i)}n&&(n.exports=t);var e=o(1),i=(o(4),o(2)),s=o(3),r=o(6);e.Activation,e.Mutation;t.prototype={activate:function(n){var t=[];if(void 0!==n&&n.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===n)var e=this.nodes[o].activate();else var e=this.nodes[o].activate(n[o]);t.push(e)}return t},propagate:function(n,t,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(n,t):this.nodes[e].propagate(n,t,o[e])},connect:function(n,o,a){var c=[];if(n instanceof t){if(void 0===o&&(this!=n?(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<n.nodes.length;u++)if(o!=e.Connection.ALL_TO_ELSE||this.nodes[h]!=n.nodes[u]){var f=this.nodes[h].connect(n.nodes[u],a);this.connections.out.push(f[0]),n.connections.in.push(f[0]),c.push(f[0])}}else if(o==e.Connection.ONE_TO_ONE){if(this.nodes.length!=n.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(n.nodes[h],a);this.connections.self.push(f[0]),c.push(f[0])}}}else if(n instanceof r)var c=n.input(this,o,a);else if(n instanceof i)for(var h=0;h<this.nodes.length;h++){var f=this.nodes[h].connect(n,a);this.connections.out.push(f[0]),c.push(f[0])}return c},gate:function(n,t){if(void 0===t)throw new Error("Please specify Gating.INPUT, Gating.OUTPUT");Array.isArray(n)||(n=[n]);var o=[],i=[];for(var s in n)s=n[s],o.includes(s.from)||o.push(s.from),i.includes(s.to)||i.push(s.to);switch(t){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],n.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],n.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];n.includes(a.connections.self)&&c.gate(a.connections.self)}}},set:function(n){for(var t in this.nodes)void 0!==n.bias&&(this.nodes[t].bias=n.bias),this.nodes[t].squash=n.squash||this.nodes[t].squash,this.nodes[t].type=n.type||this.nodes[t].type},disconnect:function(n,o){if(o=o||!1,n instanceof t)for(var e=0;e<this.nodes.length;e++)for(var s=0;s<n.nodes.length;s++){this.nodes[e].disconnect(n.nodes[s],o);for(index in this.connections.out){var r=this.connections.out[index];if(r.from==this.nodes[e]&&r.to==n.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==n.nodes[s]&&r.to==this.nodes[e]){this.connections.in.splice(index,1);break}}}else if(n instanceof i)for(var e=0;e<this.nodes.length;e++){this.nodes[e].disconnect(n,o);for(index in this.connections.out){var r=this.connections.out[index];if(r.from==this.nodes[e]&&r.to==n){this.connections.out.splice(index,1);break}}if(o)for(index in this.connections.in){var r=this.connections.in[index];if(r.from==n&&r.to==this.nodes[e]){this.connections.in.splice(index,1);break}}}},clear:function(){for(var n in this.nodes)this.nodes[n].clear()}}}).call(t,o(0)(n))},function(n,t,o){(function(n){function t(){this.output=null,this.nodes=[],this.connections={in:[],out:[],self:[]}}n&&(n.exports=t);var e=o(1),i=(o(4),o(2)),s=(o(3),o(8),o(5));e.Activation,e.Mutation;t.prototype={activate:function(n){var t=[];if(void 0!==n&&n.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===n)var e=this.nodes[o].activate();else var e=this.nodes[o].activate(n[o]);t.push(e)}return t},propagate:function(n,t,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(n,t):this.nodes[e].propagate(n,t,o[e])},connect:function(n,o,e){if(n instanceof s||n instanceof i)var r=this.output.connect(n,o,e);else if(n instanceof t)var r=n.input(this,o,e);return r},gate:function(n,t){this.output.gate(n,t)},set:function(n){for(var t in this.nodes)t=this.nodes[t],t instanceof i?(void 0!==n.bias&&(t.bias=n.bias),t.squash=n.squash||t.squash,t.type=n.type||t.type):t instanceof s&&t.set(n)},disconnect:function(n,t){if(t=t||!1,n instanceof s)for(var o=0;o<this.nodes.length;o++)for(var e=0;e<n.nodes.length;e++){this.nodes[o].disconnect(n.nodes[e],t);for(index in this.connections.out){var r=this.connections.out[index];if(r.from==this.nodes[o]&&r.to==n.nodes[e]){this.connections.out.splice(index,1);break}}if(t)for(index in this.connections.in){var r=this.connections.in[index];if(r.from==n.nodes[e]&&r.to==this.nodes[o]){this.connections.in.splice(index,1);break}}}else if(n instanceof i)for(var o=0;o<this.nodes.length;o++){this.nodes[o].disconnect(n,t);for(index in this.connections.out){var r=this.connections.out[index];if(r.from==this.nodes[o]&&r.to==n){this.connections.out.splice(index,1);break}}if(t)for(index in this.connections.in){var r=this.connections.in[index];if(r.from==n&&r.to==this.nodes[o]){this.connections.in.splice(index,1);break}}}},clear:function(){for(var n in this.nodes)this.nodes[n].clear()}},t.Dense=function(n){var o=new t,i=new s(n);return o.nodes.push(i),o.output=i,o.input=function(n,o,s){return n instanceof t&&(n=n.output),o=o||e.Connection.ALL_TO_ALL,n.connect(i,o,s)},o},t.LSTM=function(n){var o=new t,i=new s(n),r=new s(n),a=new s(n),c=new s(n),h=new s(n);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(n,o,s){n instanceof t&&(n=n.output),o=o||e.Connection.ALL_TO_ALL;var h=[],u=n.connect(a,o,s);return h=h.concat(u),h=h.concat(n.connect(i,o,s)),h=h.concat(n.connect(c,o,s)),h=h.concat(n.connect(r,o,s)),i.gate(u,e.Gating.INPUT),h},o},t.GRU=function(n){var o=new t,i=new s(n),r=new s(n),a=new s(n),c=new s(n),h=new s(n),u=new s(n);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(n,o,s){n instanceof t&&(n=n.output),o=o||e.Connection.ALL_TO_ALL;var r=[];return r=r.concat(n.connect(i,o,s)),r=r.concat(n.connect(a,o,s)),r=r.concat(n.connect(c,o,s))},o},t.Memory=function(n,o){for(var i=new t,r=null,a=0;a<o;a++){var c=new s(n);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(n,o,s){if(n instanceof t&&(n=n.output),o=o||e.Connection.ALL_TO_ALL,n.nodes.length!=i.nodes[i.nodes.length-1].nodes.length)throw new Error("Previous layer size must be same as memory size");return n.connect(i.nodes[i.nodes.length-1],e.Connection.ONE_TO_ONE,1)},i}}).call(t,o(0)(n))},function(n,t,o){(function(n){function t(n,t){if(void 0===n||void 0===t)throw new Error("No input or output size given");this.input=n,this.output=t,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++)this.connect(this.nodes[o],this.nodes[s])}n&&(n.exports=t);var e=o(2),i=o(4),s=o(1),r=o(3),a=o(9),c=(s.Activation,s.Mutation);t.prototype={activate:function(n,t){var o=[];for(node in this.nodes)if("input"==this.nodes[node].type)this.nodes[node].activate(n[node]);else if("output"==this.nodes[node].type){var e=this.nodes[node].activate();o.push(e)}else t&&(this.nodes[node].mask=Math.random()<this.dropout?0:1),this.nodes[node].activate();return o},propagate:function(n,t,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(n,t,o[--e]);for(var i=this.nodes.length-this.output-1;i>=0;i--)this.nodes[i].propagate(n,t)},clear:function(){for(var n in this.nodes)this.nodes[n].clear()},connect:function(n,t){var o=n.connect(t);for(var e in o)e=o[e],n!=t?this.connections.push(e):this.selfconns.push(e);return o},disconnect:function(n,t){var o=n==t?this.selfconns:this.connections;for(conn in o){var e=o[conn];if(e.from==n&&e.to==t){null!=e.gater&&this.ungate(e),o.splice(conn,1);break}}n.disconnect(t)},gate:function(n,t){if(-1==this.nodes.indexOf(n))throw new Error("This node is not part of the network!");if(null!=t.gater)return void(r.warnings&&console.warn("This connection is already gated!"));n.gate(t),this.gates.push(t)},ungate:function(n){var t=this.gates.indexOf(n);if(-1==t)throw new Error("This connection is not gated!");this.gates.splice(t,1),n.gater.ungate(n)},remove:function(n){var t=this.nodes.indexOf(n);if(-1==t)throw new Error("This node does not exist in the network!");for(var o=[],e=[],i=n.connections.in.length-1;i>=0;i--){var r=n.connections.in[i];s.Mutation.SUB_NODE.keep_gates&&null!=r.gater&&r.gater!=n&&o.push(r.gater),e.push(r.from),this.disconnect(r.from,n)}for(var a=[],i=n.connections.out.length-1;i>=0;i--){var r=n.connections.out[i];s.Mutation.SUB_NODE.keep_gates&&null!=r.gater&&r.gater!=n&&o.push(r.gater),a.push(r.to),this.disconnect(n,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=n.connections.gated.length-1;i>=0;i--){var f=n.connections.gated[i];this.ungate(f)}this.disconnect(n,n),this.nodes.splice(t,1)},mutate:function(n){if(void 0===n)throw new Error("No (correct) mutate method given!");switch(n){case c.ADD_NODE:var t=this.connections[Math.floor(Math.random()*this.connections.length)],o=t.gater;this.disconnect(t.from,t.to);var i=this.nodes.indexOf(t.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(t.from,s)[0],u=this.connect(s,t.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],v=Math.max(p+1,this.input);v<this.nodes.length;v++){var g=this.nodes[v];d.isProjectingTo(g)||l.push([d,g])}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 t=this.connections[Math.floor(Math.random()*this.connections.length)],_=Math.random()*(n.max-n.min)+n.min;t.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(n);break;case c.MOD_ACTIVATION:if(!n.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-(n.mutateOutput?0:this.output)-this.input)+this.input),s=this.nodes[f];s.mutate(n);break;case c.ADD_SELF_CONN:for(var O=[],p=this.input;p<this.nodes.length;p++){var s=this.nodes[p];0==s.connections.self.weight&&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],v=this.input;v<p;v++){var g=this.nodes[v];d.isProjectingTo(g)||l.push([d,g])}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),g=this.nodes[f],L=d.bias,M=d.squash;d.bias=g.bias,d.squash=g.squash,g.bias=L,g.squash=M}},train:function(n,t){t=t||{},void 0===t.rate&&r.warnings&&console.warn("Using default learning rate, please define a rate!"),void 0===t.iterations&&r.warnings&&console.warn("No target iterations given, running until error is reached!");var o=Date.now(),e=t.log||!1,i=t.error||.05,a=t.cost||s.Cost.MSE,c=t.rate||.3,h=t.shuffle||!1,u=t.iterations||0,f=t.crossValidate||!1,l=t.clear||!1,p=t.dropout||0,d=t.momentum||0,v=t.ratePolicy||s.Rate.FIXED(),g=t.schedule;if(void 0===t.iterations&&void 0===t.error?r.warnings&&console.warn("At least one of the following options must be specified: error, iterations"):void 0===t.error&&(i=-1),this.dropout=p,f)var m=t.crossValidate.testSize,O=t.crossValidate.testError,w=Math.ceil((1-m)*n.length),_=n.slice(0,w),A=n.slice(w);for(var N=c,T=0,L=1;L>i&&(0==u||T<u)&&!(f&&L<=O);){if(T++,N=v(c,T),L=0,f?(this._trainSet(_,N,d,a),l&&this.clear(),L+=this.test(A,a).error,l&&this.clear()):(L+=this._trainSet(n,N,d,a),l&&this.clear(),L/=n.length),h)for(var M,E,S=n.length;S;M=Math.floor(Math.random()*S),E=n[--S],n[S]=n[M],n[M]=E);e&&T%e==0&&console.log("iteration",T,"error",L,"rate",N),g&&T%g.iterations==0&&g.function()}if(l&&this.clear(),p)for(var S=0;S<this.nodes.length;S++)"hidden"!=this.nodes[S].type&&"constant"!=this.nodes[S].type||(this.nodes[S].mask=1-this.dropout);return{error:L,iterations:T,time:Date.now()-o}},_trainSet:function(n,t,o,e){var i=0;for(var s in n){var r=n[s].input,a=n[s].output,c=this.activate(r,!0);this.propagate(t,o,a),i+=e(a,c)}return i},test:function(n,t){t=t||s.Cost.MSE;var o,e,i,r=0,a=Date.now();for(var c in n)o=n[c].input,i=n[c].output,e=this.activate(o),r+=t(i,e);return r/=n.length,{error:r,time:Date.now()-a}},graph:function(n,t){var o=0,e=0,i={nodes:[],links:[],constraints:[{type:"alignment",axis:"x",offsets:[]},{type:"alignment",axis:"y",offsets:[]}]};for(a in this.nodes){var s=this.nodes[a];"input"==s.type?(1==this.input?i.constraints[0].offsets.push({node:a,offset:0}):i.constraints[0].offsets.push({node:a,offset:.8*n/(this.input-1)*o++}),i.constraints[1].offsets.push({node:a,offset:0})):"output"==s.type&&(1==this.output?i.constraints[0].offsets.push({node:a,offset:0}):i.constraints[0].offsets.push({node:a,offset:.8*n/(this.output-1)*e++}),i.constraints[1].offsets.push({node:a,offset:-.8*t})),i.nodes.push({id:a,name:"hidden"==s.type?s.squash.name:s.type.toUpperCase(),activation:s.activation,bias:s.bias})}var r=this.connections.concat(this.selfconns);for(connection in r)if(connection=r[connection],null==connection.gater)i.links.push({source:this.nodes.indexOf(connection.from),target:this.nodes.indexOf(connection.to),weight:connection.weight});else{var a=i.nodes.length;i.nodes.push({id:a,activation:connection.gater.activation,name:"GATE"}),i.links.push({source:this.nodes.indexOf(connection.from),target:a,weight:.5*connection.weight}),i.links.push({source:a,target:this.nodes.indexOf(connection.to),weight:.5*connection.weight}),i.links.push({source:this.nodes.indexOf(connection.gater),target:a,weight:connection.gater.activation,gate:!0})}return i},toJSON:function(){var n={nodes:[],connections:[],input:this.input,output:this.output,dropout:this.dropout};for(index in this.nodes){var t=this.nodes[index],o=t.toJSON();if(o.index=index,n.nodes.push(o),0!=t.connections.self.weight){var o=t.connections.self.toJSON();o.from=index,o.to=index,o.gater=null!=t.connections.self.gater?this.nodes.indexOf(t.connections.self.gater):null,n.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,n.connections.push(o)}return n},set:function(n){for(var t in this.nodes)this.nodes[t].bias=n.bias||this.nodes[t].bias,this.nodes[t].squash=n.squash||this.nodes[t].squash},evolve:function(n,t){function o(t){for(var o=0,s=0;s<i;s++)f&&t.clear(),o-=t.test(n,e).error;return o-=(t.nodes.length+t.connections.length+t.gates.length)*r,(o=isNaN(o)?-1/0:o)/i}var e=t.cost||s.Cost.MSE,i=t.amount||1,r=void 0!==t.growth?t.growth:1e-4,c=t.iterations||0,h=t.error||.005,u=t.log||0,f=t.clear||!1,l=t.schedule,p=Date.now();t.network=this;for(var d=new a(0,0,o,t),v=-1/0,g=-1/0,m=null;v<-h&&(0==c||d.generation<c);){d.evolve();var O=d.getFittest();f&&O.clear(),v=-O.test(n).error-(O.nodes.length+O.connections.length+O.gates.length)*r,v>g&&(g=v,m=O),u&&d.generation%u==0&&console.log("generation",d.generation,"error",O.score,"cost error",v),l&&iteration%l.iterations==0&&l.function()}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}},t.fromJSON=function(n){var o=new t(n.input,n.output);o.dropout=n.dropout,o.nodes=[],o.connections=[];for(node in n.nodes)o.nodes.push(e.fromJSON(n.nodes[node]));for(i in n.connections){var i=n.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},t.merge=function(n,o){if(n=t.fromJSON(n.toJSON()),o=t.fromJSON(o.toJSON()),n.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=n.nodes[n.nodes.length-1-e]}for(var i=n.nodes.length-1-n.output;i<n.nodes.length;i++)n.nodes[i].type="hidden";return n.connections=n.connections.concat(o.connections),n.nodes=n.nodes.concat(o.nodes),n},t.crossOver=function(n,o,s){if(n.input!=o.input||n.output!=o.output)throw new Error("Networks don't have the same input/output size!");var r=new t(n.input,n.output);r.connections=[],r.nodes=[];var a=n.score||0,c=o.score||0;if(n=t.fromJSON(n.toJSON()),o=t.fromJSON(o.toJSON()),a==c)var h=Math.max(n.nodes.length,o.nodes.length),u=Math.min(n.nodes.length,o.nodes.length),f=Math.floor(Math.random()*(h-u+1)+u);else if(a>c)var f=n.nodes.length;else var f=o.nodes.length;for(var l=0;l<f;l++)if(l<n.nodes.length&&l<o.nodes.length){var p=null;if(l>=f-n.output)for(;null==p||"output"!=p.type;)p=Math.random()>=.5?n.nodes[l]:o.nodes[l];else for(;null==p||l<f-n.output&&"output"==p.type;)p=Math.random()>=.5?n.nodes[l]:o.nodes[l];r.nodes.push(p)}else l<n.nodes.length?l>=f-n.output?r.nodes.push(n.nodes[n.nodes.length-(l-(f-n.output-1))]):r.nodes.push(n.nodes[l]):l<o.nodes.length&&(l>=f-n.output?r.nodes.push(o.nodes[o.nodes.length-(l-(f-n.output-1))]):r.nodes.push(o.nodes[l]));for(p in r.nodes)r.nodes[p]=e.fromJSON(r.nodes[p].toJSON());var d={},v={},g=n.connections.concat(n.selfconns);for(m in g){var m=g[m],O={weight:m.weight,from:n.nodes.indexOf(m.from),to:n.nodes.indexOf(m.to),gater:n.nodes.indexOf(m.gater)};if(O.to==n.nodes.length-1){if(!(O.from<f-1))continue;O.to=f-1}var w=i.innovationID(O.from,O.to);d[w]=O}var _=o.connections.concat(o.selfconns);for(m in _){var m=_[m],O={weight:m.weight,from:o.nodes.indexOf(m.from),to:o.nodes.indexOf(m.to),gater:o.nodes.indexOf(m.gater)};if(O.to==o.nodes.length-1){if(!(O.from<f-1))continue;O.to=f-1}var w=i.innovationID(O.from,O.to);v[w]=O}var A={};for(var w in d)w in v&&(A[w]=[d[w],v[w]],delete d[w],delete v[w]);var N=[];for(m in A){var m=Math.random()>=.5?A[m][0]:A[m][1];N.push(m)}if(a==c){for(m in d)N.push(d[m]);for(m in v)N.push(v[m])}else if(a>c)for(m in d)N.push(d[m]);else for(m in v)N.push(v[m]);for(m in N){var T=N[m];if(T.to<f&&T.from<f){var L=r.nodes[T.from],M=r.nodes[T.to],m=r.connect(L,M)[0];m.weight=T.weight,-1!=T.gater&&T.gater<f&&r.gate(r.nodes[T.gater],m)}}return r}}).call(t,o(0)(n))},function(n,t,o){(function(n){var t=o(7),e=o(1),i=o(2),s=o(5),r=o(6),a={Construct:function(n){var o=new t(0,0),e=[];for(item in n)if(n[item]instanceof s)for(var a in n[item].nodes)e.push(n[item].nodes[a]);else if(n[item]instanceof r)for(var c in n[item].nodes)for(var a in n[item].nodes[c].nodes)e.push(n[item].nodes[c].nodes[a]);else n[item]instanceof i&&e.push(n[item]);for(var h=[],u=[],f=e.length-1;f>=0;f--)"output"==e[f].type||e[f].connections.out.length+e[f].connections.gated.length==0?(e[f].type="output",o.output++,u.push(e[f]),e.splice(f,1)):"input"!=e[f].type&&e[f].connections.in.length||(e[f].type="input",o.input++,h.push(e[f]),e.splice(f,1));if(e=h.concat(e).concat(u),0==o.input||0==o.output)throw new Error("Given nodes have no clear input/output node!");for(var a in e){for(var l in e[a].connections.out)o.connections.push(e[a].connections.out[l]);for(var l in e[a].connections.gated)o.gates.push(e[a].connections.gated[l]);0!=e[a].connections.self.weight&&o.selfconns.push(e[a].connections.self)}return o.nodes=e,o},Perceptron:function(){var n=Array.prototype.slice.call(arguments);if(n.length<3)throw new Error("not enough layers (minimum 3) !!");var t=[];t.push(new s(n[0]));for(var o=1;o<n.length;o++){var e=n[o],e=new s(e);t.push(e),t[o-1].connect(t[o])}return a.Construct(t)},Random:function(n,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 t(n,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 n=Array.prototype.slice.call(arguments);if(n.length<3)throw new Error("not enough layers (minimum 3) !!");var t=n.pop();if("number"==typeof t){var o=new s(t);t={}}else var o=new s(n.pop());o.set({type:"output"});var i={};i.memoryToMemory=t.memoryToMemory||!1,i.outputToMemory=t.outputToMemory||!1,i.outputToGates=t.outputToGates||!1,i.inputToOutput=void 0==t.inputToOutput||t.inputToOutput,i.inputToDeep=void 0==t.inputToDeep||t.inputToDeep;var r=new s(n.shift());r.set({type:"input"});var c=n,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),v=new s(l),g=new s(l),m=f==c.length-1?o:new s(l);p.set({bias:1}),d.set({bias:1}),g.set({bias:1});var O=u.connect(v,e.Connection.ALL_TO_ALL);u.connect(p,e.Connection.ALL_TO_ALL),u.connect(g,e.Connection.ALL_TO_ALL),u.connect(d,e.Connection.ALL_TO_ALL),v.connect(p,e.Connection.ALL_TO_ALL),v.connect(d,e.Connection.ALL_TO_ALL),v.connect(g,e.Connection.ALL_TO_ALL);var w=v.connect(v,e.Connection.ONE_TO_ONE),_=v.connect(m,e.Connection.ALL_TO_ALL);if(p.gate(O,e.Gating.INPUT),d.gate(w,e.Gating.SELF),g.gate(_,e.Gating.OUTPUT),i.inputToDeep&&f>0){var O=r.connect(v,e.Connection.ALL_TO_ALL);p.gate(O,e.Gating.INPUT)}if(i.memoryToMemory){var O=v.connect(v,e.Connection.ALL_TO_ELSE);p.gate(O,e.Gating.INPUT)}if(i.outputToMemory){var O=o.connect(v,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(g,e.Connection.ALL_TO_ALL)),h.push(p),h.push(d),h.push(v),h.push(g),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 n=Array.prototype.slice.call(arguments);if(n.length<3)throw new Error("not enough layers (minimum 3) !!");var t=new s(n.shift()),o=new s(n.pop()),e=n,i=[];i.push(t);for(var c=t,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(n){var t=new s(n),o=new s(n);return t.connect(o,e.Connection.ALL_TO_ALL),t.set({type:"input"}),o.set({squash:e.Activation.STEP,type:"output"}),new a.Construct([t,o])},NARX:function(n,t,o,i,s){Array.isArray(t)||(t=[t]);var c=[],h=new r.Dense(n),u=new r.Memory(n,i),f=[],l=new r.Dense(o),p=new r.Memory(o,s);c.push(h),c.push(p);for(var d=0;d<t.length;d++){var v=new r.Dense(t[d]);f.push(v),c.push(v),void 0!==f[d-1]&&f[d-1].connect(v,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)}};n&&(n.exports=a)}).call(t,o(0)(n))},function(n,t,o){(function(n){function t(n,t,o,s){this.input=n,this.output=t,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.ADD_CONN,i.Mutation.SUB_CONN,i.Mutation.ADD_NODE,i.Mutation.SUB_NODE,i.Mutation.MOD_BIAS,i.Mutation.MOD_WEIGHT,i.Mutation.MOD_ACTIVATION],this.generation=0,this.createPool(s.network||new e(this.input,this.output))}n&&(n.exports=t);var e=(o(2),o(7)),i=o(1),s=(i.Activation,i.Mutation,i.Selection);i.Crossover;t.prototype={createPool:function(n){this.population=[];for(var t=0;t<this.popsize;t++){var o=e.fromJSON(n.toJSON());o.score=null,this.population.push(o)}},evolve:function(){null==this.population[this.population.length-1].score&&this.evaluate(),this.sort();for(var n=[],t=0;t<this.elitism;t++)n.push(this.population[t]);for(var t=0;t<this.popsize-this.elitism;t++)n.push(this.getOffspring());this.population=n,this.mutate();for(var t=0;t<this.population.length;t++)this.population[t].score=null;this.generation++},getOffspring:function(){parent1=this.getParent(),parent2=this.getParent(),1==this.equal&&(parent1.score=0,parent2.score=0);var n=this.crossover[Math.floor(Math.random()*this.crossover.length)];return e.crossOver(parent1,parent2,n)},mutate:function(){for(genome in this.population)if(Math.random()<=this.mutationRate)for(var n=0;n<this.mutationAmount;n++){var t=this.mutation[Math.floor(Math.random()*this.mutation.length)];this.population[genome].mutate(t)}},evaluate:function(){for(genome in this.population){var n=this.fitness(this.population[genome]);this.population[genome].score=n}},sort:function(){this.population.sort(function(n,t){return t.score-n.score})},getFittest:function(){return null==this.population[this.population.length-1].score&&this.evaluate(),this.sort(),this.population[0]},getAverage:function(){null==this.population[this.population.length-1].score&&this.evaluate();var n=0;for(genome in this.population)n+=this.population[genome].score;return n/this.popsize},getParent:function(){switch(this.selection){case s.POWER:this.population[0].score<this.population[1].score&&this.sort();var n=Math.floor(Math.pow(Math.random(),this.selection.power)*this.popsize);return this.population[n];case s.FITNESS_PROPORTIONATE:var t=0,o=0;for(var e in this.population){var i=this.population[e].score;o=i<o?i:o,t+=i}o=Math.abs(o),t+=o*this.popsize;var r=Math.random()*t,a=0;for(var e in this.population)if(e=this.population[e],a+=e.score+o,r<a)return e;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 c=[],h=0;h<this.selection.size;h++){var r=this.population[Math.floor(Math.random()*this.population.length)];c.push(r)}c.sort(function(n,t){return t.score-n.score});for(var h=0;h<this.selection.size;h++)if(Math.random()<this.selection.probability||h==this.selection.size-1)return c[h]}},export:function(){var n=[];for(var t in this.population)t=this.population[t],n.push(t.toJSON());return n},import:function(n){var t=[];for(var o in n)o=n[o],t.push(e.fromJSON(o));this.population=t,this.popsize=t.length}}}).call(t,o(0)(n))},function(n,t,o){(function(n){var t={LOGISTIC:function(n,o){if(!o)return 1/(1+Math.exp(-n));var e=t.LOGISTIC(n);return e*(1-e)},TANH:function(n,o){return o?1-Math.pow(t.TANH(n),2):Math.tanh(n)},IDENTITY:function(n,t){return t?1:n},STEP:function(n,t){return t?0:n>0?1:0},RELU:function(n,t){return t?n>0?1:0:n>0?n:0},SOFTSIGN:function(n,t){var o=1+Math.abs(n);return t?n/Math.pow(o,2):n/o},SINUSOID:function(n,t){return t?Math.cos(n):Math.sin(n)},GAUSSIAN:function(n,t){var o=Math.exp(-Math.pow(n,2));return t?-2*n*o:o},BENT_IDENTITY:function(n,t){var o=Math.sqrt(Math.pow(n,2)+1);return t?n/(2*o)+1:(o-1)/2+n},BIPOLAR:function(n,t){return t?0:n>0?1:-1},BIPOLAR_SIGMOID:function(n,t){var o=2/(1+Math.exp(-n))-1;return t?.5*(1+o)*(1-o):o},HARD_TANH:function(n,t){return t?n>-1&&n<1?1:0:Math.max(-1,Math.min(1,n))},ABSOLUTE:function(n,t){return t?n<0?-1:1:Math.abs(n)},INVERSE:function(n,t){return t?-1:1-n}};n&&(n.exports=t)}).call(t,o(0)(n))},function(n,t,o){(function(n){var t={ALL_TO_ALL:{name:"OUTPUT"},ALL_TO_ELSE:{name:"INPUT"},ONE_TO_ONE:{name:"SELF"}};n&&(n.exports=t)}).call(t,o(0)(n))},function(n,t,o){(function(n){var t={CROSS_ENTROPY:function(n,t){var o=0;for(var e in t)o-=n[e]*Math.log(Math.max(t[e],1e-15))+(1-n[e])*Math.log(1-Math.max(t[e],1e-15));return o},MSE:function(n,t){var o=0;for(var e in t)o+=Math.pow(n[e]-t[e],2);return o/t.length},BINARY:function(n,t){var o=0;for(var e in t)o+=Math.round(2*n[e])!=Math.round(2*t[e]);return o},MAE:function(n,t){var o=0;for(var e in t)o+=Math.abs(n[e]-t[e]);return o/t.length},MAPE:function(n,t){var o=0;for(var e in t)o+=Math.abs((t[e]-n[e])/Math.max(n[e],1e-15));return o/t.length},MSLE:function(n,t){var o=0;for(var e in t)o+=Math.log(Math.max(n[e],1e-15))-Math.log(Math.max(t[e],1e-15));return o},HINGE:function(n,t){var o=0;for(var e in t)o+=Math.max(0,1-n[e]*t[e]);return o}};n&&(n.exports=t)}).call(t,o(0)(n))},function(n,t,o){(function(n){var t={SINGLE_POINT:{name:"SINGLE_POINT",config:[.4]},TWO_POINT:{name:"TWO_POINT",config:[.4,.9]},UNIFORM:{name:"UNIFORM"},AVERAGE:{name:"AVERAGE"}};n&&(n.exports=t)}).call(t,o(0)(n))},function(n,t,o){(function(n){var t={OUTPUT:{name:"OUTPUT"},INPUT:{name:"INPUT"},SELF:{name:"SELF"}};n&&(n.exports=t)}).call(t,o(0)(n))},function(n,t,o){(function(n){var t=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:[t.LOGISTIC,t.TANH,t.RELU,t.IDENTITY,t.STEP,t.SOFTSIGN,t.SINUSOID,t.GAUSSIAN,t.BENT_IDENTITY,t.BIPOLAR,t.BIPOLAR_SIGMOID,t.HARD_TANH,t.ABSOLUTE]},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],n&&(n.exports=e)}).call(t,o(0)(n))},function(n,t,o){(function(n){var t={FIXED:function(){return function(n,t){return n}},STEP:function(n,t){return n=n||.9,t=t||100,function(o,e){return o*Math.pow(n,Math.floor(e/t))}},EXP:function(n){return n=n||.999,function(t,o){return t*Math.pow(n,o)}},INV:function(n,t){return n=n||.001,t=t||2,function(o,e){return o*Math.pow(1+n*e,-t)}}};n&&(n.exports=t)}).call(t,o(0)(n))},function(n,t,o){(function(n){var t={FITNESS_PROPORTIONATE:{name:"FITNESS_PROPORTIONATE"},POWER:{name:"POWER",power:4},TOURNAMENT:{name:"TOURNAMENT",size:5,probability:.5}};n&&(n.exports=t)}).call(t,o(0)(n))},function(n,t,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(t,e))&&(n.exports=i),void 0!==n&&n.exports&&(n.exports=s),"object"==typeof window&&(!function(){var n=window.neataptic;s.ninja=function(){return window.neataptic=n,s}}(),window.neataptic=s)}])});