forked from BrainJS/brain.js
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix BrainJS#110 and ensure test tests for value
- Loading branch information
1 parent
6b4e68a
commit 88b0dda
Showing
10 changed files
with
29 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* license: MIT (http://opensource.org/licenses/MIT) | ||
* author: Heather Arthur <[email protected]> | ||
* homepage: https://github.com/brainjs/brain.js#readme | ||
* version: 1.0.0-rc.7 | ||
* version: 1.0.0-rc.8 | ||
* | ||
* acorn: | ||
* license: MIT (http://opensource.org/licenses/MIT) | ||
|
@@ -3702,7 +3702,7 @@ var RNN = function () { | |
} | ||
} | ||
|
||
var src = '\n if (typeof input === \'undefined\') input = [];\n if (typeof maxPredictionLength === \'undefined\') maxPredictionLength = 100;\n if (typeof isSampleI === \'undefined\') isSampleI = false;\n if (typeof temperature === \'undefined\') temperature = 1;\n ' + (this.dataFormatter !== null ? this.dataFormatter.toFunctionString() : '') + '\n \n ' + (this.dataFormatter !== null && typeof this.formatDataIn === 'function' ? 'input = formatDataIn(input);' : '') + '\n \n var json = ' + jsonString + ';\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 prevStates = states;\n states = [];\n ' + statesRaw.join(';\n ') + ';\n for (var stateIndex = 0, stateMax = ' + statesRaw.length + '; stateIndex < stateMax; stateIndex++) {\n var 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' ? 'return formatDataOut(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 ' + (this.dataFormatter !== null && typeof this.formatDataIn === 'function' ? 'function formatDataIn(input, output) { ' + toInner(this.formatDataIn.toString()).replace(/this[.]dataFormatter[.]/g, '').replace(/this[.]dataFormatter/g, 'true') + ' }' : '') + '\n ' + (this.dataFormatter !== null && typeof this.formatDataOut === 'function' ? 'function formatDataOut(output) { ' + toInner(this.formatDataIn.toString()).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(); | ||
var src = '\n if (typeof rawInput === \'undefined\') rawInput = [];\n if (typeof maxPredictionLength === \'undefined\') maxPredictionLength = 100;\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 = ' + (this.dataFormatter !== null && typeof this.formatDataIn === 'function' ? 'formatDataIn(rawInput)' : 'rawInput') + ';\n var json = ' + jsonString + ';\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 prevStates = states;\n states = [];\n ' + statesRaw.join(';\n ') + ';\n for (var stateIndex = 0, stateMax = ' + statesRaw.length + '; stateIndex < stateMax; stateIndex++) {\n var 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' ? '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 ' + (this.dataFormatter !== null && typeof this.formatDataIn === 'function' ? 'function formatDataIn(input, output) { ' + toInner(this.formatDataIn.toString()).replace(/this[.]dataFormatter[\n\s]+[.]/g, '').replace(/this[.]dataFormatter[.]/g, '').replace(/this[.]dataFormatter/g, 'true') + ' }' : '') + '\n ' + (this.dataFormatter !== null && typeof this.formatDataOut === 'function' ? 'function formatDataOut(input, output) { ' + toInner(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', 'maxPredictionLength', 'isSampleI', 'temperature', src); | ||
} | ||
}]); | ||
|
@@ -4179,7 +4179,7 @@ var DataFormatter = function () { | |
}, { | ||
key: 'toFunctionString', | ||
value: function toFunctionString() { | ||
return '\nvar characterTable = ' + JSON.stringify(this.characterTable) + ';\nvar indexTable = ' + JSON.stringify(this.indexTable) + ';\nvar characters = ' + JSON.stringify(this.characters) + ';\n' + this.toIndexes.toString().replace(/(let|var) indexTable = this[.]indexTable;\n/, '').replace(/this[.]/g, '') + '\n' + this.toIndexesInputOutput.toString().replace(/this[.]/g, '') + '\n' + this.toCharacters.toString().replace(/this[.]/, '') + '\n'; | ||
return '\nvar characterTable = ' + JSON.stringify(this.characterTable) + ';\nvar indexTable = ' + JSON.stringify(this.indexTable) + ';\nvar characters = ' + JSON.stringify(this.characters) + ';\n' + this.toIndexes.toString().replace(/(let|var) indexTable = this[.]indexTable;\n/, '').replace(/this[.]/g, '') + '\n' + this.toIndexesInputOutput.toString().replace(/this[.]/g, '') + '\n' + this.toCharacters.toString().replace(/(let|var) characterTable = this[.]characterTable;\n/g, '').replace(/this[.]/, '') + '\n'; | ||
} | ||
}], [{ | ||
key: 'fromAllPrintable', | ||
|
Oops, something went wrong.