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

27 lines
43 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(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.totalDeltaBias=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 h=0;h<e.length;h++){var r=e[h],c=i[h],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*c:(o.xtrace.nodes.push(r),o.xtrace.values.push(this.derivative*o.elegibility*c))}}return this.activation},propagate:function(t,n,o,e){n=n||0,t=t||.3;var i=0;if("output"==this.type)this.error.responsibility=this.error.projected=e-this.activation;else{for(var s=0;s<this.connections.out.length;s++){var r=this.connections.out[s],a=r.to;i+=a.error.responsibility*r.weight*r.gain}this.error.projected=this.derivative*i,i=0;for(var s=0;s<this.connections.gated.length;s++){var h=this.connections.gated[s],a=h.to,c=a.connections.self.gater==this?a.old:0;c+=h.weight*h.from.activation,i+=a.error.responsibility*c}this.error.gated=this.derivative*i,this.error.responsibility=this.error.projected+this.error.gated}if("constant"!=this.type){for(var s=0;s<this.connections.in.length;s++){for(var r=this.connections.in[s],u=this.error.projected*r.elegibility,l=0;l<r.xtrace.nodes.length;l++){var a=r.xtrace.nodes[l],f=r.xtrace.values[l];u+=a.error.responsibility*f}var p=t*u*this.mask;r.totalDeltaWeight+=p,o&&(r.totalDeltaWeight+=n*r.previousDeltaWeight,r.weight+=r.totalDeltaWeight,r.previousDeltaWeight=r.totalDeltaWeight,r.totalDeltaWeight=0)}var d=t*this.error.responsibility;this.totalDeltaBias+=d,o&&(this.totalDeltaBias+=n*this.pr