/**
 * Minified by jsDelivr using Terser v5.48.0.
 * Original file: /npm/convnetjs2@2.0.6/build/convnet.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
!function t(s,i,e){function r(o,h){if(!i[o]){if(!s[o]){var n="function"==typeof require&&require;if(!h&&n)return n(o,!0);if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var _=i[o]={exports:{}};s[o][0].call(_.exports,function(t){return r(s[o][1][t]||t)},_,_.exports,t,s,i,e)}return i[o].exports}for(var a="function"==typeof require&&require,o=0;o<e.length;o++)r(e[o]);return r}({1:[function(t,s,i){const e=t("./Util"),r=t("./Vol");(s.exports=function(t){t=t||{};this.out_depth=t.filters,this.sx=t.sx,this.in_depth=t.in_depth,this.in_sx=t.in_sx,this.in_sy=t.in_sy,this.sy=void 0!==t.sy?t.sy:this.sx,this.stride=void 0!==t.stride?t.stride:1,this.pad=void 0!==t.pad?t.pad:0,this.l1_decay_mul=void 0!==t.l1_decay_mul?t.l1_decay_mul:0,this.l2_decay_mul=void 0!==t.l2_decay_mul?t.l2_decay_mul:1,this.out_sx=Math.floor((this.in_sx+2*this.pad-this.sx)/this.stride+1),this.out_sy=Math.floor((this.in_sy+2*this.pad-this.sy)/this.stride+1),this.layer_type="conv";var s=void 0!==t.bias_pref?t.bias_pref:0;this.filters=[];for(var i=0;i<this.out_depth;i++)this.filters.push(new r(this.sx,this.sy,this.in_depth));this.biases=new r(1,1,this.out_depth,s)}).prototype={forward:function(t,s){this.in_act=t;for(var i=new r(0|this.out_sx,0|this.out_sy,0|this.out_depth,0),e=0|t.sx,a=0|t.sy,o=0|this.stride,h=0;h<this.out_depth;h++)for(var n=this.filters[h],u=0|-this.pad,_=0|-this.pad,d=0;d<this.out_sy;_+=o,d++){u=0|-this.pad;for(var l=0;l<this.out_sx;u+=o,l++){for(var p=0,y=0;y<n.sy;y++)for(var c=_+y,f=0;f<n.sx;f++){var m=u+f;if(c>=0&&c<a&&m>=0&&m<e)for(var v=0;v<n.depth;v++)p+=n.w[(n.sx*y+f)*n.depth+v]*t.w[(e*c+m)*t.depth+v]}p+=this.biases.w[h],i.set(l,d,h,p)}}return this.out_act=i,this.out_act},backward:function(){var t=this.in_act;t.dw=e.zeros(t.w.length);for(var s=0|t.sx,i=0|t.sy,r=0|this.stride,a=0;a<this.out_depth;a++)for(var o=this.filters[a],h=0|-this.pad,n=0|-this.pad,u=0;u<this.out_sy;n+=r,u++){h=0|-this.pad;for(var _=0;_<this.out_sx;h+=r,_++){for(var d=this.out_act.get_grad(_,u,a),l=0;l<o.sy;l++)for(var p=n+l,y=0;y<o.sx;y++){var c=h+y;if(p>=0&&p<i&&c>=0&&c<s)for(var f=0;f<o.depth;f++){var m=(s*p+c)*t.depth+f,v=(o.sx*l+y)*o.depth+f;o.dw[v]+=t.w[m]*d,t.dw[m]+=o.w[v]*d}}this.biases.dw[a]+=d}}},getParamsAndGrads:function(){for(var t=[],s=0;s<this.out_depth;s++)t.push({params:this.filters[s].w,grads:this.filters[s].dw,l2_decay_mul:this.l2_decay_mul,l1_decay_mul:this.l1_decay_mul});return t.push({params:this.biases.w,grads:this.biases.dw,l1_decay_mul:0,l2_decay_mul:0}),t},toJSON:function(){var t={};t.sx=this.sx,t.sy=this.sy,t.stride=this.stride,t.in_depth=this.in_depth,t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t.l1_decay_mul=this.l1_decay_mul,t.l2_decay_mul=this.l2_decay_mul,t.pad=this.pad,t.filters=[];for(var s=0;s<this.filters.length;s++)t.filters.push(this.filters[s].toJSON());return t.biases=this.biases.toJSON(),t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type,this.sx=t.sx,this.sy=t.sy,this.stride=t.stride,this.in_depth=t.in_depth,this.filters=[],this.l1_decay_mul=void 0!==t.l1_decay_mul?t.l1_decay_mul:1,this.l2_decay_mul=void 0!==t.l2_decay_mul?t.l2_decay_mul:1,this.pad=void 0!==t.pad?t.pad:0;for(var s=0;s<t.filters.length;s++){var i=new r(0,0,0,0);i.fromJSON(t.filters[s]),this.filters.push(i)}this.biases=new r(0,0,0,0),this.biases.fromJSON(t.biases)}}},{"./Util":18,"./Vol":19}],2:[function(t,s,i){const e=t("./Util");(s.exports=function(t){t=t||{};this.out_sx=t.in_sx,this.out_sy=t.in_sy,this.out_depth=t.in_depth,this.layer_type="dropout",this.drop_prob=void 0!==t.drop_prob?t.drop_prob:.5,this.dropped=e.zeros(this.out_sx*this.out_sy*this.out_depth)}).prototype={forward:function(t,s){this.in_act=t,void 0===s&&(s=!1);var i=t.clone(),e=t.w.length;if(s)for(var r=0;r<e;r++)Math.random()<this.drop_prob?(i.w[r]=0,this.dropped[r]=!0):this.dropped[r]=!1;else for(r=0;r<e;r++)i.w[r]*=this.drop_prob;return this.out_act=i,this.out_act},backward:function(){var t=this.in_act,s=this.out_act,i=t.w.length;t.dw=e.zeros(i);for(var r=0;r<i;r++)this.dropped[r]||(t.dw[r]=s.dw[r])},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t.drop_prob=this.drop_prob,t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type,this.drop_prob=t.drop_prob}}},{"./Util":18}],3:[function(t,s,i){const e=t("./Vol"),r=t("./Util");(s.exports=function(t){t=t||{};this.out_depth=void 0!==t.num_neurons?t.num_neurons:t.filters,this.l1_decay_mul=void 0!==t.l1_decay_mul?t.l1_decay_mul:0,this.l2_decay_mul=void 0!==t.l2_decay_mul?t.l2_decay_mul:1,this.num_inputs=t.in_sx*t.in_sy*t.in_depth,this.out_sx=1,this.out_sy=1,this.layer_type="fc";var s=void 0!==t.bias_pref?t.bias_pref:0;this.filters=[];for(var i=0;i<this.out_depth;i++)this.filters.push(new e(1,1,this.num_inputs));this.biases=new e(1,1,this.out_depth,s)}).prototype={forward:function(t,s){this.in_act=t;for(var i=new e(1,1,this.out_depth,0),r=t.w,a=0;a<this.out_depth;a++){for(var o=0,h=this.filters[a].w,n=0;n<this.num_inputs;n++)o+=r[n]*h[n];o+=this.biases.w[a],i.w[a]=o}return this.out_act=i,this.out_act},backward:function(){var t=this.in_act;t.dw=r.zeros(t.w.length);for(var s=0;s<this.out_depth;s++){for(var i=this.filters[s],e=this.out_act.dw[s],a=0;a<this.num_inputs;a++)t.dw[a]+=i.w[a]*e,i.dw[a]+=t.w[a]*e;this.biases.dw[s]+=e}},getParamsAndGrads:function(){for(var t=[],s=0;s<this.out_depth;s++)t.push({params:this.filters[s].w,grads:this.filters[s].dw,l1_decay_mul:this.l1_decay_mul,l2_decay_mul:this.l2_decay_mul});return t.push({params:this.biases.w,grads:this.biases.dw,l1_decay_mul:0,l2_decay_mul:0}),t},toJSON:function(){var t={};t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t.num_inputs=this.num_inputs,t.l1_decay_mul=this.l1_decay_mul,t.l2_decay_mul=this.l2_decay_mul,t.filters=[];for(var s=0;s<this.filters.length;s++)t.filters.push(this.filters[s].toJSON());return t.biases=this.biases.toJSON(),t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type,this.num_inputs=t.num_inputs,this.l1_decay_mul=void 0!==t.l1_decay_mul?t.l1_decay_mul:1,this.l2_decay_mul=void 0!==t.l2_decay_mul?t.l2_decay_mul:1,this.filters=[];for(var s=0;s<t.filters.length;s++){var i=new e(0,0,0,0);i.fromJSON(t.filters[s]),this.filters.push(i)}this.biases=new e(0,0,0,0),this.biases.fromJSON(t.biases)}}},{"./Util":18,"./Vol":19}],4:[function(t,s,i){var e=t("./Util").getopt;(s.exports=function(t){t=t||{};this.out_depth=e(t,["out_depth","depth"],0),this.out_sx=e(t,["out_sx","sx","width"],1),this.out_sy=e(t,["out_sy","sy","height"],1),this.layer_type="input"}).prototype={forward:function(t,s){return this.in_act=t,this.out_act=t,this.out_act},backward:function(){},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type}}},{"./Util":18}],5:[function(t,s,i){s.exports={ConvLayer:t("./ConvLayer"),DropoutLayer:t("./DropoutLayer"),FullyConnLayer:t("./FullyConnLayer"),InputLayer:t("./InputLayer"),LocalResponseNormalizationLayer:t("./LocalResponseNormalizationLayer"),MaxoutLayer:t("./MaxoutLayer"),PoolLayer:t("./PoolLayer"),SigmoidLayer:t("./SigmoidLayer"),SoftmaxLayer:t("./SoftmaxLayer"),SVMLayer:t("./SVMLayer"),TanhLayer:t("./TanhLayer"),RegressionLayer:t("./RegressionLayer"),ReluLayer:t("./ReluLayer"),LocalResponseNormalizationLayer:t("./LocalResponseNormalizationLayer")}},{"./ConvLayer":1,"./DropoutLayer":2,"./FullyConnLayer":3,"./InputLayer":4,"./LocalResponseNormalizationLayer":6,"./MaxoutLayer":8,"./PoolLayer":10,"./RegressionLayer":11,"./ReluLayer":12,"./SVMLayer":13,"./SigmoidLayer":14,"./SoftmaxLayer":15,"./TanhLayer":16}],6:[function(t,s,i){const e=t("./Util");(s.exports=function(t){t=t||{};this.k=t.k,this.n=t.n,this.alpha=t.alpha,this.beta=t.beta,this.out_sx=t.in_sx,this.out_sy=t.in_sy,this.out_depth=t.in_depth,this.layer_type="lrn",this.n%2==0&&console.log("WARNING n should be odd for LRN layer")}).prototype={forward:function(t,s){this.in_act=t;var i=t.cloneAndZero();this.S_cache_=t.cloneAndZero();for(var e=Math.floor(this.n/2),r=0;r<t.sx;r++)for(var a=0;a<t.sy;a++)for(var o=0;o<t.depth;o++){for(var h=t.get(r,a,o),n=0,u=Math.max(0,o-e);u<=Math.min(o+e,t.depth-1);u++){var _=t.get(r,a,u);n+=_*_}n*=this.alpha/this.n,n+=this.k,this.S_cache_.set(r,a,o,n),n=Math.pow(n,this.beta),i.set(r,a,o,h/n)}return this.out_act=i,this.out_act},backward:function(){var t=this.in_act;t.dw=e.zeros(t.w.length);this.out_act;for(var s=Math.floor(this.n/2),i=0;i<t.sx;i++)for(var r=0;r<t.sy;r++)for(var a=0;a<t.depth;a++)for(var o=this.out_act.get_grad(i,r,a),h=this.S_cache_.get(i,r,a),n=Math.pow(h,this.beta),u=n*n,_=Math.max(0,a-s);_<=Math.min(a+s,t.depth-1);_++){var d=t.get(i,r,_),l=-d*this.beta*Math.pow(h,this.beta-1)*this.alpha/this.n*2*d;_===a&&(l+=n),l/=u,l*=o,t.add_grad(i,r,_,l)}},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.k=this.k,t.n=this.n,t.alpha=this.alpha,t.beta=this.beta,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.out_depth=this.out_depth,t.layer_type=this.layer_type,t},fromJSON:function(t){this.k=t.k,this.n=t.n,this.alpha=t.alpha,this.beta=t.beta,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.out_depth=t.out_depth,this.layer_type=t.layer_type}}},{"./Util":18}],7:[function(t,s,i){var e=t("./Util").getopt;(s.exports=function(t,s,i){i=i||{};void 0===t&&(t=[]),void 0===s&&(s=[]),this.data=t,this.labels=s,this.train_ratio=e(i,"train_ratio",.7),this.num_folds=e(i,"num_folds",10),this.num_candidates=e(i,"num_candidates",50),this.num_epochs=e(i,"num_epochs",50),this.ensemble_size=e(i,"ensemble_size",10),this.batch_size_min=e(i,"batch_size_min",10),this.batch_size_max=e(i,"batch_size_max",300),this.l2_decay_min=e(i,"l2_decay_min",-4),this.l2_decay_max=e(i,"l2_decay_max",2),this.learning_rate_min=e(i,"learning_rate_min",-4),this.learning_rate_max=e(i,"learning_rate_max",0),this.momentum_min=e(i,"momentum_min",.9),this.momentum_max=e(i,"momentum_max",.9),this.neurons_min=e(i,"neurons_min",5),this.neurons_max=e(i,"neurons_max",30),this.folds=[],this.candidates=[],this.evaluated_candidates=[],this.unique_labels=arrUnique(s),this.iter=0,this.foldix=0,this.finish_fold_callback=null,this.finish_batch_callback=null,this.data.length>0&&(this.sampleFolds(),this.sampleCandidates())}).prototype={sampleFolds:function(){var t=this.data.length,s=Math.floor(this.train_ratio*t);this.folds=[];for(var i=0;i<this.num_folds;i++){var e=randperm(t);this.folds.push({train_ix:e.slice(0,s),test_ix:e.slice(s,t)})}},sampleCandidate:function(){var t=this.data[0].w.length,s=this.unique_labels.length,i=[];i.push({type:"input",out_sx:1,out_sy:1,out_depth:t});for(var e=weightedSample([0,1,2,3],[.2,.3,.3,.2]),r=0;r<e;r++){var a=randi(this.neurons_min,this.neurons_max),o=["tanh","maxout","relu"][randi(0,3)];if(randf(0,1)<.5){var h=Math.random();i.push({type:"fc",num_neurons:a,activation:o,drop_prob:h})}else i.push({type:"fc",num_neurons:a,activation:o})}i.push({type:"softmax",num_classes:s});var n=new Net;n.makeLayers(i);var u,_=randi(this.batch_size_min,this.batch_size_max),d=Math.pow(10,randf(this.l2_decay_min,this.l2_decay_max)),l=Math.pow(10,randf(this.learning_rate_min,this.learning_rate_max)),p=randf(this.momentum_min,this.momentum_max),y=randf(0,1);u=y<.33?{method:"adadelta",batch_size:_,l2_decay:d}:y<.66?{method:"adagrad",learning_rate:l,batch_size:_,l2_decay:d}:{method:"sgd",learning_rate:l,momentum:p,batch_size:_,l2_decay:d};var c=new Trainer(n,u),f={acc:[],accv:0};return f.layer_defs=i,f.trainer_def=u,f.net=n,f.trainer=c,f},sampleCandidates:function(){this.candidates=[];for(var t=0;t<this.num_candidates;t++){var s=this.sampleCandidate();this.candidates.push(s)}},step:function(){this.iter++;for(var t=this.folds[this.foldix],s=t.train_ix[randi(0,t.train_ix.length)],i=0;i<this.candidates.length;i++){var e=this.data[s],r=this.labels[s];this.candidates[i].trainer.train(e,r)}var a=this.num_epochs*t.train_ix.length;if(this.iter>=a){var o=this.evalValErrors();for(i=0;i<this.candidates.length;i++){(h=this.candidates[i]).acc.push(o[i]),h.accv+=o[i]}if(this.iter=0,this.foldix++,null!==this.finish_fold_callback&&this.finish_fold_callback(),this.foldix>=this.folds.length){for(i=0;i<this.candidates.length;i++)this.evaluated_candidates.push(this.candidates[i]);this.evaluated_candidates.sort(function(t,s){return t.accv/t.acc.length>s.accv/s.acc.length?-1:1}),this.evaluated_candidates.length>3*this.ensemble_size&&(this.evaluated_candidates=this.evaluated_candidates.slice(0,3*this.ensemble_size)),null!==this.finish_batch_callback&&this.finish_batch_callback(),this.sampleCandidates(),this.foldix=0}else for(i=0;i<this.candidates.length;i++){var h=this.candidates[i],n=new Net;n.makeLayers(h.layer_defs);var u=new Trainer(n,h.trainer_def);h.net=n,h.trainer=u}}},evalValErrors:function(){for(var t=[],s=this.folds[this.foldix],i=0;i<this.candidates.length;i++){for(var e=this.candidates[i].net,r=0,a=0;a<s.test_ix.length;a++){var o=this.data[s.test_ix[a]],h=this.labels[s.test_ix[a]];e.forward(o),r+=e.getPrediction()===h?1:0}r/=s.test_ix.length,t.push(r)}return t},predict_soft:function(t){var s,i,e=[],r=0;0===this.evaluated_candidates.length?(r=this.candidates.length,e=this.candidates):(r=Math.min(this.ensemble_size,this.evaluated_candidates.length),e=this.evaluated_candidates);for(var a=0;a<r;a++){var o=e[a].net.forward(t);if(0===a)s=o,i=o.w.length;else for(var h=0;h<i;h++)s.w[h]+=o.w[h]}for(h=0;h<i;h++)s.w[h]/=r;return s},predict:function(t){var s=this.predict_soft(t);if(0!==s.w.length)var i=maxmin(s.w).maxi;else i=-1;return i},toJSON:function(){for(var t=Math.min(this.ensemble_size,this.evaluated_candidates.length),s={nets:[]},i=0;i<t;i++)s.nets.push(this.evaluated_candidates[i].net.toJSON());return s},fromJSON:function(t){this.ensemble_size=t.nets.length,this.evaluated_candidates=[];for(var s=0;s<this.ensemble_size;s++){var i=new Net;i.fromJSON(t.nets[s]);var e={};e.net=i,this.evaluated_candidates.push(e)}},onFinishFold:function(t){this.finish_fold_callback=t},onFinishBatch:function(t){this.finish_batch_callback=t}}},{"./Util":18}],8:[function(t,s,i){const e=t("./Util");(s.exports=function(t){t=t||{};this.group_size=void 0!==t.group_size?t.group_size:2,this.out_sx=t.in_sx,this.out_sy=t.in_sy,this.out_depth=Math.floor(t.in_depth/this.group_size),this.layer_type="maxout",this.switches=e.zeros(this.out_sx*this.out_sy*this.out_depth)}).prototype={forward:function(t,s){this.in_act=t;var i=this.out_depth,e=new Vol(this.out_sx,this.out_sy,this.out_depth,0);if(1===this.out_sx&&1===this.out_sy)for(var r=0;r<i;r++){for(var a=r*this.group_size,o=t.w[a],h=0,n=1;n<this.group_size;n++){(l=t.w[a+n])>o&&(o=l,h=n)}e.w[r]=o,this.switches[r]=a+h}else for(var u=0,_=0;_<t.sx;_++)for(var d=0;d<t.sy;d++)for(r=0;r<i;r++){for(a=r*this.group_size,o=t.get(_,d,a),h=0,n=1;n<this.group_size;n++){var l;(l=t.get(_,d,a+n))>o&&(o=l,h=n)}e.set(_,d,r,o),this.switches[u]=a+h,u++}return this.out_act=e,this.out_act},backward:function(){var t=this.in_act,s=this.out_act,i=this.out_depth;if(t.dw=e.zeros(t.w.length),1===this.out_sx&&1===this.out_sy)for(var r=0;r<i;r++){var a=s.dw[r];t.dw[this.switches[r]]=a}else for(var o=0,h=0;h<s.sx;h++)for(var n=0;n<s.sy;n++)for(r=0;r<i;r++){a=s.get_grad(h,n,r);t.set_grad(h,n,this.switches[o],a),o++}},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t.group_size=this.group_size,t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type,this.group_size=t.group_size,this.switches=e.zeros(this.group_size)}}},{"./Util":18}],9:[function(t,s,i){var{assert:e}=t("./Util"),r=t("./Layers");(s.exports=function(t){this.layers=[]}).prototype={makeLayers:function(t){e(t.length>=2,"Error! At least one input layer and one loss layer are required."),e("input"===t[0].type,"Error! First layer must be the input layer, to declare size of inputs");t=function(){for(var s=[],i=0;i<t.length;i++){var e=t[i];if("softmax"!==e.type&&"svm"!==e.type||s.push({type:"fc",num_neurons:e.num_classes}),"regression"===e.type&&s.push({type:"fc",num_neurons:e.num_neurons}),"fc"!==e.type&&"conv"!==e.type||void 0!==e.bias_pref||(e.bias_pref=0,void 0!==e.activation&&"relu"===e.activation&&(e.bias_pref=.1)),s.push(e),void 0!==e.activation)if("relu"===e.activation)s.push({type:"relu"});else if("sigmoid"===e.activation)s.push({type:"sigmoid"});else if("tanh"===e.activation)s.push({type:"tanh"});else if("maxout"===e.activation){var r="undefined"!==e.group_size?e.group_size:2;s.push({type:"maxout",group_size:r})}else console.log("ERROR unsupported activation "+e.activation);void 0!==e.drop_prob&&"dropout"!==e.type&&s.push({type:"dropout",drop_prob:e.drop_prob})}return s}(),this.layers=[];for(var s=0;s<t.length;s++){var i=t[s];if(s>0){var a=this.layers[s-1];i.in_sx=a.out_sx,i.in_sy=a.out_sy,i.in_depth=a.out_depth}switch(i.type){case"fc":this.layers.push(new r.FullyConnLayer(i));break;case"lrn":this.layers.push(new r.LocalResponseNormalizationLayer(i));break;case"dropout":this.layers.push(new r.DropoutLayer(i));break;case"input":this.layers.push(new r.InputLayer(i));break;case"softmax":this.layers.push(new r.SoftmaxLayer(i));break;case"regression":this.layers.push(new r.RegressionLayer(i));break;case"conv":this.layers.push(new r.ConvLayer(i));break;case"pool":this.layers.push(new r.PoolLayer(i));break;case"relu":this.layers.push(new r.ReluLayer(i));break;case"sigmoid":this.layers.push(new r.SigmoidLayer(i));break;case"tanh":this.layers.push(new r.TanhLayer(i));break;case"maxout":this.layers.push(new r.MaxoutLayer(i));break;case"svm":this.layers.push(new r.SVMLayer(i));break;default:console.log("ERROR: UNRECOGNIZED LAYER TYPE: "+i.type)}}},forward:function(t,s){void 0===s&&(s=!1);for(var i=this.layers[0].forward(t,s),e=1;e<this.layers.length;e++)i=this.layers[e].forward(i,s);return i},getCostLoss:function(t,s){this.forward(t,!1);var i=this.layers.length;return this.layers[i-1].backward(s)},backward:function(t){for(var s=this.layers.length,i=this.layers[s-1].backward(t),e=s-2;e>=0;e--)this.layers[e].backward();return i},getParamsAndGrads:function(){for(var t=[],s=0;s<this.layers.length;s++)for(var i=this.layers[s].getParamsAndGrads(),e=0;e<i.length;e++)t.push(i[e]);return t},getPrediction:function(){var t=this.layers[this.layers.length-1];e("softmax"===t.layer_type,"getPrediction function assumes softmax as last layer of the net!");for(var s=t.out_act.w,i=s[0],r=0,a=1;a<s.length;a++)s[a]>i&&(i=s[a],r=a);return r},toJSON:function(){for(var t={layers:[]},s=0;s<this.layers.length;s++)t.layers.push(this.layers[s].toJSON());return t},fromJSON:function(t){this.layers=[];for(var s=0;s<t.layers.length;s++){var i,e=t.layers[s],a=e.layer_type;"input"===a&&(i=new r.InputLayer),"relu"===a&&(i=new r.ReluLayer),"sigmoid"===a&&(i=new r.SigmoidLayer),"tanh"===a&&(i=new r.TanhLayer),"dropout"===a&&(i=new r.DropoutLayer),"conv"===a&&(i=new r.ConvLayer),"pool"===a&&(i=new r.PoolLayer),"lrn"===a&&(i=new r.LocalResponseNormalizationLayer),"softmax"===a&&(i=new r.SoftmaxLayer),"regression"===a&&(i=new r.RegressionLayer),"fc"===a&&(i=new r.FullyConnLayer),"maxout"===a&&(i=new r.MaxoutLayer),"svm"===a&&(i=new r.SVMLayer),i.fromJSON(e),this.layers.push(i)}}}},{"./Layers":5,"./Util":18}],10:[function(t,s,i){const e=t("./Util"),r=t("./Vol");(s.exports=function(t){t=t||{};this.sx=t.sx,this.in_depth=t.in_depth,this.in_sx=t.in_sx,this.in_sy=t.in_sy,this.sy=void 0!==t.sy?t.sy:this.sx,this.stride=void 0!==t.stride?t.stride:2,this.pad=void 0!==t.pad?t.pad:0,this.out_depth=this.in_depth,this.out_sx=Math.floor((this.in_sx+2*this.pad-this.sx)/this.stride+1),this.out_sy=Math.floor((this.in_sy+2*this.pad-this.sy)/this.stride+1),this.layer_type="pool",this.switchx=e.zeros(this.out_sx*this.out_sy*this.out_depth),this.switchy=e.zeros(this.out_sx*this.out_sy*this.out_depth)}).prototype={forward:function(t,s){this.in_act=t;for(var i=new r(this.out_sx,this.out_sy,this.out_depth,0),e=0,a=0;a<this.out_depth;a++)for(var o=-this.pad,h=-this.pad,n=0;n<this.out_sx;o+=this.stride,n++){h=-this.pad;for(var u=0;u<this.out_sy;h+=this.stride,u++){for(var _=-99999,d=-1,l=-1,p=0;p<this.sx;p++)for(var y=0;y<this.sy;y++){var c=h+y,f=o+p;if(c>=0&&c<t.sy&&f>=0&&f<t.sx){var m=t.get(f,c,a);m>_&&(_=m,d=f,l=c)}}this.switchx[e]=d,this.switchy[e]=l,e++,i.set(n,u,a,_)}}return this.out_act=i,this.out_act},backward:function(){var t=this.in_act;t.dw=e.zeros(t.w.length);this.out_act;for(var s=0,i=0;i<this.out_depth;i++){this.pad,this.pad;for(var r=0;r<this.out_sx;this.stride,r++){-this.pad;for(var a=0;a<this.out_sy;this.stride,a++){var o=this.out_act.get_grad(r,a,i);t.add_grad(this.switchx[s],this.switchy[s],i,o),s++}}}},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.sx=this.sx,t.sy=this.sy,t.stride=this.stride,t.in_depth=this.in_depth,t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t.pad=this.pad,t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type,this.sx=t.sx,this.sy=t.sy,this.stride=t.stride,this.in_depth=t.in_depth,this.pad=void 0!==t.pad?t.pad:0,this.switchx=e.zeros(this.out_sx*this.out_sy*this.out_depth),this.switchy=e.zeros(this.out_sx*this.out_sy*this.out_depth)}}},{"./Util":18,"./Vol":19}],11:[function(t,s,i){const e=t("./Util");(s.exports=function(t){t=t||{};this.num_inputs=t.in_sx*t.in_sy*t.in_depth,this.out_depth=this.num_inputs,this.out_sx=1,this.out_sy=1,this.layer_type="regression"}).prototype={forward:function(t,s){return this.in_act=t,this.out_act=t,t},backward:function(t){var s=this.in_act;s.dw=e.zeros(s.w.length);var i=0;if(t instanceof Array||t instanceof Float64Array)for(var r=0;r<this.out_depth;r++){var a=s.w[r]-t[r];s.dw[r]=a,i+=.5*a*a}else if("number"==typeof t){a=s.w[0]-t;s.dw[0]=a,i+=.5*a*a}else{r=t.dim;var o=t.val;a=s.w[r]-o;s.dw[r]=a,i+=.5*a*a}return i},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t.num_inputs=this.num_inputs,t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type,this.num_inputs=t.num_inputs}}},{"./Util":18}],12:[function(t,s,i){const e=t("./Util");(s.exports=function(t){t=t||{};this.out_sx=t.in_sx,this.out_sy=t.in_sy,this.out_depth=t.in_depth,this.layer_type="relu"}).prototype={forward:function(t,s){this.in_act=t;for(var i=t.clone(),e=t.w.length,r=i.w,a=0;a<e;a++)r[a]<0&&(r[a]=0);return this.out_act=i,this.out_act},backward:function(){var t=this.in_act,s=this.out_act,i=t.w.length;t.dw=e.zeros(i);for(var r=0;r<i;r++)s.w[r]<=0?t.dw[r]=0:t.dw[r]=s.dw[r]},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type}}},{"./Util":18}],13:[function(t,s,i){const e=t("./Util");(s.exports=function(t){t=t||{};this.num_inputs=t.in_sx*t.in_sy*t.in_depth,this.out_depth=this.num_inputs,this.out_sx=1,this.out_sy=1,this.layer_type="svm"}).prototype={forward:function(t,s){return this.in_act=t,this.out_act=t,t},backward:function(t){var s=this.in_act;s.dw=e.zeros(s.w.length);for(var i=s.w[t],r=0,a=0;a<this.out_depth;a++)if(t!==a){var o=-i+s.w[a]+1;o>0&&(s.dw[a]+=1,s.dw[t]-=1,r+=o)}return r},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t.num_inputs=this.num_inputs,t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type,this.num_inputs=t.num_inputs}}},{"./Util":18}],14:[function(t,s,i){const e=t("./Util");(s.exports=function(t){t=t||{};this.out_sx=t.in_sx,this.out_sy=t.in_sy,this.out_depth=t.in_depth,this.layer_type="sigmoid"}).prototype={forward:function(t,s){this.in_act=t;for(var i=t.cloneAndZero(),e=t.w.length,r=i.w,a=t.w,o=0;o<e;o++)r[o]=1/(1+Math.exp(-a[o]));return this.out_act=i,this.out_act},backward:function(){var t=this.in_act,s=this.out_act,i=t.w.length;t.dw=e.zeros(i);for(var r=0;r<i;r++){var a=s.w[r];t.dw[r]=a*(1-a)*s.dw[r]}},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type}}},{"./Util":18}],15:[function(t,s,i){const e=t("./Util"),r=t("./Vol");(s.exports=function(t){t=t||{};this.num_inputs=t.in_sx*t.in_sy*t.in_depth,this.out_depth=this.num_inputs,this.out_sx=1,this.out_sy=1,this.layer_type="softmax"}).prototype={forward:function(t,s){this.in_act=t;for(var i=new r(1,1,this.out_depth,0),a=t.w,o=t.w[0],h=1;h<this.out_depth;h++)a[h]>o&&(o=a[h]);var n=e.zeros(this.out_depth),u=0;for(h=0;h<this.out_depth;h++){var _=Math.exp(a[h]-o);u+=_,n[h]=_}for(h=0;h<this.out_depth;h++)n[h]/=u,i.w[h]=n[h];return this.es=n,this.out_act=i,this.out_act},backward:function(t){var s=this.in_act;s.dw=e.zeros(s.w.length);for(var i=0;i<this.out_depth;i++){var r=-((i===t?1:0)-this.es[i]);s.dw[i]=r}return-Math.log(this.es[t])},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t.num_inputs=this.num_inputs,t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type,this.num_inputs=t.num_inputs}}},{"./Util":18,"./Vol":19}],16:[function(t,s,i){const e=t("./Util");function r(t){var s=Math.exp(2*t);return(s-1)/(s+1)}(s.exports=function(t){t=t||{};this.out_sx=t.in_sx,this.out_sy=t.in_sy,this.out_depth=t.in_depth,this.layer_type="tanh"}).prototype={forward:function(t,s){this.in_act=t;for(var i=t.cloneAndZero(),e=t.w.length,a=0;a<e;a++)i.w[a]=r(t.w[a]);return this.out_act=i,this.out_act},backward:function(){var t=this.in_act,s=this.out_act,i=t.w.length;t.dw=e.zeros(i);for(var r=0;r<i;r++){var a=s.w[r];t.dw[r]=(1-a*a)*s.dw[r]}},getParamsAndGrads:function(){return[]},toJSON:function(){var t={};return t.out_depth=this.out_depth,t.out_sx=this.out_sx,t.out_sy=this.out_sy,t.layer_type=this.layer_type,t},fromJSON:function(t){this.out_depth=t.out_depth,this.out_sx=t.out_sx,this.out_sy=t.out_sy,this.layer_type=t.layer_type}}},{"./Util":18}],17:[function(t,s,i){const e=t("./Util");(s.exports=function(t,s){this.net=t;s=s||{};this.learning_rate=void 0!==s.learning_rate?s.learning_rate:.01,this.l1_decay=void 0!==s.l1_decay?s.l1_decay:0,this.l2_decay=void 0!==s.l2_decay?s.l2_decay:0,this.batch_size=void 0!==s.batch_size?s.batch_size:1,this.method=void 0!==s.method?s.method:"sgd",this.momentum=void 0!==s.momentum?s.momentum:.9,this.ro=void 0!==s.ro?s.ro:.95,this.eps=void 0!==s.eps?s.eps:1e-8,this.beta1=void 0!==s.beta1?s.beta1:.9,this.beta2=void 0!==s.beta2?s.beta2:.999,this.k=0,this.gsum=[],this.xsum=[],"regression"===this.net.layers[this.net.layers.length-1].layer_type?this.regression=!0:this.regression=!1}).prototype={train:function(t,s){var i=(new Date).getTime();this.net.forward(t,!0);var r=(new Date).getTime()-i,a=(i=(new Date).getTime(),this.net.backward(s)),o=0,h=0,n=(new Date).getTime()-i;if(this.regression&&s.constructor!==Array&&console.log("Warning: a regression net requires an array as training output vector."),this.k++,this.k%this.batch_size===0){var u=this.net.getParamsAndGrads();if(0===this.gsum.length&&("sgd"!==this.method||this.momentum>0))for(var _=0;_<u.length;_++)this.gsum.push(e.zeros(u[_].params.length)),"adam"===this.method||"adadelta"===this.method?this.xsum.push(e.zeros(u[_].params.length)):this.xsum.push([]);for(_=0;_<u.length;_++)for(var d=u[_],l=d.params,p=d.grads,y=void 0!==d.l2_decay_mul?d.l2_decay_mul:1,c=void 0!==d.l1_decay_mul?d.l1_decay_mul:1,f=this.l2_decay*y,m=this.l1_decay*c,v=l.length,w=0;w<v;w++){o+=f*l[w]*l[w]/2,h+=m*Math.abs(l[w]);var x=m*(l[w]>0?1:-1),g=(f*l[w]+x+p[w])/this.batch_size,b=this.gsum[_],L=this.xsum[_];if("adam"===this.method){b[w]=b[w]*this.beta1+(1-this.beta1)*g,L[w]=L[w]*this.beta2+(1-this.beta2)*g*g;var z=b[w]*(1-Math.pow(this.beta1,this.k)),S=L[w]*(1-Math.pow(this.beta2,this.k)),N=-this.learning_rate*z/(Math.sqrt(S)+this.eps);l[w]+=N}else if("adagrad"===this.method){b[w]=b[w]+g*g;N=-this.learning_rate/Math.sqrt(b[w]+this.eps)*g;l[w]+=N}else if("windowgrad"===this.method){b[w]=this.ro*b[w]+(1-this.ro)*g*g;N=-this.learning_rate/Math.sqrt(b[w]+this.eps)*g;l[w]+=N}else if("adadelta"===this.method){b[w]=this.ro*b[w]+(1-this.ro)*g*g;N=-Math.sqrt((L[w]+this.eps)/(b[w]+this.eps))*g;L[w]=this.ro*L[w]+(1-this.ro)*N*N,l[w]+=N}else if("nesterov"===this.method){N=b[w];b[w]=b[w]*this.momentum+this.learning_rate*g,N=this.momentum*N-(1+this.momentum)*b[w],l[w]+=N}else if(this.momentum>0){N=this.momentum*b[w]-this.learning_rate*g;b[w]=N,l[w]+=N}else l[w]+=-this.learning_rate*g;p[w]=0}}return{fwd_time:r,bwd_time:n,l2_decay_loss:o,l1_decay_loss:h,cost_loss:a,softmax_loss:a,loss:a+h+o}}}},{"./Util":18}],18:[function(t,s,i){var e=s.exports={},r=!1,a=0;e.gaussRandom=function(){if(r)return r=!1,a;var t=2*Math.random()-1,s=2*Math.random()-1,i=t*t+s*s;if(0==i||i>1)return e.gaussRandom();var o=Math.sqrt(-2*Math.log(i)/i);return a=s*o,r=!0,t*o},e.randf=function(t,s){return Math.random()*(s-t)+t},e.randi=function(t,s){return Math.floor(Math.random()*(s-t)+t)},e.randn=function(t,s){return t+e.gaussRandom()*s},e.zeros=function(t){if(void 0===t||isNaN(t))return[];if("undefined"==typeof ArrayBuffer){for(var s=new Array(t),i=0;i<t;i++)s[i]=0;return s}return new Float64Array(t)},e.arrContains=function(t,s){for(var i=0,e=t.length;i<e;i++)if(t[i]===s)return!0;return!1},e.arrUnique=function(t){for(var s=[],i=0,e=t.length;i<e;i++)arrContains(s,t[i])||s.push(t[i]);return s},e.maxmin=function(t){if(0===t.length)return{};for(var s=t[0],i=t[0],e=0,r=0,a=t.length,o=1;o<a;o++)t[o]>s&&(s=t[o],e=o),t[o]<i&&(i=t[o],r=o);return{maxi:e,maxv:s,mini:r,minv:i,dv:s-i}},e.randperm=function(t){for(var s,i=t,e=0,r=[],a=0;a<t;a++)r[a]=a;for(;i--;)e=Math.floor(Math.random()*(i+1)),s=r[i],r[i]=r[e],r[e]=s;return r},e.weightedSample=function(t,s){for(var i=randf(0,1),e=0,r=0,a=t.length;r<a;r++)if(i<(e+=s[r]))return t[r]},e.getopt=function(t,s,i){if("string"==typeof s)return void 0!==t[s]?t[s]:i;for(var e=i,r=0;r<s.length;r++){var a=s[r];void 0!==t[a]&&(e=t[a])}return e},e.assert=function(t,s){if(!t){if(s=s||"Assertion failed","undefined"!=typeof Error)throw new Error(s);throw s}}},{}],19:[function(t,s,i){const e=t("./Util");var r=s.exports=function(t,s,i,r){if("[object Array]"===Object.prototype.toString.call(t)){this.sx=1,this.sy=1,this.depth=t.length,this.w=e.zeros(this.depth),this.dw=e.zeros(this.depth);for(var a=0;a<this.depth;a++)this.w[a]=t[a]}else{this.sx=t,this.sy=s,this.depth=i;var o=t*s*i;if(this.w=e.zeros(o),this.dw=e.zeros(o),void 0===r){var h=Math.sqrt(1/(t*s*i));for(a=0;a<o;a++)this.w[a]=e.randn(0,h)}else for(a=0;a<o;a++)this.w[a]=r}};r.prototype={get:function(t,s,i){var e=(this.sx*s+t)*this.depth+i;return this.w[e]},set:function(t,s,i,e){var r=(this.sx*s+t)*this.depth+i;this.w[r]=e},add:function(t,s,i,e){var r=(this.sx*s+t)*this.depth+i;this.w[r]+=e},get_grad:function(t,s,i){var e=(this.sx*s+t)*this.depth+i;return this.dw[e]},set_grad:function(t,s,i,e){var r=(this.sx*s+t)*this.depth+i;this.dw[r]=e},add_grad:function(t,s,i,e){var r=(this.sx*s+t)*this.depth+i;this.dw[r]+=e},cloneAndZero:function(){return new r(this.sx,this.sy,this.depth,0)},clone:function(){for(var t=new r(this.sx,this.sy,this.depth,0),s=this.w.length,i=0;i<s;i++)t.w[i]=this.w[i];return t},addFrom:function(t){for(var s=0;s<this.w.length;s++)this.w[s]+=t.w[s]},addFromScaled:function(t,s){for(var i=0;i<this.w.length;i++)this.w[i]+=s*t.w[i]},setConst:function(t){for(var s=0;s<this.w.length;s++)this.w[s]=t},toJSON:function(){var t={};return t.sx=this.sx,t.sy=this.sy,t.depth=this.depth,t.w=this.w,t},fromJSON:function(t){this.sx=t.sx,this.sy=t.sy,this.depth=t.depth;var s=this.sx*this.sy*this.depth;this.w=e.zeros(s),this.dw=e.zeros(s);for(var i=0;i<s;i++)this.w[i]=t.w[i]}}},{"./Util":18}],20:[function(t,s,i){const e=t("./Util"),r=t("./Vol");var a=s.exports={};a.augment=function(t,s,i,a,o){if(void 0===o)o=!1;if(void 0===i)i=e.randi(0,t.sx-s);if(void 0===a)a=e.randi(0,t.sy-s);var h;if(s!==t.sx||0!==i||0!==a){h=new r(s,s,t.depth,0);for(var n=0;n<s;n++)for(var u=0;u<s;u++)if(!(n+i<0||n+i>=t.sx||u+a<0||u+a>=t.sy))for(var _=0;_<t.depth;_++)h.set(n,u,_,t.get(n+i,u+a,_))}else h=t;if(o){var d=h.cloneAndZero();for(n=0;n<h.sx;n++)for(u=0;u<h.sy;u++)for(_=0;_<h.depth;_++)d.set(n,u,_,h.get(h.sx-n-1,u,_));h=d}return h},a.img_to_vol=function(t,s){if(void 0===s)s=!1;var i=document.createElement("canvas");i.width=t.width,i.height=t.height;var e=i.getContext("2d");try{e.drawImage(t,0,0)}catch(t){if("NS_ERROR_NOT_AVAILABLE"===t.name)return!1;throw t}try{var a=e.getImageData(0,0,i.width,i.height)}catch(t){if("IndexSizeError"===t.name)return!1;throw t}for(var o=a.data,h=t.width,n=t.height,u=[],_=0;_<o.length;_++)u.push(o[_]/255-.5);var d=new r(h,n,4,0);if(d.w=u,s){var l=new r(h,n,1,0);for(_=0;_<h;_++)for(var p=0;p<n;p++)l.set(_,p,0,d.get(_,p,0));d=l}return d}},{"./Util":18,"./Vol":19}],21:[function(t,s,i){convnetjs2=convnetjs=t("./index")},{"./index":22}],22:[function(t,s,i){var e=s.exports=t("./Util");Object.assign(e,{ConvLayer:t("./ConvLayer"),DropoutLayer:t("./DropoutLayer"),FullyConnLayer:t("./FullyConnLayer"),InputLayer:t("./InputLayer"),LocalResponseNormalizationLayer:t("./LocalResponseNormalizationLayer"),MagicNet:t("./MagicNet"),MaxoutLayer:t("./MaxoutLayer"),Net:t("./Net"),PoolLayer:t("./PoolLayer"),SigmoidLayer:t("./SigmoidLayer"),SoftmaxLayer:t("./SoftmaxLayer"),SVMLayer:t("./SVMLayer"),TanhLayer:t("./TanhLayer"),Trainer:t("./Trainer"),Util:t("./Util"),Vol:t("./Vol"),VolUtil:t("./VolUtil")}),e.SGDTrainer=e.Trainer,e.augment=e.VolUtil.augment,e.img_to_vol=e.VolUtil.img_to_vol},{"./ConvLayer":1,"./DropoutLayer":2,"./FullyConnLayer":3,"./InputLayer":4,"./LocalResponseNormalizationLayer":6,"./MagicNet":7,"./MaxoutLayer":8,"./Net":9,"./PoolLayer":10,"./SVMLayer":13,"./SigmoidLayer":14,"./SoftmaxLayer":15,"./TanhLayer":16,"./Trainer":17,"./Util":18,"./Vol":19,"./VolUtil":20}]},{},[21]);
//# sourceMappingURL=/sm/618a958a6965ed193f8778a1a756062f6d50bc504947a555ab6c03456d972fb9.map