From 772eb8c9be8b925d7894d025d7c3d183259ff319 Mon Sep 17 00:00:00 2001 From: Robert Plummer Date: Sun, 4 Nov 2018 14:44:04 -0500 Subject: [PATCH] fix: Resolve issue with different size hidden layers for recurrent neural networks Fixes https://github.com/BrainJS/brain.js/issues/294 --- browser.js | 10 +++------- browser.min.js | 14 +++++++------- dist/recurrent/rnn.js | 8 ++------ dist/recurrent/rnn.js.map | 2 +- package.json | 2 +- src/recurrent/rnn.js | 4 ++-- test/recurrent/rnn.js | 37 ++++++++++++++++++++++++++++++++++--- 7 files changed, 50 insertions(+), 27 deletions(-) diff --git a/browser.js b/browser.js index 094c0a09a..778fd643b 100644 --- a/browser.js +++ b/browser.js @@ -6,7 +6,7 @@ * license: MIT (http://opensource.org/licenses/MIT) * author: Heather Arthur * homepage: https://github.com/brainjs/brain.js#readme - * version: 1.4.3 + * version: 1.4.4 * * acorn: * license: MIT (http://opensource.org/licenses/MIT) @@ -4236,13 +4236,11 @@ var RNN = function () { }, { key: 'mapModel', value: function mapModel() { - var _this = this; - var model = this.model; var hiddenLayers = model.hiddenLayers; var allMatrices = model.allMatrices; this.initialLayerInputs = this.hiddenLayers.map(function (size) { - return new _matrix2.default(_this.hiddenLayers[0], 1); + return new _matrix2.default(size, 1); }); this.createInputMatrix(); @@ -4572,8 +4570,6 @@ var RNN = function () { }, { key: 'fromJSON', value: function fromJSON(json) { - var _this2 = this; - var defaults = this.constructor.defaults; var options = json.options; this.model = null; @@ -4619,7 +4615,7 @@ var RNN = function () { equationConnections: [] }; this.initialLayerInputs = this.hiddenLayers.map(function (size) { - return new _matrix2.default(_this2.hiddenLayers[0], 1); + return new _matrix2.default(size, 1); }); this.bindEquation(); } diff --git a/browser.min.js b/browser.min.js index 53e5f2ac1..8c41a6bee 100644 --- a/browser.min.js +++ b/browser.min.js @@ -6,7 +6,7 @@ * license: MIT (http://opensource.org/licenses/MIT) * author: Heather Arthur * homepage: https://github.com/brainjs/brain.js#readme - * version: 1.4.3 + * version: 1.4.4 * * acorn: * license: MIT (http://opensource.org/licenses/MIT) @@ -213,7 +213,7 @@ "use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,e){for(var n=0;n0?t.equationConnections[t.equationConnections.length-1]:this.initialLayerInputs,o=this.getEquation(r,r.input(t.input),i[0],n[0]);a.push(o);for(var u=1,s=e.length;u-1;t--)this.model.equations[t].runBackpropagate()}},{key:"run",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(!this.isRunnable)return null;for(var e=this.model;e.equations.length-1)return"typeof prevStates["+o+"] === 'object' ? prevStates["+o+"].product : new Matrix("+t.rows+", "+t.columns+")";case i.right:if(o>-1)return"typeof prevStates["+o+"] === 'object' ? prevStates["+o+"].product : new Matrix("+t.rows+", "+t.columns+")";case i.product:return"new Matrix("+t.rows+", "+t.columns+")";default:throw Error("unknown state")}}if(t===i.product)return"states["+r+"].product";if(t===i.right)return"states["+r+"].right";if(t===i.left)return"states["+r+"].left"}}function e(t){for(var e=a.equationConnections[0],n=i[0].states,r=0,o=n.length;r0&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,t);var r=this.constructor.defaults;Object.assign(this,r,e),this.stepCache={},this.runs=0,this.totalCost=null,this.ratioClipped=null,this.model=null,this.inputLookup=null,this.outputLookup=null,e.json&&this.fromJSON(e.json)}return _createClass(t,[{key:"initialize",value:function(){this.model={input:null,hiddenLayers:[],output:null,equations:[],allMatrices:[],equationConnections:[],outputConnector:null},null!==this.dataFormatter&&(this.inputSize=this.inputRange=this.outputSize=this.dataFormatter.characters.length),this.mapModel()}},{key:"createHiddenLayers",value:function(){this.model.hiddenLayers.push(this.getModel(this.hiddenLayers[0],this.inputSize));for(var t=this.hiddenLayers[0],e=1;e0?t.equationConnections[t.equationConnections.length-1]:this.initialLayerInputs,a=this.getEquation(e,e.inputMatrixToRow(t.input),n[0],t.hiddenLayers[0]);r.push(a);for(var i=1,o=this.hiddenLayers.length;i1&&void 0!==arguments[1]?arguments[1]:null,r=this.runInput(t);return this.runBackpropagate(t),this.step(e),r}},{key:"runInput",value:function(t){this.runs++;for(var e=this.model,r=t.length,n=0,a=0,i=void 0;e.equations.length<=t.length+1;)this.bindEquation();for(var o=-1,u=t.length;o0;)n[e].runBackpropagate(t[e-1]+1),e--;n[0].runBackpropagate(0)}},{key:"step",value:function(){for(var t=(arguments.length>0&&void 0!==arguments[0]&&arguments[0],this.learningRate),e=this.regc,r=this.clipval,n=this.model,a=0,i=0,o=n.allMatrices,u=0;ur&&(f=r,a++),f<-r&&(f=-r,a++),i++,l[p]=c+-t*f/Math.sqrt(d[p]+this.smoothEps)-e*c}}this.ratioClipped=a/i}},{key:"run",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=this.maxPredictionLength+t.length+(this.dataFormatter?this.dataFormatter.specialIndexes.length:0);if(!this.isRunnable)return null;for(var a=this.formatDataIn(t),i=this.model,o=[],u=0;;){for(var s=0===u?0:u=n)break;o.push(m)}return this.formatDataOut(a,o.slice(a.length).map(function(t){return t-1}))}},{key:"train",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e=Object.assign({},this.constructor.trainDefaults,e);var r=e.iterations,n=e.errorThresh,a=!0===e.log?console.log:e.log,i=e.logPeriod,o=e.learningRate||this.learningRate,u=e.callback,s=e.callbackPeriod,l=1/0,h=void 0;for(this.hasOwnProperty("setupData")&&(t=this.setupData(t)),this.model||this.initialize(),h=0;hn;h++){for(var d=0,p=0;p-1)return"typeof prevStates["+o+"] === 'object' ? prevStates["+o+"].product : new Matrix("+t.rows+", "+t.columns+")";case i.right:if(o>-1)return"typeof prevStates["+o+"] === 'object' ? prevStates["+o+"].product : new Matrix("+t.rows+", "+t.columns+")";case i.product:return"new Matrix("+t.rows+", "+t.columns+")";default:throw Error("unknown state")}}if(t===i.product)return"states["+n+"].product";if(t===i.right)return"states["+n+"].right";if(t===i.left)return"states["+n+"].left"}}function e(t){for(var e=a.equationConnections[0],r=i[0].states,n=0,o=r.length;n= maxPredictionLength) {\n break;\n }\n\n output.push(nextIndex);\n }\n "+(null!==this.dataFormatter&&"function"==typeof this.formatDataOut?"return formatDataOut(input, output.slice(input.length).map(function(value) { return value - 1; }))":"return output.slice(input.length).map(function(value) { return value - 1; })")+";\n function Matrix(rows, columns) {\n this.rows = rows;\n this.columns = columns;\n this.weights = zeros(rows * columns);\n }\n "+(null!==this.dataFormatter&&"function"==typeof this.formatDataIn?"function formatDataIn(input, output) { "+n(this.formatDataIn.toString()).replace(/this[.]dataFormatter[\n\s]+[.]/g,"").replace(/this[.]dataFormatter[.]/g,"").replace(/this[.]dataFormatter/g,"true")+" }":"")+"\n "+(null!==this.dataFormatter&&"function"==typeof this.formatDataOut?"function formatDataOut(input, output) { "+n(this.formatDataOut.toString()).replace(/this[.]dataFormatter[\n\s]+[.]/g,"").replace(/this[.]dataFormatter[.]/g,"").replace(/this[.]dataFormatter/g,"true")+" }":"")+"\n "+_zeros2.default.toString()+"\n "+_softmax2.default.toString().replace("_2.default","Matrix")+"\n "+_random.randomF.toString()+"\n "+_sampleI2.default.toString()+"\n "+_maxI2.default.toString();return new Function("rawInput","isSampleI","temperature",g)}},{key:"isRunnable",get:function(){return 0!==this.model.equations.length||(console.error("No equations bound, did you run train()?"),!1)}}]),t}();exports.default=RNN,RNN.defaults={inputSize:20,inputRange:20,hiddenLayers:[20,20],outputSize:20,learningRate:.01,decayRate:.999,smoothEps:1e-8,regc:1e-6,clipval:5,maxPredictionLength:100,setupData:function(t){if(!("string"==typeof t[0]||Array.isArray(t[0])||t[0].hasOwnProperty("input")&&t[0].hasOwnProperty("output")))return t;var e=[],r=[];if("string"==typeof t[0]||Array.isArray(t[0])){if(null===this.dataFormatter){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:null;return null!==this.dataFormatter?this.dataFormatter.indexTable.hasOwnProperty("stop-input")?this.dataFormatter.toIndexesInputOutput(t,e):this.dataFormatter.toIndexes(t):t},formatDataOut:function(t,e){return null!==this.dataFormatter?this.dataFormatter.toCharacters(e).join(""):e},dataFormatter:null},RNN.trainDefaults={iterations:2e4,errorThresh:.005,log:!1,logPeriod:10,learningRate:.3,callback:null,callbackPeriod:10,keepNetworkIntact:!1}; +"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,e){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,t);var r=this.constructor.defaults;Object.assign(this,r,e),this.stepCache={},this.runs=0,this.totalCost=null,this.ratioClipped=null,this.model=null,this.inputLookup=null,this.outputLookup=null,e.json&&this.fromJSON(e.json)}return _createClass(t,[{key:"initialize",value:function(){this.model={input:null,hiddenLayers:[],output:null,equations:[],allMatrices:[],equationConnections:[],outputConnector:null},null!==this.dataFormatter&&(this.inputSize=this.inputRange=this.outputSize=this.dataFormatter.characters.length),this.mapModel()}},{key:"createHiddenLayers",value:function(){this.model.hiddenLayers.push(this.getModel(this.hiddenLayers[0],this.inputSize));for(var t=this.hiddenLayers[0],e=1;e0?t.equationConnections[t.equationConnections.length-1]:this.initialLayerInputs,a=this.getEquation(e,e.inputMatrixToRow(t.input),n[0],t.hiddenLayers[0]);r.push(a);for(var i=1,o=this.hiddenLayers.length;i1&&void 0!==arguments[1]?arguments[1]:null,r=this.runInput(t);return this.runBackpropagate(t),this.step(e),r}},{key:"runInput",value:function(t){this.runs++;for(var e=this.model,r=t.length,n=0,a=0,i=void 0;e.equations.length<=t.length+1;)this.bindEquation();for(var o=-1,u=t.length;o0;)n[e].runBackpropagate(t[e-1]+1),e--;n[0].runBackpropagate(0)}},{key:"step",value:function(){for(var t=(arguments.length>0&&void 0!==arguments[0]&&arguments[0],this.learningRate),e=this.regc,r=this.clipval,n=this.model,a=0,i=0,o=n.allMatrices,u=0;ur&&(f=r,a++),f<-r&&(f=-r,a++),i++,l[p]=c+-t*f/Math.sqrt(d[p]+this.smoothEps)-e*c}}this.ratioClipped=a/i}},{key:"run",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=this.maxPredictionLength+t.length+(this.dataFormatter?this.dataFormatter.specialIndexes.length:0);if(!this.isRunnable)return null;for(var a=this.formatDataIn(t),i=this.model,o=[],u=0;;){for(var s=0===u?0:u=n)break;o.push(m)}return this.formatDataOut(a,o.slice(a.length).map(function(t){return t-1}))}},{key:"train",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e=Object.assign({},this.constructor.trainDefaults,e);var r=e.iterations,n=e.errorThresh,a=!0===e.log?console.log:e.log,i=e.logPeriod,o=e.learningRate||this.learningRate,u=e.callback,s=e.callbackPeriod,l=1/0,h=void 0;for(this.hasOwnProperty("setupData")&&(t=this.setupData(t)),this.model||this.initialize(),h=0;hn;h++){for(var d=0,p=0;p-1)return"typeof prevStates["+o+"] === 'object' ? prevStates["+o+"].product : new Matrix("+t.rows+", "+t.columns+")";case i.right:if(o>-1)return"typeof prevStates["+o+"] === 'object' ? prevStates["+o+"].product : new Matrix("+t.rows+", "+t.columns+")";case i.product:return"new Matrix("+t.rows+", "+t.columns+")";default:throw Error("unknown state")}}if(t===i.product)return"states["+n+"].product";if(t===i.right)return"states["+n+"].right";if(t===i.left)return"states["+n+"].left"}}function e(t){for(var e=a.equationConnections[0],r=i[0].states,n=0,o=r.length;n= maxPredictionLength) {\n break;\n }\n\n output.push(nextIndex);\n }\n "+(null!==this.dataFormatter&&"function"==typeof this.formatDataOut?"return formatDataOut(input, output.slice(input.length).map(function(value) { return value - 1; }))":"return output.slice(input.length).map(function(value) { return value - 1; })")+";\n function Matrix(rows, columns) {\n this.rows = rows;\n this.columns = columns;\n this.weights = zeros(rows * columns);\n }\n "+(null!==this.dataFormatter&&"function"==typeof this.formatDataIn?"function formatDataIn(input, output) { "+n(this.formatDataIn.toString()).replace(/this[.]dataFormatter[\n\s]+[.]/g,"").replace(/this[.]dataFormatter[.]/g,"").replace(/this[.]dataFormatter/g,"true")+" }":"")+"\n "+(null!==this.dataFormatter&&"function"==typeof this.formatDataOut?"function formatDataOut(input, output) { "+n(this.formatDataOut.toString()).replace(/this[.]dataFormatter[\n\s]+[.]/g,"").replace(/this[.]dataFormatter[.]/g,"").replace(/this[.]dataFormatter/g,"true")+" }":"")+"\n "+_zeros2.default.toString()+"\n "+_softmax2.default.toString().replace("_2.default","Matrix")+"\n "+_random.randomF.toString()+"\n "+_sampleI2.default.toString()+"\n "+_maxI2.default.toString();return new Function("rawInput","isSampleI","temperature",g)}},{key:"isRunnable",get:function(){return 0!==this.model.equations.length||(console.error("No equations bound, did you run train()?"),!1)}}]),t}();exports.default=RNN,RNN.defaults={inputSize:20,inputRange:20,hiddenLayers:[20,20],outputSize:20,learningRate:.01,decayRate:.999,smoothEps:1e-8,regc:1e-6,clipval:5,maxPredictionLength:100,setupData:function(t){if(!("string"==typeof t[0]||Array.isArray(t[0])||t[0].hasOwnProperty("input")&&t[0].hasOwnProperty("output")))return t;var e=[],r=[];if("string"==typeof t[0]||Array.isArray(t[0])){if(null===this.dataFormatter){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:null;return null!==this.dataFormatter?this.dataFormatter.indexTable.hasOwnProperty("stop-input")?this.dataFormatter.toIndexesInputOutput(t,e):this.dataFormatter.toIndexes(t):t},formatDataOut:function(t,e){return null!==this.dataFormatter?this.dataFormatter.toCharacters(e).join(""):e},dataFormatter:null},RNN.trainDefaults={iterations:2e4,errorThresh:.005,log:!1,logPeriod:10,learningRate:.3,callback:null,callbackPeriod:10,keepNetworkIntact:!1}; },{"../utilities/data-formatter":37,"../utilities/random":42,"../utilities/zeros":46,"./matrix":16,"./matrix/copy":14,"./matrix/equation":15,"./matrix/max-i":17,"./matrix/random-matrix":23,"./matrix/sample-i":28,"./matrix/softmax":31}],36:[function(require,module,exports){ "use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _toConsumableArray(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);ethis.errorThresh){if("function"==typeof this.floodCallback)return this.floodCallback()}else if("function"==typeof this.doneTrainingCallback)return this.doneTrainingCallback({error:n,iterations:this.i})}}]),e}(_stream.Writable);exports.default=TrainStream; @@ -252,7 +252,6 @@ var CrossValidate=require("./dist/cross-validate").default,likely=require("./dist/likely").default,lookup=require("./dist/lookup").default,NeuralNetwork=require("./dist/neural-network").default,NeuralNetworkGPU=require("./dist/neural-network-gpu").default,TrainStream=require("./dist/train-stream").default,RNNTimeStep=require("./dist/recurrent/rnn-time-step").default,LSTMTimeStep=require("./dist/recurrent/lstm-time-step").default,GRUTimeStep=require("./dist/recurrent/gru-time-step").default,RNN=require("./dist/recurrent/rnn").default,LSTM=require("./dist/recurrent/lstm").default,GRU=require("./dist/recurrent/gru").default,utilities={max:require("./dist/utilities/max").default,mse:require("./dist/utilities/mse").default,ones:require("./dist/utilities/ones").default,random:require("./dist/utilities/random").default,randomWeight:require("./dist/utilities/random-weight").default,randos:require("./dist/utilities/randos").default,range:require("./dist/utilities/range").default,toArray:require("./dist/utilities/to-array").default,DataFormatter:require("./dist/utilities/data-formatter").default,zeros:require("./dist/utilities/zeros").default},brain={CrossValidate:CrossValidate,likely:likely,lookup:lookup,NeuralNetwork:NeuralNetwork,NeuralNetworkGPU:NeuralNetworkGPU,TrainStream:TrainStream,recurrent:{RNNTimeStep:RNNTimeStep,LSTMTimeStep:LSTMTimeStep,GRUTimeStep:GRUTimeStep,RNN:RNN,LSTM:LSTM,GRU:GRU},utilities:utilities};"undefined"!=typeof window&&(window.brain=brain),"undefined"!=typeof self&&(self.brain=brain),"undefined"!=typeof module&&(module.exports=brain); },{"./dist/cross-validate":1,"./dist/likely":2,"./dist/lookup":3,"./dist/neural-network":5,"./dist/neural-network-gpu":4,"./dist/recurrent/gru":7,"./dist/recurrent/gru-time-step":6,"./dist/recurrent/lstm":9,"./dist/recurrent/lstm-time-step":8,"./dist/recurrent/rnn":35,"./dist/recurrent/rnn-time-step":34,"./dist/train-stream":36,"./dist/utilities/data-formatter":37,"./dist/utilities/max":38,"./dist/utilities/mse":39,"./dist/utilities/ones":40,"./dist/utilities/random":42,"./dist/utilities/random-weight":41,"./dist/utilities/randos":43,"./dist/utilities/range":44,"./dist/utilities/to-array":45,"./dist/utilities/zeros":46}],48:[function(require,module,exports){ "use strict";function getLens(o){var r=o.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=o.indexOf("=");return-1===e&&(e=r),[e,e===r?0:4-e%4]}function byteLength(o){var r=getLens(o),e=r[0],t=r[1];return 3*(e+t)/4-t}function _byteLength(o,r,e){return 3*(r+e)/4-e}function toByteArray(o){for(var r,e=getLens(o),t=e[0],n=e[1],u=new Arr(_byteLength(o,t,n)),p=0,a=n>0?t-4:t,h=0;h>16&255,u[p++]=r>>8&255,u[p++]=255&r;return 2===n&&(r=revLookup[o.charCodeAt(h)]<<2|revLookup[o.charCodeAt(h+1)]>>4,u[p++]=255&r),1===n&&(r=revLookup[o.charCodeAt(h)]<<10|revLookup[o.charCodeAt(h+1)]<<4|revLookup[o.charCodeAt(h+2)]>>2,u[p++]=r>>8&255,u[p++]=255&r),u}function tripletToBase64(o){return lookup[o>>18&63]+lookup[o>>12&63]+lookup[o>>6&63]+lookup[63&o]}function encodeChunk(o,r,e){for(var t,n=[],u=r;up?p:u+16383));return 1===t?(r=o[e-1],n.push(lookup[r>>2]+lookup[r<<4&63]+"==")):2===t&&(r=(o[e-2]<<8)+o[e-1],n.push(lookup[r>>10]+lookup[r>>4&63]+lookup[r<<2&63]+"=")),n.join("")}exports.byteLength=byteLength,exports.toByteArray=toByteArray,exports.fromByteArray=fromByteArray;for(var lookup=[],revLookup=[],Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;it)return!1;if((i+=e[s+1])>=t)return!0}}function i(t,i){return t<65?36===t:t<91||(t<97?95===t:t<123||(t<=65535?t>=170&&M.test(String.fromCharCode(t)):!1!==i&&e(t,U)))}function s(t,i){return t<48?36===t:t<58||!(t<65)&&(t<91||(t<97?95===t:t<123||(t<=65535?t>=170&&F.test(String.fromCharCode(t)):!1!==i&&(e(t,U)||e(t,G)))))}function r(t,e){return new q(t,{beforeExpr:!0,binop:e})}function a(t,e){return void 0===e&&(e={}),e.keyword=t,j[t]=new q(t,e)}function n(t,e){return 10===t||13===t||!e&&(8232===t||8233===t)}function o(t,e){return $.call(t,e)}function h(t,e){for(var i=1,s=0;;){K.lastIndex=s;var r=K.exec(t);if(!(r&&r.index=2015&&(e.ecmaVersion-=2009),null==e.allowReserved&&(e.allowReserved=e.ecmaVersion<5),tt(e.onToken)){var s=e.onToken;e.onToken=function(t){return s.push(t)}}return tt(e.onComment)&&(e.onComment=c(e,e.onComment)),e}function c(t,e){return function(i,s,r,a,n,o){var h={type:i?"Block":"Line",value:s,start:r,end:a};t.locations&&(h.loc=new it(this,n,o)),t.ranges&&(h.range=[r,a]),e.push(h)}}function u(t){return new RegExp("^(?:"+t.replace(/ /g,"|")+")$")}function l(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1}function d(t,e,i,s){return t.type=e,t.end=i,this.options.locations&&(t.loc.end=s),this.options.ranges&&(t.range[1]=i),t}function f(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function m(t){return 36===t||t>=40&&t<=43||46===t||63===t||t>=91&&t<=94||t>=123&&t<=125}function x(t){return i(t,!0)||36===t||95===t}function g(t){return s(t,!0)||36===t||95===t||8204===t||8205===t}function v(t){return t>=65&&t<=90||t>=97&&t<=122}function y(t){return t>=0&&t<=1114111}function _(t){return 100===t||68===t||115===t||83===t||119===t||87===t}function b(t){return v(t)||95===t}function k(t){return b(t)||C(t)}function C(t){return t>=48&&t<=57}function S(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function E(t){return t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:t-48}function w(t){return t>=48&&t<=55}function A(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function I(t,e){return new at(e,t).parse()}function P(t,e,i){var s=new at(i,t,e);return s.nextToken(),s.parseExpression()}function L(t,e){return new at(e,t)}function N(e,i,s){t.parse_dammit=e,t.LooseParser=i,t.pluginsLoose=s}var T={3:"abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",5:"class enum extends super const export import",6:"enum",strict:"implements interface let package private protected public static yield",strictBind:"eval arguments"},V="break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this",R={5:V,6:V+" const class extends export import super"},D=/^in(stanceof)?$/,O="ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙՠ-ֈא-תׯ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࡠ-ࡪࢠ-ࢴࢶ-ࢽऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱৼਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚౠౡಀಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൔ-ൖൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡸᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᲀ-ᲈᲐ-ᲺᲽ-Ჿᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄯㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿯ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞹꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꣾꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭥꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ",B="‌‍·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛࣓-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఄా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳷-᳹᷀-᷹᷻-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-ꣅ꣐-꣙꣠-꣱ꣿ-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_",M=new RegExp("["+O+"]"),F=new RegExp("["+O+B+"]");O=B=null;var U=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,190,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,26,230,43,117,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,68,12,0,67,12,65,1,31,6129,15,754,9486,286,82,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541],G=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,280,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239],q=function(t,e){void 0===e&&(e={}),this.label=t,this.keyword=e.keyword,this.beforeExpr=!!e.beforeExpr,this.startsExpr=!!e.startsExpr,this.isLoop=!!e.isLoop,this.isAssign=!!e.isAssign,this.prefix=!!e.prefix,this.postfix=!!e.postfix,this.binop=e.binop||null,this.updateContext=null},H={beforeExpr:!0},W={startsExpr:!0},j={},z={num:new q("num",W),regexp:new q("regexp",W),string:new q("string",W),name:new q("name",W),eof:new q("eof"),bracketL:new q("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new q("]"),braceL:new q("{",{beforeExpr:!0,startsExpr:!0}),braceR:new q("}"),parenL:new q("(",{beforeExpr:!0,startsExpr:!0}),parenR:new q(")"),comma:new q(",",H),semi:new q(";",H),colon:new q(":",H),dot:new q("."),question:new q("?",H),arrow:new q("=>",H),template:new q("template"),invalidTemplate:new q("invalidTemplate"),ellipsis:new q("...",H),backQuote:new q("`",W),dollarBraceL:new q("${",{beforeExpr:!0,startsExpr:!0}),eq:new q("=",{beforeExpr:!0,isAssign:!0}),assign:new q("_=",{beforeExpr:!0,isAssign:!0}),incDec:new q("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new q("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:r("||",1),logicalAND:r("&&",2),bitwiseOR:r("|",3),bitwiseXOR:r("^",4),bitwiseAND:r("&",5),equality:r("==/!=/===/!==",6),relational:r("/<=/>=",7),bitShift:r("<>/>>>",8),plusMin:new q("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:r("%",10),star:r("*",10),slash:r("/",10),starstar:new q("**",{beforeExpr:!0}),_break:a("break"),_case:a("case",H),_catch:a("catch"),_continue:a("continue"),_debugger:a("debugger"),_default:a("default",H),_do:a("do",{isLoop:!0,beforeExpr:!0}),_else:a("else",H),_finally:a("finally"),_for:a("for",{isLoop:!0}),_function:a("function",W),_if:a("if"),_return:a("return",H),_switch:a("switch"),_throw:a("throw",H),_try:a("try"),_var:a("var"),_const:a("const"),_while:a("while",{isLoop:!0}),_with:a("with"),_new:a("new",{beforeExpr:!0,startsExpr:!0}),_this:a("this",W),_super:a("super",W),_class:a("class",W),_extends:a("extends",H),_export:a("export"),_import:a("import"),_null:a("null",W),_true:a("true",W),_false:a("false",W),_in:a("in",{beforeExpr:!0,binop:7}),_instanceof:a("instanceof",{beforeExpr:!0,binop:7}),_typeof:a("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:a("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:a("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},Q=/\r\n?|\n|\u2028|\u2029/,K=new RegExp(Q.source,"g"),X=/[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/,Y=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,Z=Object.prototype,$=Z.hasOwnProperty,J=Z.toString,tt=Array.isArray||function(t){return"[object Array]"===J.call(t)},et=function(t,e){this.line=t,this.column=e};et.prototype.offset=function(t){return new et(this.line,this.column+t)};var it=function(t,e,i){this.start=e,this.end=i,null!==t.sourceFile&&(this.source=t.sourceFile)},st={ecmaVersion:7,sourceType:"script",onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!1,allowImportExportEverywhere:!1,allowAwaitOutsideFunction:!1,allowHashBang:!1,locations:!1,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1,plugins:{}},rt={},at=function(t,e,i){this.options=t=p(t),this.sourceFile=t.sourceFile,this.keywords=u(R[t.ecmaVersion>=6?6:5]);var s="";if(!t.allowReserved){for(var r=t.ecmaVersion;!(s=T[r]);r--);"module"===t.sourceType&&(s+=" await")}this.reservedWords=u(s);var a=(s?s+" ":"")+T.strict;this.reservedWordsStrict=u(a),this.reservedWordsStrictBind=u(a+" "+T.strictBind),this.input=String(e),this.containsEsc=!1,this.loadPlugins(t.plugins),i?(this.pos=i,this.lineStart=this.input.lastIndexOf("\n",i-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(Q).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=z.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule="module"===t.sourceType,this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.inFunction=this.inGenerator=this.inAsync=!1,this.yieldPos=this.awaitPos=0,this.labels=[],0===this.pos&&t.allowHashBang&&"#!"===this.input.slice(0,2)&&this.skipLineComment(2),this.scopeStack=[],this.enterFunctionScope(),this.regexpState=null};at.prototype.isKeyword=function(t){return this.keywords.test(t)},at.prototype.isReservedWord=function(t){return this.reservedWords.test(t)},at.prototype.extend=function(t,e){this[t]=e(this[t])},at.prototype.loadPlugins=function(t){var e=this;for(var i in t){var s=rt[i];if(!s)throw new Error("Plugin '"+i+"' not found");s(e,t[i])}},at.prototype.parse=function(){var t=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(t)};var nt=at.prototype,ot=/^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;nt.strictDirective=function(t){for(var e=this;;){Y.lastIndex=t,t+=Y.exec(e.input)[0].length;var i=ot.exec(e.input.slice(t));if(!i)return!1;if("use strict"===(i[1]||i[2]))return!0;t+=i[0].length}},nt.eat=function(t){return this.type===t&&(this.next(),!0)},nt.isContextual=function(t){return this.type===z.name&&this.value===t&&!this.containsEsc},nt.eatContextual=function(t){return!!this.isContextual(t)&&(this.next(),!0)},nt.expectContextual=function(t){this.eatContextual(t)||this.unexpected()},nt.canInsertSemicolon=function(){return this.type===z.eof||this.type===z.braceR||Q.test(this.input.slice(this.lastTokEnd,this.start))},nt.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0},nt.semicolon=function(){this.eat(z.semi)||this.insertSemicolon()||this.unexpected()},nt.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0},nt.expect=function(t){this.eat(t)||this.unexpected()},nt.unexpected=function(t){this.raise(null!=t?t:this.start,"Unexpected token")},nt.checkPatternErrors=function(t,e){if(t){t.trailingComma>-1&&this.raiseRecoverable(t.trailingComma,"Comma is not permitted after the rest element");var i=e?t.parenthesizedAssign:t.parenthesizedBind;i>-1&&this.raiseRecoverable(i,"Parenthesized pattern")}},nt.checkExpressionErrors=function(t,e){if(!t)return!1;var i=t.shorthandAssign,s=t.doubleProto;if(!e)return i>=0||s>=0;i>=0&&this.raise(i,"Shorthand property assignments are valid only in destructuring patterns"),s>=0&&this.raiseRecoverable(s,"Redefinition of __proto__ property")},nt.checkYieldAwaitInDefaultParams=function(){this.yieldPos&&(!this.awaitPos||this.yieldPos=6&&(t.sourceType=this.options.sourceType),this.finishNode(t,"Program")};var pt={kind:"loop"},ct={kind:"switch"};ht.isLet=function(){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;Y.lastIndex=this.pos;var t=Y.exec(this.input),e=this.pos+t[0].length,r=this.input.charCodeAt(e);if(91===r||123===r)return!0;if(i(r,!0)){for(var a=e+1;s(this.input.charCodeAt(a),!0);)++a;var n=this.input.slice(e,a);if(!D.test(n))return!0}return!1},ht.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;Y.lastIndex=this.pos;var t=Y.exec(this.input),e=this.pos+t[0].length;return!(Q.test(this.input.slice(this.pos,e))||"function"!==this.input.slice(e,e+8)||e+8!==this.input.length&&s(this.input.charAt(e+8)))},ht.parseStatement=function(t,e,i){var s,r=this.type,a=this.startNode();switch(this.isLet()&&(r=z._var,s="let"),r){case z._break:case z._continue:return this.parseBreakContinueStatement(a,r.keyword);case z._debugger:return this.parseDebuggerStatement(a);case z._do:return this.parseDoStatement(a);case z._for:return this.parseForStatement(a);case z._function:return!t&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(a,!1);case z._class:return t||this.unexpected(),this.parseClass(a,!0);case z._if:return this.parseIfStatement(a);case z._return:return this.parseReturnStatement(a);case z._switch:return this.parseSwitchStatement(a);case z._throw:return this.parseThrowStatement(a);case z._try:return this.parseTryStatement(a);case z._const:case z._var:return s=s||this.value,t||"var"===s||this.unexpected(),this.parseVarStatement(a,s);case z._while:return this.parseWhileStatement(a);case z._with:return this.parseWithStatement(a);case z.braceL:return this.parseBlock();case z.semi:return this.parseEmptyStatement(a);case z._export:case z._import:return this.options.allowImportExportEverywhere||(e||this.raise(this.start,"'import' and 'export' may only appear at the top level"),this.inModule||this.raise(this.start,"'import' and 'export' may appear only with 'sourceType: module'")),r===z._import?this.parseImport(a):this.parseExport(a,i);default:if(this.isAsyncFunction())return t||this.unexpected(),this.next(),this.parseFunctionStatement(a,!0);var n=this.value,o=this.parseExpression();return r===z.name&&"Identifier"===o.type&&this.eat(z.colon)?this.parseLabeledStatement(a,n,o):this.parseExpressionStatement(a,o)}},ht.parseBreakContinueStatement=function(t,e){var i=this,s="break"===e;this.next(),this.eat(z.semi)||this.insertSemicolon()?t.label=null:this.type!==z.name?this.unexpected():(t.label=this.parseIdent(),this.semicolon());for(var r=0;r=6?this.eat(z.semi):this.semicolon(),this.finishNode(t,"DoWhileStatement")},ht.parseForStatement=function(t){this.next();var e=this.options.ecmaVersion>=9&&(this.inAsync||!this.inFunction&&this.options.allowAwaitOutsideFunction)&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(pt),this.enterLexicalScope(),this.expect(z.parenL),this.type===z.semi)return e>-1&&this.unexpected(e),this.parseFor(t,null);var i=this.isLet();if(this.type===z._var||this.type===z._const||i){var s=this.startNode(),r=i?"let":this.value;return this.next(),(this.parseVar(s,!0,r),this.finishNode(s,"VariableDeclaration"),!(this.type===z._in||this.options.ecmaVersion>=6&&this.isContextual("of"))||1!==s.declarations.length||"var"!==r&&s.declarations[0].init)?(e>-1&&this.unexpected(e),this.parseFor(t,s)):(this.options.ecmaVersion>=9&&(this.type===z._in?e>-1&&this.unexpected(e):t.await=e>-1),this.parseForIn(t,s))}var a=new l,n=this.parseExpression(!0,a);return this.type===z._in||this.options.ecmaVersion>=6&&this.isContextual("of")?(this.options.ecmaVersion>=9&&(this.type===z._in?e>-1&&this.unexpected(e):t.await=e>-1),this.toAssignable(n,!1,a),this.checkLVal(n),this.parseForIn(t,n)):(this.checkExpressionErrors(a,!0),e>-1&&this.unexpected(e),this.parseFor(t,n))},ht.parseFunctionStatement=function(t,e){return this.next(),this.parseFunction(t,!0,!1,e)},ht.parseIfStatement=function(t){return this.next(),t.test=this.parseParenExpression(),t.consequent=this.parseStatement(!this.strict&&this.type===z._function),t.alternate=this.eat(z._else)?this.parseStatement(!this.strict&&this.type===z._function):null,this.finishNode(t,"IfStatement")},ht.parseReturnStatement=function(t){return this.inFunction||this.options.allowReturnOutsideFunction||this.raise(this.start,"'return' outside of function"),this.next(),this.eat(z.semi)||this.insertSemicolon()?t.argument=null:(t.argument=this.parseExpression(),this.semicolon()),this.finishNode(t,"ReturnStatement")},ht.parseSwitchStatement=function(t){var e=this;this.next(),t.discriminant=this.parseParenExpression(),t.cases=[],this.expect(z.braceL),this.labels.push(ct),this.enterLexicalScope();for(var i,s=!1;this.type!==z.braceR;)if(e.type===z._case||e.type===z._default){var r=e.type===z._case;i&&e.finishNode(i,"SwitchCase"),t.cases.push(i=e.startNode()),i.consequent=[],e.next(),r?i.test=e.parseExpression():(s&&e.raiseRecoverable(e.lastTokStart,"Multiple default clauses"),s=!0,i.test=null),e.expect(z.colon)}else i||e.unexpected(),i.consequent.push(e.parseStatement(!0));return this.exitLexicalScope(),i&&this.finishNode(i,"SwitchCase"),this.next(),this.labels.pop(),this.finishNode(t,"SwitchStatement")},ht.parseThrowStatement=function(t){return this.next(),Q.test(this.input.slice(this.lastTokEnd,this.start))&&this.raise(this.lastTokEnd,"Illegal newline after throw"),t.argument=this.parseExpression(),this.semicolon(),this.finishNode(t,"ThrowStatement")};var ut=[];ht.parseTryStatement=function(t){if(this.next(),t.block=this.parseBlock(),t.handler=null,this.type===z._catch){var e=this.startNode();this.next(),this.eat(z.parenL)?(e.param=this.parseBindingAtom(),this.enterLexicalScope(),this.checkLVal(e.param,"let"),this.expect(z.parenR)):(this.options.ecmaVersion<10&&this.unexpected(),e.param=null,this.enterLexicalScope()),e.body=this.parseBlock(!1),this.exitLexicalScope(),t.handler=this.finishNode(e,"CatchClause")}return t.finalizer=this.eat(z._finally)?this.parseBlock():null,t.handler||t.finalizer||this.raise(t.start,"Missing catch or finally clause"),this.finishNode(t,"TryStatement")},ht.parseVarStatement=function(t,e){return this.next(),this.parseVar(t,!1,e),this.semicolon(),this.finishNode(t,"VariableDeclaration")},ht.parseWhileStatement=function(t){return this.next(),t.test=this.parseParenExpression(),this.labels.push(pt),t.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(t,"WhileStatement")},ht.parseWithStatement=function(t){return this.strict&&this.raise(this.start,"'with' in strict mode"),this.next(),t.object=this.parseParenExpression(),t.body=this.parseStatement(!1),this.finishNode(t,"WithStatement")},ht.parseEmptyStatement=function(t){return this.next(),this.finishNode(t,"EmptyStatement")},ht.parseLabeledStatement=function(t,e,i){for(var s=this,r=0,a=s.labels;r=0;o--){var h=s.labels[o];if(h.statementStart!==t.start)break;h.statementStart=s.start,h.kind=n}return this.labels.push({name:e,kind:n,statementStart:this.start}),t.body=this.parseStatement(!0),("ClassDeclaration"===t.body.type||"VariableDeclaration"===t.body.type&&"var"!==t.body.kind||"FunctionDeclaration"===t.body.type&&(this.strict||t.body.generator||t.body.async))&&this.raiseRecoverable(t.body.start,"Invalid labeled declaration"),this.labels.pop(),t.label=i,this.finishNode(t,"LabeledStatement")},ht.parseExpressionStatement=function(t,e){return t.expression=e,this.semicolon(),this.finishNode(t,"ExpressionStatement")},ht.parseBlock=function(t){var e=this;void 0===t&&(t=!0);var i=this.startNode();for(i.body=[],this.expect(z.braceL),t&&this.enterLexicalScope();!this.eat(z.braceR);){var s=e.parseStatement(!0);i.body.push(s)}return t&&this.exitLexicalScope(),this.finishNode(i,"BlockStatement")},ht.parseFor=function(t,e){return t.init=e,this.expect(z.semi),t.test=this.type===z.semi?null:this.parseExpression(),this.expect(z.semi),t.update=this.type===z.parenR?null:this.parseExpression(),this.expect(z.parenR),this.exitLexicalScope(),t.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(t,"ForStatement")},ht.parseForIn=function(t,e){var i=this.type===z._in?"ForInStatement":"ForOfStatement";return this.next(),"ForInStatement"===i&&("AssignmentPattern"===e.type||"VariableDeclaration"===e.type&&null!=e.declarations[0].init&&(this.strict||"Identifier"!==e.declarations[0].id.type))&&this.raise(e.start,"Invalid assignment in for-in loop head"),t.left=e,t.right="ForInStatement"===i?this.parseExpression():this.parseMaybeAssign(),this.expect(z.parenR),this.exitLexicalScope(),t.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(t,i)},ht.parseVar=function(t,e,i){var s=this;for(t.declarations=[],t.kind=i;;){var r=s.startNode();if(s.parseVarId(r,i),s.eat(z.eq)?r.init=s.parseMaybeAssign(e):"const"!==i||s.type===z._in||s.options.ecmaVersion>=6&&s.isContextual("of")?"Identifier"===r.id.type||e&&(s.type===z._in||s.isContextual("of"))?r.init=null:s.raise(s.lastTokEnd,"Complex binding patterns require an initialization value"):s.unexpected(),t.declarations.push(s.finishNode(r,"VariableDeclarator")),!s.eat(z.comma))break}return t},ht.parseVarId=function(t,e){t.id=this.parseBindingAtom(e),this.checkLVal(t.id,e,!1)},ht.parseFunction=function(t,e,i,s){this.initFunction(t),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!s)&&(t.generator=this.eat(z.star)),this.options.ecmaVersion>=8&&(t.async=!!s),e&&(t.id="nullableID"===e&&this.type!==z.name?null:this.parseIdent(),t.id&&this.checkLVal(t.id,this.inModule&&!this.inFunction?"let":"var"));var r=this.inGenerator,a=this.inAsync,n=this.yieldPos,o=this.awaitPos,h=this.inFunction;return this.inGenerator=t.generator,this.inAsync=t.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,this.enterFunctionScope(),e||(t.id=this.type===z.name?this.parseIdent():null),this.parseFunctionParams(t),this.parseFunctionBody(t,i),this.inGenerator=r,this.inAsync=a,this.yieldPos=n,this.awaitPos=o,this.inFunction=h,this.finishNode(t,e?"FunctionDeclaration":"FunctionExpression")},ht.parseFunctionParams=function(t){this.expect(z.parenL),t.params=this.parseBindingList(z.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()},ht.parseClass=function(t,e){var i=this;this.next(),this.parseClassId(t,e),this.parseClassSuper(t);var s=this.startNode(),r=!1;for(s.body=[],this.expect(z.braceL);!this.eat(z.braceR);){var a=i.parseClassMember(s);a&&"MethodDefinition"===a.type&&"constructor"===a.kind&&(r&&i.raise(a.start,"Duplicate constructor in the same class"),r=!0)}return t.body=this.finishNode(s,"ClassBody"),this.finishNode(t,e?"ClassDeclaration":"ClassExpression")},ht.parseClassMember=function(t){var e=this;if(this.eat(z.semi))return null;var i=this.startNode(),s=function(t,s){void 0===s&&(s=!1);var r=e.start,a=e.startLoc;return!!e.eatContextual(t)&&(!(e.type===z.parenL||s&&e.canInsertSemicolon())||(i.key&&e.unexpected(),i.computed=!1,i.key=e.startNodeAt(r,a),i.key.name=t,e.finishNode(i.key,"Identifier"),!1))};i.kind="method",i.static=s("static");var r=this.eat(z.star),a=!1;r||(this.options.ecmaVersion>=8&&s("async",!0)?(a=!0,r=this.options.ecmaVersion>=9&&this.eat(z.star)):s("get")?i.kind="get":s("set")&&(i.kind="set")),i.key||this.parsePropertyName(i);var n=i.key;return i.computed||i.static||!("Identifier"===n.type&&"constructor"===n.name||"Literal"===n.type&&"constructor"===n.value)?i.static&&"Identifier"===n.type&&"prototype"===n.name&&this.raise(n.start,"Classes may not have a static property named prototype"):("method"!==i.kind&&this.raise(n.start,"Constructor can't have get/set modifier"),r&&this.raise(n.start,"Constructor can't be a generator"),a&&this.raise(n.start,"Constructor can't be an async method"),i.kind="constructor"),this.parseClassMethod(t,i,r,a),"get"===i.kind&&0!==i.value.params.length&&this.raiseRecoverable(i.value.start,"getter should have no params"),"set"===i.kind&&1!==i.value.params.length&&this.raiseRecoverable(i.value.start,"setter should have exactly one param"),"set"===i.kind&&"RestElement"===i.value.params[0].type&&this.raiseRecoverable(i.value.params[0].start,"Setter cannot use rest params"),i},ht.parseClassMethod=function(t,e,i,s){e.value=this.parseMethod(i,s),t.body.push(this.finishNode(e,"MethodDefinition"))},ht.parseClassId=function(t,e){t.id=this.type===z.name?this.parseIdent():!0===e?this.unexpected():null},ht.parseClassSuper=function(t){t.superClass=this.eat(z._extends)?this.parseExprSubscripts():null},ht.parseExport=function(t,e){var i=this;if(this.next(),this.eat(z.star))return this.expectContextual("from"),this.type!==z.string&&this.unexpected(),t.source=this.parseExprAtom(),this.semicolon(),this.finishNode(t,"ExportAllDeclaration");if(this.eat(z._default)){this.checkExport(e,"default",this.lastTokStart);var s;if(this.type===z._function||(s=this.isAsyncFunction())){var r=this.startNode();this.next(),s&&this.next(),t.declaration=this.parseFunction(r,"nullableID",!1,s)}else if(this.type===z._class){var a=this.startNode();t.declaration=this.parseClass(a,"nullableID")}else t.declaration=this.parseMaybeAssign(),this.semicolon();return this.finishNode(t,"ExportDefaultDeclaration")}if(this.shouldParseExportStatement())t.declaration=this.parseStatement(!0),"VariableDeclaration"===t.declaration.type?this.checkVariableExport(e,t.declaration.declarations):this.checkExport(e,t.declaration.id.name,t.declaration.id.start),t.specifiers=[],t.source=null;else{if(t.declaration=null,t.specifiers=this.parseExportSpecifiers(e),this.eatContextual("from"))this.type!==z.string&&this.unexpected(),t.source=this.parseExprAtom();else{for(var n=0,o=t.specifiers;n=6&&t)switch(t.type){case"Identifier":this.inAsync&&"await"===t.name&&this.raise(t.start,"Can not use 'await' as identifier inside an async function");break;case"ObjectPattern":case"ArrayPattern":case"RestElement":break;case"ObjectExpression":t.type="ObjectPattern",i&&this.checkPatternErrors(i,!0);for(var r=0,a=t.properties;r=9&&"SpreadElement"===t.type||this.options.ecmaVersion>=6&&(t.computed||t.method||t.shorthand))){var s,r=t.key;switch(r.type){case"Identifier":s=r.name;break;case"Literal":s=String(r.value);break;default:return}var a=t.kind;if(this.options.ecmaVersion>=6)return void("__proto__"===s&&"init"===a&&(e.proto&&(i&&i.doubleProto<0?i.doubleProto=r.start:this.raiseRecoverable(r.start,"Redefinition of __proto__ property")),e.proto=!0));s="$"+s;var n=e[s];if(n){var o;o="init"===a?this.strict&&n.init||n.get||n.set:n.init||n[a],o&&this.raiseRecoverable(r.start,"Redefinition of property")}else n=e[s]={init:!1,get:!1,set:!1};n[a]=!0}},dt.parseExpression=function(t,e){var i=this,s=this.start,r=this.startLoc,a=this.parseMaybeAssign(t,e);if(this.type===z.comma){var n=this.startNodeAt(s,r);for(n.expressions=[a];this.eat(z.comma);)n.expressions.push(i.parseMaybeAssign(t,e));return this.finishNode(n,"SequenceExpression")}return a},dt.parseMaybeAssign=function(t,e,i){if(this.inGenerator&&this.isContextual("yield"))return this.parseYield();var s=!1,r=-1,a=-1;e?(r=e.parenthesizedAssign,a=e.trailingComma,e.parenthesizedAssign=e.trailingComma=-1):(e=new l,s=!0);var n=this.start,o=this.startLoc;this.type!==z.parenL&&this.type!==z.name||(this.potentialArrowAt=this.start);var h=this.parseMaybeConditional(t,e);if(i&&(h=i.call(this,h,n,o)),this.type.isAssign){var p=this.startNodeAt(n,o);return p.operator=this.value,p.left=this.type===z.eq?this.toAssignable(h,!1,e):h,s||l.call(e),e.shorthandAssign=-1,this.checkLVal(h),this.next(),p.right=this.parseMaybeAssign(t),this.finishNode(p,"AssignmentExpression")}return s&&this.checkExpressionErrors(e,!0),r>-1&&(e.parenthesizedAssign=r),a>-1&&(e.trailingComma=a),h},dt.parseMaybeConditional=function(t,e){var i=this.start,s=this.startLoc,r=this.parseExprOps(t,e);if(this.checkExpressionErrors(e))return r;if(this.eat(z.question)){var a=this.startNodeAt(i,s);return a.test=r,a.consequent=this.parseMaybeAssign(),this.expect(z.colon),a.alternate=this.parseMaybeAssign(t),this.finishNode(a,"ConditionalExpression")}return r},dt.parseExprOps=function(t,e){var i=this.start,s=this.startLoc,r=this.parseMaybeUnary(e,!1);return this.checkExpressionErrors(e)?r:r.start===i&&"ArrowFunctionExpression"===r.type?r:this.parseExprOp(r,i,s,-1,t)},dt.parseExprOp=function(t,e,i,s,r){var a=this.type.binop;if(null!=a&&(!r||this.type!==z._in)&&a>s){var n=this.type===z.logicalOR||this.type===z.logicalAND,o=this.value;this.next();var h=this.start,p=this.startLoc,c=this.parseExprOp(this.parseMaybeUnary(null,!1),h,p,a,r),u=this.buildBinary(e,i,t,c,o,n);return this.parseExprOp(u,e,i,s,r)}return t},dt.buildBinary=function(t,e,i,s,r,a){var n=this.startNodeAt(t,e);return n.left=i,n.operator=r,n.right=s,this.finishNode(n,a?"LogicalExpression":"BinaryExpression")},dt.parseMaybeUnary=function(t,e){var i,s=this,r=this.start,a=this.startLoc;if(this.isContextual("await")&&(this.inAsync||!this.inFunction&&this.options.allowAwaitOutsideFunction))i=this.parseAwait(),e=!0;else if(this.type.prefix){var n=this.startNode(),o=this.type===z.incDec;n.operator=this.value,n.prefix=!0,this.next(),n.argument=this.parseMaybeUnary(null,!0),this.checkExpressionErrors(t,!0),o?this.checkLVal(n.argument):this.strict&&"delete"===n.operator&&"Identifier"===n.argument.type?this.raiseRecoverable(n.start,"Deleting local variable in strict mode"):e=!0,i=this.finishNode(n,o?"UpdateExpression":"UnaryExpression")}else{if(i=this.parseExprSubscripts(t),this.checkExpressionErrors(t))return i;for(;this.type.postfix&&!this.canInsertSemicolon();){var h=s.startNodeAt(r,a);h.operator=s.value,h.prefix=!1,h.argument=i,s.checkLVal(i),s.next(),i=s.finishNode(h,"UpdateExpression")}}return!e&&this.eat(z.starstar)?this.buildBinary(r,a,i,this.parseMaybeUnary(null,!1),"**",!1):i},dt.parseExprSubscripts=function(t){var e=this.start,i=this.startLoc,s=this.parseExprAtom(t),r="ArrowFunctionExpression"===s.type&&")"!==this.input.slice(this.lastTokStart,this.lastTokEnd);if(this.checkExpressionErrors(t)||r)return s;var a=this.parseSubscripts(s,e,i);return t&&"MemberExpression"===a.type&&(t.parenthesizedAssign>=a.start&&(t.parenthesizedAssign=-1),t.parenthesizedBind>=a.start&&(t.parenthesizedBind=-1)),a},dt.parseSubscripts=function(t,e,i,s){for(var r=this,a=this.options.ecmaVersion>=8&&"Identifier"===t.type&&"async"===t.name&&this.lastTokEnd===t.end&&!this.canInsertSemicolon()&&"async"===this.input.slice(t.start,t.end),n=void 0;;)if((n=r.eat(z.bracketL))||r.eat(z.dot)){var o=r.startNodeAt(e,i);o.object=t,o.property=n?r.parseExpression():r.parseIdent(!0),o.computed=!!n,n&&r.expect(z.bracketR),t=r.finishNode(o,"MemberExpression")}else if(!s&&r.eat(z.parenL)){var h=new l,p=r.yieldPos,c=r.awaitPos;r.yieldPos=0,r.awaitPos=0;var u=r.parseExprList(z.parenR,r.options.ecmaVersion>=8,!1,h);if(a&&!r.canInsertSemicolon()&&r.eat(z.arrow))return r.checkPatternErrors(h,!1),r.checkYieldAwaitInDefaultParams(),r.yieldPos=p,r.awaitPos=c,r.parseArrowExpression(r.startNodeAt(e,i),u,!0);r.checkExpressionErrors(h,!0),r.yieldPos=p||r.yieldPos,r.awaitPos=c||r.awaitPos;var d=r.startNodeAt(e,i);d.callee=t,d.arguments=u,t=r.finishNode(d,"CallExpression")}else{if(r.type!==z.backQuote)return t;var f=r.startNodeAt(e,i);f.tag=t,f.quasi=r.parseTemplate({isTagged:!0}),t=r.finishNode(f,"TaggedTemplateExpression")}},dt.parseExprAtom=function(t){var e,i=this.potentialArrowAt===this.start;switch(this.type){case z._super:return this.inFunction||this.raise(this.start,"'super' outside of function or class"),e=this.startNode(),this.next(),this.type!==z.dot&&this.type!==z.bracketL&&this.type!==z.parenL&&this.unexpected(),this.finishNode(e,"Super");case z._this:return e=this.startNode(),this.next(),this.finishNode(e,"ThisExpression");case z.name:var s=this.start,r=this.startLoc,a=this.containsEsc,n=this.parseIdent(this.type!==z.name);if(this.options.ecmaVersion>=8&&!a&&"async"===n.name&&!this.canInsertSemicolon()&&this.eat(z._function))return this.parseFunction(this.startNodeAt(s,r),!1,!1,!0);if(i&&!this.canInsertSemicolon()){if(this.eat(z.arrow))return this.parseArrowExpression(this.startNodeAt(s,r),[n],!1);if(this.options.ecmaVersion>=8&&"async"===n.name&&this.type===z.name&&!a)return n=this.parseIdent(),!this.canInsertSemicolon()&&this.eat(z.arrow)||this.unexpected(),this.parseArrowExpression(this.startNodeAt(s,r),[n],!0)}return n;case z.regexp:var o=this.value;return e=this.parseLiteral(o.value),e.regex={pattern:o.pattern,flags:o.flags},e;case z.num:case z.string:return this.parseLiteral(this.value);case z._null:case z._true:case z._false:return e=this.startNode(),e.value=this.type===z._null?null:this.type===z._true,e.raw=this.type.keyword,this.next(),this.finishNode(e,"Literal");case z.parenL:var h=this.start,p=this.parseParenAndDistinguishExpression(i);return t&&(t.parenthesizedAssign<0&&!this.isSimpleAssignTarget(p)&&(t.parenthesizedAssign=h),t.parenthesizedBind<0&&(t.parenthesizedBind=h)),p;case z.bracketL:return e=this.startNode(),this.next(),e.elements=this.parseExprList(z.bracketR,!0,!0,t),this.finishNode(e,"ArrayExpression");case z.braceL:return this.parseObj(!1,t);case z._function:return e=this.startNode(),this.next(),this.parseFunction(e,!1);case z._class:return this.parseClass(this.startNode(),!1);case z._new:return this.parseNew();case z.backQuote:return this.parseTemplate();default:this.unexpected()}},dt.parseLiteral=function(t){var e=this.startNode();return e.value=t,e.raw=this.input.slice(this.start,this.end),this.next(),this.finishNode(e,"Literal")},dt.parseParenExpression=function(){this.expect(z.parenL);var t=this.parseExpression();return this.expect(z.parenR),t},dt.parseParenAndDistinguishExpression=function(t){var e,i=this,s=this.start,r=this.startLoc,a=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var n,o=this.start,h=this.startLoc,p=[],c=!0,u=!1,d=new l,f=this.yieldPos,m=this.awaitPos;for(this.yieldPos=0,this.awaitPos=0;this.type!==z.parenR;){if(c?c=!1:i.expect(z.comma),a&&i.afterTrailingComma(z.parenR,!0)){u=!0;break}if(i.type===z.ellipsis){n=i.start,p.push(i.parseParenItem(i.parseRestBinding())),i.type===z.comma&&i.raise(i.start,"Comma is not permitted after the rest element");break}p.push(i.parseMaybeAssign(!1,d,i.parseParenItem))}var x=this.start,g=this.startLoc;if(this.expect(z.parenR),t&&!this.canInsertSemicolon()&&this.eat(z.arrow))return this.checkPatternErrors(d,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=f,this.awaitPos=m,this.parseParenArrowList(s,r,p);p.length&&!u||this.unexpected(this.lastTokStart),n&&this.unexpected(n),this.checkExpressionErrors(d,!0),this.yieldPos=f||this.yieldPos,this.awaitPos=m||this.awaitPos,p.length>1?(e=this.startNodeAt(o,h),e.expressions=p,this.finishNodeAt(e,"SequenceExpression",x,g)):e=p[0]}else e=this.parseParenExpression();if(this.options.preserveParens){var v=this.startNodeAt(s,r);return v.expression=e,this.finishNode(v,"ParenthesizedExpression")}return e},dt.parseParenItem=function(t){return t},dt.parseParenArrowList=function(t,e,i){return this.parseArrowExpression(this.startNodeAt(t,e),i)};var ft=[];dt.parseNew=function(){var t=this.startNode(),e=this.parseIdent(!0);if(this.options.ecmaVersion>=6&&this.eat(z.dot)){t.meta=e;var i=this.containsEsc;return t.property=this.parseIdent(!0),("target"!==t.property.name||i)&&this.raiseRecoverable(t.property.start,"The only valid meta property for new is new.target"),this.inFunction||this.raiseRecoverable(t.start,"new.target can only be used in functions"),this.finishNode(t,"MetaProperty")}var s=this.start,r=this.startLoc;return t.callee=this.parseSubscripts(this.parseExprAtom(),s,r,!0),this.eat(z.parenL)?t.arguments=this.parseExprList(z.parenR,this.options.ecmaVersion>=8,!1):t.arguments=ft,this.finishNode(t,"NewExpression")},dt.parseTemplateElement=function(t){var e=t.isTagged,i=this.startNode();return this.type===z.invalidTemplate?(e||this.raiseRecoverable(this.start,"Bad escape sequence in untagged template literal"),i.value={raw:this.value,cooked:null}):i.value={raw:this.input.slice(this.start,this.end).replace(/\r\n?/g,"\n"),cooked:this.value},this.next(),i.tail=this.type===z.backQuote,this.finishNode(i,"TemplateElement")},dt.parseTemplate=function(t){var e=this;void 0===t&&(t={});var i=t.isTagged;void 0===i&&(i=!1);var s=this.startNode();this.next(),s.expressions=[];var r=this.parseTemplateElement({isTagged:i});for(s.quasis=[r];!r.tail;)e.expect(z.dollarBraceL),s.expressions.push(e.parseExpression()),e.expect(z.braceR),s.quasis.push(r=e.parseTemplateElement({isTagged:i}));return this.next(),this.finishNode(s,"TemplateLiteral")},dt.isAsyncProp=function(t){return!t.computed&&"Identifier"===t.key.type&&"async"===t.key.name&&(this.type===z.name||this.type===z.num||this.type===z.string||this.type===z.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===z.star)&&!Q.test(this.input.slice(this.lastTokEnd,this.start))},dt.parseObj=function(t,e){var i=this,s=this.startNode(),r=!0,a={};for(s.properties=[],this.next();!this.eat(z.braceR);){if(r)r=!1;else if(i.expect(z.comma),i.afterTrailingComma(z.braceR))break;var n=i.parseProperty(t,e);t||i.checkPropClash(n,a,e),s.properties.push(n)}return this.finishNode(s,t?"ObjectPattern":"ObjectExpression")},dt.parseProperty=function(t,e){var i,s,r,a,n=this.startNode();if(this.options.ecmaVersion>=9&&this.eat(z.ellipsis))return t?(n.argument=this.parseIdent(!1),this.type===z.comma&&this.raise(this.start,"Comma is not permitted after the rest element"),this.finishNode(n,"RestElement")):(this.type===z.parenL&&e&&(e.parenthesizedAssign<0&&(e.parenthesizedAssign=this.start),e.parenthesizedBind<0&&(e.parenthesizedBind=this.start)),n.argument=this.parseMaybeAssign(!1,e),this.type===z.comma&&e&&e.trailingComma<0&&(e.trailingComma=this.start),this.finishNode(n,"SpreadElement"));this.options.ecmaVersion>=6&&(n.method=!1,n.shorthand=!1,(t||e)&&(r=this.start,a=this.startLoc),t||(i=this.eat(z.star)));var o=this.containsEsc;return this.parsePropertyName(n),!t&&!o&&this.options.ecmaVersion>=8&&!i&&this.isAsyncProp(n)?(s=!0,i=this.options.ecmaVersion>=9&&this.eat(z.star),this.parsePropertyName(n,e)):s=!1,this.parsePropertyValue(n,t,i,s,r,a,e,o),this.finishNode(n,"Property")},dt.parsePropertyValue=function(t,e,i,s,r,a,n,o){if((i||s)&&this.type===z.colon&&this.unexpected(),this.eat(z.colon))t.value=e?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,n),t.kind="init";else if(this.options.ecmaVersion>=6&&this.type===z.parenL)e&&this.unexpected(),t.kind="init",t.method=!0,t.value=this.parseMethod(i,s);else if(e||o||!(this.options.ecmaVersion>=5)||t.computed||"Identifier"!==t.key.type||"get"!==t.key.name&&"set"!==t.key.name||this.type===z.comma||this.type===z.braceR)this.options.ecmaVersion>=6&&!t.computed&&"Identifier"===t.key.type?(this.checkUnreserved(t.key),t.kind="init",e?t.value=this.parseMaybeDefault(r,a,t.key):this.type===z.eq&&n?(n.shorthandAssign<0&&(n.shorthandAssign=this.start),t.value=this.parseMaybeDefault(r,a,t.key)):t.value=t.key,t.shorthand=!0):this.unexpected();else{(i||s)&&this.unexpected(),t.kind=t.key.name,this.parsePropertyName(t),t.value=this.parseMethod(!1);var h="get"===t.kind?0:1;if(t.value.params.length!==h){var p=t.value.start;"get"===t.kind?this.raiseRecoverable(p,"getter should have no params"):this.raiseRecoverable(p,"setter should have exactly one param")}else"set"===t.kind&&"RestElement"===t.value.params[0].type&&this.raiseRecoverable(t.value.params[0].start,"Setter cannot use rest params")}},dt.parsePropertyName=function(t){if(this.options.ecmaVersion>=6){if(this.eat(z.bracketL))return t.computed=!0,t.key=this.parseMaybeAssign(),this.expect(z.bracketR),t.key;t.computed=!1}return t.key=this.type===z.num||this.type===z.string?this.parseExprAtom():this.parseIdent(!0)},dt.initFunction=function(t){t.id=null,this.options.ecmaVersion>=6&&(t.generator=!1,t.expression=!1),this.options.ecmaVersion>=8&&(t.async=!1)},dt.parseMethod=function(t,e){var i=this.startNode(),s=this.inGenerator,r=this.inAsync,a=this.yieldPos,n=this.awaitPos,o=this.inFunction;return this.initFunction(i),this.options.ecmaVersion>=6&&(i.generator=t),this.options.ecmaVersion>=8&&(i.async=!!e),this.inGenerator=i.generator,this.inAsync=i.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,this.enterFunctionScope(),this.expect(z.parenL),i.params=this.parseBindingList(z.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(i,!1),this.inGenerator=s,this.inAsync=r,this.yieldPos=a,this.awaitPos=n,this.inFunction=o,this.finishNode(i,"FunctionExpression")},dt.parseArrowExpression=function(t,e,i){var s=this.inGenerator,r=this.inAsync,a=this.yieldPos,n=this.awaitPos,o=this.inFunction;return this.enterFunctionScope(),this.initFunction(t),this.options.ecmaVersion>=8&&(t.async=!!i),this.inGenerator=!1,this.inAsync=t.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,t.params=this.toAssignableList(e,!0),this.parseFunctionBody(t,!0),this.inGenerator=s,this.inAsync=r,this.yieldPos=a,this.awaitPos=n,this.inFunction=o,this.finishNode(t,"ArrowFunctionExpression")},dt.parseFunctionBody=function(t,e){var i=e&&this.type!==z.braceL,s=this.strict,r=!1;if(i)t.body=this.parseMaybeAssign(),t.expression=!0,this.checkParams(t,!1);else{var a=this.options.ecmaVersion>=7&&!this.isSimpleParamList(t.params);s&&!a||(r=this.strictDirective(this.end))&&a&&this.raiseRecoverable(t.start,"Illegal 'use strict' directive in function with non-simple parameter list");var n=this.labels;this.labels=[],r&&(this.strict=!0),this.checkParams(t,!s&&!r&&!e&&this.isSimpleParamList(t.params)),t.body=this.parseBlock(!1),t.expression=!1,this.adaptDirectivePrologue(t.body.body),this.labels=n}this.exitFunctionScope(),this.strict&&t.id&&this.checkLVal(t.id,"none"),this.strict=s},dt.isSimpleParamList=function(t){for(var e=0,i=t;e0;)e[i]=arguments[i+1];for(var s=0,r=e;s=1;e--){var i=t.context[e];if("function"===i.token)return i.generator}return!1},kt.updateContext=function(t){var e,i=this.type;i.keyword&&t===z.dot?this.exprAllowed=!1:(e=i.updateContext)?e.call(this,t):this.exprAllowed=i.beforeExpr},z.parenR.updateContext=z.braceR.updateContext=function(){if(1===this.context.length)return void(this.exprAllowed=!0);var t=this.context.pop();t===bt.b_stat&&"function"===this.curContext().token&&(t=this.context.pop()),this.exprAllowed=!t.isExpr},z.braceL.updateContext=function(t){this.context.push(this.braceIsBlock(t)?bt.b_stat:bt.b_expr),this.exprAllowed=!0},z.dollarBraceL.updateContext=function(){this.context.push(bt.b_tmpl),this.exprAllowed=!0},z.parenL.updateContext=function(t){var e=t===z._if||t===z._for||t===z._with||t===z._while;this.context.push(e?bt.p_stat:bt.p_expr),this.exprAllowed=!0},z.incDec.updateContext=function(){},z._function.updateContext=z._class.updateContext=function(t){t.beforeExpr&&t!==z.semi&&t!==z._else&&(t!==z.colon&&t!==z.braceL||this.curContext()!==bt.b_stat)?this.context.push(bt.f_expr):this.context.push(bt.f_stat),this.exprAllowed=!1},z.backQuote.updateContext=function(){this.curContext()===bt.q_tmpl?this.context.pop():this.context.push(bt.q_tmpl),this.exprAllowed=!1},z.star.updateContext=function(t){if(t===z._function){var e=this.context.length-1;this.context[e]===bt.f_expr?this.context[e]=bt.f_expr_gen:this.context[e]=bt.f_gen}this.exprAllowed=!0},z.name.updateContext=function(t){var e=!1;this.options.ecmaVersion>=6&&("of"===this.value&&!this.exprAllowed||"yield"===this.value&&this.inGeneratorContext())&&(e=!0),this.exprAllowed=e};var Ct={$LONE:["ASCII","ASCII_Hex_Digit","AHex","Alphabetic","Alpha","Any","Assigned","Bidi_Control","Bidi_C","Bidi_Mirrored","Bidi_M","Case_Ignorable","CI","Cased","Changes_When_Casefolded","CWCF","Changes_When_Casemapped","CWCM","Changes_When_Lowercased","CWL","Changes_When_NFKC_Casefolded","CWKCF","Changes_When_Titlecased","CWT","Changes_When_Uppercased","CWU","Dash","Default_Ignorable_Code_Point","DI","Deprecated","Dep","Diacritic","Dia","Emoji","Emoji_Component","Emoji_Modifier","Emoji_Modifier_Base","Emoji_Presentation","Extender","Ext","Grapheme_Base","Gr_Base","Grapheme_Extend","Gr_Ext","Hex_Digit","Hex","IDS_Binary_Operator","IDSB","IDS_Trinary_Operator","IDST","ID_Continue","IDC","ID_Start","IDS","Ideographic","Ideo","Join_Control","Join_C","Logical_Order_Exception","LOE","Lowercase","Lower","Math","Noncharacter_Code_Point","NChar","Pattern_Syntax","Pat_Syn","Pattern_White_Space","Pat_WS","Quotation_Mark","QMark","Radical","Regional_Indicator","RI","Sentence_Terminal","STerm","Soft_Dotted","SD","Terminal_Punctuation","Term","Unified_Ideograph","UIdeo","Uppercase","Upper","Variation_Selector","VS","White_Space","space","XID_Continue","XIDC","XID_Start","XIDS"],General_Category:["Cased_Letter","LC","Close_Punctuation","Pe","Connector_Punctuation","Pc","Control","Cc","cntrl","Currency_Symbol","Sc","Dash_Punctuation","Pd","Decimal_Number","Nd","digit","Enclosing_Mark","Me","Final_Punctuation","Pf","Format","Cf","Initial_Punctuation","Pi","Letter","L","Letter_Number","Nl","Line_Separator","Zl","Lowercase_Letter","Ll","Mark","M","Combining_Mark","Math_Symbol","Sm","Modifier_Letter","Lm","Modifier_Symbol","Sk","Nonspacing_Mark","Mn","Number","N","Open_Punctuation","Ps","Other","C","Other_Letter","Lo","Other_Number","No","Other_Punctuation","Po","Other_Symbol","So","Paragraph_Separator","Zp","Private_Use","Co","Punctuation","P","punct","Separator","Z","Space_Separator","Zs","Spacing_Mark","Mc","Surrogate","Cs","Symbol","S","Titlecase_Letter","Lt","Unassigned","Cn","Uppercase_Letter","Lu"],Script:["Adlam","Adlm","Ahom","Anatolian_Hieroglyphs","Hluw","Arabic","Arab","Armenian","Armn","Avestan","Avst","Balinese","Bali","Bamum","Bamu","Bassa_Vah","Bass","Batak","Batk","Bengali","Beng","Bhaiksuki","Bhks","Bopomofo","Bopo","Brahmi","Brah","Braille","Brai","Buginese","Bugi","Buhid","Buhd","Canadian_Aboriginal","Cans","Carian","Cari","Caucasian_Albanian","Aghb","Chakma","Cakm","Cham","Cherokee","Cher","Common","Zyyy","Coptic","Copt","Qaac","Cuneiform","Xsux","Cypriot","Cprt","Cyrillic","Cyrl","Deseret","Dsrt","Devanagari","Deva","Duployan","Dupl","Egyptian_Hieroglyphs","Egyp","Elbasan","Elba","Ethiopic","Ethi","Georgian","Geor","Glagolitic","Glag","Gothic","Goth","Grantha","Gran","Greek","Grek","Gujarati","Gujr","Gurmukhi","Guru","Han","Hani","Hangul","Hang","Hanunoo","Hano","Hatran","Hatr","Hebrew","Hebr","Hiragana","Hira","Imperial_Aramaic","Armi","Inherited","Zinh","Qaai","Inscriptional_Pahlavi","Phli","Inscriptional_Parthian","Prti","Javanese","Java","Kaithi","Kthi","Kannada","Knda","Katakana","Kana","Kayah_Li","Kali","Kharoshthi","Khar","Khmer","Khmr","Khojki","Khoj","Khudawadi","Sind","Lao","Laoo","Latin","Latn","Lepcha","Lepc","Limbu","Limb","Linear_A","Lina","Linear_B","Linb","Lisu","Lycian","Lyci","Lydian","Lydi","Mahajani","Mahj","Malayalam","Mlym","Mandaic","Mand","Manichaean","Mani","Marchen","Marc","Masaram_Gondi","Gonm","Meetei_Mayek","Mtei","Mende_Kikakui","Mend","Meroitic_Cursive","Merc","Meroitic_Hieroglyphs","Mero","Miao","Plrd","Modi","Mongolian","Mong","Mro","Mroo","Multani","Mult","Myanmar","Mymr","Nabataean","Nbat","New_Tai_Lue","Talu","Newa","Nko","Nkoo","Nushu","Nshu","Ogham","Ogam","Ol_Chiki","Olck","Old_Hungarian","Hung","Old_Italic","Ital","Old_North_Arabian","Narb","Old_Permic","Perm","Old_Persian","Xpeo","Old_South_Arabian","Sarb","Old_Turkic","Orkh","Oriya","Orya","Osage","Osge","Osmanya","Osma","Pahawh_Hmong","Hmng","Palmyrene","Palm","Pau_Cin_Hau","Pauc","Phags_Pa","Phag","Phoenician","Phnx","Psalter_Pahlavi","Phlp","Rejang","Rjng","Runic","Runr","Samaritan","Samr","Saurashtra","Saur","Sharada","Shrd","Shavian","Shaw","Siddham","Sidd","SignWriting","Sgnw","Sinhala","Sinh","Sora_Sompeng","Sora","Soyombo","Soyo","Sundanese","Sund","Syloti_Nagri","Sylo","Syriac","Syrc","Tagalog","Tglg","Tagbanwa","Tagb","Tai_Le","Tale","Tai_Tham","Lana","Tai_Viet","Tavt","Takri","Takr","Tamil","Taml","Tangut","Tang","Telugu","Telu","Thaana","Thaa","Thai","Tibetan","Tibt","Tifinagh","Tfng","Tirhuta","Tirh","Ugaritic","Ugar","Vai","Vaii","Warang_Citi","Wara","Yi","Yiii","Zanabazar_Square","Zanb"]};Array.prototype.push.apply(Ct.$LONE,Ct.General_Category),Ct.gc=Ct.General_Category,Ct.sc=Ct.Script_Extensions=Ct.scx=Ct.Script;var St=at.prototype,Et=function(t){this.parser=t,this.validFlags="gim"+(t.options.ecmaVersion>=6?"uy":"")+(t.options.ecmaVersion>=9?"s":""),this.source="",this.flags="",this.start=0,this.switchU=!1,this.switchN=!1,this.pos=0,this.lastIntValue=0,this.lastStringValue="",this.lastAssertionIsQuantifiable=!1,this.numCapturingParens=0,this.maxBackReference=0,this.groupNames=[],this.backReferenceNames=[]};Et.prototype.reset=function(t,e,i){var s=-1!==i.indexOf("u");this.start=0|t,this.source=e+"",this.flags=i,this.switchU=s&&this.parser.options.ecmaVersion>=6,this.switchN=s&&this.parser.options.ecmaVersion>=9},Et.prototype.raise=function(t){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+t)},Et.prototype.at=function(t){var e=this.source,i=e.length;if(t>=i)return-1;var s=e.charCodeAt(t);return!this.switchU||s<=55295||s>=57344||t+1>=i?s:(s<<10)+e.charCodeAt(t+1)-56613888}, Et.prototype.nextIndex=function(t){var e=this.source,i=e.length;if(t>=i)return i;var s=e.charCodeAt(t);return!this.switchU||s<=55295||s>=57344||t+1>=i?t+1:t+2},Et.prototype.current=function(){return this.at(this.pos)},Et.prototype.lookahead=function(){return this.at(this.nextIndex(this.pos))},Et.prototype.advance=function(){this.pos=this.nextIndex(this.pos)},Et.prototype.eat=function(t){return this.current()===t&&(this.advance(),!0)},St.validateRegExpFlags=function(t){for(var e=this,i=t.validFlags,s=t.flags,r=0;r-1&&e.raise(t.start,"Duplicate regular expression flag")}},St.validateRegExpPattern=function(t){this.regexp_pattern(t),!t.switchN&&this.options.ecmaVersion>=9&&t.groupNames.length>0&&(t.switchN=!0,this.regexp_pattern(t))},St.regexp_pattern=function(t){t.pos=0,t.lastIntValue=0,t.lastStringValue="",t.lastAssertionIsQuantifiable=!1,t.numCapturingParens=0,t.maxBackReference=0,t.groupNames.length=0,t.backReferenceNames.length=0,this.regexp_disjunction(t),t.pos!==t.source.length&&(t.eat(41)&&t.raise("Unmatched ')'"),(t.eat(93)||t.eat(125))&&t.raise("Lone quantifier brackets")),t.maxBackReference>t.numCapturingParens&&t.raise("Invalid escape");for(var e=0,i=t.backReferenceNames;e=9&&(i=t.eat(60)),t.eat(61)||t.eat(33))return this.regexp_disjunction(t),t.eat(41)||t.raise("Unterminated group"),t.lastAssertionIsQuantifiable=!i,!0}return t.pos=e,!1},St.regexp_eatQuantifier=function(t,e){return void 0===e&&(e=!1),!!this.regexp_eatQuantifierPrefix(t,e)&&(t.eat(63),!0)},St.regexp_eatQuantifierPrefix=function(t,e){return t.eat(42)||t.eat(43)||t.eat(63)||this.regexp_eatBracedQuantifier(t,e)},St.regexp_eatBracedQuantifier=function(t,e){var i=t.pos;if(t.eat(123)){var s=0,r=-1;if(this.regexp_eatDecimalDigits(t)&&(s=t.lastIntValue,t.eat(44)&&this.regexp_eatDecimalDigits(t)&&(r=t.lastIntValue),t.eat(125)))return-1!==r&&r=9?this.regexp_groupSpecifier(t):63===t.current()&&t.raise("Invalid group"),this.regexp_disjunction(t),t.eat(41))return t.numCapturingParens+=1,!0;t.raise("Unterminated group")}return!1},St.regexp_eatExtendedAtom=function(t){return t.eat(46)||this.regexp_eatReverseSolidusAtomEscape(t)||this.regexp_eatCharacterClass(t)||this.regexp_eatUncapturingGroup(t)||this.regexp_eatCapturingGroup(t)||this.regexp_eatInvalidBracedQuantifier(t)||this.regexp_eatExtendedPatternCharacter(t)},St.regexp_eatInvalidBracedQuantifier=function(t){return this.regexp_eatBracedQuantifier(t,!0)&&t.raise("Nothing to repeat"),!1},St.regexp_eatSyntaxCharacter=function(t){var e=t.current();return!!m(e)&&(t.lastIntValue=e,t.advance(),!0)},St.regexp_eatPatternCharacters=function(t){for(var e=t.pos,i=0;-1!==(i=t.current())&&!m(i);)t.advance();return t.pos!==e},St.regexp_eatExtendedPatternCharacter=function(t){var e=t.current();return!(-1===e||36===e||e>=40&&e<=43||46===e||63===e||91===e||94===e||124===e)&&(t.advance(),!0)},St.regexp_groupSpecifier=function(t){if(t.eat(63)){if(this.regexp_eatGroupName(t))return-1!==t.groupNames.indexOf(t.lastStringValue)&&t.raise("Duplicate capture group name"),void t.groupNames.push(t.lastStringValue);t.raise("Invalid group")}},St.regexp_eatGroupName=function(t){if(t.lastStringValue="",t.eat(60)){if(this.regexp_eatRegExpIdentifierName(t)&&t.eat(62))return!0;t.raise("Invalid capture group name")}return!1},St.regexp_eatRegExpIdentifierName=function(t){if(t.lastStringValue="",this.regexp_eatRegExpIdentifierStart(t)){for(t.lastStringValue+=f(t.lastIntValue);this.regexp_eatRegExpIdentifierPart(t);)t.lastStringValue+=f(t.lastIntValue);return!0}return!1},St.regexp_eatRegExpIdentifierStart=function(t){var e=t.pos,i=t.current();return t.advance(),92===i&&this.regexp_eatRegExpUnicodeEscapeSequence(t)&&(i=t.lastIntValue),x(i)?(t.lastIntValue=i,!0):(t.pos=e,!1)},St.regexp_eatRegExpIdentifierPart=function(t){var e=t.pos,i=t.current();return t.advance(),92===i&&this.regexp_eatRegExpUnicodeEscapeSequence(t)&&(i=t.lastIntValue),g(i)?(t.lastIntValue=i,!0):(t.pos=e,!1)},St.regexp_eatAtomEscape=function(t){return!!(this.regexp_eatBackReference(t)||this.regexp_eatCharacterClassEscape(t)||this.regexp_eatCharacterEscape(t)||t.switchN&&this.regexp_eatKGroupName(t))||(t.switchU&&(99===t.current()&&t.raise("Invalid unicode escape"),t.raise("Invalid escape")),!1)},St.regexp_eatBackReference=function(t){var e=t.pos;if(this.regexp_eatDecimalEscape(t)){var i=t.lastIntValue;if(t.switchU)return i>t.maxBackReference&&(t.maxBackReference=i),!0;if(i<=t.numCapturingParens)return!0;t.pos=e}return!1},St.regexp_eatKGroupName=function(t){if(t.eat(107)){if(this.regexp_eatGroupName(t))return t.backReferenceNames.push(t.lastStringValue),!0;t.raise("Invalid named reference")}return!1},St.regexp_eatCharacterEscape=function(t){return this.regexp_eatControlEscape(t)||this.regexp_eatCControlLetter(t)||this.regexp_eatZero(t)||this.regexp_eatHexEscapeSequence(t)||this.regexp_eatRegExpUnicodeEscapeSequence(t)||!t.switchU&&this.regexp_eatLegacyOctalEscapeSequence(t)||this.regexp_eatIdentityEscape(t)},St.regexp_eatCControlLetter=function(t){var e=t.pos;if(t.eat(99)){if(this.regexp_eatControlLetter(t))return!0;t.pos=e}return!1},St.regexp_eatZero=function(t){return 48===t.current()&&!C(t.lookahead())&&(t.lastIntValue=0,t.advance(),!0)},St.regexp_eatControlEscape=function(t){var e=t.current();return 116===e?(t.lastIntValue=9,t.advance(),!0):110===e?(t.lastIntValue=10,t.advance(),!0):118===e?(t.lastIntValue=11,t.advance(),!0):102===e?(t.lastIntValue=12,t.advance(),!0):114===e&&(t.lastIntValue=13,t.advance(),!0)},St.regexp_eatControlLetter=function(t){var e=t.current();return!!v(e)&&(t.lastIntValue=e%32,t.advance(),!0)},St.regexp_eatRegExpUnicodeEscapeSequence=function(t){var e=t.pos;if(t.eat(117)){if(this.regexp_eatFixedHexDigits(t,4)){var i=t.lastIntValue;if(t.switchU&&i>=55296&&i<=56319){var s=t.pos;if(t.eat(92)&&t.eat(117)&&this.regexp_eatFixedHexDigits(t,4)){var r=t.lastIntValue;if(r>=56320&&r<=57343)return t.lastIntValue=1024*(i-55296)+(r-56320)+65536,!0}t.pos=s,t.lastIntValue=i}return!0}if(t.switchU&&t.eat(123)&&this.regexp_eatHexDigits(t)&&t.eat(125)&&y(t.lastIntValue))return!0;t.switchU&&t.raise("Invalid unicode escape"),t.pos=e}return!1},St.regexp_eatIdentityEscape=function(t){if(t.switchU)return!!this.regexp_eatSyntaxCharacter(t)||!!t.eat(47)&&(t.lastIntValue=47,!0);var e=t.current();return!(99===e||t.switchN&&107===e)&&(t.lastIntValue=e,t.advance(),!0)},St.regexp_eatDecimalEscape=function(t){t.lastIntValue=0;var e=t.current();if(e>=49&&e<=57){do{t.lastIntValue=10*t.lastIntValue+(e-48),t.advance()}while((e=t.current())>=48&&e<=57);return!0}return!1},St.regexp_eatCharacterClassEscape=function(t){var e=t.current();if(_(e))return t.lastIntValue=-1,t.advance(),!0;if(t.switchU&&this.options.ecmaVersion>=9&&(80===e||112===e)){if(t.lastIntValue=-1,t.advance(),t.eat(123)&&this.regexp_eatUnicodePropertyValueExpression(t)&&t.eat(125))return!0;t.raise("Invalid property name")}return!1},St.regexp_eatUnicodePropertyValueExpression=function(t){var e=t.pos;if(this.regexp_eatUnicodePropertyName(t)&&t.eat(61)){var i=t.lastStringValue;if(this.regexp_eatUnicodePropertyValue(t)){var s=t.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(t,i,s),!0}}if(t.pos=e,this.regexp_eatLoneUnicodePropertyNameOrValue(t)){var r=t.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(t,r),!0}return!1},St.regexp_validateUnicodePropertyNameAndValue=function(t,e,i){Ct.hasOwnProperty(e)&&-1!==Ct[e].indexOf(i)||t.raise("Invalid property name")},St.regexp_validateUnicodePropertyNameOrValue=function(t,e){-1===Ct.$LONE.indexOf(e)&&t.raise("Invalid property name")},St.regexp_eatUnicodePropertyName=function(t){var e=0;for(t.lastStringValue="";b(e=t.current());)t.lastStringValue+=f(e),t.advance();return""!==t.lastStringValue},St.regexp_eatUnicodePropertyValue=function(t){var e=0;for(t.lastStringValue="";k(e=t.current());)t.lastStringValue+=f(e),t.advance();return""!==t.lastStringValue},St.regexp_eatLoneUnicodePropertyNameOrValue=function(t){return this.regexp_eatUnicodePropertyValue(t)},St.regexp_eatCharacterClass=function(t){if(t.eat(91)){if(t.eat(94),this.regexp_classRanges(t),t.eat(93))return!0;t.raise("Unterminated character class")}return!1},St.regexp_classRanges=function(t){for(var e=this;this.regexp_eatClassAtom(t);){var i=t.lastIntValue;if(t.eat(45)&&e.regexp_eatClassAtom(t)){var s=t.lastIntValue;!t.switchU||-1!==i&&-1!==s||t.raise("Invalid character class"),-1!==i&&-1!==s&&i>s&&t.raise("Range out of order in character class")}}},St.regexp_eatClassAtom=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatClassEscape(t))return!0;if(t.switchU){var i=t.current();(99===i||w(i))&&t.raise("Invalid class escape"),t.raise("Invalid escape")}t.pos=e}var s=t.current();return 93!==s&&(t.lastIntValue=s,t.advance(),!0)},St.regexp_eatClassEscape=function(t){var e=t.pos;if(t.eat(98))return t.lastIntValue=8,!0;if(t.switchU&&t.eat(45))return t.lastIntValue=45,!0;if(!t.switchU&&t.eat(99)){if(this.regexp_eatClassControlLetter(t))return!0;t.pos=e}return this.regexp_eatCharacterClassEscape(t)||this.regexp_eatCharacterEscape(t)},St.regexp_eatClassControlLetter=function(t){var e=t.current();return!(!C(e)&&95!==e)&&(t.lastIntValue=e%32,t.advance(),!0)},St.regexp_eatHexEscapeSequence=function(t){var e=t.pos;if(t.eat(120)){if(this.regexp_eatFixedHexDigits(t,2))return!0;t.switchU&&t.raise("Invalid escape"),t.pos=e}return!1},St.regexp_eatDecimalDigits=function(t){var e=t.pos,i=0;for(t.lastIntValue=0;C(i=t.current());)t.lastIntValue=10*t.lastIntValue+(i-48),t.advance();return t.pos!==e},St.regexp_eatHexDigits=function(t){var e=t.pos,i=0;for(t.lastIntValue=0;S(i=t.current());)t.lastIntValue=16*t.lastIntValue+E(i),t.advance();return t.pos!==e},St.regexp_eatLegacyOctalEscapeSequence=function(t){if(this.regexp_eatOctalDigit(t)){var e=t.lastIntValue;if(this.regexp_eatOctalDigit(t)){var i=t.lastIntValue;e<=3&&this.regexp_eatOctalDigit(t)?t.lastIntValue=64*e+8*i+t.lastIntValue:t.lastIntValue=8*e+i}else t.lastIntValue=e;return!0}return!1},St.regexp_eatOctalDigit=function(t){var e=t.current();return w(e)?(t.lastIntValue=e-48,t.advance(),!0):(t.lastIntValue=0,!1)},St.regexp_eatFixedHexDigits=function(t,e){var i=t.pos;t.lastIntValue=0;for(var s=0;s=this.input.length?this.finishToken(z.eof):t.override?t.override(this):void this.readToken(this.fullCharCodeAtPos())},At.readToken=function(t){return i(t,this.options.ecmaVersion>=6)||92===t?this.readWord():this.getTokenFromCode(t)},At.fullCharCodeAtPos=function(){var t=this.input.charCodeAt(this.pos);return t<=55295||t>=57344?t:(t<<10)+this.input.charCodeAt(this.pos+1)-56613888},At.skipBlockComment=function(){var t=this,e=this.options.onComment&&this.curPosition(),i=this.pos,s=this.input.indexOf("*/",this.pos+=2);if(-1===s&&this.raise(this.pos-2,"Unterminated comment"),this.pos=s+2,this.options.locations){K.lastIndex=i;for(var r;(r=K.exec(this.input))&&r.index8&&e<14||e>=5760&&X.test(String.fromCharCode(e))))break t;++t.pos}}},At.finishToken=function(t,e){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var i=this.type;this.type=t,this.value=e,this.updateContext(i)},At.readToken_dot=function(){var t=this.input.charCodeAt(this.pos+1);if(t>=48&&t<=57)return this.readNumber(!0);var e=this.input.charCodeAt(this.pos+2);return this.options.ecmaVersion>=6&&46===t&&46===e?(this.pos+=3,this.finishToken(z.ellipsis)):(++this.pos,this.finishToken(z.dot))},At.readToken_slash=function(){var t=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):61===t?this.finishOp(z.assign,2):this.finishOp(z.slash,1)},At.readToken_mult_modulo_exp=function(t){var e=this.input.charCodeAt(this.pos+1),i=1,s=42===t?z.star:z.modulo;return this.options.ecmaVersion>=7&&42===t&&42===e&&(++i,s=z.starstar,e=this.input.charCodeAt(this.pos+2)),61===e?this.finishOp(z.assign,i+1):this.finishOp(s,i)},At.readToken_pipe_amp=function(t){var e=this.input.charCodeAt(this.pos+1);return e===t?this.finishOp(124===t?z.logicalOR:z.logicalAND,2):61===e?this.finishOp(z.assign,2):this.finishOp(124===t?z.bitwiseOR:z.bitwiseAND,1)},At.readToken_caret=function(){return 61===this.input.charCodeAt(this.pos+1)?this.finishOp(z.assign,2):this.finishOp(z.bitwiseXOR,1)},At.readToken_plus_min=function(t){var e=this.input.charCodeAt(this.pos+1);return e===t?45!==e||this.inModule||62!==this.input.charCodeAt(this.pos+2)||0!==this.lastTokEnd&&!Q.test(this.input.slice(this.lastTokEnd,this.pos))?this.finishOp(z.incDec,2):(this.skipLineComment(3),this.skipSpace(),this.nextToken()):61===e?this.finishOp(z.assign,2):this.finishOp(z.plusMin,1)},At.readToken_lt_gt=function(t){var e=this.input.charCodeAt(this.pos+1),i=1;return e===t?(i=62===t&&62===this.input.charCodeAt(this.pos+2)?3:2,61===this.input.charCodeAt(this.pos+i)?this.finishOp(z.assign,i+1):this.finishOp(z.bitShift,i)):33!==e||60!==t||this.inModule||45!==this.input.charCodeAt(this.pos+2)||45!==this.input.charCodeAt(this.pos+3)?(61===e&&(i=2),this.finishOp(z.relational,i)):(this.skipLineComment(4),this.skipSpace(),this.nextToken())},At.readToken_eq_excl=function(t){var e=this.input.charCodeAt(this.pos+1);return 61===e?this.finishOp(z.equality,61===this.input.charCodeAt(this.pos+2)?3:2):61===t&&62===e&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(z.arrow)):this.finishOp(61===t?z.eq:z.prefix,1)},At.getTokenFromCode=function(t){switch(t){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(z.parenL);case 41:return++this.pos,this.finishToken(z.parenR);case 59:return++this.pos,this.finishToken(z.semi);case 44:return++this.pos,this.finishToken(z.comma);case 91:return++this.pos,this.finishToken(z.bracketL);case 93:return++this.pos,this.finishToken(z.bracketR);case 123:return++this.pos,this.finishToken(z.braceL);case 125:return++this.pos,this.finishToken(z.braceR);case 58:return++this.pos,this.finishToken(z.colon);case 63:return++this.pos,this.finishToken(z.question);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(z.backQuote);case 48:var e=this.input.charCodeAt(this.pos+1);if(120===e||88===e)return this.readRadixNumber(16);if(this.options.ecmaVersion>=6){if(111===e||79===e)return this.readRadixNumber(8);if(98===e||66===e)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(t);case 47:return this.readToken_slash();case 37:case 42:return this.readToken_mult_modulo_exp(t);case 124:case 38:return this.readToken_pipe_amp(t);case 94:return this.readToken_caret();case 43:case 45:return this.readToken_plus_min(t);case 60:case 62:return this.readToken_lt_gt(t);case 61:case 33:return this.readToken_eq_excl(t);case 126:return this.finishOp(z.prefix,1)}this.raise(this.pos,"Unexpected character '"+A(t)+"'")},At.finishOp=function(t,e){var i=this.input.slice(this.pos,this.pos+e);return this.pos+=e,this.finishToken(t,i)},At.readRegexp=function(){for(var t,e,i=this,s=this.pos;;){i.pos>=i.input.length&&i.raise(s,"Unterminated regular expression");var r=i.input.charAt(i.pos);if(Q.test(r)&&i.raise(s,"Unterminated regular expression"),t)t=!1;else{if("["===r)e=!0;else if("]"===r&&e)e=!1;else if("/"===r&&!e)break;t="\\"===r}++i.pos}var a=this.input.slice(s,this.pos);++this.pos;var n=this.pos,o=this.readWord1();this.containsEsc&&this.unexpected(n);var h=this.regexpState||(this.regexpState=new Et(this));h.reset(s,a,o),this.validateRegExpFlags(h),this.validateRegExpPattern(h);var p=null;try{p=new RegExp(a,o)}catch(t){}return this.finishToken(z.regexp,{pattern:a,flags:o,value:p})},At.readInt=function(t,e){for(var i=this,s=this.pos,r=0,a=0,n=null==e?1/0:e;a=97?o-97+10:o>=65?o-65+10:o>=48&&o<=57?o-48:1/0)>=t)break;++i.pos,r=r*t+h}return this.pos===s||null!=e&&this.pos-s!==e?null:r},At.readRadixNumber=function(t){this.pos+=2;var e=this.readInt(t);return null==e&&this.raise(this.start+2,"Expected number in radix "+t),i(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(z.num,e)},At.readNumber=function(t){var e=this.pos;t||null!==this.readInt(10)||this.raise(e,"Invalid number");var s=this.pos-e>=2&&48===this.input.charCodeAt(e);s&&this.strict&&this.raise(e,"Invalid number"),s&&/[89]/.test(this.input.slice(e,this.pos))&&(s=!1);var r=this.input.charCodeAt(this.pos);46!==r||s||(++this.pos,this.readInt(10),r=this.input.charCodeAt(this.pos)),69!==r&&101!==r||s||(r=this.input.charCodeAt(++this.pos),43!==r&&45!==r||++this.pos,null===this.readInt(10)&&this.raise(e,"Invalid number")),i(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var a=this.input.slice(e,this.pos),n=s?parseInt(a,8):parseFloat(a);return this.finishToken(z.num,n)},At.readCodePoint=function(){var t,e=this.input.charCodeAt(this.pos);if(123===e){this.options.ecmaVersion<6&&this.unexpected();var i=++this.pos;t=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,t>1114111&&this.invalidStringToken(i,"Code point out of bounds")}else t=this.readHexChar(4);return t},At.readString=function(t){for(var e=this,i="",s=++this.pos;;){e.pos>=e.input.length&&e.raise(e.start,"Unterminated string constant");var r=e.input.charCodeAt(e.pos);if(r===t)break;92===r?(i+=e.input.slice(s,e.pos),i+=e.readEscapedChar(!1),s=e.pos):(n(r,e.options.ecmaVersion>=10)&&e.raise(e.start,"Unterminated string constant"),++e.pos)}return i+=this.input.slice(s,this.pos++),this.finishToken(z.string,i)};var It={};At.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(t){if(t!==It)throw t;this.readInvalidTemplateToken()}this.inTemplateElement=!1},At.invalidStringToken=function(t,e){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw It;this.raise(t,e)},At.readTmplToken=function(){for(var t=this,e="",i=this.pos;;){t.pos>=t.input.length&&t.raise(t.start,"Unterminated template");var s=t.input.charCodeAt(t.pos);if(96===s||36===s&&123===t.input.charCodeAt(t.pos+1))return t.pos!==t.start||t.type!==z.template&&t.type!==z.invalidTemplate?(e+=t.input.slice(i,t.pos),t.finishToken(z.template,e)):36===s?(t.pos+=2,t.finishToken(z.dollarBraceL)):(++t.pos,t.finishToken(z.backQuote));if(92===s)e+=t.input.slice(i,t.pos),e+=t.readEscapedChar(!0),i=t.pos;else if(n(s)){switch(e+=t.input.slice(i,t.pos),++t.pos,s){case 13:10===t.input.charCodeAt(t.pos)&&++t.pos;case 10:e+="\n";break;default:e+=String.fromCharCode(s)}t.options.locations&&(++t.curLine,t.lineStart=t.pos),i=t.pos}else++t.pos}},At.readInvalidTemplateToken=function(){for(var t=this;this.pos=48&&e<=55){var i=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],s=parseInt(i,8);return s>255&&(i=i.slice(0,-1),s=parseInt(i,8)),this.pos+=i.length-1,e=this.input.charCodeAt(this.pos),"0"===i&&56!==e&&57!==e||!this.strict&&!t||this.invalidStringToken(this.pos-1-i.length,t?"Octal literal in template string":"Octal literal in strict mode"),String.fromCharCode(s)}return String.fromCharCode(e)}},At.readHexChar=function(t){var e=this.pos,i=this.readInt(16,t);return null===i&&this.invalidStringToken(e,"Bad character escape sequence"),i},At.readWord1=function(){var t=this;this.containsEsc=!1;for(var e="",r=!0,a=this.pos,n=this.options.ecmaVersion>=6;this.pos>1,i=-7,N=t?h-1:0,n=t?-1:1,s=a[o+N];for(N+=n,M=s&(1<<-i)-1,s>>=-i,i+=w;i>0;M=256*M+a[o+N],N+=n,i-=8);for(p=M&(1<<-i)-1,M>>=-i,i+=r;i>0;p=256*p+a[o+N],N+=n,i-=8);if(0===M)M=1-e;else{if(M===f)return p?NaN:1/0*(s?-1:1);p+=Math.pow(2,r),M-=e}return(s?-1:1)*p*Math.pow(2,M-r)},exports.write=function(a,o,t,r,h,M){var p,w,f,e=8*M-h-1,i=(1<>1,n=23===h?Math.pow(2,-24)-Math.pow(2,-77):0,s=r?0:M-1,u=r?1:-1,l=o<0||0===o&&1/o<0?1:0;for(o=Math.abs(o),isNaN(o)||o===1/0?(w=isNaN(o)?1:0,p=i):(p=Math.floor(Math.log(o)/Math.LN2),o*(f=Math.pow(2,-p))<1&&(p--,f*=2),o+=p+N>=1?n/f:n*Math.pow(2,1-N),o*f>=2&&(p++,f/=2),p+N>=i?(w=0,p=i):p+N>=1?(w=(o*f-1)*Math.pow(2,h),p+=N):(w=o*Math.pow(2,N-1)*Math.pow(2,h),p=0));h>=8;a[t+s]=255&w,s+=u,w/=256,h-=8);for(p=p<0;a[t+s]=255&p,s+=u,p/=256,e-=8);a[t+s-u]|=128*l}; + },{}],88:[function(require,module,exports){ "function"==typeof Object.create?module.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:module.exports=function(t,e){t.super_=e;var o=function(){};o.prototype=e.prototype,t.prototype=new o,t.prototype.constructor=t}; },{}],89:[function(require,module,exports){ @@ -382,9 +381,11 @@ var toString={}.toString;module.exports=Array.isArray||function(r){return"[objec },{}],91:[function(require,module,exports){ (function (process){ "use strict";function nextTick(e,n,c,r){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var s,t,o=arguments.length;switch(o){case 0:case 1:return process.nextTick(e);case 2:return process.nextTick(function(){e.call(null,n)});case 3:return process.nextTick(function(){e.call(null,n,c)});case 4:return process.nextTick(function(){e.call(null,n,c,r)});default:for(s=new Array(o-1),t=0;t1)for(var r=1;r0?("string"==typeof t||i.objectMode||Object.getPrototypeOf(t)===Buffer.prototype||(t=_uint8ArrayToBuffer(t)),n?i.endEmitted?e.emit("error",new Error("stream.unshift() after end event")):addChunk(e,i,t,!0):i.ended?e.emit("error",new Error("stream.push() after EOF")):(i.reading=!1,i.decoder&&!r?(t=i.decoder.write(t),i.objectMode||0!==t.length?addChunk(e,i,t,!1):maybeReadMore(e,i)):addChunk(e,i,t,!1))):n||(i.reading=!1)}return needMoreData(i)}function addChunk(e,t,r,n){t.flowing&&0===t.length&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,n?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&emitReadable(e)),maybeReadMore(e,t)}function chunkInvalid(e,t){var r;return _isUint8Array(t)||"string"==typeof t||void 0===t||e.objectMode||(r=new TypeError("Invalid non-string/buffer chunk")),r}function needMoreData(e){return!e.ended&&(e.needReadable||e.length=MAX_HWM?e=MAX_HWM:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function howMuchToRead(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=computeNewHighWaterMark(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function onEofChunk(e,t){if(!t.ended){if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,emitReadable(e)}}function emitReadable(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(debug("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?pna.nextTick(emitReadable_,e):emitReadable_(e))}function emitReadable_(e){debug("emit readable"),e.emit("readable"),flow(e)}function maybeReadMore(e,t){t.readingMore||(t.readingMore=!0,pna.nextTick(maybeReadMore_,e,t))}function maybeReadMore_(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):r=fromListPartial(e,t.buffer,t.decoder),r}function fromListPartial(e,t,r){var n;return ei.length?i.length:e;if(d===i.length?a+=i:a+=i.slice(0,e),0===(e-=d)){d===i.length?(++n,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=i.slice(d));break}++n}return t.length-=n,a}function copyFromBuffer(e,t){var r=Buffer.allocUnsafe(e),n=t.head,a=1;for(n.data.copy(r),e-=n.data.length;n=n.next;){var i=n.data,d=e>i.length?i.length:e;if(i.copy(r,r.length-e,0,d),0===(e-=d)){d===i.length?(++a,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=i.slice(d));break}++a}return t.length-=a,r}function endReadable(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,pna.nextTick(endReadableNT,t,e))}function endReadableNT(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function indexOf(e,t){for(var r=0,n=e.length;r=t.highWaterMark||t.ended))return debug("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?endReadable(this):emitReadable(this),null;if(0===(e=howMuchToRead(e,t))&&t.ended)return 0===t.length&&endReadable(this),null;var n=t.needReadable;debug("need readable",n),(0===t.length||t.length-e0?fromList(e,t):null,null===a?(t.needReadable=!0,e=0):t.length-=e,0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&endReadable(this)),null!==a&&this.emit("data",a),a},Readable.prototype._read=function(e){this.emit("error",new Error("_read() is not implemented"))},Readable.prototype.pipe=function(e,t){function r(e,t){debug("onunpipe"),e===s&&t&&!1===t.hasUnpiped&&(t.hasUnpiped=!0,a())}function n(){debug("onend"),e.end()}function a(){debug("cleanup"),e.removeListener("close",o),e.removeListener("finish",u),e.removeListener("drain",b),e.removeListener("error",d),e.removeListener("unpipe",r),s.removeListener("end",n),s.removeListener("end",l),s.removeListener("data",i),c=!0,!h.awaitDrain||e._writableState&&!e._writableState.needDrain||b()}function i(t){debug("ondata"),g=!1,!1!==e.write(t)||g||((1===h.pipesCount&&h.pipes===e||h.pipesCount>1&&-1!==indexOf(h.pipes,e))&&!c&&(debug("false write response, pause",s._readableState.awaitDrain),s._readableState.awaitDrain++,g=!0),s.pause())}function d(t){debug("onerror",t),l(),e.removeListener("error",d),0===EElistenerCount(e,"error")&&e.emit("error",t)}function o(){e.removeListener("finish",u),l()}function u(){debug("onfinish"),e.removeListener("close",o),l()}function l(){debug("unpipe"),s.unpipe(e)}var s=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=e;break;case 1:h.pipes=[h.pipes,e];break;default:h.pipes.push(e)}h.pipesCount+=1,debug("pipe count=%d opts=%j",h.pipesCount,t);var f=(!t||!1!==t.end)&&e!==process.stdout&&e!==process.stderr,p=f?n:l;h.endEmitted?pna.nextTick(p):s.once("end",p),e.on("unpipe",r);var b=pipeOnDrain(s);e.on("drain",b);var c=!1,g=!1;return s.on("data",i),prependListener(e,"error",d),e.once("close",o),e.once("finish",u),e.emit("pipe",s),h.flowing||(debug("pipe resume"),s.resume()),e},Readable.prototype.unpipe=function(e){var t=this._readableState,r={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,r),this);if(!e){var n=t.pipes,a=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i-1?setImmediate:pna.nextTick,Duplex;Writable.WritableState=WritableState;var util=require("core-util-is");util.inherits=require("inherits");var internalUtil={deprecate:require("util-deprecate")},Stream=require("./internal/streams/stream"),Buffer=require("safe-buffer").Buffer,OurUint8Array=global.Uint8Array||function(){},destroyImpl=require("./internal/streams/destroy");util.inherits(Writable,Stream),WritableState.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(WritableState.prototype,"buffer",{get:internalUtil.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}();var realHasInstance;"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(realHasInstance=Function.prototype[Symbol.hasInstance],Object.defineProperty(Writable,Symbol.hasInstance,{value:function(e){return!!realHasInstance.call(this,e)||this===Writable&&(e&&e._writableState instanceof WritableState)}})):realHasInstance=function(e){return e instanceof this},Writable.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},Writable.prototype.write=function(e,t,r){var i=this._writableState,n=!1,o=!i.objectMode&&_isUint8Array(e);return o&&!Buffer.isBuffer(e)&&(e=_uint8ArrayToBuffer(e)),"function"==typeof t&&(r=t,t=null),o?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof r&&(r=nop),i.ended?writeAfterEnd(this,r):(o||validChunk(this,i,e,r))&&(i.pendingcb++,n=writeOrBuffer(this,i,o,e,t,r)),n},Writable.prototype.cork=function(){this._writableState.corked++},Writable.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||clearBuffer(this,e))},Writable.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(Writable.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Writable.prototype._write=function(e,t,r){r(new Error("_write() is not implemented"))},Writable.prototype._writev=null,Writable.prototype.end=function(e,t,r){var i=this._writableState;"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!==e&&void 0!==e&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||i.finished||endWritable(this,i,r)},Object.defineProperty(Writable.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),Writable.prototype.destroy=destroyImpl.destroy,Writable.prototype._undestroy=destroyImpl.undestroy,Writable.prototype._destroy=function(e,t){this.end(),t(e)}; - }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate) },{"./_stream_duplex":94,"./internal/streams/destroy":100,"./internal/streams/stream":101,"_process":92,"core-util-is":51,"inherits":88,"process-nextick-args":91,"safe-buffer":107,"timers":112,"util-deprecate":113}],99:[function(require,module,exports){ "use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function copyBuffer(t,e,i){t.copy(e,i)}var Buffer=require("safe-buffer").Buffer,util=require("util");module.exports=function(){function t(){_classCallCheck(this,t),this.head=null,this.tail=null,this.length=0}return t.prototype.push=function(t){var e={data:t,next:null};this.length>0?this.tail.next=e:this.head=e,this.tail=e,++this.length},t.prototype.unshift=function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length},t.prototype.shift=function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}},t.prototype.clear=function(){this.head=this.tail=null,this.length=0},t.prototype.join=function(t){if(0===this.length)return"";for(var e=this.head,i=""+e.data;e=e.next;)i+=t+e.data;return i},t.prototype.concat=function(t){if(0===this.length)return Buffer.alloc(0);if(1===this.length)return this.head.data;for(var e=Buffer.allocUnsafe(t>>>0),i=this.head,n=0;i;)copyBuffer(i.data,e,n),n+=i.data.length,i=i.next;return e},t}(),util&&util.inspect&&util.inspect.custom&&(module.exports.prototype[util.inspect.custom]=function(){var t=util.inspect({length:this.length});return this.constructor.name+" "+t}); @@ -439,18 +440,17 @@ function Stream(){EE.call(this)}module.exports=Stream;var EE=require("events").E },{"./":110}],110:[function(require,module,exports){ "use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.Block=void 0;var _thaw=require("./thaw"),_thaw2=_interopRequireDefault(_thaw),_block=require("./block"),_block2=_interopRequireDefault(_block);exports.default=_thaw2.default,exports.Block=_block2.default,"undefined"!=typeof window&&(window.Thaw=_thaw2.default,window.Thaw.Block=_block2.default); + },{"./block":109,"./thaw":111}],111:[function(require,module,exports){ "use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function thaw(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Thaw(t,e)}Object.defineProperty(exports,"__esModule",{value:!0});var _extends=Object.assign||function(t){for(var e=1;e1&&void 0!==arguments[1]?arguments[1]:{};_classCallCheck(this,t);var s=_extends({},this.constructor.defaultSettings,n),a=s.each,r=s.done;this.items=e,this.i=0,this.options=n;var h=this.tick=function(){if(!(i.i<0||(i.timeout=setTimeout(h,0),thawing))){var t=e[i.i];if(i.i>=e.length)return null!==r&&(thawing=!0,r(t,i.i),thawing=!1),i.i=-1,void clearTimeout(i.timeout);null!==a?(thawing=!0,a(t,i.i),thawing=!1):void 0!==t&&t(),i.i++}};thaws.push(this),n.delay||h()}return _createClass(t,null,[{key:"stopAll",value:function(){for(var t=0;t=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},exports.setImmediate="function"==typeof setImmediate?setImmediate:function(e){var t=nextImmediateId++,i=!(arguments.length<2)&&slice.call(arguments,1);return immediateIds[t]=!0,nextTick(function(){immediateIds[t]&&(i?e.apply(null,i):e.call(null),exports.clearImmediate(t))}),t},exports.clearImmediate="function"==typeof clearImmediate?clearImmediate:function(e){delete immediateIds[e]}; - }).call(this,require("timers").setImmediate,require("timers").clearImmediate) },{"process/browser.js":92,"timers":112}],113:[function(require,module,exports){ (function (global){ function deprecate(r,e){function o(){if(!t){if(config("throwDeprecation"))throw new Error(e);config("traceDeprecation")?console.trace(e):console.warn(e),t=!0}return r.apply(this,arguments)}if(config("noDeprecation"))return r;var t=!1;return o}function config(r){try{if(!global.localStorage)return!1}catch(r){return!1}var e=global.localStorage[r];return null!=e&&"true"===String(e).toLowerCase()}module.exports=deprecate; - }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}]},{},[47])(47) }); diff --git a/dist/recurrent/rnn.js b/dist/recurrent/rnn.js index d347174d0..e662545b2 100644 --- a/dist/recurrent/rnn.js +++ b/dist/recurrent/rnn.js @@ -187,13 +187,11 @@ var RNN = function () { }, { key: 'mapModel', value: function mapModel() { - var _this = this; - var model = this.model; var hiddenLayers = model.hiddenLayers; var allMatrices = model.allMatrices; this.initialLayerInputs = this.hiddenLayers.map(function (size) { - return new _matrix2.default(_this.hiddenLayers[0], 1); + return new _matrix2.default(size, 1); }); this.createInputMatrix(); @@ -523,8 +521,6 @@ var RNN = function () { }, { key: 'fromJSON', value: function fromJSON(json) { - var _this2 = this; - var defaults = this.constructor.defaults; var options = json.options; this.model = null; @@ -570,7 +566,7 @@ var RNN = function () { equationConnections: [] }; this.initialLayerInputs = this.hiddenLayers.map(function (size) { - return new _matrix2.default(_this2.hiddenLayers[0], 1); + return new _matrix2.default(size, 1); }); this.bindEquation(); } diff --git a/dist/recurrent/rnn.js.map b/dist/recurrent/rnn.js.map index 613583067..adf4012a7 100644 --- a/dist/recurrent/rnn.js.map +++ b/dist/recurrent/rnn.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/recurrent/rnn.js"],"names":["RNN","options","defaults","constructor","Object","assign","stepCache","runs","totalCost","ratioClipped","model","inputLookup","outputLookup","json","fromJSON","input","hiddenLayers","output","equations","allMatrices","equationConnections","outputConnector","dataFormatter","inputSize","inputRange","outputSize","characters","length","mapModel","push","getModel","prevSize","d","hiddenSize","weight","RandomMatrix","transition","bias","Matrix","equation","inputMatrix","previousResult","hiddenLayer","relu","bind","add","multiply","lastHiddenSize","Equation","outputs","equationConnection","initialLayerInputs","getEquation","inputMatrixToRow","i","max","map","size","createInputMatrix","Error","createHiddenLayers","hiddenMatrix","property","hasOwnProperty","createOutputMatrix","learningRate","error","runInput","runBackpropagate","step","log2ppl","cost","bindEquation","inputIndex","inputMax","equationIndex","source","target","run","logProbabilities","probabilities","Math","log2","weights","log","deltas","slice","pow","stepSize","regc","clipval","numClipped","numTot","matrixIndex","matrix","rows","columns","cache","r","w","decayRate","sqrt","smoothEps","rawInput","isSampleI","temperature","maxPredictionLength","specialIndexes","isRunnable","formatDataIn","previousIndex","outputMatrix","j","probs","nextIndex","formatDataOut","value","data","trainDefaults","iterations","errorThresh","console","logPeriod","callback","callbackPeriod","Infinity","setupData","initialize","sum","err","trainPattern","isNaN","p","type","name","toJSON","layers","JSON","stringify","hiddenSizes","forEach","DataFormatter","states","jsonString","matrixOrigin","m","stateIndex","state","previousConnectionIndex","left","right","product","connection","indexOf","matrixToString","toInner","fnString","toString","split","shift","join","pop","replace","fileName","fnName","toLowerCase","statesRaw","usedFunctionNames","innerFunctionsSwitch","forwardFn","src","toFunctionString","zeros","softmax","randomF","sampleI","maxI","Function","Array","isArray","values","result","fromArrayInputOutput","addUnrecognized","indexTable","toIndexesInputOutput","toIndexes","toCharacters","keepNetworkIntact"],"mappings":";;;;;;;;AAAA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;AACA;;;;AACA;;;;;;;;IAEqBA,G;AACnB,iBAA0B;AAAA,QAAdC,OAAc,uEAAJ,EAAI;;AAAA;;AACxB,QAAMC,WAAW,KAAKC,WAAL,CAAiBD,QAAlC;;AAEAE,WAAOC,MAAP,CAAc,IAAd,EAAoBH,QAApB,EAA8BD,OAA9B;;AAEA,SAAKK,SAAL,GAAiB,EAAjB;AACA,SAAKC,IAAL,GAAY,CAAZ;AACA,SAAKC,SAAL,GAAiB,IAAjB;AACA,SAAKC,YAAL,GAAoB,IAApB;AACA,SAAKC,KAAL,GAAa,IAAb;;AAEA,SAAKC,WAAL,GAAmB,IAAnB;AACA,SAAKC,YAAL,GAAoB,IAApB;;AAEA,QAAIX,QAAQY,IAAZ,EAAkB;AAChB,WAAKC,QAAL,CAAcb,QAAQY,IAAtB;AACD;AACF;;;;iCAEY;AACX,WAAKH,KAAL,GAAa;AACXK,eAAO,IADI;AAEXC,sBAAc,EAFH;AAGXC,gBAAQ,IAHG;AAIXC,mBAAW,EAJA;AAKXC,qBAAa,EALF;AAMXC,6BAAqB,EANV;AAOXC,yBAAiB;AAPN,OAAb;;AAUA,UAAI,KAAKC,aAAL,KA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,aAAL,KAAuB,IAA3B,EAAiC;AAC/B,aAAO,KAAKA,aAAL,CACJqK,YADI,CACS1K,MADT,EAEJ+I,IAFI,CAEC,EAFD,CAAP;AAGD;AACD,WAAO/I,MAAP;AACD,GAnFY;AAoFbK,iBAAe;AApFF,CAAf;;AAuFAtB,IAAIsH,aAAJ,GAAoB;AAClBC,cAAY,KADM;AAElBC,eAAa,KAFK;AAGlBpC,OAAK,KAHa;AAIlBsC,aAAW,EAJO;AAKlBzD,gBAAc,GALI;AAMlB0D,YAAU,IANQ;AAOlBC,kBAAgB,EAPE;AAQlBgE,qBAAmB;AARD,CAApB","file":"rnn.js","sourcesContent":["import Matrix from './matrix';\nimport RandomMatrix from './matrix/random-matrix';\nimport Equation from './matrix/equation';\nimport sampleI from './matrix/sample-i';\nimport maxI from './matrix/max-i';\nimport softmax from './matrix/softmax';\nimport copy from './matrix/copy';\nimport { randomF } from '../utilities/random';\nimport zeros from '../utilities/zeros';\nimport DataFormatter from '../utilities/data-formatter';\n\nexport default class RNN {\n constructor(options = {}) {\n const defaults = this.constructor.defaults;\n\n Object.assign(this, defaults, options);\n\n this.stepCache = {};\n this.runs = 0;\n this.totalCost = null;\n this.ratioClipped = null;\n this.model = null;\n\n this.inputLookup = null;\n this.outputLookup = null;\n\n if (options.json) {\n this.fromJSON(options.json);\n }\n }\n\n initialize() {\n this.model = {\n input: null,\n hiddenLayers: [],\n output: null,\n equations: [],\n allMatrices: [],\n equationConnections: [],\n outputConnector: null,\n };\n\n if (this.dataFormatter !== null) {\n this.inputSize =\n this.inputRange =\n this.outputSize = this.dataFormatter.characters.length;\n }\n this.mapModel();\n }\n\n createHiddenLayers() {\n //0 is end, so add 1 to offset\n this.model.hiddenLayers.push(this.getModel(this.hiddenLayers[0], this.inputSize));\n let prevSize = this.hiddenLayers[0];\n\n for (let d = 1; d < this.hiddenLayers.length; d++) { // loop over depths\n let hiddenSize = this.hiddenLayers[d];\n this.model.hiddenLayers.push(this.getModel(hiddenSize, prevSize));\n prevSize = hiddenSize;\n }\n }\n\n /**\n *\n * @param {Number} hiddenSize\n * @param {Number} prevSize\n * @returns {object}\n */\n getModel(hiddenSize, prevSize) {\n return {\n //wxh\n weight: new RandomMatrix(hiddenSize, prevSize, 0.08),\n //whh\n transition: new RandomMatrix(hiddenSize, hiddenSize, 0.08),\n //bhh\n bias: new Matrix(hiddenSize, 1)\n };\n }\n\n /**\n *\n * @param {Equation} equation\n * @param {Matrix} inputMatrix\n * @param {Matrix} previousResult\n * @param {Object} hiddenLayer\n * @returns {Matrix}\n */\n getEquation(equation, inputMatrix, previousResult, hiddenLayer) {\n let relu = equation.relu.bind(equation);\n let add = equation.add.bind(equation);\n let multiply = equation.multiply.bind(equation);\n\n return relu(\n add(\n add(\n multiply(\n hiddenLayer.weight,\n inputMatrix\n ),\n multiply(\n hiddenLayer.transition,\n previousResult\n )\n ),\n hiddenLayer.bias\n )\n );\n }\n\n createInputMatrix() {\n //0 is end, so add 1 to offset\n this.model.input = new RandomMatrix(this.inputRange + 1, this.inputSize, 0.08);\n }\n\n createOutputMatrix() {\n let model = this.model;\n let outputSize = this.outputSize;\n let lastHiddenSize = this.hiddenLayers[this.hiddenLayers.length - 1];\n\n //0 is end, so add 1 to offset\n //whd\n model.outputConnector = new RandomMatrix(outputSize + 1, lastHiddenSize, 0.08);\n //0 is end, so add 1 to offset\n //bd\n model.output = new Matrix(outputSize + 1, 1);\n }\n\n bindEquation() {\n let model = this.model;\n let equation = new Equation();\n let outputs = [];\n let equationConnection = model.equationConnections.length > 0\n ? model.equationConnections[model.equationConnections.length - 1]\n : this.initialLayerInputs\n ;\n\n // 0 index\n let output = this.getEquation(equation, equation.inputMatrixToRow(model.input), equationConnection[0], model.hiddenLayers[0]);\n outputs.push(output);\n // 1+ indices\n for (let i = 1, max = this.hiddenLayers.length; i < max; i++) {\n output = this.getEquation(equation, output, equationConnection[i], model.hiddenLayers[i]);\n outputs.push(output);\n }\n\n model.equationConnections.push(outputs);\n equation.add(equation.multiply(model.outputConnector, output), model.output);\n model.equations.push(equation);\n }\n\n mapModel() {\n let model = this.model;\n let hiddenLayers = model.hiddenLayers;\n let allMatrices = model.allMatrices;\n this.initialLayerInputs = this.hiddenLayers.map((size) => new Matrix(this.hiddenLayers[0], 1));\n\n this.createInputMatrix();\n if (!model.input) throw new Error('net.model.input not set');\n allMatrices.push(model.input);\n\n this.createHiddenLayers();\n if (!model.hiddenLayers.length) throw new Error('net.hiddenLayers not set');\n for (let i = 0, max = hiddenLayers.length; i < max; i++) {\n let hiddenMatrix = hiddenLayers[i];\n for (let property in hiddenMatrix) {\n if (!hiddenMatrix.hasOwnProperty(property)) continue;\n allMatrices.push(hiddenMatrix[property]);\n }\n }\n\n this.createOutputMatrix();\n if (!model.outputConnector) throw new Error('net.model.outputConnector not set');\n if (!model.output) throw new Error('net.model.output not set');\n\n allMatrices.push(model.outputConnector);\n allMatrices.push(model.output);\n }\n\n /**\n *\n * @param {Number[]} input\n * @param {Number} [learningRate]\n * @returns {number}\n */\n trainPattern(input, learningRate = null) {\n const error = this.runInput(input);\n this.runBackpropagate(input);\n this.step(learningRate);\n return error;\n }\n\n /**\n *\n * @param {Number[]} input\n * @returns {number}\n */\n runInput(input) {\n this.runs++;\n let model = this.model;\n let max = input.length;\n let log2ppl = 0;\n let cost = 0;\n let equation;\n while (model.equations.length <= input.length + 1) {//last is zero\n this.bindEquation();\n }\n for (let inputIndex = -1, inputMax = input.length; inputIndex < inputMax; inputIndex++) {\n // start and end tokens are zeros\n let equationIndex = inputIndex + 1;\n equation = model.equations[equationIndex];\n\n let source = (inputIndex === -1 ? 0 : input[inputIndex] + 1); // first step: start with START token\n let target = (inputIndex === max - 1 ? 0 : input[inputIndex + 1] + 1); // last step: end with END token\n let output = equation.run(source);\n // set gradients into log probabilities\n let logProbabilities = output; // interpret output as log probabilities\n let probabilities = softmax(output); // compute the softmax probabilities\n\n log2ppl += -Math.log2(probabilities.weights[target]); // accumulate base 2 log prob and do smoothing\n cost += -Math.log(probabilities.weights[target]);\n // write gradients into log probabilities\n logProbabilities.deltas = probabilities.weights.slice(0);\n logProbabilities.deltas[target] -= 1;\n }\n\n this.totalCost = cost;\n return Math.pow(2, log2ppl / (max - 1)) / 100;\n }\n\n /**\n * @param {Number[]} input\n */\n runBackpropagate(input) {\n let i = input.length;\n let model = this.model;\n let equations = model.equations;\n while(i > 0) {\n equations[i].runBackpropagate(input[i - 1] + 1);\n i--;\n }\n equations[0].runBackpropagate(0);\n }\n\n /**\n *\n * @param {Number} [learningRate]\n */\n step(learningRate = null) {\n // perform parameter update\n //TODO: still not sure if this is ready for learningRate\n let stepSize = this.learningRate;\n let regc = this.regc;\n let clipval = this.clipval;\n let model = this.model;\n let numClipped = 0;\n let numTot = 0;\n let allMatrices = model.allMatrices;\n for (let matrixIndex = 0; matrixIndex < allMatrices.length; matrixIndex++) {\n const matrix = allMatrices[matrixIndex];\n const { weights, deltas } = matrix;\n if (!(matrixIndex in this.stepCache)) {\n this.stepCache[matrixIndex] = zeros(matrix.rows * matrix.columns);\n }\n const cache = this.stepCache[matrixIndex];\n for (let i = 0; i < weights.length; i++) {\n let r = deltas[i];\n let w = weights[i];\n // rmsprop adaptive learning rate\n cache[i] = cache[i] * this.decayRate + (1 - this.decayRate) * r * r;\n // gradient clip\n if (r > clipval) {\n r = clipval;\n numClipped++;\n }\n if (r < -clipval) {\n r = -clipval;\n numClipped++;\n }\n numTot++;\n // update (and regularize)\n weights[i] = w + -stepSize * r / Math.sqrt(cache[i] + this.smoothEps) - regc * w;\n }\n }\n this.ratioClipped = numClipped / numTot;\n }\n\n\n /**\n *\n * @returns boolean\n */\n get isRunnable(){\n if(this.model.equations.length === 0){\n console.error(`No equations bound, did you run train()?`);\n return false;\n }\n\n return true;\n }\n\n\n /**\n *\n * @param {Number[]|*} [rawInput]\n * @param {Boolean} [isSampleI]\n * @param {Number} temperature\n * @returns {*}\n */\n run(rawInput = [], isSampleI = false, temperature = 1) {\n const maxPredictionLength = this.maxPredictionLength + rawInput.length + (this.dataFormatter ? this.dataFormatter.specialIndexes.length : 0);\n if (!this.isRunnable) return null;\n const input = this.formatDataIn(rawInput);\n const model = this.model;\n const output = [];\n let i = 0;\n while (true) {\n let previousIndex = (i === 0\n ? 0\n : i < input.length\n ? input[i - 1] + 1\n : output[i - 1])\n ;\n while (model.equations.length <= i) {\n this.bindEquation();\n }\n let equation = model.equations[i];\n // sample predicted letter\n let outputMatrix = equation.run(previousIndex);\n let logProbabilities = new Matrix(model.output.rows, model.output.columns);\n copy(logProbabilities, outputMatrix);\n if (temperature !== 1 && isSampleI) {\n /**\n * scale log probabilities by temperature and re-normalize\n * if temperature is high, logProbabilities will go towards zero\n * and the softmax outputs will be more diffuse. if temperature is\n * very low, the softmax outputs will be more peaky\n */\n for (let j = 0, max = logProbabilities.weights.length; j < max; j++) {\n logProbabilities.weights[j] /= temperature;\n }\n }\n\n let probs = softmax(logProbabilities);\n let nextIndex = (isSampleI ? sampleI(probs) : maxI(probs));\n\n i++;\n if (nextIndex === 0) {\n // END token predicted, break out\n break;\n }\n if (i >= maxPredictionLength) {\n // something is wrong\n break;\n }\n\n output.push(nextIndex);\n }\n\n /**\n * we slice the input length here, not because output contains it, but it will be erroneous as we are sending the\n * network what is contained in input, so the data is essentially guessed by the network what could be next, till it\n * locks in on a value.\n * Kind of like this, values are from input:\n * 0 -> 4 (or in English: \"beginning on input\" -> \"I have no idea? I'll guess what they want next!\")\n * 2 -> 2 (oh how interesting, I've narrowed down values...)\n * 1 -> 9 (oh how interesting, I've now know what the values are...)\n * then the output looks like: [4, 2, 9,...]\n * so we then remove the erroneous data to get our true output\n */\n return this.formatDataOut(\n input,\n output\n .slice(input.length)\n .map(value => value - 1)\n );\n }\n\n /**\n *\n * @param {Object[]|String[]} data an array of objects: `{input: 'string', output: 'string'}` or an array of strings\n * @param {Object} [options]\n * @returns {{error: number, iterations: number}}\n */\n train(data, options = {}) {\n options = Object.assign({}, this.constructor.trainDefaults, options);\n let iterations = options.iterations;\n let errorThresh = options.errorThresh;\n let log = options.log === true ? console.log : options.log;\n let logPeriod = options.logPeriod;\n let learningRate = options.learningRate || this.learningRate;\n let callback = options.callback;\n let callbackPeriod = options.callbackPeriod;\n let error = Infinity;\n let i;\n\n if (this.hasOwnProperty('setupData')) {\n data = this.setupData(data);\n }\n\n if (!this.model) {\n this.initialize();\n }\n\n for (i = 0; i < iterations && error > errorThresh; i++) {\n let sum = 0;\n for (let j = 0; j < data.length; j++) {\n let err = this.trainPattern(data[j], learningRate);\n sum += err;\n }\n error = sum / data.length;\n\n if (isNaN(error)) throw new Error('network error rate is unexpected NaN, check network configurations and try again');\n if (log && (i % logPeriod === 0)) {\n log(`iterations: ${ i }, training error: ${ error }`);\n }\n if (callback && (i % callbackPeriod === 0)) {\n callback({ error: error, iterations: i });\n }\n }\n\n return {\n error: error,\n iterations: i\n };\n }\n\n /**\n *\n * @returns {Object}\n */\n toJSON() {\n const defaults = this.constructor.defaults;\n if (!this.model) {\n this.initialize();\n }\n let model = this.model;\n let options = {};\n for (let p in defaults) {\n if (defaults.hasOwnProperty(p)) {\n options[p] = this[p];\n }\n }\n\n return {\n type: this.constructor.name,\n options: options,\n input: model.input.toJSON(),\n hiddenLayers: model.hiddenLayers.map((hiddenLayer) => {\n let layers = {};\n for (let p in hiddenLayer) {\n layers[p] = hiddenLayer[p].toJSON();\n }\n return layers;\n }),\n outputConnector: this.model.outputConnector.toJSON(),\n output: this.model.output.toJSON()\n };\n }\n\n toJSONString() {\n return JSON.stringify(this.toJSON());\n }\n\n fromJSON(json) {\n const defaults = this.constructor.defaults;\n const options = json.options;\n this.model = null;\n this.hiddenLayers = null;\n const allMatrices = [];\n const input = Matrix.fromJSON(json.input);\n allMatrices.push(input);\n const hiddenLayers = [];\n\n // backward compatibility for hiddenSizes\n (json.hiddenLayers || json.hiddenSizes).forEach((hiddenLayer) => {\n let layers = {};\n for (let p in hiddenLayer) {\n layers[p] = Matrix.fromJSON(hiddenLayer[p]);\n allMatrices.push(layers[p]);\n }\n hiddenLayers.push(layers);\n });\n\n const outputConnector = Matrix.fromJSON(json.outputConnector);\n allMatrices.push(outputConnector);\n const output = Matrix.fromJSON(json.output);\n allMatrices.push(output);\n\n Object.assign(this, defaults, options);\n\n // backward compatibility\n if (options.hiddenSizes) {\n this.hiddenLayers = options.hiddenSizes;\n }\n\n if (options.hasOwnProperty('dataFormatter') && options.dataFormatter !== null) {\n this.dataFormatter = DataFormatter.fromJSON(options.dataFormatter);\n }\n\n this.model = {\n input,\n hiddenLayers,\n output,\n allMatrices,\n outputConnector,\n equations: [],\n equationConnections: [],\n };\n this.initialLayerInputs = this.hiddenLayers.map((size) => new Matrix(this.hiddenLayers[0], 1));\n this.bindEquation();\n }\n\n /**\n *\n * @returns {Function}\n */\n toFunction() {\n let model = this.model;\n let equations = this.model.equations;\n let equation = equations[1];\n let states = equation.states;\n let jsonString = JSON.stringify(this.toJSON());\n\n function matrixOrigin(m, stateIndex) {\n for (let i = 0, max = states.length; i < max; i++) {\n let state = states[i];\n\n if (i === stateIndex) {\n let j = previousConnectionIndex(m);\n switch (m) {\n case state.left:\n if (j > -1) {\n return `typeof prevStates[${ j }] === 'object' ? prevStates[${ j }].product : new Matrix(${ m.rows }, ${ m.columns })`;\n }\n case state.right:\n if (j > -1) {\n return `typeof prevStates[${ j }] === 'object' ? prevStates[${ j }].product : new Matrix(${ m.rows }, ${ m.columns })`;\n }\n case state.product:\n return `new Matrix(${ m.rows }, ${ m.columns })`;\n default:\n throw Error('unknown state');\n }\n }\n\n if (m === state.product) return `states[${ i }].product`;\n if (m === state.right) return `states[${ i }].right`;\n if (m === state.left) return `states[${ i }].left`;\n }\n }\n\n function previousConnectionIndex(m) {\n const connection = model.equationConnections[0];\n const states = equations[0].states;\n for (let i = 0, max = states.length; i < max; i++) {\n if (states[i].product === m) {\n return i;\n }\n }\n return connection.indexOf(m);\n }\n\n function matrixToString(m, stateIndex) {\n if (!m || !m.rows || !m.columns) return 'null';\n\n if (m === model.input) return `json.input`;\n if (m === model.outputConnector) return `json.outputConnector`;\n if (m === model.output) return `json.output`;\n\n for (let i = 0, max = model.hiddenLayers.length; i < max; i++) {\n let hiddenLayer = model.hiddenLayers[i];\n for (let p in hiddenLayer) {\n if (!hiddenLayer.hasOwnProperty(p)) continue;\n if (hiddenLayer[p] !== m) continue;\n return `json.hiddenLayers[${ i }].${ p }`;\n }\n }\n\n return matrixOrigin(m, stateIndex);\n }\n\n function toInner(fnString) {\n // crude, but should be sufficient for now\n // function() { body }\n fnString = fnString.toString().split('{');\n fnString.shift();\n // body }\n fnString = fnString.join('{');\n fnString = fnString.split('}');\n fnString.pop();\n // body\n return fnString.join('}').split('\\n').join('\\n ')\n .replace('product.deltas[i] = 0;', '')\n .replace('product.deltas[column] = 0;', '')\n .replace('left.deltas[leftIndex] = 0;', '')\n .replace('right.deltas[rightIndex] = 0;', '')\n .replace('product.deltas = left.deltas.slice(0);', '');\n }\n\n function fileName(fnName) {\n return `src/recurrent/matrix/${ fnName.replace(/[A-Z]/g, function(value) { return '-' + value.toLowerCase(); }) }.js`;\n }\n\n let statesRaw = [];\n let usedFunctionNames = {};\n let innerFunctionsSwitch = [];\n for (let i = 0, max = states.length; i < max; i++) {\n let state = states[i];\n statesRaw.push(`states[${ i }] = {\n name: '${ state.forwardFn.name }',\n left: ${ matrixToString(state.left, i) },\n right: ${ matrixToString(state.right, i) },\n product: ${ matrixToString(state.product, i) }\n }`);\n\n let fnName = state.forwardFn.name;\n if (!usedFunctionNames[fnName]) {\n usedFunctionNames[fnName] = true;\n innerFunctionsSwitch.push(\n ` case '${ fnName }': //compiled from ${ fileName(fnName) }\n ${ toInner(state.forwardFn.toString()) }\n break;`\n );\n }\n }\n\n const src = `\n if (typeof rawInput === 'undefined') rawInput = [];\n if (typeof isSampleI === 'undefined') isSampleI = false;\n if (typeof temperature === 'undefined') temperature = 1;\n ${ (this.dataFormatter !== null) ? this.dataFormatter.toFunctionString() : '' }\n \n var input = ${\n (this.dataFormatter !== null && typeof this.formatDataIn === 'function')\n ? 'formatDataIn(rawInput)' \n : 'rawInput'\n };\n var json = ${ jsonString };\n var maxPredictionLength = input.length + ${ this.maxPredictionLength };\n var _i = 0;\n var output = [];\n var states = [];\n var prevStates;\n while (true) {\n var previousIndex = (_i === 0\n ? 0\n : _i < input.length\n ? input[_i - 1] + 1\n : output[_i - 1])\n ;\n var rowPluckIndex = previousIndex;\n var state;\n prevStates = states;\n states = [];\n ${ statesRaw.join(';\\n ') };\n for (var stateIndex = 0, stateMax = ${ statesRaw.length }; stateIndex < stateMax; stateIndex++) {\n state = states[stateIndex];\n var product = state.product;\n var left = state.left;\n var right = state.right;\n \n switch (state.name) {\n${ innerFunctionsSwitch.join('\\n') }\n }\n }\n \n var logProbabilities = state.product;\n if (temperature !== 1 && isSampleI) {\n for (var q = 0, nq = logProbabilities.weights.length; q < nq; q++) {\n logProbabilities.weights[q] /= temperature;\n }\n }\n\n var probs = softmax(logProbabilities);\n var nextIndex = isSampleI ? sampleI(probs) : maxI(probs);\n \n _i++;\n if (nextIndex === 0) {\n break;\n }\n if (_i >= maxPredictionLength) {\n break;\n }\n\n output.push(nextIndex);\n }\n ${ (this.dataFormatter !== null && typeof this.formatDataOut === 'function') \n ? 'return formatDataOut(input, output.slice(input.length).map(function(value) { return value - 1; }))'\n : 'return output.slice(input.length).map(function(value) { return value - 1; })' };\n function Matrix(rows, columns) {\n this.rows = rows;\n this.columns = columns;\n this.weights = zeros(rows * columns);\n }\n ${ this.dataFormatter !== null && typeof this.formatDataIn === 'function'\n ? `function formatDataIn(input, output) { ${\n toInner(this.formatDataIn.toString())\n .replace(/this[.]dataFormatter[\\n\\s]+[.]/g, '')\n .replace(/this[.]dataFormatter[.]/g, '')\n .replace(/this[.]dataFormatter/g, 'true')\n } }`\n : '' }\n ${ this.dataFormatter !== null && typeof this.formatDataOut === 'function'\n ? `function formatDataOut(input, output) { ${\n toInner(this.formatDataOut.toString())\n .replace(/this[.]dataFormatter[\\n\\s]+[.]/g, '')\n .replace(/this[.]dataFormatter[.]/g, '')\n .replace(/this[.]dataFormatter/g, 'true')\n } }` \n : '' }\n ${ zeros.toString() }\n ${ softmax.toString().replace('_2.default', 'Matrix') }\n ${ randomF.toString() }\n ${ sampleI.toString() }\n ${ maxI.toString() }`;\n return new Function('rawInput', 'isSampleI', 'temperature', src);\n }\n}\n\nRNN.defaults = {\n inputSize: 20,\n inputRange: 20,\n hiddenLayers: [20,20],\n outputSize: 20,\n learningRate: 0.01,\n decayRate: 0.999,\n smoothEps: 1e-8,\n regc: 0.000001,\n clipval: 5,\n maxPredictionLength: 100,\n /**\n *\n * @param {*[]} data\n * @returns {Number[]}\n */\n setupData: function(data) {\n if (\n typeof data[0] !== 'string'\n && !Array.isArray(data[0])\n && (\n !data[0].hasOwnProperty('input')\n || !data[0].hasOwnProperty('output')\n )\n ) {\n return data;\n }\n let values = [];\n const result = [];\n if (typeof data[0] === 'string' || Array.isArray(data[0])) {\n if (this.dataFormatter === null) {\n for (let i = 0; i < data.length; i++) {\n values.push(data[i]);\n }\n this.dataFormatter = new DataFormatter(values);\n }\n for (let i = 0, max = data.length; i < max; i++) {\n result.push(this.formatDataIn(data[i]));\n }\n } else {\n if (this.dataFormatter === null) {\n for (let i = 0; i < data.length; i++) {\n values.push(data[i].input);\n values.push(data[i].output);\n }\n this.dataFormatter = DataFormatter.fromArrayInputOutput(values);\n this.dataFormatter.addUnrecognized();\n }\n for (let i = 0, max = data.length; i < max; i++) {\n result.push(this.formatDataIn(data[i].input, data[i].output));\n }\n }\n return result;\n },\n /**\n *\n * @param {*[]} input\n * @param {*[]} output\n * @returns {Number[]}\n */\n formatDataIn: function(input, output = null) {\n if (this.dataFormatter !== null) {\n if (this.dataFormatter.indexTable.hasOwnProperty('stop-input')) {\n return this.dataFormatter.toIndexesInputOutput(input, output);\n } else {\n return this.dataFormatter.toIndexes(input);\n }\n }\n return input;\n },\n /**\n *\n * @param {Number[]} input\n * @param {Number[]} output\n * @returns {*}\n */\n formatDataOut: function(input, output) {\n if (this.dataFormatter !== null) {\n return this.dataFormatter\n .toCharacters(output)\n .join('');\n }\n return output;\n },\n dataFormatter: null\n};\n\nRNN.trainDefaults = {\n iterations: 20000,\n errorThresh: 0.005,\n log: false,\n logPeriod: 10,\n learningRate: 0.3,\n callback: null,\n callbackPeriod: 10,\n keepNetworkIntact: false\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/recurrent/rnn.js"],"names":["RNN","options","defaults","constructor","Object","assign","stepCache","runs","totalCost","ratioClipped","model","inputLookup","outputLookup","json","fromJSON","input","hiddenLayers","output","equations","allMatrices","equationConnections","outputConnector","dataFormatter","inputSize","inputRange","outputSize","characters","length","mapModel","push","getModel","prevSize","d","hiddenSize","weight","RandomMatrix","transition","bias","Matrix","equation","inputMatrix","previousResult","hiddenLayer","relu","bind","add","multiply","lastHiddenSize","Equation","outputs","equationConnection","initialLayerInputs","getEquation","inputMatrixToRow","i","max","map","size","createInputMatrix","Error","createHiddenLayers","hiddenMatrix","property","hasOwnProperty","createOutputMatrix","learningRate","error","runInput","runBackpropagate","step","log2ppl","cost","bindEquation","inputIndex","inputMax","equationIndex","source","target","run","logProbabilities","probabilities","Math","log2","weights","log","deltas","slice","pow","stepSize","regc","clipval","numClipped","numTot","matrixIndex","matrix","rows","columns","cache","r","w","decayRate","sqrt","smoothEps","rawInput","isSampleI","temperature","maxPredictionLength","specialIndexes","isRunnable","formatDataIn","previousIndex","outputMatrix","j","probs","nextIndex","formatDataOut","value","data","trainDefaults","iterations","errorThresh","console","logPeriod","callback","callbackPeriod","Infinity","setupData","initialize","sum","err","trainPattern","isNaN","p","type","name","toJSON","layers","JSON","stringify","hiddenSizes","forEach","DataFormatter","states","jsonString","matrixOrigin","m","stateIndex","state","previousConnectionIndex","left","right","product","connection","indexOf","matrixToString","toInner","fnString","toString","split","shift","join","pop","replace","fileName","fnName","toLowerCase","statesRaw","usedFunctionNames","innerFunctionsSwitch","forwardFn","src","toFunctionString","zeros","softmax","randomF","sampleI","maxI","Function","Array","isArray","values","result","fromArrayInputOutput","addUnrecognized","indexTable","toIndexesInputOutput","toIndexes","toCharacters","keepNetworkIntact"],"mappings":";;;;;;;;AAAA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;AACA;;;;AACA;;;;;;;;IAEqBA,G;AACnB,iBAA0B;AAAA,QAAdC,OAAc,uEAAJ,EAAI;;AAAA;;AACxB,QAAMC,WAAW,KAAKC,WAAL,CAAiBD,QAAlC;;AAEAE,WAAOC,MAAP,CAAc,IAAd,EAAoBH,QAApB,EAA8BD,OAA9B;;AAEA,SAAKK,SAAL,GAAiB,EAAjB;AACA,SAAKC,IAAL,GAAY,CAAZ;AACA,SAAKC,SAAL,GAAiB,IAAjB;AACA,SAAKC,YAAL,GAAoB,IAApB;AACA,SAAKC,KAAL,GAAa,IAAb;;AAEA,SAAKC,WAAL,GAAmB,IAAnB;AACA,SAAKC,YAAL,GAAoB,IAApB;;AAEA,QAAIX,QAAQY,IAAZ,EAAkB;AAChB,WAAKC,QAAL,CAAcb,QAAQY,IAAtB;AACD;AACF;;;;iCAEY;AACX,WAAKH,KAAL,GAAa;AACXK,eAAO,IADI;AAEXC,sBAAc,EAFH;AAGXC,gBAAQ,IAHG;AAIXC,mBAAW,EAJA;AAKXC,qBAAa,EALF;AAMXC,6BAAqB,EANV;AAOXC,yBAAiB;AAPN,OAAb;;AAUA,UAAI,KAAKC,aAAL,KAAuB,IAA3B,EAAiC;AAC/B,aAAKC,SAAL,GACA,KAAKC,UAAL,GACA,KAAKC,UAAL,GAAkB,KAAKH,aAAL,CAAmBI,UAAnB,CAA8BC,MAFhD;AAGD;AACD,WAAKC,QAAL;AACD;;;yCAEoB;AACnB;AACA,WAAKlB,KAAL,CAAWM,YAAX,CAAwBa,IAAxB,CAA6B,KAAKC,QAAL,CAAc,KAAKd,YAAL,CAAkB,CAAlB,CAAd,EAAoC,KAAKO,SAAzC,CAA7B;AACA,UAAIQ,WAAW,KAAKf,YAAL,C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from './matrix';\nimport RandomMatrix from './matrix/random-matrix';\nimport Equation from './matrix/equation';\nimport sampleI from './matrix/sample-i';\nimport maxI from './matrix/max-i';\nimport softmax from './matrix/softmax';\nimport copy from './matrix/copy';\nimport { randomF } from '../utilities/random';\nimport zeros from '../utilities/zeros';\nimport DataFormatter from '../utilities/data-formatter';\n\nexport default class RNN {\n constructor(options = {}) {\n const defaults = this.constructor.defaults;\n\n Object.assign(this, defaults, options);\n\n this.stepCache = {};\n this.runs = 0;\n this.totalCost = null;\n this.ratioClipped = null;\n this.model = null;\n\n this.inputLookup = null;\n this.outputLookup = null;\n\n if (options.json) {\n this.fromJSON(options.json);\n }\n }\n\n initialize() {\n this.model = {\n input: null,\n hiddenLayers: [],\n output: null,\n equations: [],\n allMatrices: [],\n equationConnections: [],\n outputConnector: null,\n };\n\n if (this.dataFormatter !== null) {\n this.inputSize =\n this.inputRange =\n this.outputSize = this.dataFormatter.characters.length;\n }\n this.mapModel();\n }\n\n createHiddenLayers() {\n //0 is end, so add 1 to offset\n this.model.hiddenLayers.push(this.getModel(this.hiddenLayers[0], this.inputSize));\n let prevSize = this.hiddenLayers[0];\n\n for (let d = 1; d < this.hiddenLayers.length; d++) { // loop over depths\n let hiddenSize = this.hiddenLayers[d];\n this.model.hiddenLayers.push(this.getModel(hiddenSize, prevSize));\n prevSize = hiddenSize;\n }\n }\n\n /**\n *\n * @param {Number} hiddenSize\n * @param {Number} prevSize\n * @returns {object}\n */\n getModel(hiddenSize, prevSize) {\n return {\n //wxh\n weight: new RandomMatrix(hiddenSize, prevSize, 0.08),\n //whh\n transition: new RandomMatrix(hiddenSize, hiddenSize, 0.08),\n //bhh\n bias: new Matrix(hiddenSize, 1)\n };\n }\n\n /**\n *\n * @param {Equation} equation\n * @param {Matrix} inputMatrix\n * @param {Matrix} previousResult\n * @param {Object} hiddenLayer\n * @returns {Matrix}\n */\n getEquation(equation, inputMatrix, previousResult, hiddenLayer) {\n let relu = equation.relu.bind(equation);\n let add = equation.add.bind(equation);\n let multiply = equation.multiply.bind(equation);\n\n return relu(\n add(\n add(\n multiply(\n hiddenLayer.weight,\n inputMatrix\n ),\n multiply(\n hiddenLayer.transition,\n previousResult\n )\n ),\n hiddenLayer.bias\n )\n );\n }\n\n createInputMatrix() {\n //0 is end, so add 1 to offset\n this.model.input = new RandomMatrix(this.inputRange + 1, this.inputSize, 0.08);\n }\n\n createOutputMatrix() {\n let model = this.model;\n let outputSize = this.outputSize;\n let lastHiddenSize = this.hiddenLayers[this.hiddenLayers.length - 1];\n\n //0 is end, so add 1 to offset\n //whd\n model.outputConnector = new RandomMatrix(outputSize + 1, lastHiddenSize, 0.08);\n //0 is end, so add 1 to offset\n //bd\n model.output = new Matrix(outputSize + 1, 1);\n }\n\n bindEquation() {\n let model = this.model;\n let equation = new Equation();\n let outputs = [];\n let equationConnection = model.equationConnections.length > 0\n ? model.equationConnections[model.equationConnections.length - 1]\n : this.initialLayerInputs\n ;\n\n // 0 index\n let output = this.getEquation(equation, equation.inputMatrixToRow(model.input), equationConnection[0], model.hiddenLayers[0]);\n outputs.push(output);\n // 1+ indices\n for (let i = 1, max = this.hiddenLayers.length; i < max; i++) {\n output = this.getEquation(equation, output, equationConnection[i], model.hiddenLayers[i]);\n outputs.push(output);\n }\n\n model.equationConnections.push(outputs);\n equation.add(equation.multiply(model.outputConnector, output), model.output);\n model.equations.push(equation);\n }\n\n mapModel() {\n let model = this.model;\n let hiddenLayers = model.hiddenLayers;\n let allMatrices = model.allMatrices;\n this.initialLayerInputs = this.hiddenLayers.map((size) => new Matrix(size, 1));\n\n this.createInputMatrix();\n if (!model.input) throw new Error('net.model.input not set');\n allMatrices.push(model.input);\n\n this.createHiddenLayers();\n if (!model.hiddenLayers.length) throw new Error('net.hiddenLayers not set');\n for (let i = 0, max = hiddenLayers.length; i < max; i++) {\n let hiddenMatrix = hiddenLayers[i];\n for (let property in hiddenMatrix) {\n if (!hiddenMatrix.hasOwnProperty(property)) continue;\n allMatrices.push(hiddenMatrix[property]);\n }\n }\n\n this.createOutputMatrix();\n if (!model.outputConnector) throw new Error('net.model.outputConnector not set');\n if (!model.output) throw new Error('net.model.output not set');\n\n allMatrices.push(model.outputConnector);\n allMatrices.push(model.output);\n }\n\n /**\n *\n * @param {Number[]} input\n * @param {Number} [learningRate]\n * @returns {number}\n */\n trainPattern(input, learningRate = null) {\n const error = this.runInput(input);\n this.runBackpropagate(input);\n this.step(learningRate);\n return error;\n }\n\n /**\n *\n * @param {Number[]} input\n * @returns {number}\n */\n runInput(input) {\n this.runs++;\n let model = this.model;\n let max = input.length;\n let log2ppl = 0;\n let cost = 0;\n let equation;\n while (model.equations.length <= input.length + 1) {//last is zero\n this.bindEquation();\n }\n for (let inputIndex = -1, inputMax = input.length; inputIndex < inputMax; inputIndex++) {\n // start and end tokens are zeros\n let equationIndex = inputIndex + 1;\n equation = model.equations[equationIndex];\n\n let source = (inputIndex === -1 ? 0 : input[inputIndex] + 1); // first step: start with START token\n let target = (inputIndex === max - 1 ? 0 : input[inputIndex + 1] + 1); // last step: end with END token\n let output = equation.run(source);\n // set gradients into log probabilities\n let logProbabilities = output; // interpret output as log probabilities\n let probabilities = softmax(output); // compute the softmax probabilities\n\n log2ppl += -Math.log2(probabilities.weights[target]); // accumulate base 2 log prob and do smoothing\n cost += -Math.log(probabilities.weights[target]);\n // write gradients into log probabilities\n logProbabilities.deltas = probabilities.weights.slice(0);\n logProbabilities.deltas[target] -= 1;\n }\n\n this.totalCost = cost;\n return Math.pow(2, log2ppl / (max - 1)) / 100;\n }\n\n /**\n * @param {Number[]} input\n */\n runBackpropagate(input) {\n let i = input.length;\n let model = this.model;\n let equations = model.equations;\n while(i > 0) {\n equations[i].runBackpropagate(input[i - 1] + 1);\n i--;\n }\n equations[0].runBackpropagate(0);\n }\n\n /**\n *\n * @param {Number} [learningRate]\n */\n step(learningRate = null) {\n // perform parameter update\n //TODO: still not sure if this is ready for learningRate\n let stepSize = this.learningRate;\n let regc = this.regc;\n let clipval = this.clipval;\n let model = this.model;\n let numClipped = 0;\n let numTot = 0;\n let allMatrices = model.allMatrices;\n for (let matrixIndex = 0; matrixIndex < allMatrices.length; matrixIndex++) {\n const matrix = allMatrices[matrixIndex];\n const { weights, deltas } = matrix;\n if (!(matrixIndex in this.stepCache)) {\n this.stepCache[matrixIndex] = zeros(matrix.rows * matrix.columns);\n }\n const cache = this.stepCache[matrixIndex];\n for (let i = 0; i < weights.length; i++) {\n let r = deltas[i];\n let w = weights[i];\n // rmsprop adaptive learning rate\n cache[i] = cache[i] * this.decayRate + (1 - this.decayRate) * r * r;\n // gradient clip\n if (r > clipval) {\n r = clipval;\n numClipped++;\n }\n if (r < -clipval) {\n r = -clipval;\n numClipped++;\n }\n numTot++;\n // update (and regularize)\n weights[i] = w + -stepSize * r / Math.sqrt(cache[i] + this.smoothEps) - regc * w;\n }\n }\n this.ratioClipped = numClipped / numTot;\n }\n\n\n /**\n *\n * @returns boolean\n */\n get isRunnable(){\n if(this.model.equations.length === 0){\n console.error(`No equations bound, did you run train()?`);\n return false;\n }\n\n return true;\n }\n\n\n /**\n *\n * @param {Number[]|*} [rawInput]\n * @param {Boolean} [isSampleI]\n * @param {Number} temperature\n * @returns {*}\n */\n run(rawInput = [], isSampleI = false, temperature = 1) {\n const maxPredictionLength = this.maxPredictionLength + rawInput.length + (this.dataFormatter ? this.dataFormatter.specialIndexes.length : 0);\n if (!this.isRunnable) return null;\n const input = this.formatDataIn(rawInput);\n const model = this.model;\n const output = [];\n let i = 0;\n while (true) {\n let previousIndex = (i === 0\n ? 0\n : i < input.length\n ? input[i - 1] + 1\n : output[i - 1])\n ;\n while (model.equations.length <= i) {\n this.bindEquation();\n }\n let equation = model.equations[i];\n // sample predicted letter\n let outputMatrix = equation.run(previousIndex);\n let logProbabilities = new Matrix(model.output.rows, model.output.columns);\n copy(logProbabilities, outputMatrix);\n if (temperature !== 1 && isSampleI) {\n /**\n * scale log probabilities by temperature and re-normalize\n * if temperature is high, logProbabilities will go towards zero\n * and the softmax outputs will be more diffuse. if temperature is\n * very low, the softmax outputs will be more peaky\n */\n for (let j = 0, max = logProbabilities.weights.length; j < max; j++) {\n logProbabilities.weights[j] /= temperature;\n }\n }\n\n let probs = softmax(logProbabilities);\n let nextIndex = (isSampleI ? sampleI(probs) : maxI(probs));\n\n i++;\n if (nextIndex === 0) {\n // END token predicted, break out\n break;\n }\n if (i >= maxPredictionLength) {\n // something is wrong\n break;\n }\n\n output.push(nextIndex);\n }\n\n /**\n * we slice the input length here, not because output contains it, but it will be erroneous as we are sending the\n * network what is contained in input, so the data is essentially guessed by the network what could be next, till it\n * locks in on a value.\n * Kind of like this, values are from input:\n * 0 -> 4 (or in English: \"beginning on input\" -> \"I have no idea? I'll guess what they want next!\")\n * 2 -> 2 (oh how interesting, I've narrowed down values...)\n * 1 -> 9 (oh how interesting, I've now know what the values are...)\n * then the output looks like: [4, 2, 9,...]\n * so we then remove the erroneous data to get our true output\n */\n return this.formatDataOut(\n input,\n output\n .slice(input.length)\n .map(value => value - 1)\n );\n }\n\n /**\n *\n * @param {Object[]|String[]} data an array of objects: `{input: 'string', output: 'string'}` or an array of strings\n * @param {Object} [options]\n * @returns {{error: number, iterations: number}}\n */\n train(data, options = {}) {\n options = Object.assign({}, this.constructor.trainDefaults, options);\n let iterations = options.iterations;\n let errorThresh = options.errorThresh;\n let log = options.log === true ? console.log : options.log;\n let logPeriod = options.logPeriod;\n let learningRate = options.learningRate || this.learningRate;\n let callback = options.callback;\n let callbackPeriod = options.callbackPeriod;\n let error = Infinity;\n let i;\n\n if (this.hasOwnProperty('setupData')) {\n data = this.setupData(data);\n }\n\n if (!this.model) {\n this.initialize();\n }\n\n for (i = 0; i < iterations && error > errorThresh; i++) {\n let sum = 0;\n for (let j = 0; j < data.length; j++) {\n let err = this.trainPattern(data[j], learningRate);\n sum += err;\n }\n error = sum / data.length;\n\n if (isNaN(error)) throw new Error('network error rate is unexpected NaN, check network configurations and try again');\n if (log && (i % logPeriod === 0)) {\n log(`iterations: ${ i }, training error: ${ error }`);\n }\n if (callback && (i % callbackPeriod === 0)) {\n callback({ error: error, iterations: i });\n }\n }\n\n return {\n error: error,\n iterations: i\n };\n }\n\n /**\n *\n * @returns {Object}\n */\n toJSON() {\n const defaults = this.constructor.defaults;\n if (!this.model) {\n this.initialize();\n }\n let model = this.model;\n let options = {};\n for (let p in defaults) {\n if (defaults.hasOwnProperty(p)) {\n options[p] = this[p];\n }\n }\n\n return {\n type: this.constructor.name,\n options: options,\n input: model.input.toJSON(),\n hiddenLayers: model.hiddenLayers.map((hiddenLayer) => {\n let layers = {};\n for (let p in hiddenLayer) {\n layers[p] = hiddenLayer[p].toJSON();\n }\n return layers;\n }),\n outputConnector: this.model.outputConnector.toJSON(),\n output: this.model.output.toJSON()\n };\n }\n\n toJSONString() {\n return JSON.stringify(this.toJSON());\n }\n\n fromJSON(json) {\n const defaults = this.constructor.defaults;\n const options = json.options;\n this.model = null;\n this.hiddenLayers = null;\n const allMatrices = [];\n const input = Matrix.fromJSON(json.input);\n allMatrices.push(input);\n const hiddenLayers = [];\n\n // backward compatibility for hiddenSizes\n (json.hiddenLayers || json.hiddenSizes).forEach((hiddenLayer) => {\n let layers = {};\n for (let p in hiddenLayer) {\n layers[p] = Matrix.fromJSON(hiddenLayer[p]);\n allMatrices.push(layers[p]);\n }\n hiddenLayers.push(layers);\n });\n\n const outputConnector = Matrix.fromJSON(json.outputConnector);\n allMatrices.push(outputConnector);\n const output = Matrix.fromJSON(json.output);\n allMatrices.push(output);\n\n Object.assign(this, defaults, options);\n\n // backward compatibility\n if (options.hiddenSizes) {\n this.hiddenLayers = options.hiddenSizes;\n }\n\n if (options.hasOwnProperty('dataFormatter') && options.dataFormatter !== null) {\n this.dataFormatter = DataFormatter.fromJSON(options.dataFormatter);\n }\n\n this.model = {\n input,\n hiddenLayers,\n output,\n allMatrices,\n outputConnector,\n equations: [],\n equationConnections: [],\n };\n this.initialLayerInputs = this.hiddenLayers.map((size) => new Matrix(size, 1));\n this.bindEquation();\n }\n\n /**\n *\n * @returns {Function}\n */\n toFunction() {\n let model = this.model;\n let equations = this.model.equations;\n let equation = equations[1];\n let states = equation.states;\n let jsonString = JSON.stringify(this.toJSON());\n\n function matrixOrigin(m, stateIndex) {\n for (let i = 0, max = states.length; i < max; i++) {\n let state = states[i];\n\n if (i === stateIndex) {\n let j = previousConnectionIndex(m);\n switch (m) {\n case state.left:\n if (j > -1) {\n return `typeof prevStates[${ j }] === 'object' ? prevStates[${ j }].product : new Matrix(${ m.rows }, ${ m.columns })`;\n }\n case state.right:\n if (j > -1) {\n return `typeof prevStates[${ j }] === 'object' ? prevStates[${ j }].product : new Matrix(${ m.rows }, ${ m.columns })`;\n }\n case state.product:\n return `new Matrix(${ m.rows }, ${ m.columns })`;\n default:\n throw Error('unknown state');\n }\n }\n\n if (m === state.product) return `states[${ i }].product`;\n if (m === state.right) return `states[${ i }].right`;\n if (m === state.left) return `states[${ i }].left`;\n }\n }\n\n function previousConnectionIndex(m) {\n const connection = model.equationConnections[0];\n const states = equations[0].states;\n for (let i = 0, max = states.length; i < max; i++) {\n if (states[i].product === m) {\n return i;\n }\n }\n return connection.indexOf(m);\n }\n\n function matrixToString(m, stateIndex) {\n if (!m || !m.rows || !m.columns) return 'null';\n\n if (m === model.input) return `json.input`;\n if (m === model.outputConnector) return `json.outputConnector`;\n if (m === model.output) return `json.output`;\n\n for (let i = 0, max = model.hiddenLayers.length; i < max; i++) {\n let hiddenLayer = model.hiddenLayers[i];\n for (let p in hiddenLayer) {\n if (!hiddenLayer.hasOwnProperty(p)) continue;\n if (hiddenLayer[p] !== m) continue;\n return `json.hiddenLayers[${ i }].${ p }`;\n }\n }\n\n return matrixOrigin(m, stateIndex);\n }\n\n function toInner(fnString) {\n // crude, but should be sufficient for now\n // function() { body }\n fnString = fnString.toString().split('{');\n fnString.shift();\n // body }\n fnString = fnString.join('{');\n fnString = fnString.split('}');\n fnString.pop();\n // body\n return fnString.join('}').split('\\n').join('\\n ')\n .replace('product.deltas[i] = 0;', '')\n .replace('product.deltas[column] = 0;', '')\n .replace('left.deltas[leftIndex] = 0;', '')\n .replace('right.deltas[rightIndex] = 0;', '')\n .replace('product.deltas = left.deltas.slice(0);', '');\n }\n\n function fileName(fnName) {\n return `src/recurrent/matrix/${ fnName.replace(/[A-Z]/g, function(value) { return '-' + value.toLowerCase(); }) }.js`;\n }\n\n let statesRaw = [];\n let usedFunctionNames = {};\n let innerFunctionsSwitch = [];\n for (let i = 0, max = states.length; i < max; i++) {\n let state = states[i];\n statesRaw.push(`states[${ i }] = {\n name: '${ state.forwardFn.name }',\n left: ${ matrixToString(state.left, i) },\n right: ${ matrixToString(state.right, i) },\n product: ${ matrixToString(state.product, i) }\n }`);\n\n let fnName = state.forwardFn.name;\n if (!usedFunctionNames[fnName]) {\n usedFunctionNames[fnName] = true;\n innerFunctionsSwitch.push(\n ` case '${ fnName }': //compiled from ${ fileName(fnName) }\n ${ toInner(state.forwardFn.toString()) }\n break;`\n );\n }\n }\n\n const src = `\n if (typeof rawInput === 'undefined') rawInput = [];\n if (typeof isSampleI === 'undefined') isSampleI = false;\n if (typeof temperature === 'undefined') temperature = 1;\n ${ (this.dataFormatter !== null) ? this.dataFormatter.toFunctionString() : '' }\n \n var input = ${\n (this.dataFormatter !== null && typeof this.formatDataIn === 'function')\n ? 'formatDataIn(rawInput)' \n : 'rawInput'\n };\n var json = ${ jsonString };\n var maxPredictionLength = input.length + ${ this.maxPredictionLength };\n var _i = 0;\n var output = [];\n var states = [];\n var prevStates;\n while (true) {\n var previousIndex = (_i === 0\n ? 0\n : _i < input.length\n ? input[_i - 1] + 1\n : output[_i - 1])\n ;\n var rowPluckIndex = previousIndex;\n var state;\n prevStates = states;\n states = [];\n ${ statesRaw.join(';\\n ') };\n for (var stateIndex = 0, stateMax = ${ statesRaw.length }; stateIndex < stateMax; stateIndex++) {\n state = states[stateIndex];\n var product = state.product;\n var left = state.left;\n var right = state.right;\n \n switch (state.name) {\n${ innerFunctionsSwitch.join('\\n') }\n }\n }\n \n var logProbabilities = state.product;\n if (temperature !== 1 && isSampleI) {\n for (var q = 0, nq = logProbabilities.weights.length; q < nq; q++) {\n logProbabilities.weights[q] /= temperature;\n }\n }\n\n var probs = softmax(logProbabilities);\n var nextIndex = isSampleI ? sampleI(probs) : maxI(probs);\n \n _i++;\n if (nextIndex === 0) {\n break;\n }\n if (_i >= maxPredictionLength) {\n break;\n }\n\n output.push(nextIndex);\n }\n ${ (this.dataFormatter !== null && typeof this.formatDataOut === 'function') \n ? 'return formatDataOut(input, output.slice(input.length).map(function(value) { return value - 1; }))'\n : 'return output.slice(input.length).map(function(value) { return value - 1; })' };\n function Matrix(rows, columns) {\n this.rows = rows;\n this.columns = columns;\n this.weights = zeros(rows * columns);\n }\n ${ this.dataFormatter !== null && typeof this.formatDataIn === 'function'\n ? `function formatDataIn(input, output) { ${\n toInner(this.formatDataIn.toString())\n .replace(/this[.]dataFormatter[\\n\\s]+[.]/g, '')\n .replace(/this[.]dataFormatter[.]/g, '')\n .replace(/this[.]dataFormatter/g, 'true')\n } }`\n : '' }\n ${ this.dataFormatter !== null && typeof this.formatDataOut === 'function'\n ? `function formatDataOut(input, output) { ${\n toInner(this.formatDataOut.toString())\n .replace(/this[.]dataFormatter[\\n\\s]+[.]/g, '')\n .replace(/this[.]dataFormatter[.]/g, '')\n .replace(/this[.]dataFormatter/g, 'true')\n } }` \n : '' }\n ${ zeros.toString() }\n ${ softmax.toString().replace('_2.default', 'Matrix') }\n ${ randomF.toString() }\n ${ sampleI.toString() }\n ${ maxI.toString() }`;\n return new Function('rawInput', 'isSampleI', 'temperature', src);\n }\n}\n\nRNN.defaults = {\n inputSize: 20,\n inputRange: 20,\n hiddenLayers: [20,20],\n outputSize: 20,\n learningRate: 0.01,\n decayRate: 0.999,\n smoothEps: 1e-8,\n regc: 0.000001,\n clipval: 5,\n maxPredictionLength: 100,\n /**\n *\n * @param {*[]} data\n * @returns {Number[]}\n */\n setupData: function(data) {\n if (\n typeof data[0] !== 'string'\n && !Array.isArray(data[0])\n && (\n !data[0].hasOwnProperty('input')\n || !data[0].hasOwnProperty('output')\n )\n ) {\n return data;\n }\n let values = [];\n const result = [];\n if (typeof data[0] === 'string' || Array.isArray(data[0])) {\n if (this.dataFormatter === null) {\n for (let i = 0; i < data.length; i++) {\n values.push(data[i]);\n }\n this.dataFormatter = new DataFormatter(values);\n }\n for (let i = 0, max = data.length; i < max; i++) {\n result.push(this.formatDataIn(data[i]));\n }\n } else {\n if (this.dataFormatter === null) {\n for (let i = 0; i < data.length; i++) {\n values.push(data[i].input);\n values.push(data[i].output);\n }\n this.dataFormatter = DataFormatter.fromArrayInputOutput(values);\n this.dataFormatter.addUnrecognized();\n }\n for (let i = 0, max = data.length; i < max; i++) {\n result.push(this.formatDataIn(data[i].input, data[i].output));\n }\n }\n return result;\n },\n /**\n *\n * @param {*[]} input\n * @param {*[]} output\n * @returns {Number[]}\n */\n formatDataIn: function(input, output = null) {\n if (this.dataFormatter !== null) {\n if (this.dataFormatter.indexTable.hasOwnProperty('stop-input')) {\n return this.dataFormatter.toIndexesInputOutput(input, output);\n } else {\n return this.dataFormatter.toIndexes(input);\n }\n }\n return input;\n },\n /**\n *\n * @param {Number[]} input\n * @param {Number[]} output\n * @returns {*}\n */\n formatDataOut: function(input, output) {\n if (this.dataFormatter !== null) {\n return this.dataFormatter\n .toCharacters(output)\n .join('');\n }\n return output;\n },\n dataFormatter: null\n};\n\nRNN.trainDefaults = {\n iterations: 20000,\n errorThresh: 0.005,\n log: false,\n logPeriod: 10,\n learningRate: 0.3,\n callback: null,\n callbackPeriod: 10,\n keepNetworkIntact: false\n};\n"]} \ No newline at end of file diff --git a/package.json b/package.json index b0ad722cf..ba9f05754 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "brain.js", "description": "Neural network library", - "version": "1.4.3", + "version": "1.4.4", "author": "Heather Arthur ", "repository": { "type": "git", diff --git a/src/recurrent/rnn.js b/src/recurrent/rnn.js index e25a8be4a..b00e849d5 100644 --- a/src/recurrent/rnn.js +++ b/src/recurrent/rnn.js @@ -152,7 +152,7 @@ export default class RNN { let model = this.model; let hiddenLayers = model.hiddenLayers; let allMatrices = model.allMatrices; - this.initialLayerInputs = this.hiddenLayers.map((size) => new Matrix(this.hiddenLayers[0], 1)); + this.initialLayerInputs = this.hiddenLayers.map((size) => new Matrix(size, 1)); this.createInputMatrix(); if (!model.input) throw new Error('net.model.input not set'); @@ -506,7 +506,7 @@ export default class RNN { equations: [], equationConnections: [], }; - this.initialLayerInputs = this.hiddenLayers.map((size) => new Matrix(this.hiddenLayers[0], 1)); + this.initialLayerInputs = this.hiddenLayers.map((size) => new Matrix(size, 1)); this.bindEquation(); } diff --git a/test/recurrent/rnn.js b/test/recurrent/rnn.js index d663ac1bc..f17be3268 100644 --- a/test/recurrent/rnn.js +++ b/test/recurrent/rnn.js @@ -20,6 +20,28 @@ describe('rnn', () => { net.initialize(); assert.notEqual(net.model, null); }); + it('can setup different size hiddenLayers', () => { + const inputSize = 2; + const hiddenLayers = [5,4,3]; + const networkOptions = { + learningRate: 0.001, + decayRate: 0.75, + inputSize: inputSize, + hiddenLayers, + outputSize: inputSize + }; + + const net = new RNN(networkOptions); + net.initialize(); + net.bindEquation(); + assert.equal(net.model.hiddenLayers.length, 3); + assert.equal(net.model.hiddenLayers[0].weight.columns, inputSize); + assert.equal(net.model.hiddenLayers[0].weight.rows, hiddenLayers[0]); + assert.equal(net.model.hiddenLayers[1].weight.columns, hiddenLayers[0]); + assert.equal(net.model.hiddenLayers[1].weight.rows, hiddenLayers[1]); + assert.equal(net.model.hiddenLayers[2].weight.columns, hiddenLayers[1]); + assert.equal(net.model.hiddenLayers[2].weight.rows, hiddenLayers[2]); + }); }); describe('basic operations', () => { it('starts with zeros in input.deltas', () => { @@ -354,9 +376,12 @@ describe('rnn', () => { describe('.fromJSON', () => { it('can import model from json', () => { - let dataFormatter = new DataFormatter('abcdef'.split('')); - let jsonString = JSON.stringify(new RNN({ - inputSize: 6, //<- length + const inputSize = 6; + const hiddenLayers = [10, 20]; + const dataFormatter = new DataFormatter('abcdef'.split('')); + const jsonString = JSON.stringify(new RNN({ + inputSize, //<- length + hiddenLayers, inputRange: dataFormatter.characters.length, outputSize: dataFormatter.characters.length //<- length }).toJSON(), null, 2); @@ -368,6 +393,12 @@ describe('rnn', () => { assert.equal(clone.inputSize, 6); assert.equal(clone.inputRange, dataFormatter.characters.length); assert.equal(clone.outputSize, dataFormatter.characters.length); + + assert.equal(clone.model.hiddenLayers.length, 2); + assert.equal(clone.model.hiddenLayers[0].weight.columns, inputSize); + assert.equal(clone.model.hiddenLayers[0].weight.rows, hiddenLayers[0]); + assert.equal(clone.model.hiddenLayers[1].weight.columns, hiddenLayers[0]); + assert.equal(clone.model.hiddenLayers[1].weight.rows, hiddenLayers[1]); }); it('can import model from json using .fromJSON()', () => {