sakuya/node_modules/neataptic/mkdocs/theme/cdn/1.2.25/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(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.neataptic=n():t.neataptic=n()}(this,function(){return function(t){function n(e){if(o[e])return o[e].exports;var i=o[e]={i:e,l:!1,exports:{}};return t[e].call(i.exports,i,i.exports,n),i.l=!0,i.exports}var o={};return n.m=t,n.c=o,n.i=function(t){return t},n.d=function(t,o,e){n.o(t,o)||Object.defineProperty(t,o,{configurable:!1,enumerable:!0,get:e})},n.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(o,"a",o),o},n.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},n.p="",n(n.s=18)}([function(t,n){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,n,o){var e,i,s={Activation:o(10),Mutation:o(15),Selection:o(17),Crossover:o(13),Cost:o(12),Gating:o(14),Connection:o(11),Rate:o(16)};e=[],void 0!==(i=function(){return s}.apply(n,e))&&(t.exports=i),void 0!==t&&t.exports&&(t.exports=s),"object"==typeof window&&(!function(){var t=window.methods;s.ninja=function(){return window.methods=t,s}}(),window.methods=s)},function(t,n,o){(function(t){function n(t){this.bias="input"==t?0:.2*Math.random()-.1,this.squash=r.LOGISTIC,this.type=t||"hidden",this.activation=0,this.state=0,this.old=0,this.mask=1,this.previousDeltaBias=0,this.connections={in:[],out:[],gated:[],self:new e(this,this,0)},this.error={responsibility:0,projected:0,gated:0}}t&&(t.exports=n);var e=o(4),i=o(1),s=(o(5),o(3)),r=i.Activation,a=i.Mutation;n.prototype={activate:function(t){if(void 0!==t)return this.activation=t,this.activation;this.old=this.state,this.state=this.connections.self.gain*this.connections.self.weight*this.state+this.bias;for(var n=0;n<this.connections.in.length;n++){var o=this.connections.in[n];this.state+=o.from.activation*o.weight*o.gain}this.activation=this.squash(this.state)*this.mask,this.derivative=this.squash(this.state,!0);for(var e=[],i=[],n=0;n<this.connections.gated.length;n++){var s=this.connections.gated[n],r=s.to,a=e.indexOf(r);a>-1?i[a]+=s.weight*s.from.activation:(e.push(r),i.push(s.weight*s.from.activation+(r.connections.self.gater==this?r.old:0))),s.gain=this.activation}for(var n=0;n<this.connections.in.length;n++){var o=this.connections.in[n];o.elegibility=this.connections.self.gain*this.connections.self.weight*o.elegibility+o.from.activation*o.gain;for(var c=0;c<e.length;c++){var r=e[c],h=i[c],a=o.xtrace.nodes.indexOf(r);a>-1?o.xtrace.values[a]=r.connections.self.gain*r.connections.self.weight*o.xtrace.values[a]+this.derivative*o.elegibility*h:(o.xtrace.nodes.push(r),o.xtrace.values.push(this.derivative*o.elegibility*h))}}return this.activation},propagate:function(t,n,o){n=n||0,t=t||.3;var e=0;if("output"==this.type)this.error.responsibility=this.error.projected=o-this.activation;else{for(var i=0;i<this.connections.out.length;i++){var s=this.connections.out[i],r=s.to;e+=r.error.responsibility*s.weight*s.gain}this.error.projected=this.derivative*e,e=0;for(var i=0;i<this.connections.gated.length;i++){var a=this.connections.gated[i],r=a.to,c=r.connections.self.gater==this?r.old:0;c+=a.weight*a.from.activation,e+=r.error.responsibility*c}this.error.gated=this.derivative*e,this.error.responsibility=this.error.projected+this.error.gated}if("constant"!=this.type){for(var i=0;i<this.connections.in.length;i++){for(var s=this.connections.in[i],h=this.error.projected*s.elegibility,u=0;u<s.xtrace.nodes.length;u++){var r=s.xtrace.nodes[u],f=s.xtrace.values[u];h+=r.error.responsibility*f}var l=t*h*this.mask+n*s.previousDeltaWeight;s.weight+=l,s.previousDeltaWeight=l}var p=t*this.error.responsibility+n*this.previousDeltaBias;this.bias+=p,this.previousDeltabias=p}},connect:function(t,n){var o=[];if(void 0!==t.bias)if(t==this)0!=this.connections.self.weight?s.warnings&&console.warn(