id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
22,600
repetere/modelscript
build/modelscript.umd.js
calculateDistanceMatrix
function calculateDistanceMatrix(data, distance) { var distanceMatrix = new Array(data.length); for (var i = 0; i < data.length; ++i) { for (var j = i; j < data.length; ++j) { if (!distanceMatrix[i]) { distanceMatrix[i] = new Array(data.length); } if (!distanceMatrix[j]) { distanceMatrix[j] = new Array(data.length); } const dist = distance(data[i], data[j]); distanceMatrix[i][j] = dist; distanceMatrix[j][i] = dist; } } return distanceMatrix; }
javascript
function calculateDistanceMatrix(data, distance) { var distanceMatrix = new Array(data.length); for (var i = 0; i < data.length; ++i) { for (var j = i; j < data.length; ++j) { if (!distanceMatrix[i]) { distanceMatrix[i] = new Array(data.length); } if (!distanceMatrix[j]) { distanceMatrix[j] = new Array(data.length); } const dist = distance(data[i], data[j]); distanceMatrix[i][j] = dist; distanceMatrix[j][i] = dist; } } return distanceMatrix; }
[ "function", "calculateDistanceMatrix", "(", "data", ",", "distance", ")", "{", "var", "distanceMatrix", "=", "new", "Array", "(", "data", ".", "length", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "data", ".", "length", ";", "++", "i", ")", "{", "for", "(", "var", "j", "=", "i", ";", "j", "<", "data", ".", "length", ";", "++", "j", ")", "{", "if", "(", "!", "distanceMatrix", "[", "i", "]", ")", "{", "distanceMatrix", "[", "i", "]", "=", "new", "Array", "(", "data", ".", "length", ")", ";", "}", "if", "(", "!", "distanceMatrix", "[", "j", "]", ")", "{", "distanceMatrix", "[", "j", "]", "=", "new", "Array", "(", "data", ".", "length", ")", ";", "}", "const", "dist", "=", "distance", "(", "data", "[", "i", "]", ",", "data", "[", "j", "]", ")", ";", "distanceMatrix", "[", "i", "]", "[", "j", "]", "=", "dist", ";", "distanceMatrix", "[", "j", "]", "[", "i", "]", "=", "dist", ";", "}", "}", "return", "distanceMatrix", ";", "}" ]
Calculates the distance matrix for a given array of points @ignore @param {Array<Array<Number>>} data - the [x,y,z,...] points to cluster @param {Function} distance - Distance function to use between the points @return {Array<Array<Number>>} - matrix with the distance values
[ "Calculates", "the", "distance", "matrix", "for", "a", "given", "array", "of", "points" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L43802-L43818
22,601
repetere/modelscript
build/modelscript.umd.js
updateClusterID
function updateClusterID(data, centers, clusterID, distance) { for (var i = 0; i < data.length; i++) { clusterID[i] = src$5(centers, data[i], {distanceFunction: distance}); } return clusterID; }
javascript
function updateClusterID(data, centers, clusterID, distance) { for (var i = 0; i < data.length; i++) { clusterID[i] = src$5(centers, data[i], {distanceFunction: distance}); } return clusterID; }
[ "function", "updateClusterID", "(", "data", ",", "centers", ",", "clusterID", ",", "distance", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "data", ".", "length", ";", "i", "++", ")", "{", "clusterID", "[", "i", "]", "=", "src$5", "(", "centers", ",", "data", "[", "i", "]", ",", "{", "distanceFunction", ":", "distance", "}", ")", ";", "}", "return", "clusterID", ";", "}" ]
Updates the cluster identifier based in the new data @ignore @param {Array<Array<Number>>} data - the [x,y,z,...] points to cluster @param {Array<Array<Number>>} centers - the K centers in format [x,y,z,...] @param {Array <Number>} clusterID - the cluster identifier for each data dot @param {Function} distance - Distance function to use between the points @returns {Array} the cluster identifier for each data dot
[ "Updates", "the", "cluster", "identifier", "based", "in", "the", "new", "data" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L43829-L43834
22,602
repetere/modelscript
build/modelscript.umd.js
updateCenters
function updateCenters(data, clusterID, K) { const nDim = data[0].length; // creates empty centers with 0 size var centers = new Array(K); var centersLen = new Array(K); for (var i = 0; i < K; i++) { centers[i] = new Array(nDim); centersLen[i] = 0; for (var j = 0; j < nDim; j++) { centers[i][j] = 0; } } // add the value for all dimensions of the point for (var l = 0; l < data.length; l++) { centersLen[clusterID[l]]++; for (var dim = 0; dim < nDim; dim++) { centers[clusterID[l]][dim] += data[l][dim]; } } // divides by length for (var id = 0; id < K; id++) { for (var d = 0; d < nDim; d++) { centers[id][d] /= centersLen[id]; } } return centers; }
javascript
function updateCenters(data, clusterID, K) { const nDim = data[0].length; // creates empty centers with 0 size var centers = new Array(K); var centersLen = new Array(K); for (var i = 0; i < K; i++) { centers[i] = new Array(nDim); centersLen[i] = 0; for (var j = 0; j < nDim; j++) { centers[i][j] = 0; } } // add the value for all dimensions of the point for (var l = 0; l < data.length; l++) { centersLen[clusterID[l]]++; for (var dim = 0; dim < nDim; dim++) { centers[clusterID[l]][dim] += data[l][dim]; } } // divides by length for (var id = 0; id < K; id++) { for (var d = 0; d < nDim; d++) { centers[id][d] /= centersLen[id]; } } return centers; }
[ "function", "updateCenters", "(", "data", ",", "clusterID", ",", "K", ")", "{", "const", "nDim", "=", "data", "[", "0", "]", ".", "length", ";", "// creates empty centers with 0 size", "var", "centers", "=", "new", "Array", "(", "K", ")", ";", "var", "centersLen", "=", "new", "Array", "(", "K", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "K", ";", "i", "++", ")", "{", "centers", "[", "i", "]", "=", "new", "Array", "(", "nDim", ")", ";", "centersLen", "[", "i", "]", "=", "0", ";", "for", "(", "var", "j", "=", "0", ";", "j", "<", "nDim", ";", "j", "++", ")", "{", "centers", "[", "i", "]", "[", "j", "]", "=", "0", ";", "}", "}", "// add the value for all dimensions of the point", "for", "(", "var", "l", "=", "0", ";", "l", "<", "data", ".", "length", ";", "l", "++", ")", "{", "centersLen", "[", "clusterID", "[", "l", "]", "]", "++", ";", "for", "(", "var", "dim", "=", "0", ";", "dim", "<", "nDim", ";", "dim", "++", ")", "{", "centers", "[", "clusterID", "[", "l", "]", "]", "[", "dim", "]", "+=", "data", "[", "l", "]", "[", "dim", "]", ";", "}", "}", "// divides by length", "for", "(", "var", "id", "=", "0", ";", "id", "<", "K", ";", "id", "++", ")", "{", "for", "(", "var", "d", "=", "0", ";", "d", "<", "nDim", ";", "d", "++", ")", "{", "centers", "[", "id", "]", "[", "d", "]", "/=", "centersLen", "[", "id", "]", ";", "}", "}", "return", "centers", ";", "}" ]
Update the center values based in the new configurations of the clusters @ignore @param {Array <Array <Number>>} data - the [x,y,z,...] points to cluster @param {Array <Number>} clusterID - the cluster identifier for each data dot @param {Number} K - Number of clusters @returns {Array} he K centers in format [x,y,z,...]
[ "Update", "the", "center", "values", "based", "in", "the", "new", "configurations", "of", "the", "clusters" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L43844-L43873
22,603
repetere/modelscript
build/modelscript.umd.js
converged
function converged(centers, oldCenters, distanceFunction, tolerance) { for (var i = 0; i < centers.length; i++) { if (distanceFunction(centers[i], oldCenters[i]) > tolerance) { return false; } } return true; }
javascript
function converged(centers, oldCenters, distanceFunction, tolerance) { for (var i = 0; i < centers.length; i++) { if (distanceFunction(centers[i], oldCenters[i]) > tolerance) { return false; } } return true; }
[ "function", "converged", "(", "centers", ",", "oldCenters", ",", "distanceFunction", ",", "tolerance", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "centers", ".", "length", ";", "i", "++", ")", "{", "if", "(", "distanceFunction", "(", "centers", "[", "i", "]", ",", "oldCenters", "[", "i", "]", ")", ">", "tolerance", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
The centers have moved more than the tolerance value? @ignore @param {Array<Array<Number>>} centers - the K centers in format [x,y,z,...] @param {Array<Array<Number>>} oldCenters - the K old centers in format [x,y,z,...] @param {Function} distanceFunction - Distance function to use between the points @param {Number} tolerance - Allowed distance for the centroids to move @return {boolean}
[ "The", "centers", "have", "moved", "more", "than", "the", "tolerance", "value?" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L43884-L43891
22,604
repetere/modelscript
build/modelscript.umd.js
clone
function clone(arr) { var newArr = []; for (var i=0; i<arr.length; i++) { newArr.push(arr[i]); } return newArr; }
javascript
function clone(arr) { var newArr = []; for (var i=0; i<arr.length; i++) { newArr.push(arr[i]); } return newArr; }
[ "function", "clone", "(", "arr", ")", "{", "var", "newArr", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arr", ".", "length", ";", "i", "++", ")", "{", "newArr", ".", "push", "(", "arr", "[", "i", "]", ")", ";", "}", "return", "newArr", ";", "}" ]
Gets a shallow copy of the given array.
[ "Gets", "a", "shallow", "copy", "of", "the", "given", "array", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L43930-L43936
22,605
repetere/modelscript
build/modelscript.umd.js
pick
function pick() { if (this._remainingOptions.length === 0) { this._remainingOptions = clone(this._originalOptions); } var index = Math.floor(Math.random() * this._remainingOptions.length); return this._remainingOptions.splice(index, 1)[0]; }
javascript
function pick() { if (this._remainingOptions.length === 0) { this._remainingOptions = clone(this._originalOptions); } var index = Math.floor(Math.random() * this._remainingOptions.length); return this._remainingOptions.splice(index, 1)[0]; }
[ "function", "pick", "(", ")", "{", "if", "(", "this", ".", "_remainingOptions", ".", "length", "===", "0", ")", "{", "this", ".", "_remainingOptions", "=", "clone", "(", "this", ".", "_originalOptions", ")", ";", "}", "var", "index", "=", "Math", ".", "floor", "(", "Math", ".", "random", "(", ")", "*", "this", ".", "_remainingOptions", ".", "length", ")", ";", "return", "this", ".", "_remainingOptions", ".", "splice", "(", "index", ",", "1", ")", "[", "0", "]", ";", "}" ]
Gets a random option until all options have been returns. Then cycles again.
[ "Gets", "a", "random", "option", "until", "all", "options", "have", "been", "returns", ".", "Then", "cycles", "again", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L43939-L43946
22,606
repetere/modelscript
build/modelscript.umd.js
random$1
function random$1(data, K) { const rand = new Picker$1(data); var ans = new Array(K); for (var i = 0; i < K; ++i) { ans[i] = rand.pick(); } return ans; }
javascript
function random$1(data, K) { const rand = new Picker$1(data); var ans = new Array(K); for (var i = 0; i < K; ++i) { ans[i] = rand.pick(); } return ans; }
[ "function", "random$1", "(", "data", ",", "K", ")", "{", "const", "rand", "=", "new", "Picker$1", "(", "data", ")", ";", "var", "ans", "=", "new", "Array", "(", "K", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "K", ";", "++", "i", ")", "{", "ans", "[", "i", "]", "=", "rand", ".", "pick", "(", ")", ";", "}", "return", "ans", ";", "}" ]
Choose K different random points from the original data @ignore @param {Array<Array<Number>>} data - Points in the format to cluster [x,y,z,...] @param {Number} K - Number of clusters @return {Array<Array<Number>>} - Initial random points
[ "Choose", "K", "different", "random", "points", "from", "the", "original", "data" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L43970-L43978
22,607
repetere/modelscript
build/modelscript.umd.js
KMeansResult
function KMeansResult(clusters, centroids, converged, iterations, distance) { this.clusters = clusters; this.centroids = centroids; this.converged = converged; this.iterations = iterations; this[distanceSymbol] = distance; }
javascript
function KMeansResult(clusters, centroids, converged, iterations, distance) { this.clusters = clusters; this.centroids = centroids; this.converged = converged; this.iterations = iterations; this[distanceSymbol] = distance; }
[ "function", "KMeansResult", "(", "clusters", ",", "centroids", ",", "converged", ",", "iterations", ",", "distance", ")", "{", "this", ".", "clusters", "=", "clusters", ";", "this", ".", "centroids", "=", "centroids", ";", "this", ".", "converged", "=", "converged", ";", "this", ".", "iterations", "=", "iterations", ";", "this", "[", "distanceSymbol", "]", "=", "distance", ";", "}" ]
Result of the kmeans algorithm @param {Array<Number>} clusters - the cluster identifier for each data dot @param {Array<Array<Object>>} centroids - the K centers in format [x,y,z,...], the error and size of the cluster @param {Boolean} converged - Converge criteria satisfied @param {Number} iterations - Current number of iterations @param {Function} distance - (*Private*) Distance function to use between the points @constructor
[ "Result", "of", "the", "kmeans", "algorithm" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L44054-L44060
22,608
repetere/modelscript
build/modelscript.umd.js
errorCalculation
function errorCalculation( data, parameters, parameterizedFunction ) { var error = 0; const func = parameterizedFunction(parameters); for (var i = 0; i < data.x.length; i++) { error += Math.abs(data.y[i] - func(data.x[i])); } return error; }
javascript
function errorCalculation( data, parameters, parameterizedFunction ) { var error = 0; const func = parameterizedFunction(parameters); for (var i = 0; i < data.x.length; i++) { error += Math.abs(data.y[i] - func(data.x[i])); } return error; }
[ "function", "errorCalculation", "(", "data", ",", "parameters", ",", "parameterizedFunction", ")", "{", "var", "error", "=", "0", ";", "const", "func", "=", "parameterizedFunction", "(", "parameters", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "data", ".", "x", ".", "length", ";", "i", "++", ")", "{", "error", "+=", "Math", ".", "abs", "(", "data", ".", "y", "[", "i", "]", "-", "func", "(", "data", ".", "x", "[", "i", "]", ")", ")", ";", "}", "return", "error", ";", "}" ]
Calculate current error @ignore @param {{x:Array<number>, y:Array<number>}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ] @param {Array<number>} parameters - Array of current parameter values @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter @return {number}
[ "Calculate", "current", "error" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L52110-L52123
22,609
repetere/modelscript
build/modelscript.umd.js
gradientFunction
function gradientFunction( data, evaluatedData, params, gradientDifference, paramFunction ) { const n = params.length; const m = data.x.length; var ans = new Array(n); for (var param = 0; param < n; param++) { ans[param] = new Array(m); var auxParams = params.concat(); auxParams[param] += gradientDifference; var funcParam = paramFunction(auxParams); for (var point = 0; point < m; point++) { ans[param][point] = evaluatedData[point] - funcParam(data.x[point]); } } return new require$$0$2.Matrix(ans); }
javascript
function gradientFunction( data, evaluatedData, params, gradientDifference, paramFunction ) { const n = params.length; const m = data.x.length; var ans = new Array(n); for (var param = 0; param < n; param++) { ans[param] = new Array(m); var auxParams = params.concat(); auxParams[param] += gradientDifference; var funcParam = paramFunction(auxParams); for (var point = 0; point < m; point++) { ans[param][point] = evaluatedData[point] - funcParam(data.x[point]); } } return new require$$0$2.Matrix(ans); }
[ "function", "gradientFunction", "(", "data", ",", "evaluatedData", ",", "params", ",", "gradientDifference", ",", "paramFunction", ")", "{", "const", "n", "=", "params", ".", "length", ";", "const", "m", "=", "data", ".", "x", ".", "length", ";", "var", "ans", "=", "new", "Array", "(", "n", ")", ";", "for", "(", "var", "param", "=", "0", ";", "param", "<", "n", ";", "param", "++", ")", "{", "ans", "[", "param", "]", "=", "new", "Array", "(", "m", ")", ";", "var", "auxParams", "=", "params", ".", "concat", "(", ")", ";", "auxParams", "[", "param", "]", "+=", "gradientDifference", ";", "var", "funcParam", "=", "paramFunction", "(", "auxParams", ")", ";", "for", "(", "var", "point", "=", "0", ";", "point", "<", "m", ";", "point", "++", ")", "{", "ans", "[", "param", "]", "[", "point", "]", "=", "evaluatedData", "[", "point", "]", "-", "funcParam", "(", "data", ".", "x", "[", "point", "]", ")", ";", "}", "}", "return", "new", "require$$0$2", ".", "Matrix", "(", "ans", ")", ";", "}" ]
Difference of the matrix function over the parameters @ignore @param {{x:Array<number>, y:Array<number>}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ] @param {Array<number>} evaluatedData - Array of previous evaluated function values @param {Array<number>} params - Array of previous parameter values @param {number} gradientDifference - Adjustment for decrease the damping parameter @param {function} paramFunction - The parameters and returns a function with the independent variable as a parameter @return {Matrix}
[ "Difference", "of", "the", "matrix", "function", "over", "the", "parameters" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L52135-L52158
22,610
repetere/modelscript
build/modelscript.umd.js
step$1
function step$1( data, params, damping, gradientDifference, parameterizedFunction ) { var identity = require$$0$2.Matrix.eye(params.length).mul( damping * gradientDifference * gradientDifference ); var l = data.x.length; var evaluatedData = new Array(l); const func = parameterizedFunction(params); for (var i = 0; i < l; i++) { evaluatedData[i] = func(data.x[i]); } var gradientFunc = gradientFunction( data, evaluatedData, params, gradientDifference, parameterizedFunction ); var matrixFunc = matrixFunction(data, evaluatedData).transposeView(); var inverseMatrix = require$$0$2.inverse( identity.add(gradientFunc.mmul(gradientFunc.transposeView())) ); params = new require$$0$2.Matrix([params]); params = params.sub( inverseMatrix .mmul(gradientFunc) .mmul(matrixFunc) .mul(gradientDifference) .transposeView() ); return params.to1DArray(); }
javascript
function step$1( data, params, damping, gradientDifference, parameterizedFunction ) { var identity = require$$0$2.Matrix.eye(params.length).mul( damping * gradientDifference * gradientDifference ); var l = data.x.length; var evaluatedData = new Array(l); const func = parameterizedFunction(params); for (var i = 0; i < l; i++) { evaluatedData[i] = func(data.x[i]); } var gradientFunc = gradientFunction( data, evaluatedData, params, gradientDifference, parameterizedFunction ); var matrixFunc = matrixFunction(data, evaluatedData).transposeView(); var inverseMatrix = require$$0$2.inverse( identity.add(gradientFunc.mmul(gradientFunc.transposeView())) ); params = new require$$0$2.Matrix([params]); params = params.sub( inverseMatrix .mmul(gradientFunc) .mmul(matrixFunc) .mul(gradientDifference) .transposeView() ); return params.to1DArray(); }
[ "function", "step$1", "(", "data", ",", "params", ",", "damping", ",", "gradientDifference", ",", "parameterizedFunction", ")", "{", "var", "identity", "=", "require$$0$2", ".", "Matrix", ".", "eye", "(", "params", ".", "length", ")", ".", "mul", "(", "damping", "*", "gradientDifference", "*", "gradientDifference", ")", ";", "var", "l", "=", "data", ".", "x", ".", "length", ";", "var", "evaluatedData", "=", "new", "Array", "(", "l", ")", ";", "const", "func", "=", "parameterizedFunction", "(", "params", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "l", ";", "i", "++", ")", "{", "evaluatedData", "[", "i", "]", "=", "func", "(", "data", ".", "x", "[", "i", "]", ")", ";", "}", "var", "gradientFunc", "=", "gradientFunction", "(", "data", ",", "evaluatedData", ",", "params", ",", "gradientDifference", ",", "parameterizedFunction", ")", ";", "var", "matrixFunc", "=", "matrixFunction", "(", "data", ",", "evaluatedData", ")", ".", "transposeView", "(", ")", ";", "var", "inverseMatrix", "=", "require$$0$2", ".", "inverse", "(", "identity", ".", "add", "(", "gradientFunc", ".", "mmul", "(", "gradientFunc", ".", "transposeView", "(", ")", ")", ")", ")", ";", "params", "=", "new", "require$$0$2", ".", "Matrix", "(", "[", "params", "]", ")", ";", "params", "=", "params", ".", "sub", "(", "inverseMatrix", ".", "mmul", "(", "gradientFunc", ")", ".", "mmul", "(", "matrixFunc", ")", ".", "mul", "(", "gradientDifference", ")", ".", "transposeView", "(", ")", ")", ";", "return", "params", ".", "to1DArray", "(", ")", ";", "}" ]
Iteration for Levenberg-Marquardt @ignore @param {{x:Array<number>, y:Array<number>}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ] @param {Array<number>} params - Array of previous parameter values @param {number} damping - Levenberg-Marquardt parameter @param {number} gradientDifference - Adjustment for decrease the damping parameter @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter @return {Array<number>}
[ "Iteration", "for", "Levenberg", "-", "Marquardt" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L52189-L52227
22,611
repetere/modelscript
build/modelscript.umd.js
levenbergMarquardt
function levenbergMarquardt( data, parameterizedFunction, options = {} ) { let { maxIterations = 100, gradientDifference = 10e-2, damping = 0, errorTolerance = 10e-3, initialValues } = options; if (damping <= 0) { throw new Error('The damping option must be a positive number'); } else if (!data.x || !data.y) { throw new Error('The data parameter must have x and y elements'); } else if ( !Array.isArray(data.x) || data.x.length < 2 || !Array.isArray(data.y) || data.y.length < 2 ) { throw new Error( 'The data parameter elements must be an array with more than 2 points' ); } else { let dataLen = data.x.length; if (dataLen !== data.y.length) { throw new Error('The data parameter elements must have the same size'); } } var parameters = initialValues || new Array(parameterizedFunction.length).fill(1); if (!Array.isArray(parameters)) { throw new Error('initialValues must be an array'); } var error = errorCalculation(data, parameters, parameterizedFunction); var converged = error <= errorTolerance; for ( var iteration = 0; iteration < maxIterations && !converged; iteration++ ) { parameters = step$1( data, parameters, damping, gradientDifference, parameterizedFunction ); error = errorCalculation(data, parameters, parameterizedFunction); converged = error <= errorTolerance; } return { parameterValues: parameters, parameterError: error, iterations: iteration }; }
javascript
function levenbergMarquardt( data, parameterizedFunction, options = {} ) { let { maxIterations = 100, gradientDifference = 10e-2, damping = 0, errorTolerance = 10e-3, initialValues } = options; if (damping <= 0) { throw new Error('The damping option must be a positive number'); } else if (!data.x || !data.y) { throw new Error('The data parameter must have x and y elements'); } else if ( !Array.isArray(data.x) || data.x.length < 2 || !Array.isArray(data.y) || data.y.length < 2 ) { throw new Error( 'The data parameter elements must be an array with more than 2 points' ); } else { let dataLen = data.x.length; if (dataLen !== data.y.length) { throw new Error('The data parameter elements must have the same size'); } } var parameters = initialValues || new Array(parameterizedFunction.length).fill(1); if (!Array.isArray(parameters)) { throw new Error('initialValues must be an array'); } var error = errorCalculation(data, parameters, parameterizedFunction); var converged = error <= errorTolerance; for ( var iteration = 0; iteration < maxIterations && !converged; iteration++ ) { parameters = step$1( data, parameters, damping, gradientDifference, parameterizedFunction ); error = errorCalculation(data, parameters, parameterizedFunction); converged = error <= errorTolerance; } return { parameterValues: parameters, parameterError: error, iterations: iteration }; }
[ "function", "levenbergMarquardt", "(", "data", ",", "parameterizedFunction", ",", "options", "=", "{", "}", ")", "{", "let", "{", "maxIterations", "=", "100", ",", "gradientDifference", "=", "10e-2", ",", "damping", "=", "0", ",", "errorTolerance", "=", "10e-3", ",", "initialValues", "}", "=", "options", ";", "if", "(", "damping", "<=", "0", ")", "{", "throw", "new", "Error", "(", "'The damping option must be a positive number'", ")", ";", "}", "else", "if", "(", "!", "data", ".", "x", "||", "!", "data", ".", "y", ")", "{", "throw", "new", "Error", "(", "'The data parameter must have x and y elements'", ")", ";", "}", "else", "if", "(", "!", "Array", ".", "isArray", "(", "data", ".", "x", ")", "||", "data", ".", "x", ".", "length", "<", "2", "||", "!", "Array", ".", "isArray", "(", "data", ".", "y", ")", "||", "data", ".", "y", ".", "length", "<", "2", ")", "{", "throw", "new", "Error", "(", "'The data parameter elements must be an array with more than 2 points'", ")", ";", "}", "else", "{", "let", "dataLen", "=", "data", ".", "x", ".", "length", ";", "if", "(", "dataLen", "!==", "data", ".", "y", ".", "length", ")", "{", "throw", "new", "Error", "(", "'The data parameter elements must have the same size'", ")", ";", "}", "}", "var", "parameters", "=", "initialValues", "||", "new", "Array", "(", "parameterizedFunction", ".", "length", ")", ".", "fill", "(", "1", ")", ";", "if", "(", "!", "Array", ".", "isArray", "(", "parameters", ")", ")", "{", "throw", "new", "Error", "(", "'initialValues must be an array'", ")", ";", "}", "var", "error", "=", "errorCalculation", "(", "data", ",", "parameters", ",", "parameterizedFunction", ")", ";", "var", "converged", "=", "error", "<=", "errorTolerance", ";", "for", "(", "var", "iteration", "=", "0", ";", "iteration", "<", "maxIterations", "&&", "!", "converged", ";", "iteration", "++", ")", "{", "parameters", "=", "step$1", "(", "data", ",", "parameters", ",", "damping", ",", "gradientDifference", ",", "parameterizedFunction", ")", ";", "error", "=", "errorCalculation", "(", "data", ",", "parameters", ",", "parameterizedFunction", ")", ";", "converged", "=", "error", "<=", "errorTolerance", ";", "}", "return", "{", "parameterValues", ":", "parameters", ",", "parameterError", ":", "error", ",", "iterations", ":", "iteration", "}", ";", "}" ]
Curve fitting algorithm @param {{x:Array<number>, y:Array<number>}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ] @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter @param {object} [options] - Options object @param {number} [options.damping] - Levenberg-Marquardt parameter @param {number} [options.gradientDifference = 10e-2] - Adjustment for decrease the damping parameter @param {Array<number>} [options.initialValues] - Array of initial parameter values @param {number} [options.maxIterations = 100] - Maximum of allowed iterations @param {number} [options.errorTolerance = 10e-3] - Minimum uncertainty allowed for each point @return {{parameterValues: Array<number>, parameterError: number, iterations: number}}
[ "Curve", "fitting", "algorithm" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L52241-L52306
22,612
repetere/modelscript
build/modelscript.umd.js
createTree
function createTree (X, Y, from, to, minWindow, threshold) { minWindow = minWindow || 0.16; threshold = threshold || 0.01; if ((to - from) < minWindow) return undefined; var sum = 0; for (var i = 0; X[i] < to; i++) { if (X[i] > from) sum += Y[i]; } if (sum < threshold) { return undefined; } var center = 0; for (var j = 0; X[j] < to; j++) { if (X[i] > from) center += X[j] * Y[j]; } center = center / sum; if (((center - from) < 10e-6) || ((to - center) < 10e-6)) return undefined; if ((center - from) < (minWindow /4)) { return createTree(X, Y, center, to, minWindow, threshold); } else { if ((to - center) < (minWindow / 4)) { return createTree(X, Y, from, center, minWindow, threshold); } else { return { 'sum': sum, 'center': center, 'left': createTree(X, Y, from, center, minWindow, threshold), 'right': createTree(X, Y, center, to, minWindow, threshold) }; } } }
javascript
function createTree (X, Y, from, to, minWindow, threshold) { minWindow = minWindow || 0.16; threshold = threshold || 0.01; if ((to - from) < minWindow) return undefined; var sum = 0; for (var i = 0; X[i] < to; i++) { if (X[i] > from) sum += Y[i]; } if (sum < threshold) { return undefined; } var center = 0; for (var j = 0; X[j] < to; j++) { if (X[i] > from) center += X[j] * Y[j]; } center = center / sum; if (((center - from) < 10e-6) || ((to - center) < 10e-6)) return undefined; if ((center - from) < (minWindow /4)) { return createTree(X, Y, center, to, minWindow, threshold); } else { if ((to - center) < (minWindow / 4)) { return createTree(X, Y, from, center, minWindow, threshold); } else { return { 'sum': sum, 'center': center, 'left': createTree(X, Y, from, center, minWindow, threshold), 'right': createTree(X, Y, center, to, minWindow, threshold) }; } } }
[ "function", "createTree", "(", "X", ",", "Y", ",", "from", ",", "to", ",", "minWindow", ",", "threshold", ")", "{", "minWindow", "=", "minWindow", "||", "0.16", ";", "threshold", "=", "threshold", "||", "0.01", ";", "if", "(", "(", "to", "-", "from", ")", "<", "minWindow", ")", "return", "undefined", ";", "var", "sum", "=", "0", ";", "for", "(", "var", "i", "=", "0", ";", "X", "[", "i", "]", "<", "to", ";", "i", "++", ")", "{", "if", "(", "X", "[", "i", "]", ">", "from", ")", "sum", "+=", "Y", "[", "i", "]", ";", "}", "if", "(", "sum", "<", "threshold", ")", "{", "return", "undefined", ";", "}", "var", "center", "=", "0", ";", "for", "(", "var", "j", "=", "0", ";", "X", "[", "j", "]", "<", "to", ";", "j", "++", ")", "{", "if", "(", "X", "[", "i", "]", ">", "from", ")", "center", "+=", "X", "[", "j", "]", "*", "Y", "[", "j", "]", ";", "}", "center", "=", "center", "/", "sum", ";", "if", "(", "(", "(", "center", "-", "from", ")", "<", "10e-6", ")", "||", "(", "(", "to", "-", "center", ")", "<", "10e-6", ")", ")", "return", "undefined", ";", "if", "(", "(", "center", "-", "from", ")", "<", "(", "minWindow", "/", "4", ")", ")", "{", "return", "createTree", "(", "X", ",", "Y", ",", "center", ",", "to", ",", "minWindow", ",", "threshold", ")", ";", "}", "else", "{", "if", "(", "(", "to", "-", "center", ")", "<", "(", "minWindow", "/", "4", ")", ")", "{", "return", "createTree", "(", "X", ",", "Y", ",", "from", ",", "center", ",", "minWindow", ",", "threshold", ")", ";", "}", "else", "{", "return", "{", "'sum'", ":", "sum", ",", "'center'", ":", "center", ",", "'left'", ":", "createTree", "(", "X", ",", "Y", ",", "from", ",", "center", ",", "minWindow", ",", "threshold", ")", ",", "'right'", ":", "createTree", "(", "X", ",", "Y", ",", "center", ",", "to", ",", "minWindow", ",", "threshold", ")", "}", ";", "}", "}", "}" ]
Function that creates the tree @param {Array <number>} X - chemical shifts of the signal @param {Array <number>} Y - intensity of the signal @param {number} from - the low limit of x @param {number} to - the top limit of x @param {number} minWindow - smallest range to accept in x @param {number} threshold - smallest range to accept in y @returns {{sum: number, center: number, left: {json}, right: {json}}} left and right have the same structure than the parent, or have a undefined value if are leafs
[ "Function", "that", "creates", "the", "tree" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L53571-L53607
22,613
repetere/modelscript
build/modelscript.umd.js
S
function S(a, b, alpha, beta, gamma) { if (a === undefined || b === undefined) { return 0; } else { var C = (alpha*Math.min(a.sum, b.sum)/Math.max(a.sum, b.sum)+ (1-alpha)*Math.exp(-gamma*Math.abs(a.center - b.center))); } return beta*C + (1-beta)*(S(a.left, b.left, alpha, beta, gamma)+S(a.right, b.right, alpha, beta, gamma)); }
javascript
function S(a, b, alpha, beta, gamma) { if (a === undefined || b === undefined) { return 0; } else { var C = (alpha*Math.min(a.sum, b.sum)/Math.max(a.sum, b.sum)+ (1-alpha)*Math.exp(-gamma*Math.abs(a.center - b.center))); } return beta*C + (1-beta)*(S(a.left, b.left, alpha, beta, gamma)+S(a.right, b.right, alpha, beta, gamma)); }
[ "function", "S", "(", "a", ",", "b", ",", "alpha", ",", "beta", ",", "gamma", ")", "{", "if", "(", "a", "===", "undefined", "||", "b", "===", "undefined", ")", "{", "return", "0", ";", "}", "else", "{", "var", "C", "=", "(", "alpha", "*", "Math", ".", "min", "(", "a", ".", "sum", ",", "b", ".", "sum", ")", "/", "Math", ".", "max", "(", "a", ".", "sum", ",", "b", ".", "sum", ")", "+", "(", "1", "-", "alpha", ")", "*", "Math", ".", "exp", "(", "-", "gamma", "*", "Math", ".", "abs", "(", "a", ".", "center", "-", "b", ".", "center", ")", ")", ")", ";", "}", "return", "beta", "*", "C", "+", "(", "1", "-", "beta", ")", "*", "(", "S", "(", "a", ".", "left", ",", "b", ".", "left", ",", "alpha", ",", "beta", ",", "gamma", ")", "+", "S", "(", "a", ".", "right", ",", "b", ".", "right", ",", "alpha", ",", "beta", ",", "gamma", ")", ")", ";", "}" ]
Similarity between two nodes @param {{sum: number, center: number, left: {json}, right: {json}}} a - tree A node @param {{sum: number, center: number, left: {json}, right: {json}}} b - tree B node @param {number} alpha - weights the relative importance of intensity vs. shift match @param {number} beta - weights the relative importance of node matching and children matching @param {number} gamma - controls the attenuation of the effect of chemical shift differences @returns {number} similarity measure between tree nodes
[ "Similarity", "between", "two", "nodes" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L53618-L53626
22,614
repetere/modelscript
build/modelscript.umd.js
tree
function tree(A, B, from, to, options) { options = options || {}; for (var o in defaultOptions$n) if (!options.hasOwnProperty(o)) { options[o] = defaultOptions$n[o]; } var Atree, Btree; if (A.sum) Atree = A; else Atree = createTree(A.x, A.y, from, to, options.minWindow, options.threshold); if (B.sum) Btree = B; else Btree = createTree(B.x, B.y, from, to, options.minWindow, options.threshold); return S(Atree, Btree, options.alpha, options.beta, options.gamma); }
javascript
function tree(A, B, from, to, options) { options = options || {}; for (var o in defaultOptions$n) if (!options.hasOwnProperty(o)) { options[o] = defaultOptions$n[o]; } var Atree, Btree; if (A.sum) Atree = A; else Atree = createTree(A.x, A.y, from, to, options.minWindow, options.threshold); if (B.sum) Btree = B; else Btree = createTree(B.x, B.y, from, to, options.minWindow, options.threshold); return S(Atree, Btree, options.alpha, options.beta, options.gamma); }
[ "function", "tree", "(", "A", ",", "B", ",", "from", ",", "to", ",", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "for", "(", "var", "o", "in", "defaultOptions$n", ")", "if", "(", "!", "options", ".", "hasOwnProperty", "(", "o", ")", ")", "{", "options", "[", "o", "]", "=", "defaultOptions$n", "[", "o", "]", ";", "}", "var", "Atree", ",", "Btree", ";", "if", "(", "A", ".", "sum", ")", "Atree", "=", "A", ";", "else", "Atree", "=", "createTree", "(", "A", ".", "x", ",", "A", ".", "y", ",", "from", ",", "to", ",", "options", ".", "minWindow", ",", "options", ".", "threshold", ")", ";", "if", "(", "B", ".", "sum", ")", "Btree", "=", "B", ";", "else", "Btree", "=", "createTree", "(", "B", ".", "x", ",", "B", ".", "y", ",", "from", ",", "to", ",", "options", ".", "minWindow", ",", "options", ".", "threshold", ")", ";", "return", "S", "(", "Atree", ",", "Btree", ",", "options", ".", "alpha", ",", "options", ".", "beta", ",", "options", ".", "gamma", ")", ";", "}" ]
Builds a tree based in the spectra and compares this trees @param {{x: Array<number>, y: Array<number>}} A - first spectra to be compared @param {{x: Array<number>, y: Array<number>}} B - second spectra to be compared @param {number} from - the low limit of x @param {number} to - the top limit of x @param {{minWindow: number, threshold: number, alpha: number, beta: number, gamma: number}} options @returns {number} similarity measure between the spectra
[ "Builds", "a", "tree", "based", "in", "the", "spectra", "and", "compares", "this", "trees" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L53652-L53668
22,615
repetere/modelscript
build/modelscript.umd.js
matrixCase
function matrixCase(data, options) { var row = data.length; var col = data[0].length; if (options.size[0] === undefined) options.size = [options.size, options.size, options.size, options.size]; throw new Error('matrix not supported yet, sorry'); }
javascript
function matrixCase(data, options) { var row = data.length; var col = data[0].length; if (options.size[0] === undefined) options.size = [options.size, options.size, options.size, options.size]; throw new Error('matrix not supported yet, sorry'); }
[ "function", "matrixCase", "(", "data", ",", "options", ")", "{", "var", "row", "=", "data", ".", "length", ";", "var", "col", "=", "data", "[", "0", "]", ".", "length", ";", "if", "(", "options", ".", "size", "[", "0", "]", "===", "undefined", ")", "options", ".", "size", "=", "[", "options", ".", "size", ",", "options", ".", "size", ",", "options", ".", "size", ",", "options", ".", "size", "]", ";", "throw", "new", "Error", "(", "'matrix not supported yet, sorry'", ")", ";", "}" ]
Case when the entry is a matrix @param data @param options @returns {Array}
[ "Case", "when", "the", "entry", "is", "a", "matrix" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54520-L54526
22,616
repetere/modelscript
build/modelscript.umd.js
padArray
function padArray (data, options) { options = extend({}, defaultOptions$o, options); if (Array.isArray(data)) { if (Array.isArray(data[0])) return matrixCase(data, options); else return arrayCase(data, options); } else throw new TypeError('data should be an array'); }
javascript
function padArray (data, options) { options = extend({}, defaultOptions$o, options); if (Array.isArray(data)) { if (Array.isArray(data[0])) return matrixCase(data, options); else return arrayCase(data, options); } else throw new TypeError('data should be an array'); }
[ "function", "padArray", "(", "data", ",", "options", ")", "{", "options", "=", "extend", "(", "{", "}", ",", "defaultOptions$o", ",", "options", ")", ";", "if", "(", "Array", ".", "isArray", "(", "data", ")", ")", "{", "if", "(", "Array", ".", "isArray", "(", "data", "[", "0", "]", ")", ")", "return", "matrixCase", "(", "data", ",", "options", ")", ";", "else", "return", "arrayCase", "(", "data", ",", "options", ")", ";", "}", "else", "throw", "new", "TypeError", "(", "'data should be an array'", ")", ";", "}" ]
Pads and array @param {Array <number>} data @param {object} options
[ "Pads", "and", "array" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54533-L54544
22,617
repetere/modelscript
build/modelscript.umd.js
and
function and(arr1, arr2) { var ans = new Array(arr1.length); for (var i = 0; i < arr1.length; i++) ans[i] = arr1[i] & arr2[i]; return ans; }
javascript
function and(arr1, arr2) { var ans = new Array(arr1.length); for (var i = 0; i < arr1.length; i++) ans[i] = arr1[i] & arr2[i]; return ans; }
[ "function", "and", "(", "arr1", ",", "arr2", ")", "{", "var", "ans", "=", "new", "Array", "(", "arr1", ".", "length", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arr1", ".", "length", ";", "i", "++", ")", "ans", "[", "i", "]", "=", "arr1", "[", "i", "]", "&", "arr2", "[", "i", "]", ";", "return", "ans", ";", "}" ]
Logical AND operation @param {Array} arr1 @param {Array} arr2 @return {Array}
[ "Logical", "AND", "operation" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54831-L54836
22,618
repetere/modelscript
build/modelscript.umd.js
or
function or(arr1, arr2) { var ans = new Array(arr1.length); for (var i = 0; i < arr1.length; i++) ans[i] = arr1[i] | arr2[i]; return ans; }
javascript
function or(arr1, arr2) { var ans = new Array(arr1.length); for (var i = 0; i < arr1.length; i++) ans[i] = arr1[i] | arr2[i]; return ans; }
[ "function", "or", "(", "arr1", ",", "arr2", ")", "{", "var", "ans", "=", "new", "Array", "(", "arr1", ".", "length", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arr1", ".", "length", ";", "i", "++", ")", "ans", "[", "i", "]", "=", "arr1", "[", "i", "]", "|", "arr2", "[", "i", "]", ";", "return", "ans", ";", "}" ]
Logical OR operation @param {Array} arr1 @param {Array} arr2 @return {Array}
[ "Logical", "OR", "operation" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54844-L54849
22,619
repetere/modelscript
build/modelscript.umd.js
xor
function xor(arr1, arr2) { var ans = new Array(arr1.length); for (var i = 0; i < arr1.length; i++) ans[i] = arr1[i] ^ arr2[i]; return ans; }
javascript
function xor(arr1, arr2) { var ans = new Array(arr1.length); for (var i = 0; i < arr1.length; i++) ans[i] = arr1[i] ^ arr2[i]; return ans; }
[ "function", "xor", "(", "arr1", ",", "arr2", ")", "{", "var", "ans", "=", "new", "Array", "(", "arr1", ".", "length", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arr1", ".", "length", ";", "i", "++", ")", "ans", "[", "i", "]", "=", "arr1", "[", "i", "]", "^", "arr2", "[", "i", "]", ";", "return", "ans", ";", "}" ]
Logical XOR operation @param {Array} arr1 @param {Array} arr2 @return {Array}
[ "Logical", "XOR", "operation" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54857-L54862
22,620
repetere/modelscript
build/modelscript.umd.js
not
function not(arr) { var ans = new Array(arr.length); for (var i = 0; i < ans.length; i++) ans[i] = ~arr[i]; return ans; }
javascript
function not(arr) { var ans = new Array(arr.length); for (var i = 0; i < ans.length; i++) ans[i] = ~arr[i]; return ans; }
[ "function", "not", "(", "arr", ")", "{", "var", "ans", "=", "new", "Array", "(", "arr", ".", "length", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "ans", ".", "length", ";", "i", "++", ")", "ans", "[", "i", "]", "=", "~", "arr", "[", "i", "]", ";", "return", "ans", ";", "}" ]
Logical NOT operation @param {Array} arr @return {Array}
[ "Logical", "NOT", "operation" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54869-L54874
22,621
repetere/modelscript
build/modelscript.umd.js
getBit
function getBit(arr, n) { var index = n >> 5; // Same as Math.floor(n/32) var mask = 1 << (31 - n % 32); return Boolean(arr[index] & mask); }
javascript
function getBit(arr, n) { var index = n >> 5; // Same as Math.floor(n/32) var mask = 1 << (31 - n % 32); return Boolean(arr[index] & mask); }
[ "function", "getBit", "(", "arr", ",", "n", ")", "{", "var", "index", "=", "n", ">>", "5", ";", "// Same as Math.floor(n/32)", "var", "mask", "=", "1", "<<", "(", "31", "-", "n", "%", "32", ")", ";", "return", "Boolean", "(", "arr", "[", "index", "]", "&", "mask", ")", ";", "}" ]
Gets the n value of array arr @param {Array} arr @param {number} n @return {boolean}
[ "Gets", "the", "n", "value", "of", "array", "arr" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54882-L54886
22,622
repetere/modelscript
build/modelscript.umd.js
setBit
function setBit(arr, n, val) { var index = n >> 5; // Same as Math.floor(n/32) var mask = 1 << (31 - n % 32); if (val) arr[index] = mask | arr[index]; else arr[index] = ~mask & arr[index]; return arr; }
javascript
function setBit(arr, n, val) { var index = n >> 5; // Same as Math.floor(n/32) var mask = 1 << (31 - n % 32); if (val) arr[index] = mask | arr[index]; else arr[index] = ~mask & arr[index]; return arr; }
[ "function", "setBit", "(", "arr", ",", "n", ",", "val", ")", "{", "var", "index", "=", "n", ">>", "5", ";", "// Same as Math.floor(n/32)", "var", "mask", "=", "1", "<<", "(", "31", "-", "n", "%", "32", ")", ";", "if", "(", "val", ")", "arr", "[", "index", "]", "=", "mask", "|", "arr", "[", "index", "]", ";", "else", "arr", "[", "index", "]", "=", "~", "mask", "&", "arr", "[", "index", "]", ";", "return", "arr", ";", "}" ]
Sets the n value of array arr to the value val @param {Array} arr @param {number} n @param {boolean} val @return {Array}
[ "Sets", "the", "n", "value", "of", "array", "arr", "to", "the", "value", "val" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54895-L54903
22,623
repetere/modelscript
build/modelscript.umd.js
toBinaryString
function toBinaryString(arr) { var str = ''; for (var i = 0; i < arr.length; i++) { var obj = (arr[i] >>> 0).toString(2); str += '00000000000000000000000000000000'.substr(obj.length) + obj; } return str; }
javascript
function toBinaryString(arr) { var str = ''; for (var i = 0; i < arr.length; i++) { var obj = (arr[i] >>> 0).toString(2); str += '00000000000000000000000000000000'.substr(obj.length) + obj; } return str; }
[ "function", "toBinaryString", "(", "arr", ")", "{", "var", "str", "=", "''", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arr", ".", "length", ";", "i", "++", ")", "{", "var", "obj", "=", "(", "arr", "[", "i", "]", ">>>", "0", ")", ".", "toString", "(", "2", ")", ";", "str", "+=", "'00000000000000000000000000000000'", ".", "substr", "(", "obj", ".", "length", ")", "+", "obj", ";", "}", "return", "str", ";", "}" ]
Translates an array of numbers to a string of bits @param {Array} arr @returns {string}
[ "Translates", "an", "array", "of", "numbers", "to", "a", "string", "of", "bits" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54910-L54917
22,624
repetere/modelscript
build/modelscript.umd.js
parseBinaryString
function parseBinaryString(str) { var len = str.length / 32; var ans = new Array(len); for (var i = 0; i < len; i++) { ans[i] = parseInt(str.substr(i*32, 32), 2) | 0; } return ans; }
javascript
function parseBinaryString(str) { var len = str.length / 32; var ans = new Array(len); for (var i = 0; i < len; i++) { ans[i] = parseInt(str.substr(i*32, 32), 2) | 0; } return ans; }
[ "function", "parseBinaryString", "(", "str", ")", "{", "var", "len", "=", "str", ".", "length", "/", "32", ";", "var", "ans", "=", "new", "Array", "(", "len", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "len", ";", "i", "++", ")", "{", "ans", "[", "i", "]", "=", "parseInt", "(", "str", ".", "substr", "(", "i", "*", "32", ",", "32", ")", ",", "2", ")", "|", "0", ";", "}", "return", "ans", ";", "}" ]
Creates an array of numbers based on a string of bits @param {string} str @returns {Array}
[ "Creates", "an", "array", "of", "numbers", "based", "on", "a", "string", "of", "bits" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54924-L54931
22,625
repetere/modelscript
build/modelscript.umd.js
toHexString
function toHexString(arr) { var str = ''; for (var i = 0; i < arr.length; i++) { var obj = (arr[i] >>> 0).toString(16); str += '00000000'.substr(obj.length) + obj; } return str; }
javascript
function toHexString(arr) { var str = ''; for (var i = 0; i < arr.length; i++) { var obj = (arr[i] >>> 0).toString(16); str += '00000000'.substr(obj.length) + obj; } return str; }
[ "function", "toHexString", "(", "arr", ")", "{", "var", "str", "=", "''", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arr", ".", "length", ";", "i", "++", ")", "{", "var", "obj", "=", "(", "arr", "[", "i", "]", ">>>", "0", ")", ".", "toString", "(", "16", ")", ";", "str", "+=", "'00000000'", ".", "substr", "(", "obj", ".", "length", ")", "+", "obj", ";", "}", "return", "str", ";", "}" ]
Translates an array of numbers to a hex string @param {Array} arr @returns {string}
[ "Translates", "an", "array", "of", "numbers", "to", "a", "hex", "string" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54938-L54945
22,626
repetere/modelscript
build/modelscript.umd.js
toDebug
function toDebug(arr) { var binary = toBinaryString(arr); var str = ''; for (var i = 0; i < arr.length; i++) { str += '0000'.substr((i * 32).toString(16).length) + (i * 32).toString(16) + ':'; for (var j = 0; j < 32; j += 4) { str += ' ' + binary.substr(i * 32 + j, 4); } if (i < arr.length - 1) str += '\n'; } return str }
javascript
function toDebug(arr) { var binary = toBinaryString(arr); var str = ''; for (var i = 0; i < arr.length; i++) { str += '0000'.substr((i * 32).toString(16).length) + (i * 32).toString(16) + ':'; for (var j = 0; j < 32; j += 4) { str += ' ' + binary.substr(i * 32 + j, 4); } if (i < arr.length - 1) str += '\n'; } return str }
[ "function", "toDebug", "(", "arr", ")", "{", "var", "binary", "=", "toBinaryString", "(", "arr", ")", ";", "var", "str", "=", "''", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "arr", ".", "length", ";", "i", "++", ")", "{", "str", "+=", "'0000'", ".", "substr", "(", "(", "i", "*", "32", ")", ".", "toString", "(", "16", ")", ".", "length", ")", "+", "(", "i", "*", "32", ")", ".", "toString", "(", "16", ")", "+", "':'", ";", "for", "(", "var", "j", "=", "0", ";", "j", "<", "32", ";", "j", "+=", "4", ")", "{", "str", "+=", "' '", "+", "binary", ".", "substr", "(", "i", "*", "32", "+", "j", ",", "4", ")", ";", "}", "if", "(", "i", "<", "arr", ".", "length", "-", "1", ")", "str", "+=", "'\\n'", ";", "}", "return", "str", "}" ]
Creates a human readable string of the array @param {Array} arr @returns {string}
[ "Creates", "a", "human", "readable", "string", "of", "the", "array" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L54966-L54977
22,627
repetere/modelscript
build/modelscript.umd.js
transpose
function transpose(matrix) { var resultMatrix = new Array(matrix[0].length); for (var i = 0; i < resultMatrix.length; ++i) { resultMatrix[i] = new Array(matrix.length); } for (i = 0; i < matrix.length; ++i) { for (var j = 0; j < matrix[0].length; ++j) { resultMatrix[j][i] = matrix[i][j]; } } return resultMatrix; }
javascript
function transpose(matrix) { var resultMatrix = new Array(matrix[0].length); for (var i = 0; i < resultMatrix.length; ++i) { resultMatrix[i] = new Array(matrix.length); } for (i = 0; i < matrix.length; ++i) { for (var j = 0; j < matrix[0].length; ++j) { resultMatrix[j][i] = matrix[i][j]; } } return resultMatrix; }
[ "function", "transpose", "(", "matrix", ")", "{", "var", "resultMatrix", "=", "new", "Array", "(", "matrix", "[", "0", "]", ".", "length", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "resultMatrix", ".", "length", ";", "++", "i", ")", "{", "resultMatrix", "[", "i", "]", "=", "new", "Array", "(", "matrix", ".", "length", ")", ";", "}", "for", "(", "i", "=", "0", ";", "i", "<", "matrix", ".", "length", ";", "++", "i", ")", "{", "for", "(", "var", "j", "=", "0", ";", "j", "<", "matrix", "[", "0", "]", ".", "length", ";", "++", "j", ")", "{", "resultMatrix", "[", "j", "]", "[", "i", "]", "=", "matrix", "[", "i", "]", "[", "j", "]", ";", "}", "}", "return", "resultMatrix", ";", "}" ]
Tranpose a matrix, this method is for coordMatrixToPoints and pointsToCoordMatrix, that because only transposing the matrix you can change your representation. @param matrix @returns {Array}
[ "Tranpose", "a", "matrix", "this", "method", "is", "for", "coordMatrixToPoints", "and", "pointsToCoordMatrix", "that", "because", "only", "transposing", "the", "matrix", "you", "can", "change", "your", "representation", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L55092-L55105
22,628
repetere/modelscript
build/modelscript.umd.js
applyDotProduct
function applyDotProduct(firstVector, secondVector) { var largestVector, smallestVector; if (firstVector.length <= secondVector.length) { smallestVector = firstVector; largestVector = secondVector; } else { smallestVector = secondVector; largestVector = firstVector; } var difference = largestVector.length - smallestVector.length + 1; var dotProductApplied = new Array(difference); for (var i = 0; i < difference; ++i) { var sum = 0; for (var j = 0; j < smallestVector.length; ++j) { sum += smallestVector[j] * largestVector[i + j]; } dotProductApplied[i] = sum; } return dotProductApplied; }
javascript
function applyDotProduct(firstVector, secondVector) { var largestVector, smallestVector; if (firstVector.length <= secondVector.length) { smallestVector = firstVector; largestVector = secondVector; } else { smallestVector = secondVector; largestVector = firstVector; } var difference = largestVector.length - smallestVector.length + 1; var dotProductApplied = new Array(difference); for (var i = 0; i < difference; ++i) { var sum = 0; for (var j = 0; j < smallestVector.length; ++j) { sum += smallestVector[j] * largestVector[i + j]; } dotProductApplied[i] = sum; } return dotProductApplied; }
[ "function", "applyDotProduct", "(", "firstVector", ",", "secondVector", ")", "{", "var", "largestVector", ",", "smallestVector", ";", "if", "(", "firstVector", ".", "length", "<=", "secondVector", ".", "length", ")", "{", "smallestVector", "=", "firstVector", ";", "largestVector", "=", "secondVector", ";", "}", "else", "{", "smallestVector", "=", "secondVector", ";", "largestVector", "=", "firstVector", ";", "}", "var", "difference", "=", "largestVector", ".", "length", "-", "smallestVector", ".", "length", "+", "1", ";", "var", "dotProductApplied", "=", "new", "Array", "(", "difference", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "difference", ";", "++", "i", ")", "{", "var", "sum", "=", "0", ";", "for", "(", "var", "j", "=", "0", ";", "j", "<", "smallestVector", ".", "length", ";", "++", "j", ")", "{", "sum", "+=", "smallestVector", "[", "j", "]", "*", "largestVector", "[", "i", "+", "j", "]", ";", "}", "dotProductApplied", "[", "i", "]", "=", "sum", ";", "}", "return", "dotProductApplied", ";", "}" ]
Apply the dot product between the smaller vector and a subsets of the largest one. @param firstVector @param secondVector @returns {Array} each dot product of size of the difference between the larger and the smallest one.
[ "Apply", "the", "dot", "product", "between", "the", "smaller", "vector", "and", "a", "subsets", "of", "the", "largest", "one", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L55137-L55159
22,629
repetere/modelscript
build/modelscript.umd.js
getEquallySpacedSmooth
function getEquallySpacedSmooth(x, y, from, to, numberOfPoints) { var xLength = x.length; var step = (to - from) / (numberOfPoints - 1); var halfStep = step / 2; var output = new Array(numberOfPoints); var initialOriginalStep = x[1] - x[0]; var lastOriginalStep = x[xLength - 1] - x[xLength - 2]; // Init main variables var min = from - halfStep; var max = from + halfStep; var previousX = Number.MIN_VALUE; var previousY = 0; var nextX = x[0] - initialOriginalStep; var nextY = 0; var currentValue = 0; var slope = 0; var intercept = 0; var sumAtMin = 0; var sumAtMax = 0; var i = 0; // index of input var j = 0; // index of output function getSlope(x0, y0, x1, y1) { return (y1 - y0) / (x1 - x0); } main: while (true) { if (previousX <= min && min <= nextX) { add = integral(0, min - previousX, slope, previousY); sumAtMin = currentValue + add; } while (nextX - max >= 0) { // no overlap with original point, just consume current value var add = integral(0, max - previousX, slope, previousY); sumAtMax = currentValue + add; output[j++] = (sumAtMax - sumAtMin) / step; if (j === numberOfPoints) { break main; } min = max; max += step; sumAtMin = sumAtMax; } currentValue += integral(previousX, nextX, slope, intercept); previousX = nextX; previousY = nextY; if (i < xLength) { nextX = x[i]; nextY = y[i]; i++; } else if (i === xLength) { nextX += lastOriginalStep; nextY = 0; } slope = getSlope(previousX, previousY, nextX, nextY); intercept = -slope * previousX + previousY; } return output; }
javascript
function getEquallySpacedSmooth(x, y, from, to, numberOfPoints) { var xLength = x.length; var step = (to - from) / (numberOfPoints - 1); var halfStep = step / 2; var output = new Array(numberOfPoints); var initialOriginalStep = x[1] - x[0]; var lastOriginalStep = x[xLength - 1] - x[xLength - 2]; // Init main variables var min = from - halfStep; var max = from + halfStep; var previousX = Number.MIN_VALUE; var previousY = 0; var nextX = x[0] - initialOriginalStep; var nextY = 0; var currentValue = 0; var slope = 0; var intercept = 0; var sumAtMin = 0; var sumAtMax = 0; var i = 0; // index of input var j = 0; // index of output function getSlope(x0, y0, x1, y1) { return (y1 - y0) / (x1 - x0); } main: while (true) { if (previousX <= min && min <= nextX) { add = integral(0, min - previousX, slope, previousY); sumAtMin = currentValue + add; } while (nextX - max >= 0) { // no overlap with original point, just consume current value var add = integral(0, max - previousX, slope, previousY); sumAtMax = currentValue + add; output[j++] = (sumAtMax - sumAtMin) / step; if (j === numberOfPoints) { break main; } min = max; max += step; sumAtMin = sumAtMax; } currentValue += integral(previousX, nextX, slope, intercept); previousX = nextX; previousY = nextY; if (i < xLength) { nextX = x[i]; nextY = y[i]; i++; } else if (i === xLength) { nextX += lastOriginalStep; nextY = 0; } slope = getSlope(previousX, previousY, nextX, nextY); intercept = -slope * previousX + previousY; } return output; }
[ "function", "getEquallySpacedSmooth", "(", "x", ",", "y", ",", "from", ",", "to", ",", "numberOfPoints", ")", "{", "var", "xLength", "=", "x", ".", "length", ";", "var", "step", "=", "(", "to", "-", "from", ")", "/", "(", "numberOfPoints", "-", "1", ")", ";", "var", "halfStep", "=", "step", "/", "2", ";", "var", "output", "=", "new", "Array", "(", "numberOfPoints", ")", ";", "var", "initialOriginalStep", "=", "x", "[", "1", "]", "-", "x", "[", "0", "]", ";", "var", "lastOriginalStep", "=", "x", "[", "xLength", "-", "1", "]", "-", "x", "[", "xLength", "-", "2", "]", ";", "// Init main variables", "var", "min", "=", "from", "-", "halfStep", ";", "var", "max", "=", "from", "+", "halfStep", ";", "var", "previousX", "=", "Number", ".", "MIN_VALUE", ";", "var", "previousY", "=", "0", ";", "var", "nextX", "=", "x", "[", "0", "]", "-", "initialOriginalStep", ";", "var", "nextY", "=", "0", ";", "var", "currentValue", "=", "0", ";", "var", "slope", "=", "0", ";", "var", "intercept", "=", "0", ";", "var", "sumAtMin", "=", "0", ";", "var", "sumAtMax", "=", "0", ";", "var", "i", "=", "0", ";", "// index of input", "var", "j", "=", "0", ";", "// index of output", "function", "getSlope", "(", "x0", ",", "y0", ",", "x1", ",", "y1", ")", "{", "return", "(", "y1", "-", "y0", ")", "/", "(", "x1", "-", "x0", ")", ";", "}", "main", ":", "while", "(", "true", ")", "{", "if", "(", "previousX", "<=", "min", "&&", "min", "<=", "nextX", ")", "{", "add", "=", "integral", "(", "0", ",", "min", "-", "previousX", ",", "slope", ",", "previousY", ")", ";", "sumAtMin", "=", "currentValue", "+", "add", ";", "}", "while", "(", "nextX", "-", "max", ">=", "0", ")", "{", "// no overlap with original point, just consume current value", "var", "add", "=", "integral", "(", "0", ",", "max", "-", "previousX", ",", "slope", ",", "previousY", ")", ";", "sumAtMax", "=", "currentValue", "+", "add", ";", "output", "[", "j", "++", "]", "=", "(", "sumAtMax", "-", "sumAtMin", ")", "/", "step", ";", "if", "(", "j", "===", "numberOfPoints", ")", "{", "break", "main", ";", "}", "min", "=", "max", ";", "max", "+=", "step", ";", "sumAtMin", "=", "sumAtMax", ";", "}", "currentValue", "+=", "integral", "(", "previousX", ",", "nextX", ",", "slope", ",", "intercept", ")", ";", "previousX", "=", "nextX", ";", "previousY", "=", "nextY", ";", "if", "(", "i", "<", "xLength", ")", "{", "nextX", "=", "x", "[", "i", "]", ";", "nextY", "=", "y", "[", "i", "]", ";", "i", "++", ";", "}", "else", "if", "(", "i", "===", "xLength", ")", "{", "nextX", "+=", "lastOriginalStep", ";", "nextY", "=", "0", ";", "}", "slope", "=", "getSlope", "(", "previousX", ",", "previousY", ",", "nextX", ",", "nextY", ")", ";", "intercept", "=", "-", "slope", "*", "previousX", "+", "previousY", ";", "}", "return", "output", ";", "}" ]
function that retrieves the getEquallySpacedData with the variant "smooth" @param x @param y @param from - Initial point @param to - Final point @param numberOfPoints @returns {Array} - Array of y's equally spaced with the variant "smooth"
[ "function", "that", "retrieves", "the", "getEquallySpacedData", "with", "the", "variant", "smooth" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L55294-L55369
22,630
repetere/modelscript
build/modelscript.umd.js
getEquallySpacedSlot
function getEquallySpacedSlot(x, y, from, to, numberOfPoints) { var xLength = x.length; var step = (to - from) / (numberOfPoints - 1); var halfStep = step / 2; var lastStep = x[x.length - 1] - x[x.length - 2]; var start = from - halfStep; var output = new Array(numberOfPoints); // Init main variables var min = start; var max = start + step; var previousX = -Number.MAX_VALUE; var previousY = 0; var nextX = x[0]; var nextY = y[0]; var frontOutsideSpectra = 0; var backOutsideSpectra = true; var currentValue = 0; // for slot algorithm var currentPoints = 0; var i = 1; // index of input var j = 0; // index of output main: while (true) { if (previousX >= nextX) throw (new Error('x must be an increasing serie')); while (previousX - max > 0) { // no overlap with original point, just consume current value if (backOutsideSpectra) { currentPoints++; backOutsideSpectra = false; } output[j] = currentPoints <= 0 ? 0 : currentValue / currentPoints; j++; if (j === numberOfPoints) { break main; } min = max; max += step; currentValue = 0; currentPoints = 0; } if (previousX > min) { currentValue += previousY; currentPoints++; } if (previousX === -Number.MAX_VALUE || frontOutsideSpectra > 1) { currentPoints--; } previousX = nextX; previousY = nextY; if (i < xLength) { nextX = x[i]; nextY = y[i]; i++; } else { nextX += lastStep; nextY = 0; frontOutsideSpectra++; } } return output; }
javascript
function getEquallySpacedSlot(x, y, from, to, numberOfPoints) { var xLength = x.length; var step = (to - from) / (numberOfPoints - 1); var halfStep = step / 2; var lastStep = x[x.length - 1] - x[x.length - 2]; var start = from - halfStep; var output = new Array(numberOfPoints); // Init main variables var min = start; var max = start + step; var previousX = -Number.MAX_VALUE; var previousY = 0; var nextX = x[0]; var nextY = y[0]; var frontOutsideSpectra = 0; var backOutsideSpectra = true; var currentValue = 0; // for slot algorithm var currentPoints = 0; var i = 1; // index of input var j = 0; // index of output main: while (true) { if (previousX >= nextX) throw (new Error('x must be an increasing serie')); while (previousX - max > 0) { // no overlap with original point, just consume current value if (backOutsideSpectra) { currentPoints++; backOutsideSpectra = false; } output[j] = currentPoints <= 0 ? 0 : currentValue / currentPoints; j++; if (j === numberOfPoints) { break main; } min = max; max += step; currentValue = 0; currentPoints = 0; } if (previousX > min) { currentValue += previousY; currentPoints++; } if (previousX === -Number.MAX_VALUE || frontOutsideSpectra > 1) { currentPoints--; } previousX = nextX; previousY = nextY; if (i < xLength) { nextX = x[i]; nextY = y[i]; i++; } else { nextX += lastStep; nextY = 0; frontOutsideSpectra++; } } return output; }
[ "function", "getEquallySpacedSlot", "(", "x", ",", "y", ",", "from", ",", "to", ",", "numberOfPoints", ")", "{", "var", "xLength", "=", "x", ".", "length", ";", "var", "step", "=", "(", "to", "-", "from", ")", "/", "(", "numberOfPoints", "-", "1", ")", ";", "var", "halfStep", "=", "step", "/", "2", ";", "var", "lastStep", "=", "x", "[", "x", ".", "length", "-", "1", "]", "-", "x", "[", "x", ".", "length", "-", "2", "]", ";", "var", "start", "=", "from", "-", "halfStep", ";", "var", "output", "=", "new", "Array", "(", "numberOfPoints", ")", ";", "// Init main variables", "var", "min", "=", "start", ";", "var", "max", "=", "start", "+", "step", ";", "var", "previousX", "=", "-", "Number", ".", "MAX_VALUE", ";", "var", "previousY", "=", "0", ";", "var", "nextX", "=", "x", "[", "0", "]", ";", "var", "nextY", "=", "y", "[", "0", "]", ";", "var", "frontOutsideSpectra", "=", "0", ";", "var", "backOutsideSpectra", "=", "true", ";", "var", "currentValue", "=", "0", ";", "// for slot algorithm", "var", "currentPoints", "=", "0", ";", "var", "i", "=", "1", ";", "// index of input", "var", "j", "=", "0", ";", "// index of output", "main", ":", "while", "(", "true", ")", "{", "if", "(", "previousX", ">=", "nextX", ")", "throw", "(", "new", "Error", "(", "'x must be an increasing serie'", ")", ")", ";", "while", "(", "previousX", "-", "max", ">", "0", ")", "{", "// no overlap with original point, just consume current value", "if", "(", "backOutsideSpectra", ")", "{", "currentPoints", "++", ";", "backOutsideSpectra", "=", "false", ";", "}", "output", "[", "j", "]", "=", "currentPoints", "<=", "0", "?", "0", ":", "currentValue", "/", "currentPoints", ";", "j", "++", ";", "if", "(", "j", "===", "numberOfPoints", ")", "{", "break", "main", ";", "}", "min", "=", "max", ";", "max", "+=", "step", ";", "currentValue", "=", "0", ";", "currentPoints", "=", "0", ";", "}", "if", "(", "previousX", ">", "min", ")", "{", "currentValue", "+=", "previousY", ";", "currentPoints", "++", ";", "}", "if", "(", "previousX", "===", "-", "Number", ".", "MAX_VALUE", "||", "frontOutsideSpectra", ">", "1", ")", "{", "currentPoints", "--", ";", "}", "previousX", "=", "nextX", ";", "previousY", "=", "nextY", ";", "if", "(", "i", "<", "xLength", ")", "{", "nextX", "=", "x", "[", "i", "]", ";", "nextY", "=", "y", "[", "i", "]", ";", "i", "++", ";", "}", "else", "{", "nextX", "+=", "lastStep", ";", "nextY", "=", "0", ";", "frontOutsideSpectra", "++", ";", "}", "}", "return", "output", ";", "}" ]
function that retrieves the getEquallySpacedData with the variant "slot" @param x @param y @param from - Initial point @param to - Final point @param numberOfPoints @returns {Array} - Array of y's equally spaced with the variant "slot"
[ "function", "that", "retrieves", "the", "getEquallySpacedData", "with", "the", "variant", "slot" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L55381-L55456
22,631
repetere/modelscript
build/modelscript.umd.js
integral
function integral(x0, x1, slope, intercept) { return (0.5 * slope * x1 * x1 + intercept * x1) - (0.5 * slope * x0 * x0 + intercept * x0); }
javascript
function integral(x0, x1, slope, intercept) { return (0.5 * slope * x1 * x1 + intercept * x1) - (0.5 * slope * x0 * x0 + intercept * x0); }
[ "function", "integral", "(", "x0", ",", "x1", ",", "slope", ",", "intercept", ")", "{", "return", "(", "0.5", "*", "slope", "*", "x1", "*", "x1", "+", "intercept", "*", "x1", ")", "-", "(", "0.5", "*", "slope", "*", "x0", "*", "x0", "+", "intercept", "*", "x0", ")", ";", "}" ]
Function that calculates the integral of the line between two x-coordinates, given the slope and intercept of the line. @param x0 @param x1 @param slope @param intercept @returns {number} integral value.
[ "Function", "that", "calculates", "the", "integral", "of", "the", "line", "between", "two", "x", "-", "coordinates", "given", "the", "slope", "and", "intercept", "of", "the", "line", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L55466-L55468
22,632
repetere/modelscript
build/modelscript.umd.js
baseRange$1
function baseRange$1(start, end, step, fromRight) { var index = -1, length = nativeMax$1(nativeCeil$1((end - start) / (step || 1)), 0), result = Array(length); while (length--) { result[fromRight ? length : ++index] = start; start += step; } return result; }
javascript
function baseRange$1(start, end, step, fromRight) { var index = -1, length = nativeMax$1(nativeCeil$1((end - start) / (step || 1)), 0), result = Array(length); while (length--) { result[fromRight ? length : ++index] = start; start += step; } return result; }
[ "function", "baseRange$1", "(", "start", ",", "end", ",", "step", ",", "fromRight", ")", "{", "var", "index", "=", "-", "1", ",", "length", "=", "nativeMax$1", "(", "nativeCeil$1", "(", "(", "end", "-", "start", ")", "/", "(", "step", "||", "1", ")", ")", ",", "0", ")", ",", "result", "=", "Array", "(", "length", ")", ";", "while", "(", "length", "--", ")", "{", "result", "[", "fromRight", "?", "length", ":", "++", "index", "]", "=", "start", ";", "start", "+=", "step", ";", "}", "return", "result", ";", "}" ]
The base implementation of `_.range` and `_.rangeRight` which doesn't coerce arguments. @private @param {number} start The start of the range. @param {number} end The end of the range. @param {number} step The value to increment or decrement by. @param {boolean} [fromRight] Specify iterating from right to left. @returns {Array} Returns the range of numbers.
[ "The", "base", "implementation", "of", "_", ".", "range", "and", "_", ".", "rangeRight", "which", "doesn", "t", "coerce", "arguments", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L56120-L56130
22,633
repetere/modelscript
build/modelscript.umd.js
coefficientOfCorrelation
function coefficientOfCorrelation(actuals = [], estimates = []) { if (actuals.length !== estimates.length) throw new RangeError('arrays must have the same length'); const sumX = sum(actuals); const sumY = sum(estimates); const sumProdXY = actuals.reduce((result, val, index) => { result = result + (actuals[ index ] * estimates[ index ]); return result; }, 0); const sumXSquared = actuals.reduce((result, val) => { result = result + (val * val); return result; }, 0); const sumYSquared = estimates.reduce((result, val) => { result = result + (val * val); return result; }, 0); const N = actuals.length; const R = ( (N * sumProdXY - sumX * sumY) / Math.sqrt( (N * sumXSquared - Math.pow(sumX, 2)) * (N * sumYSquared - Math.pow(sumY, 2)) ) ); return R; }
javascript
function coefficientOfCorrelation(actuals = [], estimates = []) { if (actuals.length !== estimates.length) throw new RangeError('arrays must have the same length'); const sumX = sum(actuals); const sumY = sum(estimates); const sumProdXY = actuals.reduce((result, val, index) => { result = result + (actuals[ index ] * estimates[ index ]); return result; }, 0); const sumXSquared = actuals.reduce((result, val) => { result = result + (val * val); return result; }, 0); const sumYSquared = estimates.reduce((result, val) => { result = result + (val * val); return result; }, 0); const N = actuals.length; const R = ( (N * sumProdXY - sumX * sumY) / Math.sqrt( (N * sumXSquared - Math.pow(sumX, 2)) * (N * sumYSquared - Math.pow(sumY, 2)) ) ); return R; }
[ "function", "coefficientOfCorrelation", "(", "actuals", "=", "[", "]", ",", "estimates", "=", "[", "]", ")", "{", "if", "(", "actuals", ".", "length", "!==", "estimates", ".", "length", ")", "throw", "new", "RangeError", "(", "'arrays must have the same length'", ")", ";", "const", "sumX", "=", "sum", "(", "actuals", ")", ";", "const", "sumY", "=", "sum", "(", "estimates", ")", ";", "const", "sumProdXY", "=", "actuals", ".", "reduce", "(", "(", "result", ",", "val", ",", "index", ")", "=>", "{", "result", "=", "result", "+", "(", "actuals", "[", "index", "]", "*", "estimates", "[", "index", "]", ")", ";", "return", "result", ";", "}", ",", "0", ")", ";", "const", "sumXSquared", "=", "actuals", ".", "reduce", "(", "(", "result", ",", "val", ")", "=>", "{", "result", "=", "result", "+", "(", "val", "*", "val", ")", ";", "return", "result", ";", "}", ",", "0", ")", ";", "const", "sumYSquared", "=", "estimates", ".", "reduce", "(", "(", "result", ",", "val", ")", "=>", "{", "result", "=", "result", "+", "(", "val", "*", "val", ")", ";", "return", "result", ";", "}", ",", "0", ")", ";", "const", "N", "=", "actuals", ".", "length", ";", "const", "R", "=", "(", "(", "N", "*", "sumProdXY", "-", "sumX", "*", "sumY", ")", "/", "Math", ".", "sqrt", "(", "(", "N", "*", "sumXSquared", "-", "Math", ".", "pow", "(", "sumX", ",", "2", ")", ")", "*", "(", "N", "*", "sumYSquared", "-", "Math", ".", "pow", "(", "sumY", ",", "2", ")", ")", ")", ")", ";", "return", "R", ";", "}" ]
The coefficent of Correlation is given by R decides how well the given data fits a line or a curve. @example const actuals = [ 39, 42, 67, 76, ]; const estimates = [ 44, 40, 60, 84, ]; const R = ms.util.coefficientOfCorrelation(actuals, estimates); R.toFixed(4) // => 0.9408 @memberOf util @see {@link https://calculator.tutorvista.com/r-squared-calculator.html} @param {Number[]} actuals - numerical samples @param {Number[]} estimates - estimates values @returns {Number} R
[ "The", "coefficent", "of", "Correlation", "is", "given", "by", "R", "decides", "how", "well", "the", "given", "data", "fits", "a", "line", "or", "a", "curve", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L56661-L56685
22,634
repetere/modelscript
build/modelscript.umd.js
pivotVector
function pivotVector(vectors=[]) { return vectors.reduce((result, val, index/*, arr*/) => { val.forEach((vecVal, i) => { (index === 0) ? (result.push([vecVal, ])) : (result[ i ].push(vecVal)); }); return result; }, []); }
javascript
function pivotVector(vectors=[]) { return vectors.reduce((result, val, index/*, arr*/) => { val.forEach((vecVal, i) => { (index === 0) ? (result.push([vecVal, ])) : (result[ i ].push(vecVal)); }); return result; }, []); }
[ "function", "pivotVector", "(", "vectors", "=", "[", "]", ")", "{", "return", "vectors", ".", "reduce", "(", "(", "result", ",", "val", ",", "index", "/*, arr*/", ")", "=>", "{", "val", ".", "forEach", "(", "(", "vecVal", ",", "i", ")", "=>", "{", "(", "index", "===", "0", ")", "?", "(", "result", ".", "push", "(", "[", "vecVal", ",", "]", ")", ")", ":", "(", "result", "[", "i", "]", ".", "push", "(", "vecVal", ")", ")", ";", "}", ")", ";", "return", "result", ";", "}", ",", "[", "]", ")", ";", "}" ]
returns an array of vectors as an array of arrays @example const vectors = [ [1,2,3], [1,2,3], [3,3,4], [3,3,3] ]; const arrays = pivotVector(vectors); // => [ [1,2,3,3], [2,2,3,3], [3,3,4,3] ]; @memberOf util @param {Array[]} vectors @returns {Array[]}
[ "returns", "an", "array", "of", "vectors", "as", "an", "array", "of", "arrays" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L56707-L56716
22,635
repetere/modelscript
build/modelscript.umd.js
pivotArrays
function pivotArrays(arrays = []) { return (arrays.length) ? arrays[ 0 ].map((vectorItem, index) => { const returnArray = []; arrays.forEach((v, i) => { returnArray.push(arrays[ i ][ index ]); }); return returnArray; }) : arrays; }
javascript
function pivotArrays(arrays = []) { return (arrays.length) ? arrays[ 0 ].map((vectorItem, index) => { const returnArray = []; arrays.forEach((v, i) => { returnArray.push(arrays[ i ][ index ]); }); return returnArray; }) : arrays; }
[ "function", "pivotArrays", "(", "arrays", "=", "[", "]", ")", "{", "return", "(", "arrays", ".", "length", ")", "?", "arrays", "[", "0", "]", ".", "map", "(", "(", "vectorItem", ",", "index", ")", "=>", "{", "const", "returnArray", "=", "[", "]", ";", "arrays", ".", "forEach", "(", "(", "v", ",", "i", ")", "=>", "{", "returnArray", ".", "push", "(", "arrays", "[", "i", "]", "[", "index", "]", ")", ";", "}", ")", ";", "return", "returnArray", ";", "}", ")", ":", "arrays", ";", "}" ]
returns a matrix of values by combining arrays into a matrix @memberOf util @example const arrays = [ [ 1, 1, 3, 3 ], [ 2, 2, 3, 3 ], [ 3, 3, 4, 3 ], ]; pivotArrays(arrays); //=> [ [1, 2, 3,], [1, 2, 3,], [3, 3, 4,], [3, 3, 3,], ]; @param {Array} [vectors=[]] - array of arguments for columnArray to merge columns into a matrix @returns {Array} a matrix of column values
[ "returns", "a", "matrix", "of", "values", "by", "combining", "arrays", "into", "a", "matrix" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L56737-L56747
22,636
repetere/modelscript
build/modelscript.umd.js
MinMaxScalerTransforms
function MinMaxScalerTransforms(vector = [], nan_value = -1, return_nan=false) { const average = avg$2(vector); const standard_dev = sd(vector); const maximum = max$1(vector); const minimum = min$1(vector); const scale = (z) => { const scaledValue = (z - average) / (maximum - minimum); if (isNaN(scaledValue) && return_nan) return scaledValue; else if (isNaN(scaledValue) && return_nan === false) return (isNaN(standard_dev)) ? z : standard_dev; else return scaledValue; }; // equivalent to MinMaxScaler(z) const descale = (scaledZ) => { const descaledValue = (scaledZ * (maximum - minimum)) + average; if (isNaN(descaledValue) && return_nan) return descaledValue; else if (isNaN(descaledValue) && return_nan === false) return (isNaN(standard_dev)) ? scaledZ : standard_dev; else return descaledValue; }; const values = vector.map(scale) .map(val => { if (isNaN(val)) return nan_value; else return val; }); return { components: { average, standard_dev, maximum, minimum, }, scale, descale, values, }; }
javascript
function MinMaxScalerTransforms(vector = [], nan_value = -1, return_nan=false) { const average = avg$2(vector); const standard_dev = sd(vector); const maximum = max$1(vector); const minimum = min$1(vector); const scale = (z) => { const scaledValue = (z - average) / (maximum - minimum); if (isNaN(scaledValue) && return_nan) return scaledValue; else if (isNaN(scaledValue) && return_nan === false) return (isNaN(standard_dev)) ? z : standard_dev; else return scaledValue; }; // equivalent to MinMaxScaler(z) const descale = (scaledZ) => { const descaledValue = (scaledZ * (maximum - minimum)) + average; if (isNaN(descaledValue) && return_nan) return descaledValue; else if (isNaN(descaledValue) && return_nan === false) return (isNaN(standard_dev)) ? scaledZ : standard_dev; else return descaledValue; }; const values = vector.map(scale) .map(val => { if (isNaN(val)) return nan_value; else return val; }); return { components: { average, standard_dev, maximum, minimum, }, scale, descale, values, }; }
[ "function", "MinMaxScalerTransforms", "(", "vector", "=", "[", "]", ",", "nan_value", "=", "-", "1", ",", "return_nan", "=", "false", ")", "{", "const", "average", "=", "avg$2", "(", "vector", ")", ";", "const", "standard_dev", "=", "sd", "(", "vector", ")", ";", "const", "maximum", "=", "max$1", "(", "vector", ")", ";", "const", "minimum", "=", "min$1", "(", "vector", ")", ";", "const", "scale", "=", "(", "z", ")", "=>", "{", "const", "scaledValue", "=", "(", "z", "-", "average", ")", "/", "(", "maximum", "-", "minimum", ")", ";", "if", "(", "isNaN", "(", "scaledValue", ")", "&&", "return_nan", ")", "return", "scaledValue", ";", "else", "if", "(", "isNaN", "(", "scaledValue", ")", "&&", "return_nan", "===", "false", ")", "return", "(", "isNaN", "(", "standard_dev", ")", ")", "?", "z", ":", "standard_dev", ";", "else", "return", "scaledValue", ";", "}", ";", "// equivalent to MinMaxScaler(z)\r", "const", "descale", "=", "(", "scaledZ", ")", "=>", "{", "const", "descaledValue", "=", "(", "scaledZ", "*", "(", "maximum", "-", "minimum", ")", ")", "+", "average", ";", "if", "(", "isNaN", "(", "descaledValue", ")", "&&", "return_nan", ")", "return", "descaledValue", ";", "else", "if", "(", "isNaN", "(", "descaledValue", ")", "&&", "return_nan", "===", "false", ")", "return", "(", "isNaN", "(", "standard_dev", ")", ")", "?", "scaledZ", ":", "standard_dev", ";", "else", "return", "descaledValue", ";", "}", ";", "const", "values", "=", "vector", ".", "map", "(", "scale", ")", ".", "map", "(", "val", "=>", "{", "if", "(", "isNaN", "(", "val", ")", ")", "return", "nan_value", ";", "else", "return", "val", ";", "}", ")", ";", "return", "{", "components", ":", "{", "average", ",", "standard_dev", ",", "maximum", ",", "minimum", ",", "}", ",", "scale", ",", "descale", ",", "values", ",", "}", ";", "}" ]
This function returns two functions that can mix max scale new inputs and reverse scale new outputs @param {Number[]} values - array of numbers @returns {Object} - {scale[ Function ], descale[ Function ]}
[ "This", "function", "returns", "two", "functions", "that", "can", "mix", "max", "scale", "new", "inputs", "and", "reverse", "scale", "new", "outputs" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L56814-L56847
22,637
repetere/modelscript
build/modelscript.umd.js
approximateZPercentile
function approximateZPercentile(z, alpha=true) { // If z is greater than 6.5 standard deviations from the mean // the number of significant digits will be outside of a reasonable // range. if (z < -6.5) return 0.0; if (z > 6.5) return 1.0; let factK = 1; let sum = 0; let term = 1; let k = 0; let loopStop = Math.exp(-23); while (Math.abs(term) > loopStop) { term = 0.3989422804 * Math.pow(-1, k) * Math.pow(z, k) / (2 * k + 1) / Math.pow(2, k) * Math.pow(z, k + 1) / factK; sum += term; k++; factK *= k; } sum += 0.5; return (alpha) ? 1 - sum : sum; }
javascript
function approximateZPercentile(z, alpha=true) { // If z is greater than 6.5 standard deviations from the mean // the number of significant digits will be outside of a reasonable // range. if (z < -6.5) return 0.0; if (z > 6.5) return 1.0; let factK = 1; let sum = 0; let term = 1; let k = 0; let loopStop = Math.exp(-23); while (Math.abs(term) > loopStop) { term = 0.3989422804 * Math.pow(-1, k) * Math.pow(z, k) / (2 * k + 1) / Math.pow(2, k) * Math.pow(z, k + 1) / factK; sum += term; k++; factK *= k; } sum += 0.5; return (alpha) ? 1 - sum : sum; }
[ "function", "approximateZPercentile", "(", "z", ",", "alpha", "=", "true", ")", "{", "// If z is greater than 6.5 standard deviations from the mean\r", "// the number of significant digits will be outside of a reasonable \r", "// range.\r", "if", "(", "z", "<", "-", "6.5", ")", "return", "0.0", ";", "if", "(", "z", ">", "6.5", ")", "return", "1.0", ";", "let", "factK", "=", "1", ";", "let", "sum", "=", "0", ";", "let", "term", "=", "1", ";", "let", "k", "=", "0", ";", "let", "loopStop", "=", "Math", ".", "exp", "(", "-", "23", ")", ";", "while", "(", "Math", ".", "abs", "(", "term", ")", ">", "loopStop", ")", "{", "term", "=", "0.3989422804", "*", "Math", ".", "pow", "(", "-", "1", ",", "k", ")", "*", "Math", ".", "pow", "(", "z", ",", "k", ")", "/", "(", "2", "*", "k", "+", "1", ")", "/", "Math", ".", "pow", "(", "2", ",", "k", ")", "*", "Math", ".", "pow", "(", "z", ",", "k", "+", "1", ")", "/", "factK", ";", "sum", "+=", "term", ";", "k", "++", ";", "factK", "*=", "k", ";", "}", "sum", "+=", "0.5", ";", "return", "(", "alpha", ")", "?", "1", "-", "sum", ":", "sum", ";", "}" ]
Converts z-score into the probability @memberOf util @see {@link https://stackoverflow.com/questions/36575743/how-do-i-convert-probability-into-z-score} @param {number} z - Number of standard deviations from the mean. @returns {number} p - p-value
[ "Converts", "z", "-", "score", "into", "the", "probability" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L56856-L56883
22,638
repetere/modelscript
build/modelscript.umd.js
trackingSignal
function trackingSignal(actuals, estimates) { const runningSumOfForecastErrors = sum(forecastErrors(actuals, estimates)); const MAD = meanAbsoluteDeviation(actuals, estimates); return runningSumOfForecastErrors / MAD; }
javascript
function trackingSignal(actuals, estimates) { const runningSumOfForecastErrors = sum(forecastErrors(actuals, estimates)); const MAD = meanAbsoluteDeviation(actuals, estimates); return runningSumOfForecastErrors / MAD; }
[ "function", "trackingSignal", "(", "actuals", ",", "estimates", ")", "{", "const", "runningSumOfForecastErrors", "=", "sum", "(", "forecastErrors", "(", "actuals", ",", "estimates", ")", ")", ";", "const", "MAD", "=", "meanAbsoluteDeviation", "(", "actuals", ",", "estimates", ")", ";", "return", "runningSumOfForecastErrors", "/", "MAD", ";", "}" ]
Tracking Signal - Used to pinpoint forecasting models that need adjustment @memberOf util @see {@link https://scm.ncsu.edu/scm-articles/article/measuring-forecast-accuracy-approaches-to-forecasting-a-tutorial} @example const actuals = [ 45, 38, 43, 39 ]; const estimates = [ 41, 43, 41, 42 ]; const trackingSignal = ms.util.trackingSignal(actuals, estimates); trackingSignal.toFixed(2) // => -0.57 @param {Number[]} actuals - numerical samples @param {Number[]} estimates - estimates values @returns {Number} trackingSignal
[ "Tracking", "Signal", "-", "Used", "to", "pinpoint", "forecasting", "models", "that", "need", "adjustment" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L56957-L56961
22,639
repetere/modelscript
build/modelscript.umd.js
FPNode
function FPNode(item, parent) { if (item === void 0) { item = null; } if (parent === void 0) { parent = null; } this.item = item; this.parent = parent; /** * Support of the FPNode. (a.k.a. "count" as defined by Han). */ this.support = 1; /** * nextSameItemNode (a.k.a. "Node-link" as defined by Han): * Links to the next node in the FP-tree carrying the same * item, or null if there is none. */ this.nextSameItemNode = null; /** * PUBLIC READONLY. Children of the FPNode in an array. Empty array if there is none. */ this._children = []; }
javascript
function FPNode(item, parent) { if (item === void 0) { item = null; } if (parent === void 0) { parent = null; } this.item = item; this.parent = parent; /** * Support of the FPNode. (a.k.a. "count" as defined by Han). */ this.support = 1; /** * nextSameItemNode (a.k.a. "Node-link" as defined by Han): * Links to the next node in the FP-tree carrying the same * item, or null if there is none. */ this.nextSameItemNode = null; /** * PUBLIC READONLY. Children of the FPNode in an array. Empty array if there is none. */ this._children = []; }
[ "function", "FPNode", "(", "item", ",", "parent", ")", "{", "if", "(", "item", "===", "void", "0", ")", "{", "item", "=", "null", ";", "}", "if", "(", "parent", "===", "void", "0", ")", "{", "parent", "=", "null", ";", "}", "this", ".", "item", "=", "item", ";", "this", ".", "parent", "=", "parent", ";", "/**\n * Support of the FPNode. (a.k.a. \"count\" as defined by Han).\n */", "this", ".", "support", "=", "1", ";", "/**\n * nextSameItemNode (a.k.a. \"Node-link\" as defined by Han):\n * Links to the next node in the FP-tree carrying the same\n * item, or null if there is none.\n */", "this", ".", "nextSameItemNode", "=", "null", ";", "/**\n * PUBLIC READONLY. Children of the FPNode in an array. Empty array if there is none.\n */", "this", ".", "_children", "=", "[", "]", ";", "}" ]
FPNode composes an FPTree and represents a given item a item-prefix subtree. It keeps track of its parent if it has any, and lists his children FPNodes. @param {T} item The item it represents. @param {FPNode<T>} parent His parent, if it has any.
[ "FPNode", "composes", "an", "FPTree", "and", "represents", "a", "given", "item", "a", "item", "-", "prefix", "subtree", ".", "It", "keeps", "track", "of", "its", "parent", "if", "it", "has", "any", "and", "lists", "his", "children", "FPNodes", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L57078-L57097
22,640
repetere/modelscript
build/modelscript.umd.js
FPTree
function FPTree(supports, _support) { this.supports = supports; this._support = _support; /** * Whether or not the tree has been built */ this._isInit = false; /** * Root node of the FPTree */ this.root = new fpnode.FPNode(); /** * All first nodes (of different items) inserted in the FPTree (Heads of node-links). */ this._firstInserted = {}; /** * All last nodes (of different items) inserted in the FPTree (Foots of node-links). */ this._lastInserted = {}; }
javascript
function FPTree(supports, _support) { this.supports = supports; this._support = _support; /** * Whether or not the tree has been built */ this._isInit = false; /** * Root node of the FPTree */ this.root = new fpnode.FPNode(); /** * All first nodes (of different items) inserted in the FPTree (Heads of node-links). */ this._firstInserted = {}; /** * All last nodes (of different items) inserted in the FPTree (Foots of node-links). */ this._lastInserted = {}; }
[ "function", "FPTree", "(", "supports", ",", "_support", ")", "{", "this", ".", "supports", "=", "supports", ";", "this", ".", "_support", "=", "_support", ";", "/**\n * Whether or not the tree has been built\n */", "this", ".", "_isInit", "=", "false", ";", "/**\n * Root node of the FPTree\n */", "this", ".", "root", "=", "new", "fpnode", ".", "FPNode", "(", ")", ";", "/**\n * All first nodes (of different items) inserted in the FPTree (Heads of node-links).\n */", "this", ".", "_firstInserted", "=", "{", "}", ";", "/**\n * All last nodes (of different items) inserted in the FPTree (Foots of node-links).\n */", "this", ".", "_lastInserted", "=", "{", "}", ";", "}" ]
FPTree is a frequent-pattern tree implementation. It consists in a compact data structure that stores quantitative information about frequent patterns in a set of transactions. @param {ItemsCount} supports The support count of each unique items to be inserted the FPTree. @param {number} support The minimum support of each frequent itemset we want to mine.
[ "FPTree", "is", "a", "frequent", "-", "pattern", "tree", "implementation", ".", "It", "consists", "in", "a", "compact", "data", "structure", "that", "stores", "quantitative", "information", "about", "frequent", "patterns", "in", "a", "set", "of", "transactions", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L57159-L57178
22,641
repetere/modelscript
build/modelscript.umd.js
function(len) { if(len === undefined) len=16; var entropy = fs.randomBytes(len); var result = 0; for(var i=0; i<len; i++) { result = result + Number(entropy[i])/Math.pow(256,(i+1)); } return result }
javascript
function(len) { if(len === undefined) len=16; var entropy = fs.randomBytes(len); var result = 0; for(var i=0; i<len; i++) { result = result + Number(entropy[i])/Math.pow(256,(i+1)); } return result }
[ "function", "(", "len", ")", "{", "if", "(", "len", "===", "undefined", ")", "len", "=", "16", ";", "var", "entropy", "=", "fs", ".", "randomBytes", "(", "len", ")", ";", "var", "result", "=", "0", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "len", ";", "i", "++", ")", "{", "result", "=", "result", "+", "Number", "(", "entropy", "[", "i", "]", ")", "/", "Math", ".", "pow", "(", "256", ",", "(", "i", "+", "1", ")", ")", ";", "}", "return", "result", "}" ]
This is the core function for generating entropy @param len number of bytes of entropy to create @returns {number} A pseduo random number between 0 and 1
[ "This", "is", "the", "core", "function", "for", "generating", "entropy" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L57731-L57741
22,642
repetere/modelscript
build/modelscript.umd.js
function(n, loc, scale) { n = this._v(n, "n"); loc = this._v(loc, "r", 0); scale = this._v(scale, "nn", 1); var toReturn = []; for(var i=0; i<n; i++) { var core = this.sample([-1,1])[0] * ln(this.prng()); var x = loc - scale * core; toReturn[i] = x; } return toReturn }
javascript
function(n, loc, scale) { n = this._v(n, "n"); loc = this._v(loc, "r", 0); scale = this._v(scale, "nn", 1); var toReturn = []; for(var i=0; i<n; i++) { var core = this.sample([-1,1])[0] * ln(this.prng()); var x = loc - scale * core; toReturn[i] = x; } return toReturn }
[ "function", "(", "n", ",", "loc", ",", "scale", ")", "{", "n", "=", "this", ".", "_v", "(", "n", ",", "\"n\"", ")", ";", "loc", "=", "this", ".", "_v", "(", "loc", ",", "\"r\"", ",", "0", ")", ";", "scale", "=", "this", ".", "_v", "(", "scale", ",", "\"nn\"", ",", "1", ")", ";", "var", "toReturn", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "var", "core", "=", "this", ".", "sample", "(", "[", "-", "1", ",", "1", "]", ")", "[", "0", "]", "*", "ln", "(", "this", ".", "prng", "(", ")", ")", ";", "var", "x", "=", "loc", "-", "scale", "*", "core", ";", "toReturn", "[", "i", "]", "=", "x", ";", "}", "return", "toReturn", "}" ]
Syntax as in R library VGAM @param n The number of random variates to create. Must be a positive integer @param loc Mean @param scale Scale parameter @returns {Array} Random variates array
[ "Syntax", "as", "in", "R", "library", "VGAM" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L58026-L58042
22,643
repetere/modelscript
build/modelscript.umd.js
function(x, min, max) { x = this._v(x, "r"); min = this._v(min, "r", 0); max = this._v(max, "r", 1); if(min > max) throw new Error("Minimum value cannot be greater than maximum value"); if(x < min || x > max) return 0; if(min === max) return Infinity; return 1/(max-min); }
javascript
function(x, min, max) { x = this._v(x, "r"); min = this._v(min, "r", 0); max = this._v(max, "r", 1); if(min > max) throw new Error("Minimum value cannot be greater than maximum value"); if(x < min || x > max) return 0; if(min === max) return Infinity; return 1/(max-min); }
[ "function", "(", "x", ",", "min", ",", "max", ")", "{", "x", "=", "this", ".", "_v", "(", "x", ",", "\"r\"", ")", ";", "min", "=", "this", ".", "_v", "(", "min", ",", "\"r\"", ",", "0", ")", ";", "max", "=", "this", ".", "_v", "(", "max", ",", "\"r\"", ",", "1", ")", ";", "if", "(", "min", ">", "max", ")", "throw", "new", "Error", "(", "\"Minimum value cannot be greater than maximum value\"", ")", ";", "if", "(", "x", "<", "min", "||", "x", ">", "max", ")", "return", "0", ";", "if", "(", "min", "===", "max", ")", "return", "Infinity", ";", "return", "1", "/", "(", "max", "-", "min", ")", ";", "}" ]
Density function for uniform distribution @param x Location to get density for @param min {number} Minimum value @param max {number} Maximum value @returns {number} Density of the function given the location and parameters
[ "Density", "function", "for", "uniform", "distribution" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L58244-L58255
22,644
repetere/modelscript
build/modelscript.umd.js
function(len, alphabet) { len = this._v(len, "n"); alphabet = this._v(alphabet, "str", "abcdefghijklmnopqrstuvwxyz"); var lib = alphabet.split(""); var arr = this.sample(lib, len, true); return arr.join(""); }
javascript
function(len, alphabet) { len = this._v(len, "n"); alphabet = this._v(alphabet, "str", "abcdefghijklmnopqrstuvwxyz"); var lib = alphabet.split(""); var arr = this.sample(lib, len, true); return arr.join(""); }
[ "function", "(", "len", ",", "alphabet", ")", "{", "len", "=", "this", ".", "_v", "(", "len", ",", "\"n\"", ")", ";", "alphabet", "=", "this", ".", "_v", "(", "alphabet", ",", "\"str\"", ",", "\"abcdefghijklmnopqrstuvwxyz\"", ")", ";", "var", "lib", "=", "alphabet", ".", "split", "(", "\"\"", ")", ";", "var", "arr", "=", "this", ".", "sample", "(", "lib", ",", "len", ",", "true", ")", ";", "return", "arr", ".", "join", "(", "\"\"", ")", ";", "}" ]
Generate a random word of specified length using library of characters. Uses English alphabet if no library is specified @param len Number of letters in this word @param {string} alphabet to use @returns {string} String of randomly selected characters from the alphabet
[ "Generate", "a", "random", "word", "of", "specified", "length", "using", "library", "of", "characters", ".", "Uses", "English", "alphabet", "if", "no", "library", "is", "specified" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L58287-L58295
22,645
repetere/modelscript
build/modelscript.umd.js
flip
function flip(obj) { var newObj = Object.create(null), key; for (key in obj) { newObj[obj[key]] = key; } return newObj; }
javascript
function flip(obj) { var newObj = Object.create(null), key; for (key in obj) { newObj[obj[key]] = key; } return newObj; }
[ "function", "flip", "(", "obj", ")", "{", "var", "newObj", "=", "Object", ".", "create", "(", "null", ")", ",", "key", ";", "for", "(", "key", "in", "obj", ")", "{", "newObj", "[", "obj", "[", "key", "]", "]", "=", "key", ";", "}", "return", "newObj", ";", "}" ]
Exchanges all keys with their associated values in an object. @param {Object.<string, string>} obj An object of strings. @return {Object.<string, string>} An object of strings.
[ "Exchanges", "all", "keys", "with", "their", "associated", "values", "in", "an", "object", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L68192-L68201
22,646
repetere/modelscript
build/modelscript.umd.js
merge
function merge(var_args) { var args = [].slice.call(arguments), newObj = Object.create(null), id = 0, key; while (args[id]) { for (key in args[id]) { newObj[key] = args[id][key]; } id++; } return newObj; }
javascript
function merge(var_args) { var args = [].slice.call(arguments), newObj = Object.create(null), id = 0, key; while (args[id]) { for (key in args[id]) { newObj[key] = args[id][key]; } id++; } return newObj; }
[ "function", "merge", "(", "var_args", ")", "{", "var", "args", "=", "[", "]", ".", "slice", ".", "call", "(", "arguments", ")", ",", "newObj", "=", "Object", ".", "create", "(", "null", ")", ",", "id", "=", "0", ",", "key", ";", "while", "(", "args", "[", "id", "]", ")", "{", "for", "(", "key", "in", "args", "[", "id", "]", ")", "{", "newObj", "[", "key", "]", "=", "args", "[", "id", "]", "[", "key", "]", ";", "}", "id", "++", ";", "}", "return", "newObj", ";", "}" ]
Merge several objects. Properties from earlier objects are overwritten by laters's in case of conflict. @param {...Object.<string, string>} var_args One or more objects of strings. @return {!Object.<string, string>} An object of strings.
[ "Merge", "several", "objects", ".", "Properties", "from", "earlier", "objects", "are", "overwritten", "by", "laters", "s", "in", "case", "of", "conflict", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L68211-L68225
22,647
repetere/modelscript
build/modelscript.umd.js
stemmingProcess
function stemmingProcess(){ if(find(current_word)) return // Confix Stripping // Try to remove prefixes first before suffixes if the specification is met if(precedenceAdjustmentSpecification(original_word)){ // Step 4, 5 removePrefixes(); if(find(current_word)) return // Step 2, 3 removeSuffixes(); if(find(current_word)){ return } else{ // if the trial is failed, restore the original word // and continue to normal rule precedence (suffix first, prefix afterwards) current_word = original_word; removals = []; } } // Step 2, 3 removeSuffixes(); if(find(current_word)) return // Step 4, 5 removePrefixes(); if(find(current_word)) return //ECS Loop Restore Prefixes loopRestorePrefixes(); }
javascript
function stemmingProcess(){ if(find(current_word)) return // Confix Stripping // Try to remove prefixes first before suffixes if the specification is met if(precedenceAdjustmentSpecification(original_word)){ // Step 4, 5 removePrefixes(); if(find(current_word)) return // Step 2, 3 removeSuffixes(); if(find(current_word)){ return } else{ // if the trial is failed, restore the original word // and continue to normal rule precedence (suffix first, prefix afterwards) current_word = original_word; removals = []; } } // Step 2, 3 removeSuffixes(); if(find(current_word)) return // Step 4, 5 removePrefixes(); if(find(current_word)) return //ECS Loop Restore Prefixes loopRestorePrefixes(); }
[ "function", "stemmingProcess", "(", ")", "{", "if", "(", "find", "(", "current_word", ")", ")", "return", "// Confix Stripping", "// Try to remove prefixes first before suffixes if the specification is met", "if", "(", "precedenceAdjustmentSpecification", "(", "original_word", ")", ")", "{", "// Step 4, 5", "removePrefixes", "(", ")", ";", "if", "(", "find", "(", "current_word", ")", ")", "return", "// Step 2, 3", "removeSuffixes", "(", ")", ";", "if", "(", "find", "(", "current_word", ")", ")", "{", "return", "}", "else", "{", "// if the trial is failed, restore the original word", "// and continue to normal rule precedence (suffix first, prefix afterwards)", "current_word", "=", "original_word", ";", "removals", "=", "[", "]", ";", "}", "}", "// Step 2, 3", "removeSuffixes", "(", ")", ";", "if", "(", "find", "(", "current_word", ")", ")", "return", "// Step 4, 5", "removePrefixes", "(", ")", ";", "if", "(", "find", "(", "current_word", ")", ")", "return", "//ECS Loop Restore Prefixes", "loopRestorePrefixes", "(", ")", ";", "}" ]
Stemming from step 2-5
[ "Stemming", "from", "step", "2", "-", "5" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L70896-L70933
22,648
repetere/modelscript
build/modelscript.umd.js
createPredicateIndexFinder
function createPredicateIndexFinder(dir) { return function(array, predicate, context) { predicate = cb(predicate, context); var length = getLength(array); var index = dir > 0 ? 0 : length - 1; for (; index >= 0 && index < length; index += dir) { if (predicate(array[index], index, array)) return index; } return -1; }; }
javascript
function createPredicateIndexFinder(dir) { return function(array, predicate, context) { predicate = cb(predicate, context); var length = getLength(array); var index = dir > 0 ? 0 : length - 1; for (; index >= 0 && index < length; index += dir) { if (predicate(array[index], index, array)) return index; } return -1; }; }
[ "function", "createPredicateIndexFinder", "(", "dir", ")", "{", "return", "function", "(", "array", ",", "predicate", ",", "context", ")", "{", "predicate", "=", "cb", "(", "predicate", ",", "context", ")", ";", "var", "length", "=", "getLength", "(", "array", ")", ";", "var", "index", "=", "dir", ">", "0", "?", "0", ":", "length", "-", "1", ";", "for", "(", ";", "index", ">=", "0", "&&", "index", "<", "length", ";", "index", "+=", "dir", ")", "{", "if", "(", "predicate", "(", "array", "[", "index", "]", ",", "index", ",", "array", ")", ")", "return", "index", ";", "}", "return", "-", "1", ";", "}", ";", "}" ]
Generator function to create the findIndex and findLastIndex functions
[ "Generator", "function", "to", "create", "the", "findIndex", "and", "findLastIndex", "functions" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L71768-L71778
22,649
repetere/modelscript
build/modelscript.umd.js
function(sourceFunc, boundFunc, context, callingContext, args) { if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args); var self = baseCreate(sourceFunc.prototype); var result = sourceFunc.apply(self, args); if (_.isObject(result)) return result; return self; }
javascript
function(sourceFunc, boundFunc, context, callingContext, args) { if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args); var self = baseCreate(sourceFunc.prototype); var result = sourceFunc.apply(self, args); if (_.isObject(result)) return result; return self; }
[ "function", "(", "sourceFunc", ",", "boundFunc", ",", "context", ",", "callingContext", ",", "args", ")", "{", "if", "(", "!", "(", "callingContext", "instanceof", "boundFunc", ")", ")", "return", "sourceFunc", ".", "apply", "(", "context", ",", "args", ")", ";", "var", "self", "=", "baseCreate", "(", "sourceFunc", ".", "prototype", ")", ";", "var", "result", "=", "sourceFunc", ".", "apply", "(", "self", ",", "args", ")", ";", "if", "(", "_", ".", "isObject", "(", "result", ")", ")", "return", "result", ";", "return", "self", ";", "}" ]
Determines whether to execute a function as a constructor or a normal function with the provided arguments
[ "Determines", "whether", "to", "execute", "a", "function", "as", "a", "constructor", "or", "a", "normal", "function", "with", "the", "provided", "arguments" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L71854-L71860
22,650
repetere/modelscript
build/modelscript.umd.js
svdJs
function svdJs() { var A = this; var V = Matrix$b.I(A.rows()); var S = A.transpose(); var U = Matrix$b.I(A.cols()); var err = Number.MAX_VALUE; var i = 0; var maxLoop = 100; while(err > 2.2737e-13 && i < maxLoop) { var qr = S.transpose().qrJs(); S = qr.R; V = V.x(qr.Q); qr = S.transpose().qrJs(); U = U.x(qr.Q); S = qr.R; var e = S.triu(1).unroll().norm(); var f = S.diagonal().norm(); if(f == 0) f = 1; err = e / f; i++; } var ss = S.diagonal(); var s = []; for(var i = 1; i <= ss.cols(); i++) { var ssn = ss.e(i); s.push(Math.abs(ssn)); if(ssn < 0) { for(var j = 0; j < U.rows(); j++) { V.elements[j][i - 1] = -(V.elements[j][i - 1]); } } } return {U: U, S: $V(s).toDiagonalMatrix(), V: V}; }
javascript
function svdJs() { var A = this; var V = Matrix$b.I(A.rows()); var S = A.transpose(); var U = Matrix$b.I(A.cols()); var err = Number.MAX_VALUE; var i = 0; var maxLoop = 100; while(err > 2.2737e-13 && i < maxLoop) { var qr = S.transpose().qrJs(); S = qr.R; V = V.x(qr.Q); qr = S.transpose().qrJs(); U = U.x(qr.Q); S = qr.R; var e = S.triu(1).unroll().norm(); var f = S.diagonal().norm(); if(f == 0) f = 1; err = e / f; i++; } var ss = S.diagonal(); var s = []; for(var i = 1; i <= ss.cols(); i++) { var ssn = ss.e(i); s.push(Math.abs(ssn)); if(ssn < 0) { for(var j = 0; j < U.rows(); j++) { V.elements[j][i - 1] = -(V.elements[j][i - 1]); } } } return {U: U, S: $V(s).toDiagonalMatrix(), V: V}; }
[ "function", "svdJs", "(", ")", "{", "var", "A", "=", "this", ";", "var", "V", "=", "Matrix$b", ".", "I", "(", "A", ".", "rows", "(", ")", ")", ";", "var", "S", "=", "A", ".", "transpose", "(", ")", ";", "var", "U", "=", "Matrix$b", ".", "I", "(", "A", ".", "cols", "(", ")", ")", ";", "var", "err", "=", "Number", ".", "MAX_VALUE", ";", "var", "i", "=", "0", ";", "var", "maxLoop", "=", "100", ";", "while", "(", "err", ">", "2.2737e-13", "&&", "i", "<", "maxLoop", ")", "{", "var", "qr", "=", "S", ".", "transpose", "(", ")", ".", "qrJs", "(", ")", ";", "S", "=", "qr", ".", "R", ";", "V", "=", "V", ".", "x", "(", "qr", ".", "Q", ")", ";", "qr", "=", "S", ".", "transpose", "(", ")", ".", "qrJs", "(", ")", ";", "U", "=", "U", ".", "x", "(", "qr", ".", "Q", ")", ";", "S", "=", "qr", ".", "R", ";", "var", "e", "=", "S", ".", "triu", "(", "1", ")", ".", "unroll", "(", ")", ".", "norm", "(", ")", ";", "var", "f", "=", "S", ".", "diagonal", "(", ")", ".", "norm", "(", ")", ";", "if", "(", "f", "==", "0", ")", "f", "=", "1", ";", "err", "=", "e", "/", "f", ";", "i", "++", ";", "}", "var", "ss", "=", "S", ".", "diagonal", "(", ")", ";", "var", "s", "=", "[", "]", ";", "for", "(", "var", "i", "=", "1", ";", "i", "<=", "ss", ".", "cols", "(", ")", ";", "i", "++", ")", "{", "var", "ssn", "=", "ss", ".", "e", "(", "i", ")", ";", "s", ".", "push", "(", "Math", ".", "abs", "(", "ssn", ")", ")", ";", "if", "(", "ssn", "<", "0", ")", "{", "for", "(", "var", "j", "=", "0", ";", "j", "<", "U", ".", "rows", "(", ")", ";", "j", "++", ")", "{", "V", ".", "elements", "[", "j", "]", "[", "i", "-", "1", "]", "=", "-", "(", "V", ".", "elements", "[", "j", "]", "[", "i", "-", "1", "]", ")", ";", "}", "}", "}", "return", "{", "U", ":", "U", ",", "S", ":", "$V", "(", "s", ")", ".", "toDiagonalMatrix", "(", ")", ",", "V", ":", "V", "}", ";", "}" ]
singular value decomposition in pure javascript
[ "singular", "value", "decomposition", "in", "pure", "javascript" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74021-L74064
22,651
repetere/modelscript
build/modelscript.umd.js
svdPack
function svdPack() { var result = lapack$1.sgesvd('A', 'A', this.elements); return { U: $M(result.U), S: $M(result.S).column(1).toDiagonalMatrix(), V: $M(result.VT).transpose() }; }
javascript
function svdPack() { var result = lapack$1.sgesvd('A', 'A', this.elements); return { U: $M(result.U), S: $M(result.S).column(1).toDiagonalMatrix(), V: $M(result.VT).transpose() }; }
[ "function", "svdPack", "(", ")", "{", "var", "result", "=", "lapack$1", ".", "sgesvd", "(", "'A'", ",", "'A'", ",", "this", ".", "elements", ")", ";", "return", "{", "U", ":", "$M", "(", "result", ".", "U", ")", ",", "S", ":", "$M", "(", "result", ".", "S", ")", ".", "column", "(", "1", ")", ".", "toDiagonalMatrix", "(", ")", ",", "V", ":", "$M", "(", "result", ".", "VT", ")", ".", "transpose", "(", ")", "}", ";", "}" ]
singular value decomposition using LAPACK
[ "singular", "value", "decomposition", "using", "LAPACK" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74067-L74075
22,652
repetere/modelscript
build/modelscript.umd.js
qrJs
function qrJs() { var m = this.rows(); var n = this.cols(); var Q = Matrix$b.I(m); var A = this; for(var k = 1; k < Math.min(m, n); k++) { var ak = A.slice(k, 0, k, k).col(1); var oneZero = [1]; while(oneZero.length <= m - k) oneZero.push(0); oneZero = $V(oneZero); var vk = ak.add(oneZero.x(ak.norm() * Math.sign(ak.e(1)))); var Vk = $M(vk); var Hk = Matrix$b.I(m - k + 1).subtract(Vk.x(2).x(Vk.transpose()).div(Vk.transpose().x(Vk).e(1, 1))); var Qk = identSize(Hk, m, n, k); A = Qk.x(A); // slow way to compute Q Q = Q.x(Qk); } return {Q: Q, R: A}; }
javascript
function qrJs() { var m = this.rows(); var n = this.cols(); var Q = Matrix$b.I(m); var A = this; for(var k = 1; k < Math.min(m, n); k++) { var ak = A.slice(k, 0, k, k).col(1); var oneZero = [1]; while(oneZero.length <= m - k) oneZero.push(0); oneZero = $V(oneZero); var vk = ak.add(oneZero.x(ak.norm() * Math.sign(ak.e(1)))); var Vk = $M(vk); var Hk = Matrix$b.I(m - k + 1).subtract(Vk.x(2).x(Vk.transpose()).div(Vk.transpose().x(Vk).e(1, 1))); var Qk = identSize(Hk, m, n, k); A = Qk.x(A); // slow way to compute Q Q = Q.x(Qk); } return {Q: Q, R: A}; }
[ "function", "qrJs", "(", ")", "{", "var", "m", "=", "this", ".", "rows", "(", ")", ";", "var", "n", "=", "this", ".", "cols", "(", ")", ";", "var", "Q", "=", "Matrix$b", ".", "I", "(", "m", ")", ";", "var", "A", "=", "this", ";", "for", "(", "var", "k", "=", "1", ";", "k", "<", "Math", ".", "min", "(", "m", ",", "n", ")", ";", "k", "++", ")", "{", "var", "ak", "=", "A", ".", "slice", "(", "k", ",", "0", ",", "k", ",", "k", ")", ".", "col", "(", "1", ")", ";", "var", "oneZero", "=", "[", "1", "]", ";", "while", "(", "oneZero", ".", "length", "<=", "m", "-", "k", ")", "oneZero", ".", "push", "(", "0", ")", ";", "oneZero", "=", "$V", "(", "oneZero", ")", ";", "var", "vk", "=", "ak", ".", "add", "(", "oneZero", ".", "x", "(", "ak", ".", "norm", "(", ")", "*", "Math", ".", "sign", "(", "ak", ".", "e", "(", "1", ")", ")", ")", ")", ";", "var", "Vk", "=", "$M", "(", "vk", ")", ";", "var", "Hk", "=", "Matrix$b", ".", "I", "(", "m", "-", "k", "+", "1", ")", ".", "subtract", "(", "Vk", ".", "x", "(", "2", ")", ".", "x", "(", "Vk", ".", "transpose", "(", ")", ")", ".", "div", "(", "Vk", ".", "transpose", "(", ")", ".", "x", "(", "Vk", ")", ".", "e", "(", "1", ",", "1", ")", ")", ")", ";", "var", "Qk", "=", "identSize", "(", "Hk", ",", "m", ",", "n", ",", "k", ")", ";", "A", "=", "Qk", ".", "x", "(", "A", ")", ";", "// slow way to compute Q", "Q", "=", "Q", ".", "x", "(", "Qk", ")", ";", "}", "return", "{", "Q", ":", "Q", ",", "R", ":", "A", "}", ";", "}" ]
QR decomposition in pure javascript
[ "QR", "decomposition", "in", "pure", "javascript" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74078-L74102
22,653
repetere/modelscript
build/modelscript.umd.js
qrPack
function qrPack() { var qr = lapack$1.qr(this.elements); return { Q: $M(qr.Q), R: $M(qr.R) }; }
javascript
function qrPack() { var qr = lapack$1.qr(this.elements); return { Q: $M(qr.Q), R: $M(qr.R) }; }
[ "function", "qrPack", "(", ")", "{", "var", "qr", "=", "lapack$1", ".", "qr", "(", "this", ".", "elements", ")", ";", "return", "{", "Q", ":", "$M", "(", "qr", ".", "Q", ")", ",", "R", ":", "$M", "(", "qr", ".", "R", ")", "}", ";", "}" ]
QR decomposition using LAPACK
[ "QR", "decomposition", "using", "LAPACK" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74105-L74112
22,654
repetere/modelscript
build/modelscript.umd.js
function(k, U) { var U = U || pca$1(this).U; var Ureduce= U.slice(1, U.rows(), 1, k); return {Z: this.x(Ureduce), U: U}; }
javascript
function(k, U) { var U = U || pca$1(this).U; var Ureduce= U.slice(1, U.rows(), 1, k); return {Z: this.x(Ureduce), U: U}; }
[ "function", "(", "k", ",", "U", ")", "{", "var", "U", "=", "U", "||", "pca$1", "(", "this", ")", ".", "U", ";", "var", "Ureduce", "=", "U", ".", "slice", "(", "1", ",", "U", ".", "rows", "(", ")", ",", "1", ",", "k", ")", ";", "return", "{", "Z", ":", "this", ".", "x", "(", "Ureduce", ")", ",", "U", ":", "U", "}", ";", "}" ]
project a matrix onto a lower dim
[ "project", "a", "matrix", "onto", "a", "lower", "dim" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74127-L74131
22,655
repetere/modelscript
build/modelscript.umd.js
function(U) { var k = this.cols(); var Ureduce = U.slice(1, U.rows(), 1, k); return this.x(Ureduce.transpose()); }
javascript
function(U) { var k = this.cols(); var Ureduce = U.slice(1, U.rows(), 1, k); return this.x(Ureduce.transpose()); }
[ "function", "(", "U", ")", "{", "var", "k", "=", "this", ".", "cols", "(", ")", ";", "var", "Ureduce", "=", "U", ".", "slice", "(", "1", ",", "U", ".", "rows", "(", ")", ",", "1", ",", "k", ")", ";", "return", "this", ".", "x", "(", "Ureduce", ".", "transpose", "(", ")", ")", ";", "}" ]
recover a matrix to a higher dimension
[ "recover", "a", "matrix", "to", "a", "higher", "dimension" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74134-L74138
22,656
repetere/modelscript
build/modelscript.umd.js
function(k) { if(!k) k = 0; return this.map(function(x, i, j) { return j - i >= k ? x : 0; }); }
javascript
function(k) { if(!k) k = 0; return this.map(function(x, i, j) { return j - i >= k ? x : 0; }); }
[ "function", "(", "k", ")", "{", "if", "(", "!", "k", ")", "k", "=", "0", ";", "return", "this", ".", "map", "(", "function", "(", "x", ",", "i", ",", "j", ")", "{", "return", "j", "-", "i", ">=", "k", "?", "x", ":", "0", ";", "}", ")", ";", "}" ]
grab the upper triangular part of the matrix
[ "grab", "the", "upper", "triangular", "part", "of", "the", "matrix" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74141-L74148
22,657
repetere/modelscript
build/modelscript.umd.js
function() { var v = []; for(var i = 1; i <= this.cols(); i++) { for(var j = 1; j <= this.rows(); j++) { v.push(this.e(j, i)); } } return $V(v); }
javascript
function() { var v = []; for(var i = 1; i <= this.cols(); i++) { for(var j = 1; j <= this.rows(); j++) { v.push(this.e(j, i)); } } return $V(v); }
[ "function", "(", ")", "{", "var", "v", "=", "[", "]", ";", "for", "(", "var", "i", "=", "1", ";", "i", "<=", "this", ".", "cols", "(", ")", ";", "i", "++", ")", "{", "for", "(", "var", "j", "=", "1", ";", "j", "<=", "this", ".", "rows", "(", ")", ";", "j", "++", ")", "{", "v", ".", "push", "(", "this", ".", "e", "(", "j", ",", "i", ")", ")", ";", "}", "}", "return", "$V", "(", "v", ")", ";", "}" ]
unroll a matrix into a vector
[ "unroll", "a", "matrix", "into", "a", "vector" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74151-L74161
22,658
repetere/modelscript
build/modelscript.umd.js
function(startRow, endRow, startCol, endCol) { var x = []; if(endRow == 0) endRow = this.rows(); if(endCol == 0) endCol = this.cols(); for(i = startRow; i <= endRow; i++) { var row = []; for(j = startCol; j <= endCol; j++) { row.push(this.e(i, j)); } x.push(row); } return $M(x); }
javascript
function(startRow, endRow, startCol, endCol) { var x = []; if(endRow == 0) endRow = this.rows(); if(endCol == 0) endCol = this.cols(); for(i = startRow; i <= endRow; i++) { var row = []; for(j = startCol; j <= endCol; j++) { row.push(this.e(i, j)); } x.push(row); } return $M(x); }
[ "function", "(", "startRow", ",", "endRow", ",", "startCol", ",", "endCol", ")", "{", "var", "x", "=", "[", "]", ";", "if", "(", "endRow", "==", "0", ")", "endRow", "=", "this", ".", "rows", "(", ")", ";", "if", "(", "endCol", "==", "0", ")", "endCol", "=", "this", ".", "cols", "(", ")", ";", "for", "(", "i", "=", "startRow", ";", "i", "<=", "endRow", ";", "i", "++", ")", "{", "var", "row", "=", "[", "]", ";", "for", "(", "j", "=", "startCol", ";", "j", "<=", "endCol", ";", "j", "++", ")", "{", "row", ".", "push", "(", "this", ".", "e", "(", "i", ",", "j", ")", ")", ";", "}", "x", ".", "push", "(", "row", ")", ";", "}", "return", "$M", "(", "x", ")", ";", "}" ]
return a sub-block of the matrix
[ "return", "a", "sub", "-", "block", "of", "the", "matrix" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74164-L74184
22,659
repetere/modelscript
build/modelscript.umd.js
function(matrix) { if(typeof(matrix) == 'number') { return this.map(function(x, i, j) { return x + matrix}); } else { var M = matrix.elements || matrix; if (typeof(M[0][0]) == 'undefined') { M = Matrix$b.create(M).elements; } if (!this.isSameSizeAs(M)) { return null; } return this.map(function(x, i, j) { return x + M[i - 1][j - 1]; }); } }
javascript
function(matrix) { if(typeof(matrix) == 'number') { return this.map(function(x, i, j) { return x + matrix}); } else { var M = matrix.elements || matrix; if (typeof(M[0][0]) == 'undefined') { M = Matrix$b.create(M).elements; } if (!this.isSameSizeAs(M)) { return null; } return this.map(function(x, i, j) { return x + M[i - 1][j - 1]; }); } }
[ "function", "(", "matrix", ")", "{", "if", "(", "typeof", "(", "matrix", ")", "==", "'number'", ")", "{", "return", "this", ".", "map", "(", "function", "(", "x", ",", "i", ",", "j", ")", "{", "return", "x", "+", "matrix", "}", ")", ";", "}", "else", "{", "var", "M", "=", "matrix", ".", "elements", "||", "matrix", ";", "if", "(", "typeof", "(", "M", "[", "0", "]", "[", "0", "]", ")", "==", "'undefined'", ")", "{", "M", "=", "Matrix$b", ".", "create", "(", "M", ")", ".", "elements", ";", "}", "if", "(", "!", "this", ".", "isSameSizeAs", "(", "M", ")", ")", "{", "return", "null", ";", "}", "return", "this", ".", "map", "(", "function", "(", "x", ",", "i", ",", "j", ")", "{", "return", "x", "+", "M", "[", "i", "-", "1", "]", "[", "j", "-", "1", "]", ";", "}", ")", ";", "}", "}" ]
Returns the result of adding the argument to the matrix
[ "Returns", "the", "result", "of", "adding", "the", "argument", "to", "the", "matrix" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74268-L74277
22,660
repetere/modelscript
build/modelscript.umd.js
function() { var dim = this.dimensions(); var r = []; for (var i = 1; i <= dim.cols; i++) { r.push(this.col(i).sum() / dim.rows); } return $V(r); }
javascript
function() { var dim = this.dimensions(); var r = []; for (var i = 1; i <= dim.cols; i++) { r.push(this.col(i).sum() / dim.rows); } return $V(r); }
[ "function", "(", ")", "{", "var", "dim", "=", "this", ".", "dimensions", "(", ")", ";", "var", "r", "=", "[", "]", ";", "for", "(", "var", "i", "=", "1", ";", "i", "<=", "dim", ".", "cols", ";", "i", "++", ")", "{", "r", ".", "push", "(", "this", ".", "col", "(", "i", ")", ".", "sum", "(", ")", "/", "dim", ".", "rows", ")", ";", "}", "return", "$V", "(", "r", ")", ";", "}" ]
Returns a Vector of each colum averaged.
[ "Returns", "a", "Vector", "of", "each", "colum", "averaged", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74374-L74381
22,661
repetere/modelscript
build/modelscript.umd.js
function() { var matrix_rows = []; var n = this.elements.length; for (var i = 0; i < n; i++) { matrix_rows.push(this.elements[i]); } return matrix_rows; }
javascript
function() { var matrix_rows = []; var n = this.elements.length; for (var i = 0; i < n; i++) { matrix_rows.push(this.elements[i]); } return matrix_rows; }
[ "function", "(", ")", "{", "var", "matrix_rows", "=", "[", "]", ";", "var", "n", "=", "this", ".", "elements", ".", "length", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "matrix_rows", ".", "push", "(", "this", ".", "elements", "[", "i", "]", ")", ";", "}", "return", "matrix_rows", ";", "}" ]
Returns a array representation of the matrix
[ "Returns", "a", "array", "representation", "of", "the", "matrix" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74625-L74632
22,662
repetere/modelscript
build/modelscript.umd.js
function() { var maxes = []; for(var i = 1; i <= this.rows(); i++) { var max = null; var maxIndex = -1; for(var j = 1; j <= this.cols(); j++) { if(max === null || this.e(i, j) > max) { max = this.e(i, j); maxIndex = j; } } maxes.push(maxIndex); } return $V(maxes); }
javascript
function() { var maxes = []; for(var i = 1; i <= this.rows(); i++) { var max = null; var maxIndex = -1; for(var j = 1; j <= this.cols(); j++) { if(max === null || this.e(i, j) > max) { max = this.e(i, j); maxIndex = j; } } maxes.push(maxIndex); } return $V(maxes); }
[ "function", "(", ")", "{", "var", "maxes", "=", "[", "]", ";", "for", "(", "var", "i", "=", "1", ";", "i", "<=", "this", ".", "rows", "(", ")", ";", "i", "++", ")", "{", "var", "max", "=", "null", ";", "var", "maxIndex", "=", "-", "1", ";", "for", "(", "var", "j", "=", "1", ";", "j", "<=", "this", ".", "cols", "(", ")", ";", "j", "++", ")", "{", "if", "(", "max", "===", "null", "||", "this", ".", "e", "(", "i", ",", "j", ")", ">", "max", ")", "{", "max", "=", "this", ".", "e", "(", "i", ",", "j", ")", ";", "maxIndex", "=", "j", ";", "}", "}", "maxes", ".", "push", "(", "maxIndex", ")", ";", "}", "return", "$V", "(", "maxes", ")", ";", "}" ]
return the indexes of the columns with the largest value for each row
[ "return", "the", "indexes", "of", "the", "columns", "with", "the", "largest", "value", "for", "each", "row" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74661-L74679
22,663
repetere/modelscript
build/modelscript.umd.js
function() { var mins = []; for(var i = 1; i <= this.rows(); i++) { var min = null; var minIndex = -1; for(var j = 1; j <= this.cols(); j++) { if(min === null || this.e(i, j) < min) { min = this.e(i, j); minIndex = j; } } mins.push(minIndex); } return $V(mins); }
javascript
function() { var mins = []; for(var i = 1; i <= this.rows(); i++) { var min = null; var minIndex = -1; for(var j = 1; j <= this.cols(); j++) { if(min === null || this.e(i, j) < min) { min = this.e(i, j); minIndex = j; } } mins.push(minIndex); } return $V(mins); }
[ "function", "(", ")", "{", "var", "mins", "=", "[", "]", ";", "for", "(", "var", "i", "=", "1", ";", "i", "<=", "this", ".", "rows", "(", ")", ";", "i", "++", ")", "{", "var", "min", "=", "null", ";", "var", "minIndex", "=", "-", "1", ";", "for", "(", "var", "j", "=", "1", ";", "j", "<=", "this", ".", "cols", "(", ")", ";", "j", "++", ")", "{", "if", "(", "min", "===", "null", "||", "this", ".", "e", "(", "i", ",", "j", ")", "<", "min", ")", "{", "min", "=", "this", ".", "e", "(", "i", ",", "j", ")", ";", "minIndex", "=", "j", ";", "}", "}", "mins", ".", "push", "(", "minIndex", ")", ";", "}", "return", "$V", "(", "mins", ")", ";", "}" ]
return the indexes of the columns with the smallest values for each row
[ "return", "the", "indexes", "of", "the", "columns", "with", "the", "smallest", "values", "for", "each", "row" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74702-L74720
22,664
repetere/modelscript
build/modelscript.umd.js
function(k, j, P, A, L) { var maxIndex = 0; var maxValue = 0; for(var i = k; i <= A.rows(); i++) { if(Math.abs(A.e(i, j)) > maxValue) { maxValue = Math.abs(A.e(k, j)); maxIndex = i; } } if(maxIndex != k) { var tmp = A.elements[k - 1]; A.elements[k - 1] = A.elements[maxIndex - 1]; A.elements[maxIndex - 1] = tmp; P.elements[k - 1][k - 1] = 0; P.elements[k - 1][maxIndex - 1] = 1; P.elements[maxIndex - 1][maxIndex - 1] = 0; P.elements[maxIndex - 1][k - 1] = 1; } return P; }
javascript
function(k, j, P, A, L) { var maxIndex = 0; var maxValue = 0; for(var i = k; i <= A.rows(); i++) { if(Math.abs(A.e(i, j)) > maxValue) { maxValue = Math.abs(A.e(k, j)); maxIndex = i; } } if(maxIndex != k) { var tmp = A.elements[k - 1]; A.elements[k - 1] = A.elements[maxIndex - 1]; A.elements[maxIndex - 1] = tmp; P.elements[k - 1][k - 1] = 0; P.elements[k - 1][maxIndex - 1] = 1; P.elements[maxIndex - 1][maxIndex - 1] = 0; P.elements[maxIndex - 1][k - 1] = 1; } return P; }
[ "function", "(", "k", ",", "j", ",", "P", ",", "A", ",", "L", ")", "{", "var", "maxIndex", "=", "0", ";", "var", "maxValue", "=", "0", ";", "for", "(", "var", "i", "=", "k", ";", "i", "<=", "A", ".", "rows", "(", ")", ";", "i", "++", ")", "{", "if", "(", "Math", ".", "abs", "(", "A", ".", "e", "(", "i", ",", "j", ")", ")", ">", "maxValue", ")", "{", "maxValue", "=", "Math", ".", "abs", "(", "A", ".", "e", "(", "k", ",", "j", ")", ")", ";", "maxIndex", "=", "i", ";", "}", "}", "if", "(", "maxIndex", "!=", "k", ")", "{", "var", "tmp", "=", "A", ".", "elements", "[", "k", "-", "1", "]", ";", "A", ".", "elements", "[", "k", "-", "1", "]", "=", "A", ".", "elements", "[", "maxIndex", "-", "1", "]", ";", "A", ".", "elements", "[", "maxIndex", "-", "1", "]", "=", "tmp", ";", "P", ".", "elements", "[", "k", "-", "1", "]", "[", "k", "-", "1", "]", "=", "0", ";", "P", ".", "elements", "[", "k", "-", "1", "]", "[", "maxIndex", "-", "1", "]", "=", "1", ";", "P", ".", "elements", "[", "maxIndex", "-", "1", "]", "[", "maxIndex", "-", "1", "]", "=", "0", ";", "P", ".", "elements", "[", "maxIndex", "-", "1", "]", "[", "k", "-", "1", "]", "=", "1", ";", "}", "return", "P", ";", "}" ]
perorm a partial pivot on the matrix. essentially move the largest row below-or-including the pivot and replace the pivot's row with it. a pivot matrix is returned so multiplication can perform the transform.
[ "perorm", "a", "partial", "pivot", "on", "the", "matrix", ".", "essentially", "move", "the", "largest", "row", "below", "-", "or", "-", "including", "the", "pivot", "and", "replace", "the", "pivot", "s", "row", "with", "it", ".", "a", "pivot", "matrix", "is", "returned", "so", "multiplication", "can", "perform", "the", "transform", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74744-L74767
22,665
repetere/modelscript
build/modelscript.umd.js
luPack
function luPack() { var lu = lapack$1.lu(this.elements); return { L: $M(lu.L), U: $M(lu.U), P: $M(lu.P) // don't pass back IPIV }; }
javascript
function luPack() { var lu = lapack$1.lu(this.elements); return { L: $M(lu.L), U: $M(lu.U), P: $M(lu.P) // don't pass back IPIV }; }
[ "function", "luPack", "(", ")", "{", "var", "lu", "=", "lapack$1", ".", "lu", "(", "this", ".", "elements", ")", ";", "return", "{", "L", ":", "$M", "(", "lu", ".", "L", ")", ",", "U", ":", "$M", "(", "lu", ".", "U", ")", ",", "P", ":", "$M", "(", "lu", ".", "P", ")", "// don't pass back IPIV", "}", ";", "}" ]
LU factorization from LAPACK
[ "LU", "factorization", "from", "LAPACK" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74812-L74820
22,666
repetere/modelscript
build/modelscript.umd.js
luJs
function luJs() { var A = this.dup(); var L = Matrix$b.I(A.rows()); var P = Matrix$b.I(A.rows()); var U = Matrix$b.Zeros(A.rows(), A.cols()); var p = 1; for(var k = 1; k <= Math.min(A.cols(), A.rows()); k++) { P = A.partialPivot(k, p, P, A, L); for(var i = k + 1; i <= A.rows(); i++) { var l = A.e(i, p) / A.e(k, p); L.elements[i - 1][k - 1] = l; for(var j = k + 1 ; j <= A.cols(); j++) { A.elements[i - 1][j - 1] -= A.e(k, j) * l; } } for(var j = k; j <= A.cols(); j++) { U.elements[k - 1][j - 1] = A.e(k, j); } if(p < A.cols()) p++; } return {L: L, U: U, P: P}; }
javascript
function luJs() { var A = this.dup(); var L = Matrix$b.I(A.rows()); var P = Matrix$b.I(A.rows()); var U = Matrix$b.Zeros(A.rows(), A.cols()); var p = 1; for(var k = 1; k <= Math.min(A.cols(), A.rows()); k++) { P = A.partialPivot(k, p, P, A, L); for(var i = k + 1; i <= A.rows(); i++) { var l = A.e(i, p) / A.e(k, p); L.elements[i - 1][k - 1] = l; for(var j = k + 1 ; j <= A.cols(); j++) { A.elements[i - 1][j - 1] -= A.e(k, j) * l; } } for(var j = k; j <= A.cols(); j++) { U.elements[k - 1][j - 1] = A.e(k, j); } if(p < A.cols()) p++; } return {L: L, U: U, P: P}; }
[ "function", "luJs", "(", ")", "{", "var", "A", "=", "this", ".", "dup", "(", ")", ";", "var", "L", "=", "Matrix$b", ".", "I", "(", "A", ".", "rows", "(", ")", ")", ";", "var", "P", "=", "Matrix$b", ".", "I", "(", "A", ".", "rows", "(", ")", ")", ";", "var", "U", "=", "Matrix$b", ".", "Zeros", "(", "A", ".", "rows", "(", ")", ",", "A", ".", "cols", "(", ")", ")", ";", "var", "p", "=", "1", ";", "for", "(", "var", "k", "=", "1", ";", "k", "<=", "Math", ".", "min", "(", "A", ".", "cols", "(", ")", ",", "A", ".", "rows", "(", ")", ")", ";", "k", "++", ")", "{", "P", "=", "A", ".", "partialPivot", "(", "k", ",", "p", ",", "P", ",", "A", ",", "L", ")", ";", "for", "(", "var", "i", "=", "k", "+", "1", ";", "i", "<=", "A", ".", "rows", "(", ")", ";", "i", "++", ")", "{", "var", "l", "=", "A", ".", "e", "(", "i", ",", "p", ")", "/", "A", ".", "e", "(", "k", ",", "p", ")", ";", "L", ".", "elements", "[", "i", "-", "1", "]", "[", "k", "-", "1", "]", "=", "l", ";", "for", "(", "var", "j", "=", "k", "+", "1", ";", "j", "<=", "A", ".", "cols", "(", ")", ";", "j", "++", ")", "{", "A", ".", "elements", "[", "i", "-", "1", "]", "[", "j", "-", "1", "]", "-=", "A", ".", "e", "(", "k", ",", "j", ")", "*", "l", ";", "}", "}", "for", "(", "var", "j", "=", "k", ";", "j", "<=", "A", ".", "cols", "(", ")", ";", "j", "++", ")", "{", "U", ".", "elements", "[", "k", "-", "1", "]", "[", "j", "-", "1", "]", "=", "A", ".", "e", "(", "k", ",", "j", ")", ";", "}", "if", "(", "p", "<", "A", ".", "cols", "(", ")", ")", "p", "++", ";", "}", "return", "{", "L", ":", "L", ",", "U", ":", "U", ",", "P", ":", "P", "}", ";", "}" ]
pure Javascript LU factorization
[ "pure", "Javascript", "LU", "factorization" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L74823-L74851
22,667
repetere/modelscript
build/modelscript.umd.js
function(fn) { var elements = []; this.each(function(x, i) { elements.push(fn(x, i)); }); return Vector.create(elements); }
javascript
function(fn) { var elements = []; this.each(function(x, i) { elements.push(fn(x, i)); }); return Vector.create(elements); }
[ "function", "(", "fn", ")", "{", "var", "elements", "=", "[", "]", ";", "this", ".", "each", "(", "function", "(", "x", ",", "i", ")", "{", "elements", ".", "push", "(", "fn", "(", "x", ",", "i", ")", ")", ";", "}", ")", ";", "return", "Vector", ".", "create", "(", "elements", ")", ";", "}" ]
Maps the vector to another vector according to the given function
[ "Maps", "the", "vector", "to", "another", "vector", "according", "to", "the", "given", "function" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75083-L75089
22,668
repetere/modelscript
build/modelscript.umd.js
function(vector) { var angle = this.angleFrom(vector); return (angle === null) ? null : (Math.abs(angle - Math.PI) <= sylvester.precision); }
javascript
function(vector) { var angle = this.angleFrom(vector); return (angle === null) ? null : (Math.abs(angle - Math.PI) <= sylvester.precision); }
[ "function", "(", "vector", ")", "{", "var", "angle", "=", "this", ".", "angleFrom", "(", "vector", ")", ";", "return", "(", "angle", "===", "null", ")", "?", "null", ":", "(", "Math", ".", "abs", "(", "angle", "-", "Math", ".", "PI", ")", "<=", "sylvester", ".", "precision", ")", ";", "}" ]
Returns true iff the vector is antiparallel to the argument
[ "Returns", "true", "iff", "the", "vector", "is", "antiparallel", "to", "the", "argument" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75133-L75136
22,669
repetere/modelscript
build/modelscript.umd.js
function(v) { if (typeof(v) == 'number') return this.map(function(k) { return k - v; }); var V = v.elements || v; if (this.elements.length != V.length) { return null; } return this.map(function(x, i) { return x - V[i - 1]; }); }
javascript
function(v) { if (typeof(v) == 'number') return this.map(function(k) { return k - v; }); var V = v.elements || v; if (this.elements.length != V.length) { return null; } return this.map(function(x, i) { return x - V[i - 1]; }); }
[ "function", "(", "v", ")", "{", "if", "(", "typeof", "(", "v", ")", "==", "'number'", ")", "return", "this", ".", "map", "(", "function", "(", "k", ")", "{", "return", "k", "-", "v", ";", "}", ")", ";", "var", "V", "=", "v", ".", "elements", "||", "v", ";", "if", "(", "this", ".", "elements", ".", "length", "!=", "V", ".", "length", ")", "{", "return", "null", ";", "}", "return", "this", ".", "map", "(", "function", "(", "x", ",", "i", ")", "{", "return", "x", "-", "V", "[", "i", "-", "1", "]", ";", "}", ")", ";", "}" ]
Returns the result of subtracting the argument from the vector
[ "Returns", "the", "result", "of", "subtracting", "the", "argument", "from", "the", "vector" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75155-L75162
22,670
repetere/modelscript
build/modelscript.umd.js
function(vector) { var B = vector.elements || vector; if (this.elements.length != 3 || B.length != 3) { return null; } var A = this.elements; return Vector.create([ (A[1] * B[2]) - (A[2] * B[1]), (A[2] * B[0]) - (A[0] * B[2]), (A[0] * B[1]) - (A[1] * B[0]) ]); }
javascript
function(vector) { var B = vector.elements || vector; if (this.elements.length != 3 || B.length != 3) { return null; } var A = this.elements; return Vector.create([ (A[1] * B[2]) - (A[2] * B[1]), (A[2] * B[0]) - (A[0] * B[2]), (A[0] * B[1]) - (A[1] * B[0]) ]); }
[ "function", "(", "vector", ")", "{", "var", "B", "=", "vector", ".", "elements", "||", "vector", ";", "if", "(", "this", ".", "elements", ".", "length", "!=", "3", "||", "B", ".", "length", "!=", "3", ")", "{", "return", "null", ";", "}", "var", "A", "=", "this", ".", "elements", ";", "return", "Vector", ".", "create", "(", "[", "(", "A", "[", "1", "]", "*", "B", "[", "2", "]", ")", "-", "(", "A", "[", "2", "]", "*", "B", "[", "1", "]", ")", ",", "(", "A", "[", "2", "]", "*", "B", "[", "0", "]", ")", "-", "(", "A", "[", "0", "]", "*", "B", "[", "2", "]", ")", ",", "(", "A", "[", "0", "]", "*", "B", "[", "1", "]", ")", "-", "(", "A", "[", "1", "]", "*", "B", "[", "0", "]", ")", "]", ")", ";", "}" ]
Returns the vector product of the vector with the argument Both vectors must have dimensionality 3
[ "Returns", "the", "vector", "product", "of", "the", "vector", "with", "the", "argument", "Both", "vectors", "must", "have", "dimensionality", "3" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75245-L75254
22,671
repetere/modelscript
build/modelscript.umd.js
function(x) { var index = null, n = this.elements.length; for (var i = 0; i < n; i++) { if (index === null && this.elements[i] == x) { index = i + 1; } } return index; }
javascript
function(x) { var index = null, n = this.elements.length; for (var i = 0; i < n; i++) { if (index === null && this.elements[i] == x) { index = i + 1; } } return index; }
[ "function", "(", "x", ")", "{", "var", "index", "=", "null", ",", "n", "=", "this", ".", "elements", ".", "length", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "if", "(", "index", "===", "null", "&&", "this", ".", "elements", "[", "i", "]", "==", "x", ")", "{", "index", "=", "i", "+", "1", ";", "}", "}", "return", "index", ";", "}" ]
Returns the index of the first match found
[ "Returns", "the", "index", "of", "the", "first", "match", "found" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75282-L75290
22,672
repetere/modelscript
build/modelscript.umd.js
function() { var rows = this.elements.length; var elements = []; for (var i = 0; i < rows; i++) { elements.push([this.elements[i]]); } return matrix$2.create(elements); }
javascript
function() { var rows = this.elements.length; var elements = []; for (var i = 0; i < rows; i++) { elements.push([this.elements[i]]); } return matrix$2.create(elements); }
[ "function", "(", ")", "{", "var", "rows", "=", "this", ".", "elements", ".", "length", ";", "var", "elements", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "rows", ";", "i", "++", ")", "{", "elements", ".", "push", "(", "[", "this", ".", "elements", "[", "i", "]", "]", ")", ";", "}", "return", "matrix$2", ".", "create", "(", "elements", ")", ";", "}" ]
Transpose a Vector, return a 1xn Matrix
[ "Transpose", "a", "Vector", "return", "a", "1xn", "Matrix" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75303-L75311
22,673
repetere/modelscript
build/modelscript.umd.js
function(t, obj) { var V, R = null, x, y, z; if (t.determinant) { R = t.elements; } switch (this.elements.length) { case 2: V = obj.elements || obj; if (V.length != 2) { return null; } if (!R) { R = matrix$2.Rotation(t).elements; } x = this.elements[0] - V[0]; y = this.elements[1] - V[1]; return Vector.create([ V[0] + R[0][0] * x + R[0][1] * y, V[1] + R[1][0] * x + R[1][1] * y ]); break; case 3: if (!obj.direction) { return null; } var C = obj.pointClosestTo(this).elements; if (!R) { R = matrix$2.Rotation(t, obj.direction).elements; } x = this.elements[0] - C[0]; y = this.elements[1] - C[1]; z = this.elements[2] - C[2]; return Vector.create([ C[0] + R[0][0] * x + R[0][1] * y + R[0][2] * z, C[1] + R[1][0] * x + R[1][1] * y + R[1][2] * z, C[2] + R[2][0] * x + R[2][1] * y + R[2][2] * z ]); break; default: return null; } }
javascript
function(t, obj) { var V, R = null, x, y, z; if (t.determinant) { R = t.elements; } switch (this.elements.length) { case 2: V = obj.elements || obj; if (V.length != 2) { return null; } if (!R) { R = matrix$2.Rotation(t).elements; } x = this.elements[0] - V[0]; y = this.elements[1] - V[1]; return Vector.create([ V[0] + R[0][0] * x + R[0][1] * y, V[1] + R[1][0] * x + R[1][1] * y ]); break; case 3: if (!obj.direction) { return null; } var C = obj.pointClosestTo(this).elements; if (!R) { R = matrix$2.Rotation(t, obj.direction).elements; } x = this.elements[0] - C[0]; y = this.elements[1] - C[1]; z = this.elements[2] - C[2]; return Vector.create([ C[0] + R[0][0] * x + R[0][1] * y + R[0][2] * z, C[1] + R[1][0] * x + R[1][1] * y + R[1][2] * z, C[2] + R[2][0] * x + R[2][1] * y + R[2][2] * z ]); break; default: return null; } }
[ "function", "(", "t", ",", "obj", ")", "{", "var", "V", ",", "R", "=", "null", ",", "x", ",", "y", ",", "z", ";", "if", "(", "t", ".", "determinant", ")", "{", "R", "=", "t", ".", "elements", ";", "}", "switch", "(", "this", ".", "elements", ".", "length", ")", "{", "case", "2", ":", "V", "=", "obj", ".", "elements", "||", "obj", ";", "if", "(", "V", ".", "length", "!=", "2", ")", "{", "return", "null", ";", "}", "if", "(", "!", "R", ")", "{", "R", "=", "matrix$2", ".", "Rotation", "(", "t", ")", ".", "elements", ";", "}", "x", "=", "this", ".", "elements", "[", "0", "]", "-", "V", "[", "0", "]", ";", "y", "=", "this", ".", "elements", "[", "1", "]", "-", "V", "[", "1", "]", ";", "return", "Vector", ".", "create", "(", "[", "V", "[", "0", "]", "+", "R", "[", "0", "]", "[", "0", "]", "*", "x", "+", "R", "[", "0", "]", "[", "1", "]", "*", "y", ",", "V", "[", "1", "]", "+", "R", "[", "1", "]", "[", "0", "]", "*", "x", "+", "R", "[", "1", "]", "[", "1", "]", "*", "y", "]", ")", ";", "break", ";", "case", "3", ":", "if", "(", "!", "obj", ".", "direction", ")", "{", "return", "null", ";", "}", "var", "C", "=", "obj", ".", "pointClosestTo", "(", "this", ")", ".", "elements", ";", "if", "(", "!", "R", ")", "{", "R", "=", "matrix$2", ".", "Rotation", "(", "t", ",", "obj", ".", "direction", ")", ".", "elements", ";", "}", "x", "=", "this", ".", "elements", "[", "0", "]", "-", "C", "[", "0", "]", ";", "y", "=", "this", ".", "elements", "[", "1", "]", "-", "C", "[", "1", "]", ";", "z", "=", "this", ".", "elements", "[", "2", "]", "-", "C", "[", "2", "]", ";", "return", "Vector", ".", "create", "(", "[", "C", "[", "0", "]", "+", "R", "[", "0", "]", "[", "0", "]", "*", "x", "+", "R", "[", "0", "]", "[", "1", "]", "*", "y", "+", "R", "[", "0", "]", "[", "2", "]", "*", "z", ",", "C", "[", "1", "]", "+", "R", "[", "1", "]", "[", "0", "]", "*", "x", "+", "R", "[", "1", "]", "[", "1", "]", "*", "y", "+", "R", "[", "1", "]", "[", "2", "]", "*", "z", ",", "C", "[", "2", "]", "+", "R", "[", "2", "]", "[", "0", "]", "*", "x", "+", "R", "[", "2", "]", "[", "1", "]", "*", "y", "+", "R", "[", "2", "]", "[", "2", "]", "*", "z", "]", ")", ";", "break", ";", "default", ":", "return", "null", ";", "}", "}" ]
Rotates the vector about the given object. The object should be a point if the vector is 2D, and a line if it is 3D. Be careful with line directions!
[ "Rotates", "the", "vector", "about", "the", "given", "object", ".", "The", "object", "should", "be", "a", "point", "if", "the", "vector", "is", "2D", "and", "a", "line", "if", "it", "is", "3D", ".", "Be", "careful", "with", "line", "directions!" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75346-L75377
22,674
repetere/modelscript
build/modelscript.umd.js
function() { var V = this.dup(); switch (V.elements.length) { case 3: break; case 2: V.elements.push(0); break; default: return null; } return V; }
javascript
function() { var V = this.dup(); switch (V.elements.length) { case 3: break; case 2: V.elements.push(0); break; default: return null; } return V; }
[ "function", "(", ")", "{", "var", "V", "=", "this", ".", "dup", "(", ")", ";", "switch", "(", "V", ".", "elements", ".", "length", ")", "{", "case", "3", ":", "break", ";", "case", "2", ":", "V", ".", "elements", ".", "push", "(", "0", ")", ";", "break", ";", "default", ":", "return", "null", ";", "}", "return", "V", ";", "}" ]
Utility to make sure vectors are 3D. If they are 2D, a zero z-component is added
[ "Utility", "to", "make", "sure", "vectors", "are", "3D", ".", "If", "they", "are", "2D", "a", "zero", "z", "-", "component", "is", "added" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75395-L75403
22,675
repetere/modelscript
build/modelscript.umd.js
function(obj) { var theta; if (obj.normal) { // obj is a plane theta = this.normal.angleFrom(obj.normal); return (Math.abs(theta) <= sylvester.precision || Math.abs(Math.PI - theta) <= sylvester.precision); } else if (obj.direction) { // obj is a line return this.normal.isPerpendicularTo(obj.direction); } return null; }
javascript
function(obj) { var theta; if (obj.normal) { // obj is a plane theta = this.normal.angleFrom(obj.normal); return (Math.abs(theta) <= sylvester.precision || Math.abs(Math.PI - theta) <= sylvester.precision); } else if (obj.direction) { // obj is a line return this.normal.isPerpendicularTo(obj.direction); } return null; }
[ "function", "(", "obj", ")", "{", "var", "theta", ";", "if", "(", "obj", ".", "normal", ")", "{", "// obj is a plane", "theta", "=", "this", ".", "normal", ".", "angleFrom", "(", "obj", ".", "normal", ")", ";", "return", "(", "Math", ".", "abs", "(", "theta", ")", "<=", "sylvester", ".", "precision", "||", "Math", ".", "abs", "(", "Math", ".", "PI", "-", "theta", ")", "<=", "sylvester", ".", "precision", ")", ";", "}", "else", "if", "(", "obj", ".", "direction", ")", "{", "// obj is a line", "return", "this", ".", "normal", ".", "isPerpendicularTo", "(", "obj", ".", "direction", ")", ";", "}", "return", "null", ";", "}" ]
Returns true iff the plane is parallel to the argument. Will return true if the planes are equal, or if you give a line and it lies in the plane.
[ "Returns", "true", "iff", "the", "plane", "is", "parallel", "to", "the", "argument", ".", "Will", "return", "true", "if", "the", "planes", "are", "equal", "or", "if", "you", "give", "a", "line", "and", "it", "lies", "in", "the", "plane", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75491-L75502
22,676
repetere/modelscript
build/modelscript.umd.js
function(plane) { var theta = this.normal.angleFrom(plane.normal); return (Math.abs(Math.PI/2 - theta) <= sylvester.precision); }
javascript
function(plane) { var theta = this.normal.angleFrom(plane.normal); return (Math.abs(Math.PI/2 - theta) <= sylvester.precision); }
[ "function", "(", "plane", ")", "{", "var", "theta", "=", "this", ".", "normal", ".", "angleFrom", "(", "plane", ".", "normal", ")", ";", "return", "(", "Math", ".", "abs", "(", "Math", ".", "PI", "/", "2", "-", "theta", ")", "<=", "sylvester", ".", "precision", ")", ";", "}" ]
Returns true iff the receiver is perpendicular to the argument
[ "Returns", "true", "iff", "the", "receiver", "is", "perpendicular", "to", "the", "argument" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75505-L75508
22,677
repetere/modelscript
build/modelscript.umd.js
function(obj) { if (obj.normal) { return null; } if (obj.direction) { return (this.contains(obj.anchor) && this.contains(obj.anchor.add(obj.direction))); } else { var P = obj.elements || obj; var A = this.anchor.elements, N = this.normal.elements; var diff = Math.abs(N[0]*(A[0] - P[0]) + N[1]*(A[1] - P[1]) + N[2]*(A[2] - (P[2] || 0))); return (diff <= sylvester.precision); } }
javascript
function(obj) { if (obj.normal) { return null; } if (obj.direction) { return (this.contains(obj.anchor) && this.contains(obj.anchor.add(obj.direction))); } else { var P = obj.elements || obj; var A = this.anchor.elements, N = this.normal.elements; var diff = Math.abs(N[0]*(A[0] - P[0]) + N[1]*(A[1] - P[1]) + N[2]*(A[2] - (P[2] || 0))); return (diff <= sylvester.precision); } }
[ "function", "(", "obj", ")", "{", "if", "(", "obj", ".", "normal", ")", "{", "return", "null", ";", "}", "if", "(", "obj", ".", "direction", ")", "{", "return", "(", "this", ".", "contains", "(", "obj", ".", "anchor", ")", "&&", "this", ".", "contains", "(", "obj", ".", "anchor", ".", "add", "(", "obj", ".", "direction", ")", ")", ")", ";", "}", "else", "{", "var", "P", "=", "obj", ".", "elements", "||", "obj", ";", "var", "A", "=", "this", ".", "anchor", ".", "elements", ",", "N", "=", "this", ".", "normal", ".", "elements", ";", "var", "diff", "=", "Math", ".", "abs", "(", "N", "[", "0", "]", "*", "(", "A", "[", "0", "]", "-", "P", "[", "0", "]", ")", "+", "N", "[", "1", "]", "*", "(", "A", "[", "1", "]", "-", "P", "[", "1", "]", ")", "+", "N", "[", "2", "]", "*", "(", "A", "[", "2", "]", "-", "(", "P", "[", "2", "]", "||", "0", ")", ")", ")", ";", "return", "(", "diff", "<=", "sylvester", ".", "precision", ")", ";", "}", "}" ]
Returns true iff the plane contains the given point or line
[ "Returns", "true", "iff", "the", "plane", "contains", "the", "given", "point", "or", "line" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75526-L75536
22,678
repetere/modelscript
build/modelscript.umd.js
function(point) { var P = point.elements || point; var A = this.anchor.elements, N = this.normal.elements; var dot = (A[0] - P[0]) * N[0] + (A[1] - P[1]) * N[1] + (A[2] - (P[2] || 0)) * N[2]; return vector.create([P[0] + N[0] * dot, P[1] + N[1] * dot, (P[2] || 0) + N[2] * dot]); }
javascript
function(point) { var P = point.elements || point; var A = this.anchor.elements, N = this.normal.elements; var dot = (A[0] - P[0]) * N[0] + (A[1] - P[1]) * N[1] + (A[2] - (P[2] || 0)) * N[2]; return vector.create([P[0] + N[0] * dot, P[1] + N[1] * dot, (P[2] || 0) + N[2] * dot]); }
[ "function", "(", "point", ")", "{", "var", "P", "=", "point", ".", "elements", "||", "point", ";", "var", "A", "=", "this", ".", "anchor", ".", "elements", ",", "N", "=", "this", ".", "normal", ".", "elements", ";", "var", "dot", "=", "(", "A", "[", "0", "]", "-", "P", "[", "0", "]", ")", "*", "N", "[", "0", "]", "+", "(", "A", "[", "1", "]", "-", "P", "[", "1", "]", ")", "*", "N", "[", "1", "]", "+", "(", "A", "[", "2", "]", "-", "(", "P", "[", "2", "]", "||", "0", ")", ")", "*", "N", "[", "2", "]", ";", "return", "vector", ".", "create", "(", "[", "P", "[", "0", "]", "+", "N", "[", "0", "]", "*", "dot", ",", "P", "[", "1", "]", "+", "N", "[", "1", "]", "*", "dot", ",", "(", "P", "[", "2", "]", "||", "0", ")", "+", "N", "[", "2", "]", "*", "dot", "]", ")", ";", "}" ]
Returns the point in the plane closest to the given point
[ "Returns", "the", "point", "in", "the", "plane", "closest", "to", "the", "given", "point" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75588-L75593
22,679
repetere/modelscript
build/modelscript.umd.js
function(obj) { if (obj.normal) { // obj is a plane var A = this.anchor.elements, N = this.normal.elements; var A1 = A[0], A2 = A[1], A3 = A[2], N1 = N[0], N2 = N[1], N3 = N[2]; var newA = this.anchor.reflectionIn(obj).elements; // Add the plane's normal to its anchor, then mirror that in the other plane var AN1 = A1 + N1, AN2 = A2 + N2, AN3 = A3 + N3; var Q = obj.pointClosestTo([AN1, AN2, AN3]).elements; var newN = [Q[0] + (Q[0] - AN1) - newA[0], Q[1] + (Q[1] - AN2) - newA[1], Q[2] + (Q[2] - AN3) - newA[2]]; return Plane$1.create(newA, newN); } else if (obj.direction) { // obj is a line return this.rotate(Math.PI, obj); } else { // obj is a point var P = obj.elements || obj; return Plane$1.create(this.anchor.reflectionIn([P[0], P[1], (P[2] || 0)]), this.normal); } }
javascript
function(obj) { if (obj.normal) { // obj is a plane var A = this.anchor.elements, N = this.normal.elements; var A1 = A[0], A2 = A[1], A3 = A[2], N1 = N[0], N2 = N[1], N3 = N[2]; var newA = this.anchor.reflectionIn(obj).elements; // Add the plane's normal to its anchor, then mirror that in the other plane var AN1 = A1 + N1, AN2 = A2 + N2, AN3 = A3 + N3; var Q = obj.pointClosestTo([AN1, AN2, AN3]).elements; var newN = [Q[0] + (Q[0] - AN1) - newA[0], Q[1] + (Q[1] - AN2) - newA[1], Q[2] + (Q[2] - AN3) - newA[2]]; return Plane$1.create(newA, newN); } else if (obj.direction) { // obj is a line return this.rotate(Math.PI, obj); } else { // obj is a point var P = obj.elements || obj; return Plane$1.create(this.anchor.reflectionIn([P[0], P[1], (P[2] || 0)]), this.normal); } }
[ "function", "(", "obj", ")", "{", "if", "(", "obj", ".", "normal", ")", "{", "// obj is a plane", "var", "A", "=", "this", ".", "anchor", ".", "elements", ",", "N", "=", "this", ".", "normal", ".", "elements", ";", "var", "A1", "=", "A", "[", "0", "]", ",", "A2", "=", "A", "[", "1", "]", ",", "A3", "=", "A", "[", "2", "]", ",", "N1", "=", "N", "[", "0", "]", ",", "N2", "=", "N", "[", "1", "]", ",", "N3", "=", "N", "[", "2", "]", ";", "var", "newA", "=", "this", ".", "anchor", ".", "reflectionIn", "(", "obj", ")", ".", "elements", ";", "// Add the plane's normal to its anchor, then mirror that in the other plane", "var", "AN1", "=", "A1", "+", "N1", ",", "AN2", "=", "A2", "+", "N2", ",", "AN3", "=", "A3", "+", "N3", ";", "var", "Q", "=", "obj", ".", "pointClosestTo", "(", "[", "AN1", ",", "AN2", ",", "AN3", "]", ")", ".", "elements", ";", "var", "newN", "=", "[", "Q", "[", "0", "]", "+", "(", "Q", "[", "0", "]", "-", "AN1", ")", "-", "newA", "[", "0", "]", ",", "Q", "[", "1", "]", "+", "(", "Q", "[", "1", "]", "-", "AN2", ")", "-", "newA", "[", "1", "]", ",", "Q", "[", "2", "]", "+", "(", "Q", "[", "2", "]", "-", "AN3", ")", "-", "newA", "[", "2", "]", "]", ";", "return", "Plane$1", ".", "create", "(", "newA", ",", "newN", ")", ";", "}", "else", "if", "(", "obj", ".", "direction", ")", "{", "// obj is a line", "return", "this", ".", "rotate", "(", "Math", ".", "PI", ",", "obj", ")", ";", "}", "else", "{", "// obj is a point", "var", "P", "=", "obj", ".", "elements", "||", "obj", ";", "return", "Plane$1", ".", "create", "(", "this", ".", "anchor", ".", "reflectionIn", "(", "[", "P", "[", "0", "]", ",", "P", "[", "1", "]", ",", "(", "P", "[", "2", "]", "||", "0", ")", "]", ")", ",", "this", ".", "normal", ")", ";", "}", "}" ]
Returns the reflection of the plane in the given point, line or plane.
[ "Returns", "the", "reflection", "of", "the", "plane", "in", "the", "given", "point", "line", "or", "plane", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75615-L75634
22,680
repetere/modelscript
build/modelscript.umd.js
function(anchor, v1, v2) { anchor = vector.create(anchor); anchor = anchor.to3D(); if (anchor === null) { return null; } v1 = vector.create(v1); v1 = v1.to3D(); if (v1 === null) { return null; } if (typeof(v2) == 'undefined') { v2 = null; } else { v2 = vector.create(v2); v2 = v2.to3D(); if (v2 === null) { return null; } } var A1 = anchor.elements[0], A2 = anchor.elements[1], A3 = anchor.elements[2]; var v11 = v1.elements[0], v12 = v1.elements[1], v13 = v1.elements[2]; var normal, mod; if (v2 !== null) { var v21 = v2.elements[0], v22 = v2.elements[1], v23 = v2.elements[2]; normal = vector.create([ (v12 - A2) * (v23 - A3) - (v13 - A3) * (v22 - A2), (v13 - A3) * (v21 - A1) - (v11 - A1) * (v23 - A3), (v11 - A1) * (v22 - A2) - (v12 - A2) * (v21 - A1) ]); mod = normal.modulus(); if (mod === 0) { return null; } normal = vector.create([normal.elements[0] / mod, normal.elements[1] / mod, normal.elements[2] / mod]); } else { mod = Math.sqrt(v11*v11 + v12*v12 + v13*v13); if (mod === 0) { return null; } normal = vector.create([v1.elements[0] / mod, v1.elements[1] / mod, v1.elements[2] / mod]); } this.anchor = anchor; this.normal = normal; return this; }
javascript
function(anchor, v1, v2) { anchor = vector.create(anchor); anchor = anchor.to3D(); if (anchor === null) { return null; } v1 = vector.create(v1); v1 = v1.to3D(); if (v1 === null) { return null; } if (typeof(v2) == 'undefined') { v2 = null; } else { v2 = vector.create(v2); v2 = v2.to3D(); if (v2 === null) { return null; } } var A1 = anchor.elements[0], A2 = anchor.elements[1], A3 = anchor.elements[2]; var v11 = v1.elements[0], v12 = v1.elements[1], v13 = v1.elements[2]; var normal, mod; if (v2 !== null) { var v21 = v2.elements[0], v22 = v2.elements[1], v23 = v2.elements[2]; normal = vector.create([ (v12 - A2) * (v23 - A3) - (v13 - A3) * (v22 - A2), (v13 - A3) * (v21 - A1) - (v11 - A1) * (v23 - A3), (v11 - A1) * (v22 - A2) - (v12 - A2) * (v21 - A1) ]); mod = normal.modulus(); if (mod === 0) { return null; } normal = vector.create([normal.elements[0] / mod, normal.elements[1] / mod, normal.elements[2] / mod]); } else { mod = Math.sqrt(v11*v11 + v12*v12 + v13*v13); if (mod === 0) { return null; } normal = vector.create([v1.elements[0] / mod, v1.elements[1] / mod, v1.elements[2] / mod]); } this.anchor = anchor; this.normal = normal; return this; }
[ "function", "(", "anchor", ",", "v1", ",", "v2", ")", "{", "anchor", "=", "vector", ".", "create", "(", "anchor", ")", ";", "anchor", "=", "anchor", ".", "to3D", "(", ")", ";", "if", "(", "anchor", "===", "null", ")", "{", "return", "null", ";", "}", "v1", "=", "vector", ".", "create", "(", "v1", ")", ";", "v1", "=", "v1", ".", "to3D", "(", ")", ";", "if", "(", "v1", "===", "null", ")", "{", "return", "null", ";", "}", "if", "(", "typeof", "(", "v2", ")", "==", "'undefined'", ")", "{", "v2", "=", "null", ";", "}", "else", "{", "v2", "=", "vector", ".", "create", "(", "v2", ")", ";", "v2", "=", "v2", ".", "to3D", "(", ")", ";", "if", "(", "v2", "===", "null", ")", "{", "return", "null", ";", "}", "}", "var", "A1", "=", "anchor", ".", "elements", "[", "0", "]", ",", "A2", "=", "anchor", ".", "elements", "[", "1", "]", ",", "A3", "=", "anchor", ".", "elements", "[", "2", "]", ";", "var", "v11", "=", "v1", ".", "elements", "[", "0", "]", ",", "v12", "=", "v1", ".", "elements", "[", "1", "]", ",", "v13", "=", "v1", ".", "elements", "[", "2", "]", ";", "var", "normal", ",", "mod", ";", "if", "(", "v2", "!==", "null", ")", "{", "var", "v21", "=", "v2", ".", "elements", "[", "0", "]", ",", "v22", "=", "v2", ".", "elements", "[", "1", "]", ",", "v23", "=", "v2", ".", "elements", "[", "2", "]", ";", "normal", "=", "vector", ".", "create", "(", "[", "(", "v12", "-", "A2", ")", "*", "(", "v23", "-", "A3", ")", "-", "(", "v13", "-", "A3", ")", "*", "(", "v22", "-", "A2", ")", ",", "(", "v13", "-", "A3", ")", "*", "(", "v21", "-", "A1", ")", "-", "(", "v11", "-", "A1", ")", "*", "(", "v23", "-", "A3", ")", ",", "(", "v11", "-", "A1", ")", "*", "(", "v22", "-", "A2", ")", "-", "(", "v12", "-", "A2", ")", "*", "(", "v21", "-", "A1", ")", "]", ")", ";", "mod", "=", "normal", ".", "modulus", "(", ")", ";", "if", "(", "mod", "===", "0", ")", "{", "return", "null", ";", "}", "normal", "=", "vector", ".", "create", "(", "[", "normal", ".", "elements", "[", "0", "]", "/", "mod", ",", "normal", ".", "elements", "[", "1", "]", "/", "mod", ",", "normal", ".", "elements", "[", "2", "]", "/", "mod", "]", ")", ";", "}", "else", "{", "mod", "=", "Math", ".", "sqrt", "(", "v11", "*", "v11", "+", "v12", "*", "v12", "+", "v13", "*", "v13", ")", ";", "if", "(", "mod", "===", "0", ")", "{", "return", "null", ";", "}", "normal", "=", "vector", ".", "create", "(", "[", "v1", ".", "elements", "[", "0", "]", "/", "mod", ",", "v1", ".", "elements", "[", "1", "]", "/", "mod", ",", "v1", ".", "elements", "[", "2", "]", "/", "mod", "]", ")", ";", "}", "this", ".", "anchor", "=", "anchor", ";", "this", ".", "normal", "=", "normal", ";", "return", "this", ";", "}" ]
Sets the anchor point and normal to the plane. If three arguments are specified, the normal is calculated by assuming the three points should lie in the same plane. If only two are sepcified, the second is taken to be the normal. Normal vector is normalised before storage.
[ "Sets", "the", "anchor", "point", "and", "normal", "to", "the", "plane", ".", "If", "three", "arguments", "are", "specified", "the", "normal", "is", "calculated", "by", "assuming", "the", "three", "points", "should", "lie", "in", "the", "same", "plane", ".", "If", "only", "two", "are", "sepcified", "the", "second", "is", "taken", "to", "be", "the", "normal", ".", "Normal", "vector", "is", "normalised", "before", "storage", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75640-L75672
22,681
repetere/modelscript
build/modelscript.umd.js
function(obj) { if (obj.start && obj.end) { return this.contains(obj.start) && this.contains(obj.end); } var dist = this.distanceFrom(obj); return (dist !== null && dist <= sylvester.precision); }
javascript
function(obj) { if (obj.start && obj.end) { return this.contains(obj.start) && this.contains(obj.end); } var dist = this.distanceFrom(obj); return (dist !== null && dist <= sylvester.precision); }
[ "function", "(", "obj", ")", "{", "if", "(", "obj", ".", "start", "&&", "obj", ".", "end", ")", "{", "return", "this", ".", "contains", "(", "obj", ".", "start", ")", "&&", "this", ".", "contains", "(", "obj", ".", "end", ")", ";", "}", "var", "dist", "=", "this", ".", "distanceFrom", "(", "obj", ")", ";", "return", "(", "dist", "!==", "null", "&&", "dist", "<=", "sylvester", ".", "precision", ")", ";", "}" ]
Returns true iff the argument is a point on the line, or if the argument is a line segment lying within the receiver
[ "Returns", "true", "iff", "the", "argument", "is", "a", "point", "on", "the", "line", "or", "if", "the", "argument", "is", "a", "line", "segment", "lying", "within", "the", "receiver" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75800-L75804
22,682
repetere/modelscript
build/modelscript.umd.js
function(point) { if (!this.contains(point)) { return null; } var P = point.elements || point; var A = this.anchor.elements, D = this.direction.elements; return (P[0] - A[0]) * D[0] + (P[1] - A[1]) * D[1] + ((P[2] || 0) - A[2]) * D[2]; }
javascript
function(point) { if (!this.contains(point)) { return null; } var P = point.elements || point; var A = this.anchor.elements, D = this.direction.elements; return (P[0] - A[0]) * D[0] + (P[1] - A[1]) * D[1] + ((P[2] || 0) - A[2]) * D[2]; }
[ "function", "(", "point", ")", "{", "if", "(", "!", "this", ".", "contains", "(", "point", ")", ")", "{", "return", "null", ";", "}", "var", "P", "=", "point", ".", "elements", "||", "point", ";", "var", "A", "=", "this", ".", "anchor", ".", "elements", ",", "D", "=", "this", ".", "direction", ".", "elements", ";", "return", "(", "P", "[", "0", "]", "-", "A", "[", "0", "]", ")", "*", "D", "[", "0", "]", "+", "(", "P", "[", "1", "]", "-", "A", "[", "1", "]", ")", "*", "D", "[", "1", "]", "+", "(", "(", "P", "[", "2", "]", "||", "0", ")", "-", "A", "[", "2", "]", ")", "*", "D", "[", "2", "]", ";", "}" ]
Returns the distance from the anchor of the given point. Negative values are returned for points that are in the opposite direction to the line's direction from the line's anchor point.
[ "Returns", "the", "distance", "from", "the", "anchor", "of", "the", "given", "point", ".", "Negative", "values", "are", "returned", "for", "points", "that", "are", "in", "the", "opposite", "direction", "to", "the", "line", "s", "direction", "from", "the", "line", "s", "anchor", "point", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75809-L75814
22,683
repetere/modelscript
build/modelscript.umd.js
function(obj) { if (obj.normal || (obj.start && obj.end)) { return obj.intersectionWith(this); } if (!this.intersects(obj)) { return null; } var P = this.anchor.elements, X = this.direction.elements, Q = obj.anchor.elements, Y = obj.direction.elements; var X1 = X[0], X2 = X[1], X3 = X[2], Y1 = Y[0], Y2 = Y[1], Y3 = Y[2]; var PsubQ1 = P[0] - Q[0], PsubQ2 = P[1] - Q[1], PsubQ3 = P[2] - Q[2]; var XdotQsubP = - X1*PsubQ1 - X2*PsubQ2 - X3*PsubQ3; var YdotPsubQ = Y1*PsubQ1 + Y2*PsubQ2 + Y3*PsubQ3; var XdotX = X1*X1 + X2*X2 + X3*X3; var YdotY = Y1*Y1 + Y2*Y2 + Y3*Y3; var XdotY = X1*Y1 + X2*Y2 + X3*Y3; var k = (XdotQsubP * YdotY / XdotX + XdotY * YdotPsubQ) / (YdotY - XdotY * XdotY); return vector.create([P[0] + k*X1, P[1] + k*X2, P[2] + k*X3]); }
javascript
function(obj) { if (obj.normal || (obj.start && obj.end)) { return obj.intersectionWith(this); } if (!this.intersects(obj)) { return null; } var P = this.anchor.elements, X = this.direction.elements, Q = obj.anchor.elements, Y = obj.direction.elements; var X1 = X[0], X2 = X[1], X3 = X[2], Y1 = Y[0], Y2 = Y[1], Y3 = Y[2]; var PsubQ1 = P[0] - Q[0], PsubQ2 = P[1] - Q[1], PsubQ3 = P[2] - Q[2]; var XdotQsubP = - X1*PsubQ1 - X2*PsubQ2 - X3*PsubQ3; var YdotPsubQ = Y1*PsubQ1 + Y2*PsubQ2 + Y3*PsubQ3; var XdotX = X1*X1 + X2*X2 + X3*X3; var YdotY = Y1*Y1 + Y2*Y2 + Y3*Y3; var XdotY = X1*Y1 + X2*Y2 + X3*Y3; var k = (XdotQsubP * YdotY / XdotX + XdotY * YdotPsubQ) / (YdotY - XdotY * XdotY); return vector.create([P[0] + k*X1, P[1] + k*X2, P[2] + k*X3]); }
[ "function", "(", "obj", ")", "{", "if", "(", "obj", ".", "normal", "||", "(", "obj", ".", "start", "&&", "obj", ".", "end", ")", ")", "{", "return", "obj", ".", "intersectionWith", "(", "this", ")", ";", "}", "if", "(", "!", "this", ".", "intersects", "(", "obj", ")", ")", "{", "return", "null", ";", "}", "var", "P", "=", "this", ".", "anchor", ".", "elements", ",", "X", "=", "this", ".", "direction", ".", "elements", ",", "Q", "=", "obj", ".", "anchor", ".", "elements", ",", "Y", "=", "obj", ".", "direction", ".", "elements", ";", "var", "X1", "=", "X", "[", "0", "]", ",", "X2", "=", "X", "[", "1", "]", ",", "X3", "=", "X", "[", "2", "]", ",", "Y1", "=", "Y", "[", "0", "]", ",", "Y2", "=", "Y", "[", "1", "]", ",", "Y3", "=", "Y", "[", "2", "]", ";", "var", "PsubQ1", "=", "P", "[", "0", "]", "-", "Q", "[", "0", "]", ",", "PsubQ2", "=", "P", "[", "1", "]", "-", "Q", "[", "1", "]", ",", "PsubQ3", "=", "P", "[", "2", "]", "-", "Q", "[", "2", "]", ";", "var", "XdotQsubP", "=", "-", "X1", "*", "PsubQ1", "-", "X2", "*", "PsubQ2", "-", "X3", "*", "PsubQ3", ";", "var", "YdotPsubQ", "=", "Y1", "*", "PsubQ1", "+", "Y2", "*", "PsubQ2", "+", "Y3", "*", "PsubQ3", ";", "var", "XdotX", "=", "X1", "*", "X1", "+", "X2", "*", "X2", "+", "X3", "*", "X3", ";", "var", "YdotY", "=", "Y1", "*", "Y1", "+", "Y2", "*", "Y2", "+", "Y3", "*", "Y3", ";", "var", "XdotY", "=", "X1", "*", "Y1", "+", "X2", "*", "Y2", "+", "X3", "*", "Y3", ";", "var", "k", "=", "(", "XdotQsubP", "*", "YdotY", "/", "XdotX", "+", "XdotY", "*", "YdotPsubQ", ")", "/", "(", "YdotY", "-", "XdotY", "*", "XdotY", ")", ";", "return", "vector", ".", "create", "(", "[", "P", "[", "0", "]", "+", "k", "*", "X1", ",", "P", "[", "1", "]", "+", "k", "*", "X2", ",", "P", "[", "2", "]", "+", "k", "*", "X3", "]", ")", ";", "}" ]
Returns the unique intersection point with the argument, if one exists
[ "Returns", "the", "unique", "intersection", "point", "with", "the", "argument", "if", "one", "exists" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75828-L75842
22,684
repetere/modelscript
build/modelscript.umd.js
function(segment) { return (this.start.eql(segment.start) && this.end.eql(segment.end)) || (this.start.eql(segment.end) && this.end.eql(segment.start)); }
javascript
function(segment) { return (this.start.eql(segment.start) && this.end.eql(segment.end)) || (this.start.eql(segment.end) && this.end.eql(segment.start)); }
[ "function", "(", "segment", ")", "{", "return", "(", "this", ".", "start", ".", "eql", "(", "segment", ".", "start", ")", "&&", "this", ".", "end", ".", "eql", "(", "segment", ".", "end", ")", ")", "||", "(", "this", ".", "start", ".", "eql", "(", "segment", ".", "end", ")", "&&", "this", ".", "end", ".", "eql", "(", "segment", ".", "start", ")", ")", ";", "}" ]
Returns true iff the line segment is equal to the argument
[ "Returns", "true", "iff", "the", "line", "segment", "is", "equal", "to", "the", "argument" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75975-L75978
22,685
repetere/modelscript
build/modelscript.umd.js
function() { var A = this.start.elements, B = this.end.elements; var C1 = B[0] - A[0], C2 = B[1] - A[1], C3 = B[2] - A[2]; return Math.sqrt(C1*C1 + C2*C2 + C3*C3); }
javascript
function() { var A = this.start.elements, B = this.end.elements; var C1 = B[0] - A[0], C2 = B[1] - A[1], C3 = B[2] - A[2]; return Math.sqrt(C1*C1 + C2*C2 + C3*C3); }
[ "function", "(", ")", "{", "var", "A", "=", "this", ".", "start", ".", "elements", ",", "B", "=", "this", ".", "end", ".", "elements", ";", "var", "C1", "=", "B", "[", "0", "]", "-", "A", "[", "0", "]", ",", "C2", "=", "B", "[", "1", "]", "-", "A", "[", "1", "]", ",", "C3", "=", "B", "[", "2", "]", "-", "A", "[", "2", "]", ";", "return", "Math", ".", "sqrt", "(", "C1", "*", "C1", "+", "C2", "*", "C2", "+", "C3", "*", "C3", ")", ";", "}" ]
Returns the length of the line segment
[ "Returns", "the", "length", "of", "the", "line", "segment" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75986-L75990
22,686
repetere/modelscript
build/modelscript.umd.js
function() { var A = this.start.elements, B = this.end.elements; return vector.create([B[0] - A[0], B[1] - A[1], B[2] - A[2]]); }
javascript
function() { var A = this.start.elements, B = this.end.elements; return vector.create([B[0] - A[0], B[1] - A[1], B[2] - A[2]]); }
[ "function", "(", ")", "{", "var", "A", "=", "this", ".", "start", ".", "elements", ",", "B", "=", "this", ".", "end", ".", "elements", ";", "return", "vector", ".", "create", "(", "[", "B", "[", "0", "]", "-", "A", "[", "0", "]", ",", "B", "[", "1", "]", "-", "A", "[", "1", "]", ",", "B", "[", "2", "]", "-", "A", "[", "2", "]", "]", ")", ";", "}" ]
Returns the line segment as a vector equal to its end point relative to its endpoint
[ "Returns", "the", "line", "segment", "as", "a", "vector", "equal", "to", "its", "end", "point", "relative", "to", "its", "endpoint" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L75994-L75997
22,687
repetere/modelscript
build/modelscript.umd.js
function(obj) { var P = this.pointClosestTo(obj); return (P === null) ? null : P.distanceFrom(obj); }
javascript
function(obj) { var P = this.pointClosestTo(obj); return (P === null) ? null : P.distanceFrom(obj); }
[ "function", "(", "obj", ")", "{", "var", "P", "=", "this", ".", "pointClosestTo", "(", "obj", ")", ";", "return", "(", "P", "===", "null", ")", "?", "null", ":", "P", ".", "distanceFrom", "(", "obj", ")", ";", "}" ]
Returns the distance between the argument and the line segment's closest point to the argument
[ "Returns", "the", "distance", "between", "the", "argument", "and", "the", "line", "segment", "s", "closest", "point", "to", "the", "argument" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L76027-L76030
22,688
repetere/modelscript
build/modelscript.umd.js
function(obj) { if (obj.start && obj.end) { return this.contains(obj.start) && this.contains(obj.end); } var P = (obj.elements || obj).slice(); if (P.length == 2) { P.push(0); } if (this.start.eql(P)) { return true; } var S = this.start.elements; var V = vector.create([S[0] - P[0], S[1] - P[1], S[2] - (P[2] || 0)]); var vect = this.toVector(); return V.isAntiparallelTo(vect) && V.modulus() <= vect.modulus(); }
javascript
function(obj) { if (obj.start && obj.end) { return this.contains(obj.start) && this.contains(obj.end); } var P = (obj.elements || obj).slice(); if (P.length == 2) { P.push(0); } if (this.start.eql(P)) { return true; } var S = this.start.elements; var V = vector.create([S[0] - P[0], S[1] - P[1], S[2] - (P[2] || 0)]); var vect = this.toVector(); return V.isAntiparallelTo(vect) && V.modulus() <= vect.modulus(); }
[ "function", "(", "obj", ")", "{", "if", "(", "obj", ".", "start", "&&", "obj", ".", "end", ")", "{", "return", "this", ".", "contains", "(", "obj", ".", "start", ")", "&&", "this", ".", "contains", "(", "obj", ".", "end", ")", ";", "}", "var", "P", "=", "(", "obj", ".", "elements", "||", "obj", ")", ".", "slice", "(", ")", ";", "if", "(", "P", ".", "length", "==", "2", ")", "{", "P", ".", "push", "(", "0", ")", ";", "}", "if", "(", "this", ".", "start", ".", "eql", "(", "P", ")", ")", "{", "return", "true", ";", "}", "var", "S", "=", "this", ".", "start", ".", "elements", ";", "var", "V", "=", "vector", ".", "create", "(", "[", "S", "[", "0", "]", "-", "P", "[", "0", "]", ",", "S", "[", "1", "]", "-", "P", "[", "1", "]", ",", "S", "[", "2", "]", "-", "(", "P", "[", "2", "]", "||", "0", ")", "]", ")", ";", "var", "vect", "=", "this", ".", "toVector", "(", ")", ";", "return", "V", ".", "isAntiparallelTo", "(", "vect", ")", "&&", "V", ".", "modulus", "(", ")", "<=", "vect", ".", "modulus", "(", ")", ";", "}" ]
Returns true iff the given point lies on the segment
[ "Returns", "true", "iff", "the", "given", "point", "lies", "on", "the", "segment" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L76033-L76042
22,689
repetere/modelscript
build/modelscript.umd.js
function(obj) { if (!this.line.intersects(obj)) { return null; } var P = this.line.intersectionWith(obj); return (this.contains(P) ? P : null); }
javascript
function(obj) { if (!this.line.intersects(obj)) { return null; } var P = this.line.intersectionWith(obj); return (this.contains(P) ? P : null); }
[ "function", "(", "obj", ")", "{", "if", "(", "!", "this", ".", "line", ".", "intersects", "(", "obj", ")", ")", "{", "return", "null", ";", "}", "var", "P", "=", "this", ".", "line", ".", "intersectionWith", "(", "obj", ")", ";", "return", "(", "this", ".", "contains", "(", "P", ")", "?", "P", ":", "null", ")", ";", "}" ]
Returns the unique point of intersection with the argument
[ "Returns", "the", "unique", "point", "of", "intersection", "with", "the", "argument" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L76050-L76054
22,690
repetere/modelscript
build/modelscript.umd.js
function(obj) { if (obj.normal) { // obj is a plane var V = this.line.intersectionWith(obj); if (V === null) { return null; } return this.pointClosestTo(V); } else { // obj is a line (segment) or point var P = this.line.pointClosestTo(obj); if (P === null) { return null; } if (this.contains(P)) { return P; } return (this.line.positionOf(P) < 0 ? this.start : this.end).dup(); } }
javascript
function(obj) { if (obj.normal) { // obj is a plane var V = this.line.intersectionWith(obj); if (V === null) { return null; } return this.pointClosestTo(V); } else { // obj is a line (segment) or point var P = this.line.pointClosestTo(obj); if (P === null) { return null; } if (this.contains(P)) { return P; } return (this.line.positionOf(P) < 0 ? this.start : this.end).dup(); } }
[ "function", "(", "obj", ")", "{", "if", "(", "obj", ".", "normal", ")", "{", "// obj is a plane", "var", "V", "=", "this", ".", "line", ".", "intersectionWith", "(", "obj", ")", ";", "if", "(", "V", "===", "null", ")", "{", "return", "null", ";", "}", "return", "this", ".", "pointClosestTo", "(", "V", ")", ";", "}", "else", "{", "// obj is a line (segment) or point", "var", "P", "=", "this", ".", "line", ".", "pointClosestTo", "(", "obj", ")", ";", "if", "(", "P", "===", "null", ")", "{", "return", "null", ";", "}", "if", "(", "this", ".", "contains", "(", "P", ")", ")", "{", "return", "P", ";", "}", "return", "(", "this", ".", "line", ".", "positionOf", "(", "P", ")", "<", "0", "?", "this", ".", "start", ":", "this", ".", "end", ")", ".", "dup", "(", ")", ";", "}", "}" ]
Returns the point on the line segment closest to the given object
[ "Returns", "the", "point", "on", "the", "line", "segment", "closest", "to", "the", "given", "object" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L76057-L76070
22,691
repetere/modelscript
build/modelscript.umd.js
function(startPoint, endPoint) { startPoint = vector.create(startPoint).to3D(); endPoint = vector.create(endPoint).to3D(); if (startPoint === null || endPoint === null) { return null; } this.line = line.create(startPoint, endPoint.subtract(startPoint)); this.start = startPoint; this.end = endPoint; return this; }
javascript
function(startPoint, endPoint) { startPoint = vector.create(startPoint).to3D(); endPoint = vector.create(endPoint).to3D(); if (startPoint === null || endPoint === null) { return null; } this.line = line.create(startPoint, endPoint.subtract(startPoint)); this.start = startPoint; this.end = endPoint; return this; }
[ "function", "(", "startPoint", ",", "endPoint", ")", "{", "startPoint", "=", "vector", ".", "create", "(", "startPoint", ")", ".", "to3D", "(", ")", ";", "endPoint", "=", "vector", ".", "create", "(", "endPoint", ")", ".", "to3D", "(", ")", ";", "if", "(", "startPoint", "===", "null", "||", "endPoint", "===", "null", ")", "{", "return", "null", ";", "}", "this", ".", "line", "=", "line", ".", "create", "(", "startPoint", ",", "endPoint", ".", "subtract", "(", "startPoint", ")", ")", ";", "this", ".", "start", "=", "startPoint", ";", "this", ".", "end", "=", "endPoint", ";", "return", "this", ";", "}" ]
Set the start and end-points of the segment
[ "Set", "the", "start", "and", "end", "-", "points", "of", "the", "segment" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L76073-L76081
22,692
repetere/modelscript
build/modelscript.umd.js
createCentroids
function createCentroids(k) { var Centroid = []; var maxes = this.Observations.maxColumns(); //console.log(maxes); for(var i = 1; i <= k; i++) { var centroid = []; for(var j = 1; j <= this.Observations.cols(); j++) { centroid.push(Math.random() * maxes.e(j)); } Centroid.push(centroid); } //console.log(centroid) return $M(Centroid); }
javascript
function createCentroids(k) { var Centroid = []; var maxes = this.Observations.maxColumns(); //console.log(maxes); for(var i = 1; i <= k; i++) { var centroid = []; for(var j = 1; j <= this.Observations.cols(); j++) { centroid.push(Math.random() * maxes.e(j)); } Centroid.push(centroid); } //console.log(centroid) return $M(Centroid); }
[ "function", "createCentroids", "(", "k", ")", "{", "var", "Centroid", "=", "[", "]", ";", "var", "maxes", "=", "this", ".", "Observations", ".", "maxColumns", "(", ")", ";", "//console.log(maxes);", "for", "(", "var", "i", "=", "1", ";", "i", "<=", "k", ";", "i", "++", ")", "{", "var", "centroid", "=", "[", "]", ";", "for", "(", "var", "j", "=", "1", ";", "j", "<=", "this", ".", "Observations", ".", "cols", "(", ")", ";", "j", "++", ")", "{", "centroid", ".", "push", "(", "Math", ".", "random", "(", ")", "*", "maxes", ".", "e", "(", "j", ")", ")", ";", "}", "Centroid", ".", "push", "(", "centroid", ")", ";", "}", "//console.log(centroid)", "return", "$M", "(", "Centroid", ")", ";", "}" ]
create an initial centroid matrix with initial values between 0 and the max of feature data X.
[ "create", "an", "initial", "centroid", "matrix", "with", "initial", "values", "between", "0", "and", "the", "max", "of", "feature", "data", "X", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L76337-L76354
22,693
repetere/modelscript
build/modelscript.umd.js
distanceFrom
function distanceFrom(Centroids) { var distances = []; for(var i = 1; i <= this.Observations.rows(); i++) { var distance = []; for(var j = 1; j <= Centroids.rows(); j++) { distance.push(this.Observations.row(i).distanceFrom(Centroids.row(j))); } distances.push(distance); } return $M(distances); }
javascript
function distanceFrom(Centroids) { var distances = []; for(var i = 1; i <= this.Observations.rows(); i++) { var distance = []; for(var j = 1; j <= Centroids.rows(); j++) { distance.push(this.Observations.row(i).distanceFrom(Centroids.row(j))); } distances.push(distance); } return $M(distances); }
[ "function", "distanceFrom", "(", "Centroids", ")", "{", "var", "distances", "=", "[", "]", ";", "for", "(", "var", "i", "=", "1", ";", "i", "<=", "this", ".", "Observations", ".", "rows", "(", ")", ";", "i", "++", ")", "{", "var", "distance", "=", "[", "]", ";", "for", "(", "var", "j", "=", "1", ";", "j", "<=", "Centroids", ".", "rows", "(", ")", ";", "j", "++", ")", "{", "distance", ".", "push", "(", "this", ".", "Observations", ".", "row", "(", "i", ")", ".", "distanceFrom", "(", "Centroids", ".", "row", "(", "j", ")", ")", ")", ";", "}", "distances", ".", "push", "(", "distance", ")", ";", "}", "return", "$M", "(", "distances", ")", ";", "}" ]
get the euclidian distance between the feature data X and a given centroid matrix C.
[ "get", "the", "euclidian", "distance", "between", "the", "feature", "data", "X", "and", "a", "given", "centroid", "matrix", "C", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L76358-L76372
22,694
repetere/modelscript
build/modelscript.umd.js
cluster
function cluster(k) { var Centroids = this.createCentroids(k); var LastDistances = Matrix$d.Zero(this.Observations.rows(), this.Observations.cols()); var Distances = this.distanceFrom(Centroids); var Groups; while(!(LastDistances.eql(Distances))) { Groups = Distances.minColumnIndexes(); LastDistances = Distances; var newCentroids = []; for(var i = 1; i <= Centroids.rows(); i++) { var centroid = []; for(var j = 1; j <= Centroids.cols(); j++) { var sum = 0; var count = 0; for(var l = 1; l <= this.Observations.rows(); l++) { if(Groups.e(l) == i) { count++; sum += this.Observations.e(l, j); } } centroid.push(sum / count); } newCentroids.push(centroid); } Centroids = $M(newCentroids); Distances = this.distanceFrom(Centroids); } return Groups; }
javascript
function cluster(k) { var Centroids = this.createCentroids(k); var LastDistances = Matrix$d.Zero(this.Observations.rows(), this.Observations.cols()); var Distances = this.distanceFrom(Centroids); var Groups; while(!(LastDistances.eql(Distances))) { Groups = Distances.minColumnIndexes(); LastDistances = Distances; var newCentroids = []; for(var i = 1; i <= Centroids.rows(); i++) { var centroid = []; for(var j = 1; j <= Centroids.cols(); j++) { var sum = 0; var count = 0; for(var l = 1; l <= this.Observations.rows(); l++) { if(Groups.e(l) == i) { count++; sum += this.Observations.e(l, j); } } centroid.push(sum / count); } newCentroids.push(centroid); } Centroids = $M(newCentroids); Distances = this.distanceFrom(Centroids); } return Groups; }
[ "function", "cluster", "(", "k", ")", "{", "var", "Centroids", "=", "this", ".", "createCentroids", "(", "k", ")", ";", "var", "LastDistances", "=", "Matrix$d", ".", "Zero", "(", "this", ".", "Observations", ".", "rows", "(", ")", ",", "this", ".", "Observations", ".", "cols", "(", ")", ")", ";", "var", "Distances", "=", "this", ".", "distanceFrom", "(", "Centroids", ")", ";", "var", "Groups", ";", "while", "(", "!", "(", "LastDistances", ".", "eql", "(", "Distances", ")", ")", ")", "{", "Groups", "=", "Distances", ".", "minColumnIndexes", "(", ")", ";", "LastDistances", "=", "Distances", ";", "var", "newCentroids", "=", "[", "]", ";", "for", "(", "var", "i", "=", "1", ";", "i", "<=", "Centroids", ".", "rows", "(", ")", ";", "i", "++", ")", "{", "var", "centroid", "=", "[", "]", ";", "for", "(", "var", "j", "=", "1", ";", "j", "<=", "Centroids", ".", "cols", "(", ")", ";", "j", "++", ")", "{", "var", "sum", "=", "0", ";", "var", "count", "=", "0", ";", "for", "(", "var", "l", "=", "1", ";", "l", "<=", "this", ".", "Observations", ".", "rows", "(", ")", ";", "l", "++", ")", "{", "if", "(", "Groups", ".", "e", "(", "l", ")", "==", "i", ")", "{", "count", "++", ";", "sum", "+=", "this", ".", "Observations", ".", "e", "(", "l", ",", "j", ")", ";", "}", "}", "centroid", ".", "push", "(", "sum", "/", "count", ")", ";", "}", "newCentroids", ".", "push", "(", "centroid", ")", ";", "}", "Centroids", "=", "$M", "(", "newCentroids", ")", ";", "Distances", "=", "this", ".", "distanceFrom", "(", "Centroids", ")", ";", "}", "return", "Groups", ";", "}" ]
categorize the feature data X into k clusters. return a vector containing the results.
[ "categorize", "the", "feature", "data", "X", "into", "k", "clusters", ".", "return", "a", "vector", "containing", "the", "results", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L76376-L76413
22,695
repetere/modelscript
build/modelscript.umd.js
function (str) { var allPairs = [], pairs; var words = str.split(/\s+/); for (var i = 0; i < words.length; i++) { pairs = letterPairs(words[i]); allPairs.push.apply(allPairs, pairs); } return allPairs; }
javascript
function (str) { var allPairs = [], pairs; var words = str.split(/\s+/); for (var i = 0; i < words.length; i++) { pairs = letterPairs(words[i]); allPairs.push.apply(allPairs, pairs); } return allPairs; }
[ "function", "(", "str", ")", "{", "var", "allPairs", "=", "[", "]", ",", "pairs", ";", "var", "words", "=", "str", ".", "split", "(", "/", "\\s+", "/", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "words", ".", "length", ";", "i", "++", ")", "{", "pairs", "=", "letterPairs", "(", "words", "[", "i", "]", ")", ";", "allPairs", ".", "push", ".", "apply", "(", "allPairs", ",", "pairs", ")", ";", "}", "return", "allPairs", ";", "}" ]
Get all of the pairs in all of the words for a string
[ "Get", "all", "of", "the", "pairs", "in", "all", "of", "the", "words", "for", "a", "string" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L79378-L79386
22,696
repetere/modelscript
build/modelscript.umd.js
function (str1, str2) { var sanitized_str1 = sanitize(str1); var sanitized_str2 = sanitize(str2); var pairs1 = wordLetterPairs(sanitized_str1); var pairs2 = wordLetterPairs(sanitized_str2); var intersection = 0, union = pairs1.length + pairs2.length; if (union === 0) { if (sanitized_str1 === sanitized_str2) { return 1; } else { return 0; } } else { var i, j, pair1, pair2; for (i = 0; i < pairs1.length; i++) { pair1 = pairs1[i]; for (j = 0; j < pairs2.length; j++) { pair2 = pairs2[j]; if (pair1 == pair2) { intersection ++; delete pairs2[j]; break; } } } return 2 * intersection / union; } }
javascript
function (str1, str2) { var sanitized_str1 = sanitize(str1); var sanitized_str2 = sanitize(str2); var pairs1 = wordLetterPairs(sanitized_str1); var pairs2 = wordLetterPairs(sanitized_str2); var intersection = 0, union = pairs1.length + pairs2.length; if (union === 0) { if (sanitized_str1 === sanitized_str2) { return 1; } else { return 0; } } else { var i, j, pair1, pair2; for (i = 0; i < pairs1.length; i++) { pair1 = pairs1[i]; for (j = 0; j < pairs2.length; j++) { pair2 = pairs2[j]; if (pair1 == pair2) { intersection ++; delete pairs2[j]; break; } } } return 2 * intersection / union; } }
[ "function", "(", "str1", ",", "str2", ")", "{", "var", "sanitized_str1", "=", "sanitize", "(", "str1", ")", ";", "var", "sanitized_str2", "=", "sanitize", "(", "str2", ")", ";", "var", "pairs1", "=", "wordLetterPairs", "(", "sanitized_str1", ")", ";", "var", "pairs2", "=", "wordLetterPairs", "(", "sanitized_str2", ")", ";", "var", "intersection", "=", "0", ",", "union", "=", "pairs1", ".", "length", "+", "pairs2", ".", "length", ";", "if", "(", "union", "===", "0", ")", "{", "if", "(", "sanitized_str1", "===", "sanitized_str2", ")", "{", "return", "1", ";", "}", "else", "{", "return", "0", ";", "}", "}", "else", "{", "var", "i", ",", "j", ",", "pair1", ",", "pair2", ";", "for", "(", "i", "=", "0", ";", "i", "<", "pairs1", ".", "length", ";", "i", "++", ")", "{", "pair1", "=", "pairs1", "[", "i", "]", ";", "for", "(", "j", "=", "0", ";", "j", "<", "pairs2", ".", "length", ";", "j", "++", ")", "{", "pair2", "=", "pairs2", "[", "j", "]", ";", "if", "(", "pair1", "==", "pair2", ")", "{", "intersection", "++", ";", "delete", "pairs2", "[", "j", "]", ";", "break", ";", "}", "}", "}", "return", "2", "*", "intersection", "/", "union", ";", "}", "}" ]
Compare two strings, and spit out a number from 0-1
[ "Compare", "two", "strings", "and", "spit", "out", "a", "number", "from", "0", "-", "1" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L79394-L79421
22,697
repetere/modelscript
build/modelscript.umd.js
function(tokens) { if(typeof tokens === "string") { tokens = [tokens]; } var results = []; var rule_count = rules$3.length; var num_tokens = tokens.length; var i, token, r, rule; for (i = 0; i < num_tokens; i++) { token = tokens[i]; // Check the conversion table if (conversionTable[token.toLowerCase()]) { results = results.concat(conversionTable[token.toLowerCase()].split(/\W+/)); } // Apply the rules else { var matched = false; for ( r = 0; r < rule_count; r++) { rule = rules$3[r]; if (token.match(rule.regex)) { results = results.concat(token.replace(rule.regex, rule.output).split(/\W+/)); matched = true; break; } } if (!matched) { results.push(token); } } } return results; }
javascript
function(tokens) { if(typeof tokens === "string") { tokens = [tokens]; } var results = []; var rule_count = rules$3.length; var num_tokens = tokens.length; var i, token, r, rule; for (i = 0; i < num_tokens; i++) { token = tokens[i]; // Check the conversion table if (conversionTable[token.toLowerCase()]) { results = results.concat(conversionTable[token.toLowerCase()].split(/\W+/)); } // Apply the rules else { var matched = false; for ( r = 0; r < rule_count; r++) { rule = rules$3[r]; if (token.match(rule.regex)) { results = results.concat(token.replace(rule.regex, rule.output).split(/\W+/)); matched = true; break; } } if (!matched) { results.push(token); } } } return results; }
[ "function", "(", "tokens", ")", "{", "if", "(", "typeof", "tokens", "===", "\"string\"", ")", "{", "tokens", "=", "[", "tokens", "]", ";", "}", "var", "results", "=", "[", "]", ";", "var", "rule_count", "=", "rules$3", ".", "length", ";", "var", "num_tokens", "=", "tokens", ".", "length", ";", "var", "i", ",", "token", ",", "r", ",", "rule", ";", "for", "(", "i", "=", "0", ";", "i", "<", "num_tokens", ";", "i", "++", ")", "{", "token", "=", "tokens", "[", "i", "]", ";", "// Check the conversion table", "if", "(", "conversionTable", "[", "token", ".", "toLowerCase", "(", ")", "]", ")", "{", "results", "=", "results", ".", "concat", "(", "conversionTable", "[", "token", ".", "toLowerCase", "(", ")", "]", ".", "split", "(", "/", "\\W+", "/", ")", ")", ";", "}", "// Apply the rules", "else", "{", "var", "matched", "=", "false", ";", "for", "(", "r", "=", "0", ";", "r", "<", "rule_count", ";", "r", "++", ")", "{", "rule", "=", "rules$3", "[", "r", "]", ";", "if", "(", "token", ".", "match", "(", "rule", ".", "regex", ")", ")", "{", "results", "=", "results", ".", "concat", "(", "token", ".", "replace", "(", "rule", ".", "regex", ",", "rule", ".", "output", ")", ".", "split", "(", "/", "\\W+", "/", ")", ")", ";", "matched", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "matched", ")", "{", "results", ".", "push", "(", "token", ")", ";", "}", "}", "}", "return", "results", ";", "}" ]
Accepts a list of tokens to expand.
[ "Accepts", "a", "list", "of", "tokens", "to", "expand", "." ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.umd.js#L79443-L79477
22,698
repetere/modelscript
build/modelscript.cjs.js
StandardScalerTransforms
function StandardScalerTransforms(vector = [], nan_value = -1, return_nan=false) { const average = avg(vector); const standard_dev = sd(vector); const maximum = max(vector); const minimum = min(vector); const scale = (z) => { const scaledValue = (z - average) / standard_dev; if (isNaN(scaledValue) && return_nan) return scaledValue; else if (isNaN(scaledValue) && return_nan === false) return (isNaN(standard_dev)) ? z : standard_dev; else return scaledValue; }; // equivalent to MinMaxScaler(z) const descale = (scaledZ) => { const descaledValue = (scaledZ * standard_dev) + average; if (isNaN(descaledValue) && return_nan) return descaledValue; else if (isNaN(descaledValue) && return_nan === false) return (isNaN(standard_dev)) ? scaledZ : standard_dev; else return descaledValue; }; const values = vector.map(scale) .map(val => { if (isNaN(val)) return nan_value; else return val; }); return { components: { average, standard_dev, maximum, minimum, }, scale, descale, values, }; }
javascript
function StandardScalerTransforms(vector = [], nan_value = -1, return_nan=false) { const average = avg(vector); const standard_dev = sd(vector); const maximum = max(vector); const minimum = min(vector); const scale = (z) => { const scaledValue = (z - average) / standard_dev; if (isNaN(scaledValue) && return_nan) return scaledValue; else if (isNaN(scaledValue) && return_nan === false) return (isNaN(standard_dev)) ? z : standard_dev; else return scaledValue; }; // equivalent to MinMaxScaler(z) const descale = (scaledZ) => { const descaledValue = (scaledZ * standard_dev) + average; if (isNaN(descaledValue) && return_nan) return descaledValue; else if (isNaN(descaledValue) && return_nan === false) return (isNaN(standard_dev)) ? scaledZ : standard_dev; else return descaledValue; }; const values = vector.map(scale) .map(val => { if (isNaN(val)) return nan_value; else return val; }); return { components: { average, standard_dev, maximum, minimum, }, scale, descale, values, }; }
[ "function", "StandardScalerTransforms", "(", "vector", "=", "[", "]", ",", "nan_value", "=", "-", "1", ",", "return_nan", "=", "false", ")", "{", "const", "average", "=", "avg", "(", "vector", ")", ";", "const", "standard_dev", "=", "sd", "(", "vector", ")", ";", "const", "maximum", "=", "max", "(", "vector", ")", ";", "const", "minimum", "=", "min", "(", "vector", ")", ";", "const", "scale", "=", "(", "z", ")", "=>", "{", "const", "scaledValue", "=", "(", "z", "-", "average", ")", "/", "standard_dev", ";", "if", "(", "isNaN", "(", "scaledValue", ")", "&&", "return_nan", ")", "return", "scaledValue", ";", "else", "if", "(", "isNaN", "(", "scaledValue", ")", "&&", "return_nan", "===", "false", ")", "return", "(", "isNaN", "(", "standard_dev", ")", ")", "?", "z", ":", "standard_dev", ";", "else", "return", "scaledValue", ";", "}", ";", "// equivalent to MinMaxScaler(z)\r", "const", "descale", "=", "(", "scaledZ", ")", "=>", "{", "const", "descaledValue", "=", "(", "scaledZ", "*", "standard_dev", ")", "+", "average", ";", "if", "(", "isNaN", "(", "descaledValue", ")", "&&", "return_nan", ")", "return", "descaledValue", ";", "else", "if", "(", "isNaN", "(", "descaledValue", ")", "&&", "return_nan", "===", "false", ")", "return", "(", "isNaN", "(", "standard_dev", ")", ")", "?", "scaledZ", ":", "standard_dev", ";", "else", "return", "descaledValue", ";", "}", ";", "const", "values", "=", "vector", ".", "map", "(", "scale", ")", ".", "map", "(", "val", "=>", "{", "if", "(", "isNaN", "(", "val", ")", ")", "return", "nan_value", ";", "else", "return", "val", ";", "}", ")", ";", "return", "{", "components", ":", "{", "average", ",", "standard_dev", ",", "maximum", ",", "minimum", ",", "}", ",", "scale", ",", "descale", ",", "values", ",", "}", ";", "}" ]
This function returns two functions that can standard scale new inputs and reverse scale new outputs @param {Number[]} values - array of numbers @returns {Object} - {scale[ Function ], descale[ Function ]}
[ "This", "function", "returns", "two", "functions", "that", "can", "standard", "scale", "new", "inputs", "and", "reverse", "scale", "new", "outputs" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.cjs.js#L377-L410
22,699
repetere/modelscript
build/modelscript.cjs.js
assocationRuleLearning
function assocationRuleLearning(transactions =[], options) { return new Promise((resolve, reject) => { try { const config = Object.assign({}, { support: 0.4, minLength: 2, summary: true, valuesMap: new Map(), }, options); const fpgrowth = new FPGrowth(config.support); fpgrowth.exec(transactions) .then(results => { const itemsets = (results.itemsets) ? results.itemsets : results; // console.log('itemsets', itemsets) if (config.summary) { resolve(itemsets .map(itemset => ({ items_labels: itemset.items.map(item => config.valuesMap.get(item)), items: itemset.items, support: itemset.support, support_percent: itemset.support / transactions.length, })) .filter(itemset => itemset.items.length > 1) .sort((a, b) => b.support - a.support)); } else { resolve(results); } }) .catch(reject); } catch (e) { reject(e); } }); }
javascript
function assocationRuleLearning(transactions =[], options) { return new Promise((resolve, reject) => { try { const config = Object.assign({}, { support: 0.4, minLength: 2, summary: true, valuesMap: new Map(), }, options); const fpgrowth = new FPGrowth(config.support); fpgrowth.exec(transactions) .then(results => { const itemsets = (results.itemsets) ? results.itemsets : results; // console.log('itemsets', itemsets) if (config.summary) { resolve(itemsets .map(itemset => ({ items_labels: itemset.items.map(item => config.valuesMap.get(item)), items: itemset.items, support: itemset.support, support_percent: itemset.support / transactions.length, })) .filter(itemset => itemset.items.length > 1) .sort((a, b) => b.support - a.support)); } else { resolve(results); } }) .catch(reject); } catch (e) { reject(e); } }); }
[ "function", "assocationRuleLearning", "(", "transactions", "=", "[", "]", ",", "options", ")", "{", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "try", "{", "const", "config", "=", "Object", ".", "assign", "(", "{", "}", ",", "{", "support", ":", "0.4", ",", "minLength", ":", "2", ",", "summary", ":", "true", ",", "valuesMap", ":", "new", "Map", "(", ")", ",", "}", ",", "options", ")", ";", "const", "fpgrowth", "=", "new", "FPGrowth", "(", "config", ".", "support", ")", ";", "fpgrowth", ".", "exec", "(", "transactions", ")", ".", "then", "(", "results", "=>", "{", "const", "itemsets", "=", "(", "results", ".", "itemsets", ")", "?", "results", ".", "itemsets", ":", "results", ";", "// console.log('itemsets', itemsets)\r", "if", "(", "config", ".", "summary", ")", "{", "resolve", "(", "itemsets", ".", "map", "(", "itemset", "=>", "(", "{", "items_labels", ":", "itemset", ".", "items", ".", "map", "(", "item", "=>", "config", ".", "valuesMap", ".", "get", "(", "item", ")", ")", ",", "items", ":", "itemset", ".", "items", ",", "support", ":", "itemset", ".", "support", ",", "support_percent", ":", "itemset", ".", "support", "/", "transactions", ".", "length", ",", "}", ")", ")", ".", "filter", "(", "itemset", "=>", "itemset", ".", "items", ".", "length", ">", "1", ")", ".", "sort", "(", "(", "a", ",", "b", ")", "=>", "b", ".", "support", "-", "a", ".", "support", ")", ")", ";", "}", "else", "{", "resolve", "(", "results", ")", ";", "}", "}", ")", ".", "catch", "(", "reject", ")", ";", "}", "catch", "(", "e", ")", "{", "reject", "(", "e", ")", ";", "}", "}", ")", ";", "}" ]
returns association rule learning results @memberOf calc @see {@link https://github.com/alexisfacques/Node-FPGrowth} @param {Array} transactions - sparse matrix of transactions @param {Object} options @param {Number} [options.support=0.4] - support level @param {Number} [options.minLength=2] - minimum assocation array size @param {Boolean} [options.summary=true] - return summarized results @param {Map} [options.valuesMap=new Map()] - map of values and labels (used for summary results) @returns {Object} Returns the result from Node-FPGrowth or a summary of support and strong associations
[ "returns", "association", "rule", "learning", "results" ]
b507fad9b3ecfb4a9ec4d44d41052a8082dac763
https://github.com/repetere/modelscript/blob/b507fad9b3ecfb4a9ec4d44d41052a8082dac763/build/modelscript.cjs.js#L742-L775