sakuya/node_modules/neataptic/docs/cdn/1.2.16/neataptic.min.js

27 lines
42 KiB
JavaScript
Raw Normal View History

2022-04-10 00:37:53 +08:00
/*!
* 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