exports.runVector = function (gameState) { var m = this.model(this.assumptions, this.outTransitions); var c = []; var vector = math.range(0, this.assumptions.maxScore)._data.map((r) => { return this.runProbability(gameState, r, m, c).reduce((p, c) => p + c); }); // var sum = vector.reduce((a, b) => a + b); // return vector.map(i => i / sum); return vector; }
exports.getClusters = function getClusters(A) { const clusters = []; const n = A.size()[0]; for (let i = 0; i < n; i++) { if (A.subset(math.index(i, i)) > 0.0001) { const rowMatrix = A.subset(math.index(i, math.range(0, n))); let cluster = this.rowMatrixToArray(rowMatrix).map( (x, index) => {return (x > 0.001) ? index : -1;}); cluster = cluster.filter((x) => x >= 0); clusters.push(cluster); } } return clusters; };
_exports.getClusters = function getClusters(A) { var clusters = []; var n = A.size()[0]; for (var i = 0; i < n; i++) { if (A.subset(math.index(i, i)) > 0.0001) { var rowMatrix = A.subset(math.index(i, math.range(0, n))); var cluster = this.rowMatrixToArray(rowMatrix).map(function (x, index) { return x > 0.001 ? index : -1; }); cluster = cluster.filter(function (x) { return x >= 0; }); clusters.push(cluster); } } return clusters; };
, fft = require('ndfft') , math = require('mathjs') , WIN = 1024 , frameRate = 44100 , times, signal, re, im, amplitudes var writeValuesToFile = function(filename, x, y) { var dataStr = '' y.forEach(function(val, i) { dataStr += '' + x[i] + ' ' + val + '\n' }) fs.writeFileSync(filename, dataStr) } // Generate a signal cos(2PI 500 t) + cos(2PI 1500 t) times = math.emultiply(math.range(0, WIN - 1).toMatrix(), 1 / frameRate) signal = math.add( math.multiply(math.cos(math.emultiply(times, 2 * math.PI * 500)), 0.6), math.multiply(math.cos(math.emultiply(times, 2 * math.PI * 1500)), 0.35) ) re = signal.toArray() im = math.squeeze(math.zeros([1, WIN])).toArray() // Compute the frequency spectrum with a FFT fft(1, re, im) amplitudes = math.epow(math.add(math.epow(re, 2), math.epow(im, 2)), 0.5) amplitudes = math.emultiply(amplitudes, 2/WIN) // Recompute the original signal by performing the inverse transform fft(-1, re, im)