sakuya/node_modules/neataptic/docs/cdn/1.2.23/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=r.LOGISTIC,this.type=n||"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}}n&&(n.exports=t);var e=o(4),i=o(1),s=(o(5),o(3)),r=i.Activation,a=i.Mutation;t.prototype={activate:function(n){if(void 0!==n)return this.activation=n,this.activation;this.old=this.state,this.state=this.connections.self.gain*this.connections.self.weight*this.state+this.bias;for(var t=0;t<this.connections.in.length;t++){var o=this.connections.in[t];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=[],t=0;t<this.connections.gated.length;t++){var s=this.connections.gated[t],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 t=0;t<this.connections.in.length;t++){var o=this.connections.in[t];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(n,t,o){t=t||0,n=n||.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=n*h*this.mask+t*s.previousDeltaWeight;s.weight+=l,s.previousDeltaWeight=l}var p=n*this.error.responsibility+t*this.previousDeltaBias;this.bias+=p,this.previousDeltabias=p}},connect:function(n,t){var o=[];if(void 0!==n.bias)if(n==this)0!=this.connections.self.weight?s.warnings&&console.warn("This connection already exists!"):this.connections.self.weight=t||1,o.push(this.connections.self);else{if(this.isProjectingTo(n))throw new Error("Already projecting a connection to this node!");var i=new e(this,n,t);n.connections.in.push(i),this.connections.out.push(i),o.push(i)}else for(var r=0;r<n.nodes.length;r++){var i=new e(this,n.nodes[r],t);n.nodes[r].connections.in.push(i),this.connections.out.push(i),n.connections.in.push(i),o.push(i)}return o},disconnect:function(n,t){if(this==n)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==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=0;t<n.length;t++){var o=n[t];this.connections.gated.push(o),o.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=0;n<this.connections.in.length;n++){var t=this.connections.in[n];t.elegibility=0,t.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 a.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 a.MOD_BIAS:var o=Math.random()*(n.max-n.min)+n.min;this.bias+=o}},isProjectingTo:function(n){for(var t=0;t<this.connections.out.length;t++){if(this.connections.out[t].to==n)return!0}return n==this&&0!=this.connections.self.weight},isProjectedBy:function(n){for(var t=0;t<this.connections.in.length;t++){if(this.connections.in[t].from==n)return!0}return n==this&&0!=this.connections.self.weight},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 r)if(r[squash].name==n.squash){o.squash=r[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++){var r=Math.random()*this.input*Math.sqrt(2/this.input);this.connect(this.nodes[o],this.nodes[s],r)}}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){for(var o=[],e=0;e<this.nodes.length;e++)if("input"==this.nodes[e].type)this.nodes[e].activate(n[e]);else if("output"==this.nodes[e].type){var i=this.nodes[e].activate();o.push(i)}else t&&(this.nodes[e].mask=Math.random()<this.dropout?0:1),this.nodes[e].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>=this.input;i--)this.nodes[i].propagate(n,t)},clear:function(){for(var n=0;n<this.nodes.length;n++)this.nodes[n].clear()},connect:function(n,t,o){for(var e=n.connect(t,o),i=0;i<e.length;i++){var s=e[i];n!=t?this.connections.push(s):this.selfconns.push(s)}return e},disconnect:function(n,t){for(var o=n==t?this.selfconns:this.connections,e=0;e<o.length;e++){var i=o[e];if(i.from==n&&i.to==t){null!=i.gater&&this.ungate(i),o.splice(e,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!");var o=[];this.disconnect(n,n);for(var 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],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 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];-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(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,g=t.batchSize||1,v=t.ratePolicy||s.Rate.FIXED(),m=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 O=t.crossValidate.testSize,w=t.crossValidate.testError,_=Math.ceil((1-O)*n.length),A=n.slice(0,_),N=n.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(n,g,T,d,a),l&&this.clear()),h)for(var E,x,b=n.length;b;E=Math.floor(Math.random()*b),x=n[--b],n[b]=n[E],n[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(n,t,o,e,i){for(var s=0,r=0;r<n.length;r++){var a=n[r].input,c=n[r].output,h=this.activate(a,!0);this.propagate(o,e,c),s+=i(c,h)}return s/r},test:function(n,t){t=t||s.Cost.MSE;for(var o,e,i,r=0,a=Date.now(),c=0;c<n.length;c++)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){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*n/(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*n/(this.output-1)*e++}),i.constraints[1].offsets.push({node:s,offset:-.8*t})),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 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=0;t<this.nodes.length;t++)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),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(n).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}},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=o.input-1;i>=0;i--)o.nodes.splice(i,1);for(var i=n.nodes.length-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(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=n.output,p=0;p<f;p++){if(p<f-l){var d=Math.random(),g=d>=.5?n.nodes[p]:o.nodes[p],v=d<.5?n.nodes[p]:o.nodes[p];void 0!==g&&"output"!=g.type||(g=v)}else if(Math.random()>=.5)var g=n.nodes[n.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<n.connections.length;p++){var _=n.connections[p],A={weight:_.weight,from:n.nodes.indexOf(_.from),to:n.nodes.indexOf(_.to),gater:n.nodes.indexOf(_.gater)};i.innovationID(A.from,A.to);O.push(A)}for(var p=0;p<n.selfconns.length;p++){var _=n.selfconns[p],A={weight:_.weight,from:n.nodes.indexOf(_.from),to:n.nodes.indexOf(_.to),gater:n.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(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){for(var o=new t(0,0),e=[],a=0;a<n.length;a++)if(n[a]instanceof s)for(var c=0;c<n[a].nodes.length;c++)e.push(n[a].nodes[c]);else if(n[a]instanceof r)for(var c=0;c<n[a].nodes.length;c++)for(var h=0;h<n[a].nodes[c].nodes.length;h++)e.push(n[a].nodes[c].nodes[h]);else n[a]instanceof i&&e.push(n[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 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),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 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 g=new r.Dense(t[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)}};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.FFW,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(){var n=this.getParent(),t=this.getParent();return 1==this.equal&&(n.score=0,t.score=0),e.crossOver(n,t)},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,t){var o=1/(1+Math.exp(-n));return t?o*(1-o):o},TANH:function(n,t){return t?1-Math.pow(Math.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},SELU:function(n,t){var o=1.6732632423543772,e=1.0507009873554805,i=(n>0?n:o*Math.exp(n)-o)*e;return t?n>0?e:i+o:i}};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){for(var o=0,e=0;e<t.length;e++)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){for(var o=0,e=0;e<t.length;e++)o+=Math.pow(n[e]-t[e],2);return o/t.length},BINARY:function(n,t){for(var o=0,e=0;e<t.length;e++)o+=Math.round(2*n[e])!=Math.round(2*t[e]);return o},MAE:function(n,t){for(var o=0,e=0;e<t.length;e++)o+=Math.abs(n[e]-t[e]);return o/t.length},MAPE:function(n,t){for(var o=0,e=0;e<t.length;e++)o+=Math.abs((t[e]-n[e])/Math.max(n[e],1e-15));return o/t.length},MSLE:function(n,t){for(var o=0,e=0;e<t.length;e++)o+=Math.log(Math.max(n[e],1e-15))-Math.log(Math.max(t[e],1e-15));return o},HINGE:function(n,t){for(var o=0,e=0;e<t.length;e++)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,t.INVERSE,t.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],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)}])});