diff --git a/bower.json b/bower.json index 4539408..0a7f47c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ml-gsd", - "version": "2.0.6", + "version": "5.0.1", "description": "Global Spectra Deconvolution", "keywords": [ "optimization", diff --git a/dist/ml-gsd.js b/dist/ml-gsd.js new file mode 100644 index 0000000..5a457c2 --- /dev/null +++ b/dist/ml-gsd.js @@ -0,0 +1,5496 @@ +/** + * ml-gsd - Global Spectra Deconvolution + * @version v5.0.1 + * @link https://github.com/mljs/global-spectral-deconvolution + * @license MIT + */ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = global || self, factory(global.GSD = {})); +}(this, (function (exports) { 'use strict'; + + function SavitzkyGolay(data, h) { + let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let { + windowSize = 9, + derivative = 0, + polynomial = 3 + } = options; + + if (windowSize % 2 === 0 || windowSize < 5 || !Number.isInteger(windowSize)) { + throw new RangeError('Invalid window size (should be odd and at least 5 integer number)'); + } + + if (windowSize > data.length) { + throw new RangeError("Window size is higher than the data length ".concat(windowSize, ">").concat(data.length)); + } + + if (derivative < 0 || !Number.isInteger(derivative)) { + throw new RangeError('Derivative should be a positive integer'); + } + + if (polynomial < 1 || !Number.isInteger(polynomial)) { + throw new RangeError('Polynomial should be a positive integer'); + } + + if (polynomial >= 6) { + // eslint-disable-next-line no-console + console.warn('You should not use polynomial grade higher than 5 if you are' + ' not sure that your data arises from such a model. Possible polynomial oscillation problems'); + } + + let half = Math.floor(windowSize / 2); + let np = data.length; + let ans = new Array(np); + let weights = fullWeights(windowSize, polynomial, derivative); + let hs = 0; + let constantH = true; + + if (Array.isArray(h)) { + constantH = false; + } else { + hs = Math.pow(h, derivative); + } //For the borders + + + for (let i = 0; i < half; i++) { + let wg1 = weights[half - i - 1]; + let wg2 = weights[half + i + 1]; + let d1 = 0; + let d2 = 0; + + for (let l = 0; l < windowSize; l++) { + d1 += wg1[l] * data[l]; + d2 += wg2[l] * data[np - windowSize + l]; + } + + if (constantH) { + ans[half - i - 1] = d1 / hs; + ans[np - half + i] = d2 / hs; + } else { + hs = getHs(h, half - i - 1, half, derivative); + ans[half - i - 1] = d1 / hs; + hs = getHs(h, np - half + i, half, derivative); + ans[np - half + i] = d2 / hs; + } + } //For the internal points + + + let wg = weights[half]; + + for (let i = windowSize; i <= np; i++) { + let d = 0; + + for (let l = 0; l < windowSize; l++) d += wg[l] * data[l + i - windowSize]; + + if (!constantH) hs = getHs(h, i - half - 1, half, derivative); + ans[i - half - 1] = d / hs; + } + + return ans; + } + + function getHs(h, center, half, derivative) { + let hs = 0; + let count = 0; + + for (let i = center - half; i < center + half; i++) { + if (i >= 0 && i < h.length - 1) { + hs += h[i + 1] - h[i]; + count++; + } + } + + return Math.pow(hs / count, derivative); + } + + function GramPoly(i, m, k, s) { + let Grampoly = 0; + + if (k > 0) { + Grampoly = (4 * k - 2) / (k * (2 * m - k + 1)) * (i * GramPoly(i, m, k - 1, s) + s * GramPoly(i, m, k - 1, s - 1)) - (k - 1) * (2 * m + k) / (k * (2 * m - k + 1)) * GramPoly(i, m, k - 2, s); + } else { + if (k === 0 && s === 0) { + Grampoly = 1; + } else { + Grampoly = 0; + } + } + + return Grampoly; + } + + function GenFact(a, b) { + let gf = 1; + + if (a >= b) { + for (let j = a - b + 1; j <= a; j++) { + gf *= j; + } + } + + return gf; + } + + function Weight(i, t, m, n, s) { + let sum = 0; + + for (let k = 0; k <= n; k++) { + //console.log(k); + sum += (2 * k + 1) * (GenFact(2 * m, k) / GenFact(2 * m + k + 1, k + 1)) * GramPoly(i, m, k, 0) * GramPoly(t, m, k, s); + } + + return sum; + } + /** + * + * @param m Number of points + * @param n Polynomial grade + * @param s Derivative + */ + + + function fullWeights(m, n, s) { + let weights = new Array(m); + let np = Math.floor(m / 2); + + for (let t = -np; t <= np; t++) { + weights[t + np] = new Array(m); + + for (let j = -np; j <= np; j++) { + weights[t + np][j + np] = Weight(j, t, np, n, s); + } + } + + return weights; + } + /*function entropy(data,h,options){ + var trend = SavitzkyGolay(data,h,trendOptions); + var copy = new Array(data.length); + var sum = 0; + var max = 0; + for(var i=0;i} x - Independent variable + * @param {Array} yIn - Dependent variable + * @param {object} [options] - Options object + * @param {object} [options.sgOptions] - Options object for Savitzky-Golay filter. See https://github.com/mljs/savitzky-golay-generalized#options + * @param {number} [options.sgOptions.windowSize = 9] - points to use in the approximations + * @param {number} [options.sgOptions.polynomial = 3] - degree of the polynomial to use in the approximations + * @param {number} [options.minMaxRatio = 0.00025] - Threshold to determine if a given peak should be considered as a noise + * @param {number} [options.broadRatio = 0.00] - If `broadRatio` is higher than 0, then all the peaks which second derivative + * smaller than `broadRatio * maxAbsSecondDerivative` will be marked with the soft mask equal to true. + * @param {number} [options.noiseLevel = 0] - Noise threshold in spectrum units + * @param {boolean} [options.maxCriteria = true] - Peaks are local maximum(true) or minimum(false) + * @param {boolean} [options.smoothY = true] - Select the peak intensities from a smoothed version of the independent variables + * @param {boolean} [options.realTopDetection = false] - Use a quadratic optimizations with the peak and its 3 closest neighbors + * to determine the true x,y values of the peak? + * @param {number} [options.heightFactor = 0] - Factor to multiply the calculated height (usually 2) + * @param {boolean} [options.boundaries = false] - Return also the inflection points of the peaks + * @param {number} [options.derivativeThreshold = -1] - Filters based on the amplitude of the first derivative + * @return {Array} + */ + + function gsd(x, yIn) { + let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let { + noiseLevel, + sgOptions = { + windowSize: 9, + polynomial: 3 + }, + smoothY = true, + heightFactor = 0, + broadRatio = 0.0, + maxCriteria = true, + minMaxRatio = 0.00025, + derivativeThreshold = -1, + realTopDetection = false + } = options; + const y = yIn.slice(); + let equalSpaced = isEqualSpaced(x); + + if (noiseLevel === undefined) { + noiseLevel = equalSpaced ? getNoiseLevel(y) : 0; + } + + const yCorrection = { + m: 1, + b: noiseLevel + }; + + if (!maxCriteria) { + yCorrection.m = -1; + yCorrection.b *= -1; + } + + for (let i = 0; i < y.length; i++) { + y[i] = yCorrection.m * y[i] - yCorrection.b; + } + + for (let i = 0; i < y.length; i++) { + if (y[i] < 0) { + y[i] = 0; + } + } // If the max difference between delta x is less than 5%, then, + // we can assume it to be equally spaced variable + + + let Y = y; + let dY, ddY; + const { + windowSize, + polynomial + } = sgOptions; + + if (equalSpaced) { + if (smoothY) { + Y = SavitzkyGolay(y, x[1] - x[0], { + windowSize, + polynomial, + derivative: 0 + }); + } + + dY = SavitzkyGolay(y, x[1] - x[0], { + windowSize, + polynomial, + derivative: 1 + }); + ddY = SavitzkyGolay(y, x[1] - x[0], { + windowSize, + polynomial, + derivative: 2 + }); + } else { + if (smoothY) { + Y = SavitzkyGolay(y, x, { + windowSize, + polynomial, + derivative: 0 + }); + } + + dY = SavitzkyGolay(y, x, { + windowSize, + polynomial, + derivative: 1 + }); + ddY = SavitzkyGolay(y, x, { + windowSize, + polynomial, + derivative: 2 + }); + } // console.log('this is 2', y) + + + const X = x; + const dx = x[1] - x[0]; + let maxDdy = 0; + let maxY = 0; + + for (let i = 0; i < Y.length; i++) { + if (Math.abs(ddY[i]) > maxDdy) { + maxDdy = Math.abs(ddY[i]); + } + + if (Math.abs(Y[i]) > maxY) { + maxY = Math.abs(Y[i]); + } + } + + let lastMax = null; + let lastMin = null; + let minddY = new Array(Y.length - 2); + let intervalL = new Array(Y.length); + let intervalR = new Array(Y.length); + let broadMask = new Array(Y.length - 2); + let minddYLen = 0; + let intervalLLen = 0; + let intervalRLen = 0; + let broadMaskLen = 0; // By the intermediate value theorem We cannot find 2 consecutive maximum or minimum + + for (let i = 1; i < Y.length - 1; ++i) { + // filter based on derivativeThreshold + // console.log('pasa', y[i], dY[i], ddY[i]); + if (Math.abs(dY[i]) > derivativeThreshold) { + // Minimum in first derivative + if (dY[i] < dY[i - 1] && dY[i] <= dY[i + 1] || dY[i] <= dY[i - 1] && dY[i] < dY[i + 1]) { + lastMin = { + x: X[i], + index: i + }; + + if (dx > 0 && lastMax !== null) { + intervalL[intervalLLen++] = lastMax; + intervalR[intervalRLen++] = lastMin; + } + } // Maximum in first derivative + + + if (dY[i] >= dY[i - 1] && dY[i] > dY[i + 1] || dY[i] > dY[i - 1] && dY[i] >= dY[i + 1]) { + lastMax = { + x: X[i], + index: i + }; + + if (dx < 0 && lastMin !== null) { + intervalL[intervalLLen++] = lastMax; + intervalR[intervalRLen++] = lastMin; + } + } + } // Minimum in second derivative + + + if (ddY[i] < ddY[i - 1] && ddY[i] < ddY[i + 1]) { + // TODO should we change this to have 3 arrays ? Huge overhead creating arrays + minddY[minddYLen++] = i; // ( [X[i], Y[i], i] ); + + broadMask[broadMaskLen++] = Math.abs(ddY[i]) <= broadRatio * maxDdy; + } + } + + minddY.length = minddYLen; + intervalL.length = intervalLLen; + intervalR.length = intervalRLen; + broadMask.length = broadMaskLen; + let signals = new Array(minddY.length); + let signalsLen = 0; + let lastK = -1; + let possible, frequency, distanceJ, minDistance, gettingCloser; + + for (let j = 0; j < minddY.length; ++j) { + frequency = X[minddY[j]]; + possible = -1; + let k = lastK + 1; + minDistance = Number.MAX_VALUE; + distanceJ = 0; + gettingCloser = true; + + while (possible === -1 && k < intervalL.length && gettingCloser) { + distanceJ = Math.abs(frequency - (intervalL[k].x + intervalR[k].x) / 2); // Still getting closer? + + if (distanceJ < minDistance) { + minDistance = distanceJ; + } else { + gettingCloser = false; + } + + if (distanceJ < Math.abs(intervalL[k].x - intervalR[k].x) / 2) { + possible = k; + lastK = k; + } + + ++k; + } + + if (possible !== -1) { + if (Math.abs(Y[minddY[j]]) > minMaxRatio * maxY) { + signals[signalsLen++] = { + index: minddY[j], + x: frequency, + y: (Y[minddY[j]] + yCorrection.b) / yCorrection.m, + width: Math.abs(intervalR[possible].x - intervalL[possible].x), + // widthCorrection + soft: broadMask[j] + }; + signals[signalsLen - 1].left = intervalL[possible]; + signals[signalsLen - 1].right = intervalR[possible]; + + if (heightFactor) { + let yLeft = Y[intervalL[possible].index]; + let yRight = Y[intervalR[possible].index]; + signals[signalsLen - 1].height = heightFactor * (signals[signalsLen - 1].y - (yLeft + yRight) / 2); + } + } + } + } + + signals.length = signalsLen; + + if (realTopDetection) { + determineRealTop(signals, X, Y); + } // Correct the values to fit the original spectra data + + + for (let j = 0; j < signals.length; j++) { + signals[j].base = noiseLevel; + } + + signals.sort(function (a, b) { + return a.x - b.x; + }); + return signals; + } + + const isEqualSpaced = x => { + let tmp; + let maxDx = 0; + let minDx = Number.MAX_SAFE_INTEGER; + + for (let i = 0; i < x.length - 1; ++i) { + tmp = Math.abs(x[i + 1] - x[i]); + + if (tmp < minDx) { + minDx = tmp; + } + + if (tmp > maxDx) { + maxDx = tmp; + } + } + + return (maxDx - minDx) / maxDx < 0.05; + }; + + const getNoiseLevel = y => { + let mean = 0; + let stddev = 0; + let length = y.length; + + for (let i = 0; i < length; ++i) { + mean += y[i]; + } + + mean /= length; + let averageDeviations = new Array(length); + + for (let i = 0; i < length; ++i) { + averageDeviations[i] = Math.abs(y[i] - mean); + } + + averageDeviations.sort((a, b) => a - b); + + if (length % 2 === 1) { + stddev = averageDeviations[(length - 1) / 2] / 0.6745; + } else { + stddev = 0.5 * (averageDeviations[length / 2] + averageDeviations[length / 2 - 1]) / 0.6745; + } + + return stddev; + }; + + const determineRealTop = (peakList, x, y) => { + let alpha, beta, gamma, p, currentPoint; + + for (let j = 0; j < peakList.length; j++) { + currentPoint = peakList[j].index; // peakList[j][2]; + // The detected peak could be moved 1 or 2 units to left or right. + + if (y[currentPoint - 1] >= y[currentPoint - 2] && y[currentPoint - 1] >= y[currentPoint]) { + currentPoint--; + } else { + if (y[currentPoint + 1] >= y[currentPoint] && y[currentPoint + 1] >= y[currentPoint + 2]) { + currentPoint++; + } else { + if (y[currentPoint - 2] >= y[currentPoint - 3] && y[currentPoint - 2] >= y[currentPoint - 1]) { + currentPoint -= 2; + } else { + if (y[currentPoint + 2] >= y[currentPoint + 1] && y[currentPoint + 2] >= y[currentPoint + 3]) { + currentPoint += 2; + } + } + } + } // interpolation to a sin() function + + + if (y[currentPoint - 1] > 0 && y[currentPoint + 1] > 0 && y[currentPoint] >= y[currentPoint - 1] && y[currentPoint] >= y[currentPoint + 1] && (y[currentPoint] !== y[currentPoint - 1] || y[currentPoint] !== y[currentPoint + 1])) { + alpha = 20 * Math.log10(y[currentPoint - 1]); + beta = 20 * Math.log10(y[currentPoint]); + gamma = 20 * Math.log10(y[currentPoint + 1]); + p = 0.5 * (alpha - gamma) / (alpha - 2 * beta + gamma); // console.log(alpha, beta, gamma, `p: ${p}`); + // console.log(x[currentPoint]+" "+tmp+" "+currentPoint); + + peakList[j].x = x[currentPoint] + (x[currentPoint] - x[currentPoint - 1]) * p; + peakList[j].y = y[currentPoint] - 0.25 * (y[currentPoint - 1] - y[currentPoint + 1]) * p; + } + } + }; + + const toString = Object.prototype.toString; + function isAnyArray(object) { + return toString.call(object).endsWith('Array]'); + } + + /** + * Calculate current error + * @ignore + * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ] + * @param {Array} parameters - Array of current parameter values + * @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter + * @return {number} + */ + function errorCalculation(data, parameters, parameterizedFunction) { + let error = 0; + const func = parameterizedFunction(parameters); + + for (let i = 0; i < data.x.length; i++) { + error += Math.abs(data.y[i] - func(data.x[i])); + } + + return error; + } + + const toString$1 = Object.prototype.toString; + + function isAnyArray$1(object) { + return toString$1.call(object).endsWith('Array]'); + } + + var src = isAnyArray$1; + + const toString$2 = Object.prototype.toString; + + function isAnyArray$2(object) { + return toString$2.call(object).endsWith('Array]'); + } + + var src$1 = isAnyArray$2; + + /** + * Computes the maximum of the given values + * @param {Array} input + * @return {number} + */ + + function max(input) { + if (!src$1(input)) { + throw new TypeError('input must be an array'); + } + + if (input.length === 0) { + throw new TypeError('input must not be empty'); + } + + var maxValue = input[0]; + + for (var i = 1; i < input.length; i++) { + if (input[i] > maxValue) maxValue = input[i]; + } + + return maxValue; + } + + const toString$3 = Object.prototype.toString; + + function isAnyArray$3(object) { + return toString$3.call(object).endsWith('Array]'); + } + + var src$2 = isAnyArray$3; + + /** + * Computes the minimum of the given values + * @param {Array} input + * @return {number} + */ + + function min(input) { + if (!src$2(input)) { + throw new TypeError('input must be an array'); + } + + if (input.length === 0) { + throw new TypeError('input must not be empty'); + } + + var minValue = input[0]; + + for (var i = 1; i < input.length; i++) { + if (input[i] < minValue) minValue = input[i]; + } + + return minValue; + } + + /** + * + * @param {Array} input + * @param {object} [options={}] + * @param {Array} [options.output=[]] specify the output array, can be the input array for in place modification + */ + + function rescale(input) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + if (!src(input)) { + throw new TypeError('input must be an array'); + } else if (input.length === 0) { + throw new TypeError('input must not be empty'); + } + + var output; + + if (options.output !== undefined) { + if (!src(options.output)) { + throw new TypeError('output option must be an array if specified'); + } + + output = options.output; + } else { + output = new Array(input.length); + } + + var currentMin = min(input); + var currentMax = max(input); + + if (currentMin === currentMax) { + throw new RangeError('minimum and maximum input values are equal. Cannot rescale a constant array'); + } + + var _options$min = options.min, + minValue = _options$min === void 0 ? options.autoMinMax ? currentMin : 0 : _options$min, + _options$max = options.max, + maxValue = _options$max === void 0 ? options.autoMinMax ? currentMax : 1 : _options$max; + + if (minValue >= maxValue) { + throw new RangeError('min option must be smaller than max option'); + } + + var factor = (maxValue - minValue) / (currentMax - currentMin); + + for (var i = 0; i < input.length; i++) { + output[i] = (input[i] - currentMin) * factor + minValue; + } + + return output; + } + + const indent = ' '.repeat(2); + const indentData = ' '.repeat(4); + function inspectMatrix() { + return inspectMatrixWithOptions(this); + } + function inspectMatrixWithOptions(matrix) { + let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + maxRows = 15, + maxColumns = 10, + maxNumSize = 8 + } = options; + return "".concat(matrix.constructor.name, " {\n").concat(indent, "[\n").concat(indentData).concat(inspectData(matrix, maxRows, maxColumns, maxNumSize), "\n").concat(indent, "]\n").concat(indent, "rows: ").concat(matrix.rows, "\n").concat(indent, "columns: ").concat(matrix.columns, "\n}"); + } + + function inspectData(matrix, maxRows, maxColumns, maxNumSize) { + const { + rows, + columns + } = matrix; + const maxI = Math.min(rows, maxRows); + const maxJ = Math.min(columns, maxColumns); + const result = []; + + for (let i = 0; i < maxI; i++) { + let line = []; + + for (let j = 0; j < maxJ; j++) { + line.push(formatNumber(matrix.get(i, j), maxNumSize)); + } + + result.push("".concat(line.join(' '))); + } + + if (maxJ !== columns) { + result[result.length - 1] += " ... ".concat(columns - maxColumns, " more columns"); + } + + if (maxI !== rows) { + result.push("... ".concat(rows - maxRows, " more rows")); + } + + return result.join("\n".concat(indentData)); + } + + function formatNumber(num, maxNumSize) { + const numStr = String(num); + + if (numStr.length <= maxNumSize) { + return numStr.padEnd(maxNumSize, ' '); + } + + const precise = num.toPrecision(maxNumSize - 2); + + if (precise.length <= maxNumSize) { + return precise; + } + + const exponential = num.toExponential(maxNumSize - 2); + const eIndex = exponential.indexOf('e'); + const e = exponential.slice(eIndex); + return exponential.slice(0, maxNumSize - e.length) + e; + } + + function installMathOperations(AbstractMatrix, Matrix) { + AbstractMatrix.prototype.add = function add(value) { + if (typeof value === 'number') return this.addS(value); + return this.addM(value); + }; + + AbstractMatrix.prototype.addS = function addS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) + value); + } + } + + return this; + }; + + AbstractMatrix.prototype.addM = function addM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) + matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.add = function add(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.add(value); + }; + + AbstractMatrix.prototype.sub = function sub(value) { + if (typeof value === 'number') return this.subS(value); + return this.subM(value); + }; + + AbstractMatrix.prototype.subS = function subS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) - value); + } + } + + return this; + }; + + AbstractMatrix.prototype.subM = function subM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) - matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.sub = function sub(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.sub(value); + }; + + AbstractMatrix.prototype.subtract = AbstractMatrix.prototype.sub; + AbstractMatrix.prototype.subtractS = AbstractMatrix.prototype.subS; + AbstractMatrix.prototype.subtractM = AbstractMatrix.prototype.subM; + AbstractMatrix.subtract = AbstractMatrix.sub; + + AbstractMatrix.prototype.mul = function mul(value) { + if (typeof value === 'number') return this.mulS(value); + return this.mulM(value); + }; + + AbstractMatrix.prototype.mulS = function mulS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) * value); + } + } + + return this; + }; + + AbstractMatrix.prototype.mulM = function mulM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) * matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.mul = function mul(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.mul(value); + }; + + AbstractMatrix.prototype.multiply = AbstractMatrix.prototype.mul; + AbstractMatrix.prototype.multiplyS = AbstractMatrix.prototype.mulS; + AbstractMatrix.prototype.multiplyM = AbstractMatrix.prototype.mulM; + AbstractMatrix.multiply = AbstractMatrix.mul; + + AbstractMatrix.prototype.div = function div(value) { + if (typeof value === 'number') return this.divS(value); + return this.divM(value); + }; + + AbstractMatrix.prototype.divS = function divS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) / value); + } + } + + return this; + }; + + AbstractMatrix.prototype.divM = function divM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) / matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.div = function div(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.div(value); + }; + + AbstractMatrix.prototype.divide = AbstractMatrix.prototype.div; + AbstractMatrix.prototype.divideS = AbstractMatrix.prototype.divS; + AbstractMatrix.prototype.divideM = AbstractMatrix.prototype.divM; + AbstractMatrix.divide = AbstractMatrix.div; + + AbstractMatrix.prototype.mod = function mod(value) { + if (typeof value === 'number') return this.modS(value); + return this.modM(value); + }; + + AbstractMatrix.prototype.modS = function modS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) % value); + } + } + + return this; + }; + + AbstractMatrix.prototype.modM = function modM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) % matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.mod = function mod(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.mod(value); + }; + + AbstractMatrix.prototype.modulus = AbstractMatrix.prototype.mod; + AbstractMatrix.prototype.modulusS = AbstractMatrix.prototype.modS; + AbstractMatrix.prototype.modulusM = AbstractMatrix.prototype.modM; + AbstractMatrix.modulus = AbstractMatrix.mod; + + AbstractMatrix.prototype.and = function and(value) { + if (typeof value === 'number') return this.andS(value); + return this.andM(value); + }; + + AbstractMatrix.prototype.andS = function andS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) & value); + } + } + + return this; + }; + + AbstractMatrix.prototype.andM = function andM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) & matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.and = function and(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.and(value); + }; + + AbstractMatrix.prototype.or = function or(value) { + if (typeof value === 'number') return this.orS(value); + return this.orM(value); + }; + + AbstractMatrix.prototype.orS = function orS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) | value); + } + } + + return this; + }; + + AbstractMatrix.prototype.orM = function orM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) | matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.or = function or(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.or(value); + }; + + AbstractMatrix.prototype.xor = function xor(value) { + if (typeof value === 'number') return this.xorS(value); + return this.xorM(value); + }; + + AbstractMatrix.prototype.xorS = function xorS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) ^ value); + } + } + + return this; + }; + + AbstractMatrix.prototype.xorM = function xorM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) ^ matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.xor = function xor(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.xor(value); + }; + + AbstractMatrix.prototype.leftShift = function leftShift(value) { + if (typeof value === 'number') return this.leftShiftS(value); + return this.leftShiftM(value); + }; + + AbstractMatrix.prototype.leftShiftS = function leftShiftS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) << value); + } + } + + return this; + }; + + AbstractMatrix.prototype.leftShiftM = function leftShiftM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) << matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.leftShift = function leftShift(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.leftShift(value); + }; + + AbstractMatrix.prototype.signPropagatingRightShift = function signPropagatingRightShift(value) { + if (typeof value === 'number') return this.signPropagatingRightShiftS(value); + return this.signPropagatingRightShiftM(value); + }; + + AbstractMatrix.prototype.signPropagatingRightShiftS = function signPropagatingRightShiftS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) >> value); + } + } + + return this; + }; + + AbstractMatrix.prototype.signPropagatingRightShiftM = function signPropagatingRightShiftM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) >> matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.signPropagatingRightShift = function signPropagatingRightShift(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.signPropagatingRightShift(value); + }; + + AbstractMatrix.prototype.rightShift = function rightShift(value) { + if (typeof value === 'number') return this.rightShiftS(value); + return this.rightShiftM(value); + }; + + AbstractMatrix.prototype.rightShiftS = function rightShiftS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) >>> value); + } + } + + return this; + }; + + AbstractMatrix.prototype.rightShiftM = function rightShiftM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) >>> matrix.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.rightShift = function rightShift(matrix, value) { + const newMatrix = new Matrix(matrix); + return newMatrix.rightShift(value); + }; + + AbstractMatrix.prototype.zeroFillRightShift = AbstractMatrix.prototype.rightShift; + AbstractMatrix.prototype.zeroFillRightShiftS = AbstractMatrix.prototype.rightShiftS; + AbstractMatrix.prototype.zeroFillRightShiftM = AbstractMatrix.prototype.rightShiftM; + AbstractMatrix.zeroFillRightShift = AbstractMatrix.rightShift; + + AbstractMatrix.prototype.not = function not() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, ~this.get(i, j)); + } + } + + return this; + }; + + AbstractMatrix.not = function not(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.not(); + }; + + AbstractMatrix.prototype.abs = function abs() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.abs(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.abs = function abs(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.abs(); + }; + + AbstractMatrix.prototype.acos = function acos() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.acos(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.acos = function acos(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.acos(); + }; + + AbstractMatrix.prototype.acosh = function acosh() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.acosh(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.acosh = function acosh(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.acosh(); + }; + + AbstractMatrix.prototype.asin = function asin() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.asin(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.asin = function asin(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.asin(); + }; + + AbstractMatrix.prototype.asinh = function asinh() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.asinh(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.asinh = function asinh(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.asinh(); + }; + + AbstractMatrix.prototype.atan = function atan() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.atan(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.atan = function atan(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.atan(); + }; + + AbstractMatrix.prototype.atanh = function atanh() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.atanh(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.atanh = function atanh(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.atanh(); + }; + + AbstractMatrix.prototype.cbrt = function cbrt() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.cbrt(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.cbrt = function cbrt(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.cbrt(); + }; + + AbstractMatrix.prototype.ceil = function ceil() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.ceil(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.ceil = function ceil(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.ceil(); + }; + + AbstractMatrix.prototype.clz32 = function clz32() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.clz32(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.clz32 = function clz32(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.clz32(); + }; + + AbstractMatrix.prototype.cos = function cos() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.cos(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.cos = function cos(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.cos(); + }; + + AbstractMatrix.prototype.cosh = function cosh() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.cosh(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.cosh = function cosh(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.cosh(); + }; + + AbstractMatrix.prototype.exp = function exp() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.exp(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.exp = function exp(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.exp(); + }; + + AbstractMatrix.prototype.expm1 = function expm1() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.expm1(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.expm1 = function expm1(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.expm1(); + }; + + AbstractMatrix.prototype.floor = function floor() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.floor(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.floor = function floor(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.floor(); + }; + + AbstractMatrix.prototype.fround = function fround() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.fround(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.fround = function fround(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.fround(); + }; + + AbstractMatrix.prototype.log = function log() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.log(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.log = function log(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.log(); + }; + + AbstractMatrix.prototype.log1p = function log1p() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.log1p(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.log1p = function log1p(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.log1p(); + }; + + AbstractMatrix.prototype.log10 = function log10() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.log10(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.log10 = function log10(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.log10(); + }; + + AbstractMatrix.prototype.log2 = function log2() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.log2(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.log2 = function log2(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.log2(); + }; + + AbstractMatrix.prototype.round = function round() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.round(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.round = function round(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.round(); + }; + + AbstractMatrix.prototype.sign = function sign() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.sign(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.sign = function sign(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.sign(); + }; + + AbstractMatrix.prototype.sin = function sin() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.sin(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.sin = function sin(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.sin(); + }; + + AbstractMatrix.prototype.sinh = function sinh() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.sinh(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.sinh = function sinh(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.sinh(); + }; + + AbstractMatrix.prototype.sqrt = function sqrt() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.sqrt(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.sqrt = function sqrt(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.sqrt(); + }; + + AbstractMatrix.prototype.tan = function tan() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.tan(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.tan = function tan(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.tan(); + }; + + AbstractMatrix.prototype.tanh = function tanh() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.tanh(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.tanh = function tanh(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.tanh(); + }; + + AbstractMatrix.prototype.trunc = function trunc() { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.trunc(this.get(i, j))); + } + } + + return this; + }; + + AbstractMatrix.trunc = function trunc(matrix) { + const newMatrix = new Matrix(matrix); + return newMatrix.trunc(); + }; + + AbstractMatrix.pow = function pow(matrix, arg0) { + const newMatrix = new Matrix(matrix); + return newMatrix.pow(arg0); + }; + + AbstractMatrix.prototype.pow = function pow(value) { + if (typeof value === 'number') return this.powS(value); + return this.powM(value); + }; + + AbstractMatrix.prototype.powS = function powS(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.pow(this.get(i, j), value)); + } + } + + return this; + }; + + AbstractMatrix.prototype.powM = function powM(matrix) { + matrix = Matrix.checkMatrix(matrix); + + if (this.rows !== matrix.rows || this.columns !== matrix.columns) { + throw new RangeError('Matrices dimensions must be equal'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, Math.pow(this.get(i, j), matrix.get(i, j))); + } + } + + return this; + }; + } + + /** + * @private + * Check that a row index is not out of bounds + * @param {Matrix} matrix + * @param {number} index + * @param {boolean} [outer] + */ + function checkRowIndex(matrix, index, outer) { + let max = outer ? matrix.rows : matrix.rows - 1; + + if (index < 0 || index > max) { + throw new RangeError('Row index out of range'); + } + } + /** + * @private + * Check that a column index is not out of bounds + * @param {Matrix} matrix + * @param {number} index + * @param {boolean} [outer] + */ + + function checkColumnIndex(matrix, index, outer) { + let max = outer ? matrix.columns : matrix.columns - 1; + + if (index < 0 || index > max) { + throw new RangeError('Column index out of range'); + } + } + /** + * @private + * Check that the provided vector is an array with the right length + * @param {Matrix} matrix + * @param {Array|Matrix} vector + * @return {Array} + * @throws {RangeError} + */ + + function checkRowVector(matrix, vector) { + if (vector.to1DArray) { + vector = vector.to1DArray(); + } + + if (vector.length !== matrix.columns) { + throw new RangeError('vector size must be the same as the number of columns'); + } + + return vector; + } + /** + * @private + * Check that the provided vector is an array with the right length + * @param {Matrix} matrix + * @param {Array|Matrix} vector + * @return {Array} + * @throws {RangeError} + */ + + function checkColumnVector(matrix, vector) { + if (vector.to1DArray) { + vector = vector.to1DArray(); + } + + if (vector.length !== matrix.rows) { + throw new RangeError('vector size must be the same as the number of rows'); + } + + return vector; + } + function checkIndices(matrix, rowIndices, columnIndices) { + return { + row: checkRowIndices(matrix, rowIndices), + column: checkColumnIndices(matrix, columnIndices) + }; + } + function checkRowIndices(matrix, rowIndices) { + if (typeof rowIndices !== 'object') { + throw new TypeError('unexpected type for row indices'); + } + + let rowOut = rowIndices.some(r => { + return r < 0 || r >= matrix.rows; + }); + + if (rowOut) { + throw new RangeError('row indices are out of range'); + } + + if (!Array.isArray(rowIndices)) rowIndices = Array.from(rowIndices); + return rowIndices; + } + function checkColumnIndices(matrix, columnIndices) { + if (typeof columnIndices !== 'object') { + throw new TypeError('unexpected type for column indices'); + } + + let columnOut = columnIndices.some(c => { + return c < 0 || c >= matrix.columns; + }); + + if (columnOut) { + throw new RangeError('column indices are out of range'); + } + + if (!Array.isArray(columnIndices)) columnIndices = Array.from(columnIndices); + return columnIndices; + } + function checkRange(matrix, startRow, endRow, startColumn, endColumn) { + if (arguments.length !== 5) { + throw new RangeError('expected 4 arguments'); + } + + checkNumber('startRow', startRow); + checkNumber('endRow', endRow); + checkNumber('startColumn', startColumn); + checkNumber('endColumn', endColumn); + + if (startRow > endRow || startColumn > endColumn || startRow < 0 || startRow >= matrix.rows || endRow < 0 || endRow >= matrix.rows || startColumn < 0 || startColumn >= matrix.columns || endColumn < 0 || endColumn >= matrix.columns) { + throw new RangeError('Submatrix indices are out of range'); + } + } + function newArray(length) { + let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + let array = []; + + for (let i = 0; i < length; i++) { + array.push(value); + } + + return array; + } + + function checkNumber(name, value) { + if (typeof value !== 'number') { + throw new TypeError("".concat(name, " must be a number")); + } + } + + function sumByRow(matrix) { + let sum = newArray(matrix.rows); + + for (let i = 0; i < matrix.rows; ++i) { + for (let j = 0; j < matrix.columns; ++j) { + sum[i] += matrix.get(i, j); + } + } + + return sum; + } + function sumByColumn(matrix) { + let sum = newArray(matrix.columns); + + for (let i = 0; i < matrix.rows; ++i) { + for (let j = 0; j < matrix.columns; ++j) { + sum[j] += matrix.get(i, j); + } + } + + return sum; + } + function sumAll(matrix) { + let v = 0; + + for (let i = 0; i < matrix.rows; i++) { + for (let j = 0; j < matrix.columns; j++) { + v += matrix.get(i, j); + } + } + + return v; + } + function productByRow(matrix) { + let sum = newArray(matrix.rows, 1); + + for (let i = 0; i < matrix.rows; ++i) { + for (let j = 0; j < matrix.columns; ++j) { + sum[i] *= matrix.get(i, j); + } + } + + return sum; + } + function productByColumn(matrix) { + let sum = newArray(matrix.columns, 1); + + for (let i = 0; i < matrix.rows; ++i) { + for (let j = 0; j < matrix.columns; ++j) { + sum[j] *= matrix.get(i, j); + } + } + + return sum; + } + function productAll(matrix) { + let v = 1; + + for (let i = 0; i < matrix.rows; i++) { + for (let j = 0; j < matrix.columns; j++) { + v *= matrix.get(i, j); + } + } + + return v; + } + function varianceByRow(matrix, unbiased, mean) { + const rows = matrix.rows; + const cols = matrix.columns; + const variance = []; + + for (let i = 0; i < rows; i++) { + let sum1 = 0; + let sum2 = 0; + let x = 0; + + for (let j = 0; j < cols; j++) { + x = matrix.get(i, j) - mean[i]; + sum1 += x; + sum2 += x * x; + } + + if (unbiased) { + variance.push((sum2 - sum1 * sum1 / cols) / (cols - 1)); + } else { + variance.push((sum2 - sum1 * sum1 / cols) / cols); + } + } + + return variance; + } + function varianceByColumn(matrix, unbiased, mean) { + const rows = matrix.rows; + const cols = matrix.columns; + const variance = []; + + for (let j = 0; j < cols; j++) { + let sum1 = 0; + let sum2 = 0; + let x = 0; + + for (let i = 0; i < rows; i++) { + x = matrix.get(i, j) - mean[j]; + sum1 += x; + sum2 += x * x; + } + + if (unbiased) { + variance.push((sum2 - sum1 * sum1 / rows) / (rows - 1)); + } else { + variance.push((sum2 - sum1 * sum1 / rows) / rows); + } + } + + return variance; + } + function varianceAll(matrix, unbiased, mean) { + const rows = matrix.rows; + const cols = matrix.columns; + const size = rows * cols; + let sum1 = 0; + let sum2 = 0; + let x = 0; + + for (let i = 0; i < rows; i++) { + for (let j = 0; j < cols; j++) { + x = matrix.get(i, j) - mean; + sum1 += x; + sum2 += x * x; + } + } + + if (unbiased) { + return (sum2 - sum1 * sum1 / size) / (size - 1); + } else { + return (sum2 - sum1 * sum1 / size) / size; + } + } + function centerByRow(matrix, mean) { + for (let i = 0; i < matrix.rows; i++) { + for (let j = 0; j < matrix.columns; j++) { + matrix.set(i, j, matrix.get(i, j) - mean[i]); + } + } + } + function centerByColumn(matrix, mean) { + for (let i = 0; i < matrix.rows; i++) { + for (let j = 0; j < matrix.columns; j++) { + matrix.set(i, j, matrix.get(i, j) - mean[j]); + } + } + } + function centerAll(matrix, mean) { + for (let i = 0; i < matrix.rows; i++) { + for (let j = 0; j < matrix.columns; j++) { + matrix.set(i, j, matrix.get(i, j) - mean); + } + } + } + function getScaleByRow(matrix) { + const scale = []; + + for (let i = 0; i < matrix.rows; i++) { + let sum = 0; + + for (let j = 0; j < matrix.columns; j++) { + sum += Math.pow(matrix.get(i, j), 2) / (matrix.columns - 1); + } + + scale.push(Math.sqrt(sum)); + } + + return scale; + } + function scaleByRow(matrix, scale) { + for (let i = 0; i < matrix.rows; i++) { + for (let j = 0; j < matrix.columns; j++) { + matrix.set(i, j, matrix.get(i, j) / scale[i]); + } + } + } + function getScaleByColumn(matrix) { + const scale = []; + + for (let j = 0; j < matrix.columns; j++) { + let sum = 0; + + for (let i = 0; i < matrix.rows; i++) { + sum += Math.pow(matrix.get(i, j), 2) / (matrix.rows - 1); + } + + scale.push(Math.sqrt(sum)); + } + + return scale; + } + function scaleByColumn(matrix, scale) { + for (let i = 0; i < matrix.rows; i++) { + for (let j = 0; j < matrix.columns; j++) { + matrix.set(i, j, matrix.get(i, j) / scale[j]); + } + } + } + function getScaleAll(matrix) { + const divider = matrix.size - 1; + let sum = 0; + + for (let j = 0; j < matrix.columns; j++) { + for (let i = 0; i < matrix.rows; i++) { + sum += Math.pow(matrix.get(i, j), 2) / divider; + } + } + + return Math.sqrt(sum); + } + function scaleAll(matrix, scale) { + for (let i = 0; i < matrix.rows; i++) { + for (let j = 0; j < matrix.columns; j++) { + matrix.set(i, j, matrix.get(i, j) / scale); + } + } + } + + class AbstractMatrix { + static from1DArray(newRows, newColumns, newData) { + let length = newRows * newColumns; + + if (length !== newData.length) { + throw new RangeError('data length does not match given dimensions'); + } + + let newMatrix = new Matrix(newRows, newColumns); + + for (let row = 0; row < newRows; row++) { + for (let column = 0; column < newColumns; column++) { + newMatrix.set(row, column, newData[row * newColumns + column]); + } + } + + return newMatrix; + } + + static rowVector(newData) { + let vector = new Matrix(1, newData.length); + + for (let i = 0; i < newData.length; i++) { + vector.set(0, i, newData[i]); + } + + return vector; + } + + static columnVector(newData) { + let vector = new Matrix(newData.length, 1); + + for (let i = 0; i < newData.length; i++) { + vector.set(i, 0, newData[i]); + } + + return vector; + } + + static zeros(rows, columns) { + return new Matrix(rows, columns); + } + + static ones(rows, columns) { + return new Matrix(rows, columns).fill(1); + } + + static rand(rows, columns) { + let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + + if (typeof options !== 'object') { + throw new TypeError('options must be an object'); + } + + const { + random = Math.random + } = options; + let matrix = new Matrix(rows, columns); + + for (let i = 0; i < rows; i++) { + for (let j = 0; j < columns; j++) { + matrix.set(i, j, random()); + } + } + + return matrix; + } + + static randInt(rows, columns) { + let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + + if (typeof options !== 'object') { + throw new TypeError('options must be an object'); + } + + const { + min = 0, + max = 1000, + random = Math.random + } = options; + if (!Number.isInteger(min)) throw new TypeError('min must be an integer'); + if (!Number.isInteger(max)) throw new TypeError('max must be an integer'); + if (min >= max) throw new RangeError('min must be smaller than max'); + let interval = max - min; + let matrix = new Matrix(rows, columns); + + for (let i = 0; i < rows; i++) { + for (let j = 0; j < columns; j++) { + let value = min + Math.round(random() * interval); + matrix.set(i, j, value); + } + } + + return matrix; + } + + static eye(rows, columns, value) { + if (columns === undefined) columns = rows; + if (value === undefined) value = 1; + let min = Math.min(rows, columns); + let matrix = this.zeros(rows, columns); + + for (let i = 0; i < min; i++) { + matrix.set(i, i, value); + } + + return matrix; + } + + static diag(data, rows, columns) { + let l = data.length; + if (rows === undefined) rows = l; + if (columns === undefined) columns = rows; + let min = Math.min(l, rows, columns); + let matrix = this.zeros(rows, columns); + + for (let i = 0; i < min; i++) { + matrix.set(i, i, data[i]); + } + + return matrix; + } + + static min(matrix1, matrix2) { + matrix1 = this.checkMatrix(matrix1); + matrix2 = this.checkMatrix(matrix2); + let rows = matrix1.rows; + let columns = matrix1.columns; + let result = new Matrix(rows, columns); + + for (let i = 0; i < rows; i++) { + for (let j = 0; j < columns; j++) { + result.set(i, j, Math.min(matrix1.get(i, j), matrix2.get(i, j))); + } + } + + return result; + } + + static max(matrix1, matrix2) { + matrix1 = this.checkMatrix(matrix1); + matrix2 = this.checkMatrix(matrix2); + let rows = matrix1.rows; + let columns = matrix1.columns; + let result = new this(rows, columns); + + for (let i = 0; i < rows; i++) { + for (let j = 0; j < columns; j++) { + result.set(i, j, Math.max(matrix1.get(i, j), matrix2.get(i, j))); + } + } + + return result; + } + + static checkMatrix(value) { + return AbstractMatrix.isMatrix(value) ? value : new Matrix(value); + } + + static isMatrix(value) { + return value != null && value.klass === 'Matrix'; + } + + get size() { + return this.rows * this.columns; + } + + apply(callback) { + if (typeof callback !== 'function') { + throw new TypeError('callback must be a function'); + } + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + callback.call(this, i, j); + } + } + + return this; + } + + to1DArray() { + let array = []; + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + array.push(this.get(i, j)); + } + } + + return array; + } + + to2DArray() { + let copy = []; + + for (let i = 0; i < this.rows; i++) { + copy.push([]); + + for (let j = 0; j < this.columns; j++) { + copy[i].push(this.get(i, j)); + } + } + + return copy; + } + + toJSON() { + return this.to2DArray(); + } + + isRowVector() { + return this.rows === 1; + } + + isColumnVector() { + return this.columns === 1; + } + + isVector() { + return this.rows === 1 || this.columns === 1; + } + + isSquare() { + return this.rows === this.columns; + } + + isSymmetric() { + if (this.isSquare()) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j <= i; j++) { + if (this.get(i, j) !== this.get(j, i)) { + return false; + } + } + } + + return true; + } + + return false; + } + + isEchelonForm() { + let i = 0; + let j = 0; + let previousColumn = -1; + let isEchelonForm = true; + let checked = false; + + while (i < this.rows && isEchelonForm) { + j = 0; + checked = false; + + while (j < this.columns && checked === false) { + if (this.get(i, j) === 0) { + j++; + } else if (this.get(i, j) === 1 && j > previousColumn) { + checked = true; + previousColumn = j; + } else { + isEchelonForm = false; + checked = true; + } + } + + i++; + } + + return isEchelonForm; + } + + isReducedEchelonForm() { + let i = 0; + let j = 0; + let previousColumn = -1; + let isReducedEchelonForm = true; + let checked = false; + + while (i < this.rows && isReducedEchelonForm) { + j = 0; + checked = false; + + while (j < this.columns && checked === false) { + if (this.get(i, j) === 0) { + j++; + } else if (this.get(i, j) === 1 && j > previousColumn) { + checked = true; + previousColumn = j; + } else { + isReducedEchelonForm = false; + checked = true; + } + } + + for (let k = j + 1; k < this.rows; k++) { + if (this.get(i, k) !== 0) { + isReducedEchelonForm = false; + } + } + + i++; + } + + return isReducedEchelonForm; + } + + echelonForm() { + let result = this.clone(); + let h = 0; + let k = 0; + + while (h < result.rows && k < result.columns) { + let iMax = h; + + for (let i = h; i < result.rows; i++) { + if (result.get(i, k) > result.get(iMax, k)) { + iMax = i; + } + } + + if (result.get(iMax, k) === 0) { + k++; + } else { + result.swapRows(h, iMax); + let tmp = result.get(h, k); + + for (let j = k; j < result.columns; j++) { + result.set(h, j, result.get(h, j) / tmp); + } + + for (let i = h + 1; i < result.rows; i++) { + let factor = result.get(i, k) / result.get(h, k); + result.set(i, k, 0); + + for (let j = k + 1; j < result.columns; j++) { + result.set(i, j, result.get(i, j) - result.get(h, j) * factor); + } + } + + h++; + k++; + } + } + + return result; + } + + reducedEchelonForm() { + let result = this.echelonForm(); + let m = result.columns; + let n = result.rows; + let h = n - 1; + + while (h >= 0) { + if (result.maxRow(h) === 0) { + h--; + } else { + let p = 0; + let pivot = false; + + while (p < n && pivot === false) { + if (result.get(h, p) === 1) { + pivot = true; + } else { + p++; + } + } + + for (let i = 0; i < h; i++) { + let factor = result.get(i, p); + + for (let j = p; j < m; j++) { + let tmp = result.get(i, j) - factor * result.get(h, j); + result.set(i, j, tmp); + } + } + + h--; + } + } + + return result; + } + + set() { + throw new Error('set method is unimplemented'); + } + + get() { + throw new Error('get method is unimplemented'); + } + + repeat() { + let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + if (typeof options !== 'object') { + throw new TypeError('options must be an object'); + } + + const { + rows = 1, + columns = 1 + } = options; + + if (!Number.isInteger(rows) || rows <= 0) { + throw new TypeError('rows must be a positive integer'); + } + + if (!Number.isInteger(columns) || columns <= 0) { + throw new TypeError('columns must be a positive integer'); + } + + let matrix = new Matrix(this.rows * rows, this.columns * columns); + + for (let i = 0; i < rows; i++) { + for (let j = 0; j < columns; j++) { + matrix.setSubMatrix(this, this.rows * i, this.columns * j); + } + } + + return matrix; + } + + fill(value) { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, value); + } + } + + return this; + } + + neg() { + return this.mulS(-1); + } + + getRow(index) { + checkRowIndex(this, index); + let row = []; + + for (let i = 0; i < this.columns; i++) { + row.push(this.get(index, i)); + } + + return row; + } + + getRowVector(index) { + return Matrix.rowVector(this.getRow(index)); + } + + setRow(index, array) { + checkRowIndex(this, index); + array = checkRowVector(this, array); + + for (let i = 0; i < this.columns; i++) { + this.set(index, i, array[i]); + } + + return this; + } + + swapRows(row1, row2) { + checkRowIndex(this, row1); + checkRowIndex(this, row2); + + for (let i = 0; i < this.columns; i++) { + let temp = this.get(row1, i); + this.set(row1, i, this.get(row2, i)); + this.set(row2, i, temp); + } + + return this; + } + + getColumn(index) { + checkColumnIndex(this, index); + let column = []; + + for (let i = 0; i < this.rows; i++) { + column.push(this.get(i, index)); + } + + return column; + } + + getColumnVector(index) { + return Matrix.columnVector(this.getColumn(index)); + } + + setColumn(index, array) { + checkColumnIndex(this, index); + array = checkColumnVector(this, array); + + for (let i = 0; i < this.rows; i++) { + this.set(i, index, array[i]); + } + + return this; + } + + swapColumns(column1, column2) { + checkColumnIndex(this, column1); + checkColumnIndex(this, column2); + + for (let i = 0; i < this.rows; i++) { + let temp = this.get(i, column1); + this.set(i, column1, this.get(i, column2)); + this.set(i, column2, temp); + } + + return this; + } + + addRowVector(vector) { + vector = checkRowVector(this, vector); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) + vector[j]); + } + } + + return this; + } + + subRowVector(vector) { + vector = checkRowVector(this, vector); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) - vector[j]); + } + } + + return this; + } + + mulRowVector(vector) { + vector = checkRowVector(this, vector); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) * vector[j]); + } + } + + return this; + } + + divRowVector(vector) { + vector = checkRowVector(this, vector); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) / vector[j]); + } + } + + return this; + } + + addColumnVector(vector) { + vector = checkColumnVector(this, vector); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) + vector[i]); + } + } + + return this; + } + + subColumnVector(vector) { + vector = checkColumnVector(this, vector); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) - vector[i]); + } + } + + return this; + } + + mulColumnVector(vector) { + vector = checkColumnVector(this, vector); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) * vector[i]); + } + } + + return this; + } + + divColumnVector(vector) { + vector = checkColumnVector(this, vector); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + this.set(i, j, this.get(i, j) / vector[i]); + } + } + + return this; + } + + mulRow(index, value) { + checkRowIndex(this, index); + + for (let i = 0; i < this.columns; i++) { + this.set(index, i, this.get(index, i) * value); + } + + return this; + } + + mulColumn(index, value) { + checkColumnIndex(this, index); + + for (let i = 0; i < this.rows; i++) { + this.set(i, index, this.get(i, index) * value); + } + + return this; + } + + max() { + let v = this.get(0, 0); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + if (this.get(i, j) > v) { + v = this.get(i, j); + } + } + } + + return v; + } + + maxIndex() { + let v = this.get(0, 0); + let idx = [0, 0]; + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + if (this.get(i, j) > v) { + v = this.get(i, j); + idx[0] = i; + idx[1] = j; + } + } + } + + return idx; + } + + min() { + let v = this.get(0, 0); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + if (this.get(i, j) < v) { + v = this.get(i, j); + } + } + } + + return v; + } + + minIndex() { + let v = this.get(0, 0); + let idx = [0, 0]; + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + if (this.get(i, j) < v) { + v = this.get(i, j); + idx[0] = i; + idx[1] = j; + } + } + } + + return idx; + } + + maxRow(row) { + checkRowIndex(this, row); + let v = this.get(row, 0); + + for (let i = 1; i < this.columns; i++) { + if (this.get(row, i) > v) { + v = this.get(row, i); + } + } + + return v; + } + + maxRowIndex(row) { + checkRowIndex(this, row); + let v = this.get(row, 0); + let idx = [row, 0]; + + for (let i = 1; i < this.columns; i++) { + if (this.get(row, i) > v) { + v = this.get(row, i); + idx[1] = i; + } + } + + return idx; + } + + minRow(row) { + checkRowIndex(this, row); + let v = this.get(row, 0); + + for (let i = 1; i < this.columns; i++) { + if (this.get(row, i) < v) { + v = this.get(row, i); + } + } + + return v; + } + + minRowIndex(row) { + checkRowIndex(this, row); + let v = this.get(row, 0); + let idx = [row, 0]; + + for (let i = 1; i < this.columns; i++) { + if (this.get(row, i) < v) { + v = this.get(row, i); + idx[1] = i; + } + } + + return idx; + } + + maxColumn(column) { + checkColumnIndex(this, column); + let v = this.get(0, column); + + for (let i = 1; i < this.rows; i++) { + if (this.get(i, column) > v) { + v = this.get(i, column); + } + } + + return v; + } + + maxColumnIndex(column) { + checkColumnIndex(this, column); + let v = this.get(0, column); + let idx = [0, column]; + + for (let i = 1; i < this.rows; i++) { + if (this.get(i, column) > v) { + v = this.get(i, column); + idx[0] = i; + } + } + + return idx; + } + + minColumn(column) { + checkColumnIndex(this, column); + let v = this.get(0, column); + + for (let i = 1; i < this.rows; i++) { + if (this.get(i, column) < v) { + v = this.get(i, column); + } + } + + return v; + } + + minColumnIndex(column) { + checkColumnIndex(this, column); + let v = this.get(0, column); + let idx = [0, column]; + + for (let i = 1; i < this.rows; i++) { + if (this.get(i, column) < v) { + v = this.get(i, column); + idx[0] = i; + } + } + + return idx; + } + + diag() { + let min = Math.min(this.rows, this.columns); + let diag = []; + + for (let i = 0; i < min; i++) { + diag.push(this.get(i, i)); + } + + return diag; + } + + norm() { + let type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'frobenius'; + let result = 0; + + if (type === 'max') { + return this.max(); + } else if (type === 'frobenius') { + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + result = result + this.get(i, j) * this.get(i, j); + } + } + + return Math.sqrt(result); + } else { + throw new RangeError("unknown norm type: ".concat(type)); + } + } + + cumulativeSum() { + let sum = 0; + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + sum += this.get(i, j); + this.set(i, j, sum); + } + } + + return this; + } + + dot(vector2) { + if (AbstractMatrix.isMatrix(vector2)) vector2 = vector2.to1DArray(); + let vector1 = this.to1DArray(); + + if (vector1.length !== vector2.length) { + throw new RangeError('vectors do not have the same size'); + } + + let dot = 0; + + for (let i = 0; i < vector1.length; i++) { + dot += vector1[i] * vector2[i]; + } + + return dot; + } + + mmul(other) { + other = Matrix.checkMatrix(other); + let m = this.rows; + let n = this.columns; + let p = other.columns; + let result = new Matrix(m, p); + let Bcolj = new Float64Array(n); + + for (let j = 0; j < p; j++) { + for (let k = 0; k < n; k++) { + Bcolj[k] = other.get(k, j); + } + + for (let i = 0; i < m; i++) { + let s = 0; + + for (let k = 0; k < n; k++) { + s += this.get(i, k) * Bcolj[k]; + } + + result.set(i, j, s); + } + } + + return result; + } + + strassen2x2(other) { + other = Matrix.checkMatrix(other); + let result = new Matrix(2, 2); + const a11 = this.get(0, 0); + const b11 = other.get(0, 0); + const a12 = this.get(0, 1); + const b12 = other.get(0, 1); + const a21 = this.get(1, 0); + const b21 = other.get(1, 0); + const a22 = this.get(1, 1); + const b22 = other.get(1, 1); // Compute intermediate values. + + const m1 = (a11 + a22) * (b11 + b22); + const m2 = (a21 + a22) * b11; + const m3 = a11 * (b12 - b22); + const m4 = a22 * (b21 - b11); + const m5 = (a11 + a12) * b22; + const m6 = (a21 - a11) * (b11 + b12); + const m7 = (a12 - a22) * (b21 + b22); // Combine intermediate values into the output. + + const c00 = m1 + m4 - m5 + m7; + const c01 = m3 + m5; + const c10 = m2 + m4; + const c11 = m1 - m2 + m3 + m6; + result.set(0, 0, c00); + result.set(0, 1, c01); + result.set(1, 0, c10); + result.set(1, 1, c11); + return result; + } + + strassen3x3(other) { + other = Matrix.checkMatrix(other); + let result = new Matrix(3, 3); + const a00 = this.get(0, 0); + const a01 = this.get(0, 1); + const a02 = this.get(0, 2); + const a10 = this.get(1, 0); + const a11 = this.get(1, 1); + const a12 = this.get(1, 2); + const a20 = this.get(2, 0); + const a21 = this.get(2, 1); + const a22 = this.get(2, 2); + const b00 = other.get(0, 0); + const b01 = other.get(0, 1); + const b02 = other.get(0, 2); + const b10 = other.get(1, 0); + const b11 = other.get(1, 1); + const b12 = other.get(1, 2); + const b20 = other.get(2, 0); + const b21 = other.get(2, 1); + const b22 = other.get(2, 2); + const m1 = (a00 + a01 + a02 - a10 - a11 - a21 - a22) * b11; + const m2 = (a00 - a10) * (-b01 + b11); + const m3 = a11 * (-b00 + b01 + b10 - b11 - b12 - b20 + b22); + const m4 = (-a00 + a10 + a11) * (b00 - b01 + b11); + const m5 = (a10 + a11) * (-b00 + b01); + const m6 = a00 * b00; + const m7 = (-a00 + a20 + a21) * (b00 - b02 + b12); + const m8 = (-a00 + a20) * (b02 - b12); + const m9 = (a20 + a21) * (-b00 + b02); + const m10 = (a00 + a01 + a02 - a11 - a12 - a20 - a21) * b12; + const m11 = a21 * (-b00 + b02 + b10 - b11 - b12 - b20 + b21); + const m12 = (-a02 + a21 + a22) * (b11 + b20 - b21); + const m13 = (a02 - a22) * (b11 - b21); + const m14 = a02 * b20; + const m15 = (a21 + a22) * (-b20 + b21); + const m16 = (-a02 + a11 + a12) * (b12 + b20 - b22); + const m17 = (a02 - a12) * (b12 - b22); + const m18 = (a11 + a12) * (-b20 + b22); + const m19 = a01 * b10; + const m20 = a12 * b21; + const m21 = a10 * b02; + const m22 = a20 * b01; + const m23 = a22 * b22; + const c00 = m6 + m14 + m19; + const c01 = m1 + m4 + m5 + m6 + m12 + m14 + m15; + const c02 = m6 + m7 + m9 + m10 + m14 + m16 + m18; + const c10 = m2 + m3 + m4 + m6 + m14 + m16 + m17; + const c11 = m2 + m4 + m5 + m6 + m20; + const c12 = m14 + m16 + m17 + m18 + m21; + const c20 = m6 + m7 + m8 + m11 + m12 + m13 + m14; + const c21 = m12 + m13 + m14 + m15 + m22; + const c22 = m6 + m7 + m8 + m9 + m23; + result.set(0, 0, c00); + result.set(0, 1, c01); + result.set(0, 2, c02); + result.set(1, 0, c10); + result.set(1, 1, c11); + result.set(1, 2, c12); + result.set(2, 0, c20); + result.set(2, 1, c21); + result.set(2, 2, c22); + return result; + } + + mmulStrassen(y) { + y = Matrix.checkMatrix(y); + let x = this.clone(); + let r1 = x.rows; + let c1 = x.columns; + let r2 = y.rows; + let c2 = y.columns; + + if (c1 !== r2) { + // eslint-disable-next-line no-console + console.warn("Multiplying ".concat(r1, " x ").concat(c1, " and ").concat(r2, " x ").concat(c2, " matrix: dimensions do not match.")); + } // Put a matrix into the top left of a matrix of zeros. + // `rows` and `cols` are the dimensions of the output matrix. + + + function embed(mat, rows, cols) { + let r = mat.rows; + let c = mat.columns; + + if (r === rows && c === cols) { + return mat; + } else { + let resultat = AbstractMatrix.zeros(rows, cols); + resultat = resultat.setSubMatrix(mat, 0, 0); + return resultat; + } + } // Make sure both matrices are the same size. + // This is exclusively for simplicity: + // this algorithm can be implemented with matrices of different sizes. + + + let r = Math.max(r1, r2); + let c = Math.max(c1, c2); + x = embed(x, r, c); + y = embed(y, r, c); // Our recursive multiplication function. + + function blockMult(a, b, rows, cols) { + // For small matrices, resort to naive multiplication. + if (rows <= 512 || cols <= 512) { + return a.mmul(b); // a is equivalent to this + } // Apply dynamic padding. + + + if (rows % 2 === 1 && cols % 2 === 1) { + a = embed(a, rows + 1, cols + 1); + b = embed(b, rows + 1, cols + 1); + } else if (rows % 2 === 1) { + a = embed(a, rows + 1, cols); + b = embed(b, rows + 1, cols); + } else if (cols % 2 === 1) { + a = embed(a, rows, cols + 1); + b = embed(b, rows, cols + 1); + } + + let halfRows = parseInt(a.rows / 2, 10); + let halfCols = parseInt(a.columns / 2, 10); // Subdivide input matrices. + + let a11 = a.subMatrix(0, halfRows - 1, 0, halfCols - 1); + let b11 = b.subMatrix(0, halfRows - 1, 0, halfCols - 1); + let a12 = a.subMatrix(0, halfRows - 1, halfCols, a.columns - 1); + let b12 = b.subMatrix(0, halfRows - 1, halfCols, b.columns - 1); + let a21 = a.subMatrix(halfRows, a.rows - 1, 0, halfCols - 1); + let b21 = b.subMatrix(halfRows, b.rows - 1, 0, halfCols - 1); + let a22 = a.subMatrix(halfRows, a.rows - 1, halfCols, a.columns - 1); + let b22 = b.subMatrix(halfRows, b.rows - 1, halfCols, b.columns - 1); // Compute intermediate values. + + let m1 = blockMult(AbstractMatrix.add(a11, a22), AbstractMatrix.add(b11, b22), halfRows, halfCols); + let m2 = blockMult(AbstractMatrix.add(a21, a22), b11, halfRows, halfCols); + let m3 = blockMult(a11, AbstractMatrix.sub(b12, b22), halfRows, halfCols); + let m4 = blockMult(a22, AbstractMatrix.sub(b21, b11), halfRows, halfCols); + let m5 = blockMult(AbstractMatrix.add(a11, a12), b22, halfRows, halfCols); + let m6 = blockMult(AbstractMatrix.sub(a21, a11), AbstractMatrix.add(b11, b12), halfRows, halfCols); + let m7 = blockMult(AbstractMatrix.sub(a12, a22), AbstractMatrix.add(b21, b22), halfRows, halfCols); // Combine intermediate values into the output. + + let c11 = AbstractMatrix.add(m1, m4); + c11.sub(m5); + c11.add(m7); + let c12 = AbstractMatrix.add(m3, m5); + let c21 = AbstractMatrix.add(m2, m4); + let c22 = AbstractMatrix.sub(m1, m2); + c22.add(m3); + c22.add(m6); // Crop output to the desired size (undo dynamic padding). + + let resultat = AbstractMatrix.zeros(2 * c11.rows, 2 * c11.columns); + resultat = resultat.setSubMatrix(c11, 0, 0); + resultat = resultat.setSubMatrix(c12, c11.rows, 0); + resultat = resultat.setSubMatrix(c21, 0, c11.columns); + resultat = resultat.setSubMatrix(c22, c11.rows, c11.columns); + return resultat.subMatrix(0, rows - 1, 0, cols - 1); + } + + return blockMult(x, y, r, c); + } + + scaleRows() { + let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + if (typeof options !== 'object') { + throw new TypeError('options must be an object'); + } + + const { + min = 0, + max = 1 + } = options; + if (!Number.isFinite(min)) throw new TypeError('min must be a number'); + if (!Number.isFinite(max)) throw new TypeError('max must be a number'); + if (min >= max) throw new RangeError('min must be smaller than max'); + let newMatrix = new Matrix(this.rows, this.columns); + + for (let i = 0; i < this.rows; i++) { + const row = this.getRow(i); + rescale(row, { + min, + max, + output: row + }); + newMatrix.setRow(i, row); + } + + return newMatrix; + } + + scaleColumns() { + let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + if (typeof options !== 'object') { + throw new TypeError('options must be an object'); + } + + const { + min = 0, + max = 1 + } = options; + if (!Number.isFinite(min)) throw new TypeError('min must be a number'); + if (!Number.isFinite(max)) throw new TypeError('max must be a number'); + if (min >= max) throw new RangeError('min must be smaller than max'); + let newMatrix = new Matrix(this.rows, this.columns); + + for (let i = 0; i < this.columns; i++) { + const column = this.getColumn(i); + rescale(column, { + min: min, + max: max, + output: column + }); + newMatrix.setColumn(i, column); + } + + return newMatrix; + } + + flipRows() { + const middle = Math.ceil(this.columns / 2); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < middle; j++) { + let first = this.get(i, j); + let last = this.get(i, this.columns - 1 - j); + this.set(i, j, last); + this.set(i, this.columns - 1 - j, first); + } + } + + return this; + } + + flipColumns() { + const middle = Math.ceil(this.rows / 2); + + for (let j = 0; j < this.columns; j++) { + for (let i = 0; i < middle; i++) { + let first = this.get(i, j); + let last = this.get(this.rows - 1 - i, j); + this.set(i, j, last); + this.set(this.rows - 1 - i, j, first); + } + } + + return this; + } + + kroneckerProduct(other) { + other = Matrix.checkMatrix(other); + let m = this.rows; + let n = this.columns; + let p = other.rows; + let q = other.columns; + let result = new Matrix(m * p, n * q); + + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { + for (let k = 0; k < p; k++) { + for (let l = 0; l < q; l++) { + result.set(p * i + k, q * j + l, this.get(i, j) * other.get(k, l)); + } + } + } + } + + return result; + } + + transpose() { + let result = new Matrix(this.columns, this.rows); + + for (let i = 0; i < this.rows; i++) { + for (let j = 0; j < this.columns; j++) { + result.set(j, i, this.get(i, j)); + } + } + + return result; + } + + sortRows() { + let compareFunction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : compareNumbers; + + for (let i = 0; i < this.rows; i++) { + this.setRow(i, this.getRow(i).sort(compareFunction)); + } + + return this; + } + + sortColumns() { + let compareFunction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : compareNumbers; + + for (let i = 0; i < this.columns; i++) { + this.setColumn(i, this.getColumn(i).sort(compareFunction)); + } + + return this; + } + + subMatrix(startRow, endRow, startColumn, endColumn) { + checkRange(this, startRow, endRow, startColumn, endColumn); + let newMatrix = new Matrix(endRow - startRow + 1, endColumn - startColumn + 1); + + for (let i = startRow; i <= endRow; i++) { + for (let j = startColumn; j <= endColumn; j++) { + newMatrix.set(i - startRow, j - startColumn, this.get(i, j)); + } + } + + return newMatrix; + } + + subMatrixRow(indices, startColumn, endColumn) { + if (startColumn === undefined) startColumn = 0; + if (endColumn === undefined) endColumn = this.columns - 1; + + if (startColumn > endColumn || startColumn < 0 || startColumn >= this.columns || endColumn < 0 || endColumn >= this.columns) { + throw new RangeError('Argument out of range'); + } + + let newMatrix = new Matrix(indices.length, endColumn - startColumn + 1); + + for (let i = 0; i < indices.length; i++) { + for (let j = startColumn; j <= endColumn; j++) { + if (indices[i] < 0 || indices[i] >= this.rows) { + throw new RangeError("Row index out of range: ".concat(indices[i])); + } + + newMatrix.set(i, j - startColumn, this.get(indices[i], j)); + } + } + + return newMatrix; + } + + subMatrixColumn(indices, startRow, endRow) { + if (startRow === undefined) startRow = 0; + if (endRow === undefined) endRow = this.rows - 1; + + if (startRow > endRow || startRow < 0 || startRow >= this.rows || endRow < 0 || endRow >= this.rows) { + throw new RangeError('Argument out of range'); + } + + let newMatrix = new Matrix(endRow - startRow + 1, indices.length); + + for (let i = 0; i < indices.length; i++) { + for (let j = startRow; j <= endRow; j++) { + if (indices[i] < 0 || indices[i] >= this.columns) { + throw new RangeError("Column index out of range: ".concat(indices[i])); + } + + newMatrix.set(j - startRow, i, this.get(j, indices[i])); + } + } + + return newMatrix; + } + + setSubMatrix(matrix, startRow, startColumn) { + matrix = Matrix.checkMatrix(matrix); + let endRow = startRow + matrix.rows - 1; + let endColumn = startColumn + matrix.columns - 1; + checkRange(this, startRow, endRow, startColumn, endColumn); + + for (let i = 0; i < matrix.rows; i++) { + for (let j = 0; j < matrix.columns; j++) { + this.set(startRow + i, startColumn + j, matrix.get(i, j)); + } + } + + return this; + } + + selection(rowIndices, columnIndices) { + let indices = checkIndices(this, rowIndices, columnIndices); + let newMatrix = new Matrix(rowIndices.length, columnIndices.length); + + for (let i = 0; i < indices.row.length; i++) { + let rowIndex = indices.row[i]; + + for (let j = 0; j < indices.column.length; j++) { + let columnIndex = indices.column[j]; + newMatrix.set(i, j, this.get(rowIndex, columnIndex)); + } + } + + return newMatrix; + } + + trace() { + let min = Math.min(this.rows, this.columns); + let trace = 0; + + for (let i = 0; i < min; i++) { + trace += this.get(i, i); + } + + return trace; + } + + clone() { + let newMatrix = new Matrix(this.rows, this.columns); + + for (let row = 0; row < this.rows; row++) { + for (let column = 0; column < this.columns; column++) { + newMatrix.set(row, column, this.get(row, column)); + } + } + + return newMatrix; + } + + sum(by) { + switch (by) { + case 'row': + return sumByRow(this); + + case 'column': + return sumByColumn(this); + + case undefined: + return sumAll(this); + + default: + throw new Error("invalid option: ".concat(by)); + } + } + + product(by) { + switch (by) { + case 'row': + return productByRow(this); + + case 'column': + return productByColumn(this); + + case undefined: + return productAll(this); + + default: + throw new Error("invalid option: ".concat(by)); + } + } + + mean(by) { + const sum = this.sum(by); + + switch (by) { + case 'row': + { + for (let i = 0; i < this.rows; i++) { + sum[i] /= this.columns; + } + + return sum; + } + + case 'column': + { + for (let i = 0; i < this.columns; i++) { + sum[i] /= this.rows; + } + + return sum; + } + + case undefined: + return sum / this.size; + + default: + throw new Error("invalid option: ".concat(by)); + } + } + + variance(by) { + let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + if (typeof by === 'object') { + options = by; + by = undefined; + } + + if (typeof options !== 'object') { + throw new TypeError('options must be an object'); + } + + const { + unbiased = true, + mean = this.mean(by) + } = options; + + if (typeof unbiased !== 'boolean') { + throw new TypeError('unbiased must be a boolean'); + } + + switch (by) { + case 'row': + { + if (!Array.isArray(mean)) { + throw new TypeError('mean must be an array'); + } + + return varianceByRow(this, unbiased, mean); + } + + case 'column': + { + if (!Array.isArray(mean)) { + throw new TypeError('mean must be an array'); + } + + return varianceByColumn(this, unbiased, mean); + } + + case undefined: + { + if (typeof mean !== 'number') { + throw new TypeError('mean must be a number'); + } + + return varianceAll(this, unbiased, mean); + } + + default: + throw new Error("invalid option: ".concat(by)); + } + } + + standardDeviation(by, options) { + if (typeof by === 'object') { + options = by; + by = undefined; + } + + const variance = this.variance(by, options); + + if (by === undefined) { + return Math.sqrt(variance); + } else { + for (let i = 0; i < variance.length; i++) { + variance[i] = Math.sqrt(variance[i]); + } + + return variance; + } + } + + center(by) { + let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + if (typeof by === 'object') { + options = by; + by = undefined; + } + + if (typeof options !== 'object') { + throw new TypeError('options must be an object'); + } + + const { + center = this.mean(by) + } = options; + + switch (by) { + case 'row': + { + if (!Array.isArray(center)) { + throw new TypeError('center must be an array'); + } + + centerByRow(this, center); + return this; + } + + case 'column': + { + if (!Array.isArray(center)) { + throw new TypeError('center must be an array'); + } + + centerByColumn(this, center); + return this; + } + + case undefined: + { + if (typeof center !== 'number') { + throw new TypeError('center must be a number'); + } + + centerAll(this, center); + return this; + } + + default: + throw new Error("invalid option: ".concat(by)); + } + } + + scale(by) { + let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + if (typeof by === 'object') { + options = by; + by = undefined; + } + + if (typeof options !== 'object') { + throw new TypeError('options must be an object'); + } + + let scale = options.scale; + + switch (by) { + case 'row': + { + if (scale === undefined) { + scale = getScaleByRow(this); + } else if (!Array.isArray(scale)) { + throw new TypeError('scale must be an array'); + } + + scaleByRow(this, scale); + return this; + } + + case 'column': + { + if (scale === undefined) { + scale = getScaleByColumn(this); + } else if (!Array.isArray(scale)) { + throw new TypeError('scale must be an array'); + } + + scaleByColumn(this, scale); + return this; + } + + case undefined: + { + if (scale === undefined) { + scale = getScaleAll(this); + } else if (typeof scale !== 'number') { + throw new TypeError('scale must be a number'); + } + + scaleAll(this, scale); + return this; + } + + default: + throw new Error("invalid option: ".concat(by)); + } + } + + toString(options) { + return inspectMatrixWithOptions(this, options); + } + + } + AbstractMatrix.prototype.klass = 'Matrix'; + + if (typeof Symbol !== 'undefined') { + AbstractMatrix.prototype[Symbol.for('nodejs.util.inspect.custom')] = inspectMatrix; + } + + function compareNumbers(a, b) { + return a - b; + } // Synonyms + + + AbstractMatrix.random = AbstractMatrix.rand; + AbstractMatrix.randomInt = AbstractMatrix.randInt; + AbstractMatrix.diagonal = AbstractMatrix.diag; + AbstractMatrix.prototype.diagonal = AbstractMatrix.prototype.diag; + AbstractMatrix.identity = AbstractMatrix.eye; + AbstractMatrix.prototype.negate = AbstractMatrix.prototype.neg; + AbstractMatrix.prototype.tensorProduct = AbstractMatrix.prototype.kroneckerProduct; + class Matrix extends AbstractMatrix { + constructor(nRows, nColumns) { + super(); + + if (Matrix.isMatrix(nRows)) { + return nRows.clone(); + } else if (Number.isInteger(nRows) && nRows > 0) { + // Create an empty matrix + this.data = []; + + if (Number.isInteger(nColumns) && nColumns > 0) { + for (let i = 0; i < nRows; i++) { + this.data.push(new Float64Array(nColumns)); + } + } else { + throw new TypeError('nColumns must be a positive integer'); + } + } else if (Array.isArray(nRows)) { + // Copy the values from the 2D array + const arrayData = nRows; + nRows = arrayData.length; + nColumns = arrayData[0].length; + + if (typeof nColumns !== 'number' || nColumns === 0) { + throw new TypeError('Data must be a 2D array with at least one element'); + } + + this.data = []; + + for (let i = 0; i < nRows; i++) { + if (arrayData[i].length !== nColumns) { + throw new RangeError('Inconsistent array dimensions'); + } + + this.data.push(Float64Array.from(arrayData[i])); + } + } else { + throw new TypeError('First argument must be a positive number or an array'); + } + + this.rows = nRows; + this.columns = nColumns; + return this; + } + + set(rowIndex, columnIndex, value) { + this.data[rowIndex][columnIndex] = value; + return this; + } + + get(rowIndex, columnIndex) { + return this.data[rowIndex][columnIndex]; + } + + removeRow(index) { + checkRowIndex(this, index); + + if (this.rows === 1) { + throw new RangeError('A matrix cannot have less than one row'); + } + + this.data.splice(index, 1); + this.rows -= 1; + return this; + } + + addRow(index, array) { + if (array === undefined) { + array = index; + index = this.rows; + } + + checkRowIndex(this, index, true); + array = Float64Array.from(checkRowVector(this, array)); + this.data.splice(index, 0, array); + this.rows += 1; + return this; + } + + removeColumn(index) { + checkColumnIndex(this, index); + + if (this.columns === 1) { + throw new RangeError('A matrix cannot have less than one column'); + } + + for (let i = 0; i < this.rows; i++) { + const newRow = new Float64Array(this.columns - 1); + + for (let j = 0; j < index; j++) { + newRow[j] = this.data[i][j]; + } + + for (let j = index + 1; j < this.columns; j++) { + newRow[j - 1] = this.data[i][j]; + } + + this.data[i] = newRow; + } + + this.columns -= 1; + return this; + } + + addColumn(index, array) { + if (typeof array === 'undefined') { + array = index; + index = this.columns; + } + + checkColumnIndex(this, index, true); + array = checkColumnVector(this, array); + + for (let i = 0; i < this.rows; i++) { + const newRow = new Float64Array(this.columns + 1); + let j = 0; + + for (; j < index; j++) { + newRow[j] = this.data[i][j]; + } + + newRow[j++] = array[i]; + + for (; j < this.columns + 1; j++) { + newRow[j] = this.data[i][j - 1]; + } + + this.data[i] = newRow; + } + + this.columns += 1; + return this; + } + + } + installMathOperations(AbstractMatrix, Matrix); + + class WrapperMatrix2D extends AbstractMatrix { + constructor(data) { + super(); + this.data = data; + this.rows = data.length; + this.columns = data[0].length; + } + + set(rowIndex, columnIndex, value) { + this.data[rowIndex][columnIndex] = value; + return this; + } + + get(rowIndex, columnIndex) { + return this.data[rowIndex][columnIndex]; + } + + } + + class LuDecomposition { + constructor(matrix) { + matrix = WrapperMatrix2D.checkMatrix(matrix); + let lu = matrix.clone(); + let rows = lu.rows; + let columns = lu.columns; + let pivotVector = new Float64Array(rows); + let pivotSign = 1; + let i, j, k, p, s, t, v; + let LUcolj, kmax; + + for (i = 0; i < rows; i++) { + pivotVector[i] = i; + } + + LUcolj = new Float64Array(rows); + + for (j = 0; j < columns; j++) { + for (i = 0; i < rows; i++) { + LUcolj[i] = lu.get(i, j); + } + + for (i = 0; i < rows; i++) { + kmax = Math.min(i, j); + s = 0; + + for (k = 0; k < kmax; k++) { + s += lu.get(i, k) * LUcolj[k]; + } + + LUcolj[i] -= s; + lu.set(i, j, LUcolj[i]); + } + + p = j; + + for (i = j + 1; i < rows; i++) { + if (Math.abs(LUcolj[i]) > Math.abs(LUcolj[p])) { + p = i; + } + } + + if (p !== j) { + for (k = 0; k < columns; k++) { + t = lu.get(p, k); + lu.set(p, k, lu.get(j, k)); + lu.set(j, k, t); + } + + v = pivotVector[p]; + pivotVector[p] = pivotVector[j]; + pivotVector[j] = v; + pivotSign = -pivotSign; + } + + if (j < rows && lu.get(j, j) !== 0) { + for (i = j + 1; i < rows; i++) { + lu.set(i, j, lu.get(i, j) / lu.get(j, j)); + } + } + } + + this.LU = lu; + this.pivotVector = pivotVector; + this.pivotSign = pivotSign; + } + + isSingular() { + let data = this.LU; + let col = data.columns; + + for (let j = 0; j < col; j++) { + if (data.get(j, j) === 0) { + return true; + } + } + + return false; + } + + solve(value) { + value = Matrix.checkMatrix(value); + let lu = this.LU; + let rows = lu.rows; + + if (rows !== value.rows) { + throw new Error('Invalid matrix dimensions'); + } + + if (this.isSingular()) { + throw new Error('LU matrix is singular'); + } + + let count = value.columns; + let X = value.subMatrixRow(this.pivotVector, 0, count - 1); + let columns = lu.columns; + let i, j, k; + + for (k = 0; k < columns; k++) { + for (i = k + 1; i < columns; i++) { + for (j = 0; j < count; j++) { + X.set(i, j, X.get(i, j) - X.get(k, j) * lu.get(i, k)); + } + } + } + + for (k = columns - 1; k >= 0; k--) { + for (j = 0; j < count; j++) { + X.set(k, j, X.get(k, j) / lu.get(k, k)); + } + + for (i = 0; i < k; i++) { + for (j = 0; j < count; j++) { + X.set(i, j, X.get(i, j) - X.get(k, j) * lu.get(i, k)); + } + } + } + + return X; + } + + get determinant() { + let data = this.LU; + + if (!data.isSquare()) { + throw new Error('Matrix must be square'); + } + + let determinant = this.pivotSign; + let col = data.columns; + + for (let j = 0; j < col; j++) { + determinant *= data.get(j, j); + } + + return determinant; + } + + get lowerTriangularMatrix() { + let data = this.LU; + let rows = data.rows; + let columns = data.columns; + let X = new Matrix(rows, columns); + + for (let i = 0; i < rows; i++) { + for (let j = 0; j < columns; j++) { + if (i > j) { + X.set(i, j, data.get(i, j)); + } else if (i === j) { + X.set(i, j, 1); + } else { + X.set(i, j, 0); + } + } + } + + return X; + } + + get upperTriangularMatrix() { + let data = this.LU; + let rows = data.rows; + let columns = data.columns; + let X = new Matrix(rows, columns); + + for (let i = 0; i < rows; i++) { + for (let j = 0; j < columns; j++) { + if (i <= j) { + X.set(i, j, data.get(i, j)); + } else { + X.set(i, j, 0); + } + } + } + + return X; + } + + get pivotPermutationVector() { + return Array.from(this.pivotVector); + } + + } + + function hypotenuse(a, b) { + let r = 0; + + if (Math.abs(a) > Math.abs(b)) { + r = b / a; + return Math.abs(a) * Math.sqrt(1 + r * r); + } + + if (b !== 0) { + r = a / b; + return Math.abs(b) * Math.sqrt(1 + r * r); + } + + return 0; + } + + class QrDecomposition { + constructor(value) { + value = WrapperMatrix2D.checkMatrix(value); + let qr = value.clone(); + let m = value.rows; + let n = value.columns; + let rdiag = new Float64Array(n); + let i, j, k, s; + + for (k = 0; k < n; k++) { + let nrm = 0; + + for (i = k; i < m; i++) { + nrm = hypotenuse(nrm, qr.get(i, k)); + } + + if (nrm !== 0) { + if (qr.get(k, k) < 0) { + nrm = -nrm; + } + + for (i = k; i < m; i++) { + qr.set(i, k, qr.get(i, k) / nrm); + } + + qr.set(k, k, qr.get(k, k) + 1); + + for (j = k + 1; j < n; j++) { + s = 0; + + for (i = k; i < m; i++) { + s += qr.get(i, k) * qr.get(i, j); + } + + s = -s / qr.get(k, k); + + for (i = k; i < m; i++) { + qr.set(i, j, qr.get(i, j) + s * qr.get(i, k)); + } + } + } + + rdiag[k] = -nrm; + } + + this.QR = qr; + this.Rdiag = rdiag; + } + + solve(value) { + value = Matrix.checkMatrix(value); + let qr = this.QR; + let m = qr.rows; + + if (value.rows !== m) { + throw new Error('Matrix row dimensions must agree'); + } + + if (!this.isFullRank()) { + throw new Error('Matrix is rank deficient'); + } + + let count = value.columns; + let X = value.clone(); + let n = qr.columns; + let i, j, k, s; + + for (k = 0; k < n; k++) { + for (j = 0; j < count; j++) { + s = 0; + + for (i = k; i < m; i++) { + s += qr.get(i, k) * X.get(i, j); + } + + s = -s / qr.get(k, k); + + for (i = k; i < m; i++) { + X.set(i, j, X.get(i, j) + s * qr.get(i, k)); + } + } + } + + for (k = n - 1; k >= 0; k--) { + for (j = 0; j < count; j++) { + X.set(k, j, X.get(k, j) / this.Rdiag[k]); + } + + for (i = 0; i < k; i++) { + for (j = 0; j < count; j++) { + X.set(i, j, X.get(i, j) - X.get(k, j) * qr.get(i, k)); + } + } + } + + return X.subMatrix(0, n - 1, 0, count - 1); + } + + isFullRank() { + let columns = this.QR.columns; + + for (let i = 0; i < columns; i++) { + if (this.Rdiag[i] === 0) { + return false; + } + } + + return true; + } + + get upperTriangularMatrix() { + let qr = this.QR; + let n = qr.columns; + let X = new Matrix(n, n); + let i, j; + + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (i < j) { + X.set(i, j, qr.get(i, j)); + } else if (i === j) { + X.set(i, j, this.Rdiag[i]); + } else { + X.set(i, j, 0); + } + } + } + + return X; + } + + get orthogonalMatrix() { + let qr = this.QR; + let rows = qr.rows; + let columns = qr.columns; + let X = new Matrix(rows, columns); + let i, j, k, s; + + for (k = columns - 1; k >= 0; k--) { + for (i = 0; i < rows; i++) { + X.set(i, k, 0); + } + + X.set(k, k, 1); + + for (j = k; j < columns; j++) { + if (qr.get(k, k) !== 0) { + s = 0; + + for (i = k; i < rows; i++) { + s += qr.get(i, k) * X.get(i, j); + } + + s = -s / qr.get(k, k); + + for (i = k; i < rows; i++) { + X.set(i, j, X.get(i, j) + s * qr.get(i, k)); + } + } + } + } + + return X; + } + + } + + class SingularValueDecomposition { + constructor(value) { + let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + value = WrapperMatrix2D.checkMatrix(value); + let m = value.rows; + let n = value.columns; + const { + computeLeftSingularVectors = true, + computeRightSingularVectors = true, + autoTranspose = false + } = options; + let wantu = Boolean(computeLeftSingularVectors); + let wantv = Boolean(computeRightSingularVectors); + let swapped = false; + let a; + + if (m < n) { + if (!autoTranspose) { + a = value.clone(); // eslint-disable-next-line no-console + + console.warn('Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose'); + } else { + a = value.transpose(); + m = a.rows; + n = a.columns; + swapped = true; + let aux = wantu; + wantu = wantv; + wantv = aux; + } + } else { + a = value.clone(); + } + + let nu = Math.min(m, n); + let ni = Math.min(m + 1, n); + let s = new Float64Array(ni); + let U = new Matrix(m, nu); + let V = new Matrix(n, n); + let e = new Float64Array(n); + let work = new Float64Array(m); + let si = new Float64Array(ni); + + for (let i = 0; i < ni; i++) si[i] = i; + + let nct = Math.min(m - 1, n); + let nrt = Math.max(0, Math.min(n - 2, m)); + let mrc = Math.max(nct, nrt); + + for (let k = 0; k < mrc; k++) { + if (k < nct) { + s[k] = 0; + + for (let i = k; i < m; i++) { + s[k] = hypotenuse(s[k], a.get(i, k)); + } + + if (s[k] !== 0) { + if (a.get(k, k) < 0) { + s[k] = -s[k]; + } + + for (let i = k; i < m; i++) { + a.set(i, k, a.get(i, k) / s[k]); + } + + a.set(k, k, a.get(k, k) + 1); + } + + s[k] = -s[k]; + } + + for (let j = k + 1; j < n; j++) { + if (k < nct && s[k] !== 0) { + let t = 0; + + for (let i = k; i < m; i++) { + t += a.get(i, k) * a.get(i, j); + } + + t = -t / a.get(k, k); + + for (let i = k; i < m; i++) { + a.set(i, j, a.get(i, j) + t * a.get(i, k)); + } + } + + e[j] = a.get(k, j); + } + + if (wantu && k < nct) { + for (let i = k; i < m; i++) { + U.set(i, k, a.get(i, k)); + } + } + + if (k < nrt) { + e[k] = 0; + + for (let i = k + 1; i < n; i++) { + e[k] = hypotenuse(e[k], e[i]); + } + + if (e[k] !== 0) { + if (e[k + 1] < 0) { + e[k] = 0 - e[k]; + } + + for (let i = k + 1; i < n; i++) { + e[i] /= e[k]; + } + + e[k + 1] += 1; + } + + e[k] = -e[k]; + + if (k + 1 < m && e[k] !== 0) { + for (let i = k + 1; i < m; i++) { + work[i] = 0; + } + + for (let i = k + 1; i < m; i++) { + for (let j = k + 1; j < n; j++) { + work[i] += e[j] * a.get(i, j); + } + } + + for (let j = k + 1; j < n; j++) { + let t = -e[j] / e[k + 1]; + + for (let i = k + 1; i < m; i++) { + a.set(i, j, a.get(i, j) + t * work[i]); + } + } + } + + if (wantv) { + for (let i = k + 1; i < n; i++) { + V.set(i, k, e[i]); + } + } + } + } + + let p = Math.min(n, m + 1); + + if (nct < n) { + s[nct] = a.get(nct, nct); + } + + if (m < p) { + s[p - 1] = 0; + } + + if (nrt + 1 < p) { + e[nrt] = a.get(nrt, p - 1); + } + + e[p - 1] = 0; + + if (wantu) { + for (let j = nct; j < nu; j++) { + for (let i = 0; i < m; i++) { + U.set(i, j, 0); + } + + U.set(j, j, 1); + } + + for (let k = nct - 1; k >= 0; k--) { + if (s[k] !== 0) { + for (let j = k + 1; j < nu; j++) { + let t = 0; + + for (let i = k; i < m; i++) { + t += U.get(i, k) * U.get(i, j); + } + + t = -t / U.get(k, k); + + for (let i = k; i < m; i++) { + U.set(i, j, U.get(i, j) + t * U.get(i, k)); + } + } + + for (let i = k; i < m; i++) { + U.set(i, k, -U.get(i, k)); + } + + U.set(k, k, 1 + U.get(k, k)); + + for (let i = 0; i < k - 1; i++) { + U.set(i, k, 0); + } + } else { + for (let i = 0; i < m; i++) { + U.set(i, k, 0); + } + + U.set(k, k, 1); + } + } + } + + if (wantv) { + for (let k = n - 1; k >= 0; k--) { + if (k < nrt && e[k] !== 0) { + for (let j = k + 1; j < n; j++) { + let t = 0; + + for (let i = k + 1; i < n; i++) { + t += V.get(i, k) * V.get(i, j); + } + + t = -t / V.get(k + 1, k); + + for (let i = k + 1; i < n; i++) { + V.set(i, j, V.get(i, j) + t * V.get(i, k)); + } + } + } + + for (let i = 0; i < n; i++) { + V.set(i, k, 0); + } + + V.set(k, k, 1); + } + } + + let pp = p - 1; + let eps = Number.EPSILON; + + while (p > 0) { + let k, kase; + + for (k = p - 2; k >= -1; k--) { + if (k === -1) { + break; + } + + const alpha = Number.MIN_VALUE + eps * Math.abs(s[k] + Math.abs(s[k + 1])); + + if (Math.abs(e[k]) <= alpha || Number.isNaN(e[k])) { + e[k] = 0; + break; + } + } + + if (k === p - 2) { + kase = 4; + } else { + let ks; + + for (ks = p - 1; ks >= k; ks--) { + if (ks === k) { + break; + } + + let t = (ks !== p ? Math.abs(e[ks]) : 0) + (ks !== k + 1 ? Math.abs(e[ks - 1]) : 0); + + if (Math.abs(s[ks]) <= eps * t) { + s[ks] = 0; + break; + } + } + + if (ks === k) { + kase = 3; + } else if (ks === p - 1) { + kase = 1; + } else { + kase = 2; + k = ks; + } + } + + k++; + + switch (kase) { + case 1: + { + let f = e[p - 2]; + e[p - 2] = 0; + + for (let j = p - 2; j >= k; j--) { + let t = hypotenuse(s[j], f); + let cs = s[j] / t; + let sn = f / t; + s[j] = t; + + if (j !== k) { + f = -sn * e[j - 1]; + e[j - 1] = cs * e[j - 1]; + } + + if (wantv) { + for (let i = 0; i < n; i++) { + t = cs * V.get(i, j) + sn * V.get(i, p - 1); + V.set(i, p - 1, -sn * V.get(i, j) + cs * V.get(i, p - 1)); + V.set(i, j, t); + } + } + } + + break; + } + + case 2: + { + let f = e[k - 1]; + e[k - 1] = 0; + + for (let j = k; j < p; j++) { + let t = hypotenuse(s[j], f); + let cs = s[j] / t; + let sn = f / t; + s[j] = t; + f = -sn * e[j]; + e[j] = cs * e[j]; + + if (wantu) { + for (let i = 0; i < m; i++) { + t = cs * U.get(i, j) + sn * U.get(i, k - 1); + U.set(i, k - 1, -sn * U.get(i, j) + cs * U.get(i, k - 1)); + U.set(i, j, t); + } + } + } + + break; + } + + case 3: + { + const scale = Math.max(Math.abs(s[p - 1]), Math.abs(s[p - 2]), Math.abs(e[p - 2]), Math.abs(s[k]), Math.abs(e[k])); + const sp = s[p - 1] / scale; + const spm1 = s[p - 2] / scale; + const epm1 = e[p - 2] / scale; + const sk = s[k] / scale; + const ek = e[k] / scale; + const b = ((spm1 + sp) * (spm1 - sp) + epm1 * epm1) / 2; + const c = sp * epm1 * (sp * epm1); + let shift = 0; + + if (b !== 0 || c !== 0) { + if (b < 0) { + shift = 0 - Math.sqrt(b * b + c); + } else { + shift = Math.sqrt(b * b + c); + } + + shift = c / (b + shift); + } + + let f = (sk + sp) * (sk - sp) + shift; + let g = sk * ek; + + for (let j = k; j < p - 1; j++) { + let t = hypotenuse(f, g); + if (t === 0) t = Number.MIN_VALUE; + let cs = f / t; + let sn = g / t; + + if (j !== k) { + e[j - 1] = t; + } + + f = cs * s[j] + sn * e[j]; + e[j] = cs * e[j] - sn * s[j]; + g = sn * s[j + 1]; + s[j + 1] = cs * s[j + 1]; + + if (wantv) { + for (let i = 0; i < n; i++) { + t = cs * V.get(i, j) + sn * V.get(i, j + 1); + V.set(i, j + 1, -sn * V.get(i, j) + cs * V.get(i, j + 1)); + V.set(i, j, t); + } + } + + t = hypotenuse(f, g); + if (t === 0) t = Number.MIN_VALUE; + cs = f / t; + sn = g / t; + s[j] = t; + f = cs * e[j] + sn * s[j + 1]; + s[j + 1] = -sn * e[j] + cs * s[j + 1]; + g = sn * e[j + 1]; + e[j + 1] = cs * e[j + 1]; + + if (wantu && j < m - 1) { + for (let i = 0; i < m; i++) { + t = cs * U.get(i, j) + sn * U.get(i, j + 1); + U.set(i, j + 1, -sn * U.get(i, j) + cs * U.get(i, j + 1)); + U.set(i, j, t); + } + } + } + + e[p - 2] = f; + break; + } + + case 4: + { + if (s[k] <= 0) { + s[k] = s[k] < 0 ? -s[k] : 0; + + if (wantv) { + for (let i = 0; i <= pp; i++) { + V.set(i, k, -V.get(i, k)); + } + } + } + + while (k < pp) { + if (s[k] >= s[k + 1]) { + break; + } + + let t = s[k]; + s[k] = s[k + 1]; + s[k + 1] = t; + + if (wantv && k < n - 1) { + for (let i = 0; i < n; i++) { + t = V.get(i, k + 1); + V.set(i, k + 1, V.get(i, k)); + V.set(i, k, t); + } + } + + if (wantu && k < m - 1) { + for (let i = 0; i < m; i++) { + t = U.get(i, k + 1); + U.set(i, k + 1, U.get(i, k)); + U.set(i, k, t); + } + } + + k++; + } + p--; + break; + } + // no default + } + } + + if (swapped) { + let tmp = V; + V = U; + U = tmp; + } + + this.m = m; + this.n = n; + this.s = s; + this.U = U; + this.V = V; + } + + solve(value) { + let Y = value; + let e = this.threshold; + let scols = this.s.length; + let Ls = Matrix.zeros(scols, scols); + + for (let i = 0; i < scols; i++) { + if (Math.abs(this.s[i]) <= e) { + Ls.set(i, i, 0); + } else { + Ls.set(i, i, 1 / this.s[i]); + } + } + + let U = this.U; + let V = this.rightSingularVectors; + let VL = V.mmul(Ls); + let vrows = V.rows; + let urows = U.rows; + let VLU = Matrix.zeros(vrows, urows); + + for (let i = 0; i < vrows; i++) { + for (let j = 0; j < urows; j++) { + let sum = 0; + + for (let k = 0; k < scols; k++) { + sum += VL.get(i, k) * U.get(j, k); + } + + VLU.set(i, j, sum); + } + } + + return VLU.mmul(Y); + } + + solveForDiagonal(value) { + return this.solve(Matrix.diag(value)); + } + + inverse() { + let V = this.V; + let e = this.threshold; + let vrows = V.rows; + let vcols = V.columns; + let X = new Matrix(vrows, this.s.length); + + for (let i = 0; i < vrows; i++) { + for (let j = 0; j < vcols; j++) { + if (Math.abs(this.s[j]) > e) { + X.set(i, j, V.get(i, j) / this.s[j]); + } + } + } + + let U = this.U; + let urows = U.rows; + let ucols = U.columns; + let Y = new Matrix(vrows, urows); + + for (let i = 0; i < vrows; i++) { + for (let j = 0; j < urows; j++) { + let sum = 0; + + for (let k = 0; k < ucols; k++) { + sum += X.get(i, k) * U.get(j, k); + } + + Y.set(i, j, sum); + } + } + + return Y; + } + + get condition() { + return this.s[0] / this.s[Math.min(this.m, this.n) - 1]; + } + + get norm2() { + return this.s[0]; + } + + get rank() { + let tol = Math.max(this.m, this.n) * this.s[0] * Number.EPSILON; + let r = 0; + let s = this.s; + + for (let i = 0, ii = s.length; i < ii; i++) { + if (s[i] > tol) { + r++; + } + } + + return r; + } + + get diagonal() { + return Array.from(this.s); + } + + get threshold() { + return Number.EPSILON / 2 * Math.max(this.m, this.n) * this.s[0]; + } + + get leftSingularVectors() { + return this.U; + } + + get rightSingularVectors() { + return this.V; + } + + get diagonalMatrix() { + return Matrix.diag(this.s); + } + + } + + function inverse(matrix) { + let useSVD = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + matrix = WrapperMatrix2D.checkMatrix(matrix); + + if (useSVD) { + return new SingularValueDecomposition(matrix).inverse(); + } else { + return solve(matrix, Matrix.eye(matrix.rows)); + } + } + function solve(leftHandSide, rightHandSide) { + let useSVD = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + leftHandSide = WrapperMatrix2D.checkMatrix(leftHandSide); + rightHandSide = WrapperMatrix2D.checkMatrix(rightHandSide); + + if (useSVD) { + return new SingularValueDecomposition(leftHandSide).solve(rightHandSide); + } else { + return leftHandSide.isSquare() ? new LuDecomposition(leftHandSide).solve(rightHandSide) : new QrDecomposition(leftHandSide).solve(rightHandSide); + } + } + + /** + * Difference of the matrix function over the parameters + * @ignore + * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ] + * @param {Array} evaluatedData - Array of previous evaluated function values + * @param {Array} 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} + */ + + function gradientFunction(data, evaluatedData, params, gradientDifference, paramFunction) { + const n = params.length; + const m = data.x.length; + let ans = new Array(n); + + for (let param = 0; param < n; param++) { + ans[param] = new Array(m); + let auxParams = params.slice(); + auxParams[param] += gradientDifference; + let funcParam = paramFunction(auxParams); + + for (let point = 0; point < m; point++) { + ans[param][point] = evaluatedData[point] - funcParam(data.x[point]); + } + } + + return new Matrix(ans); + } + /** + * Matrix function over the samples + * @ignore + * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ] + * @param {Array} evaluatedData - Array of previous evaluated function values + * @return {Matrix} + */ + + + function matrixFunction(data, evaluatedData) { + const m = data.x.length; + let ans = new Array(m); + + for (let point = 0; point < m; point++) { + ans[point] = [data.y[point] - evaluatedData[point]]; + } + + return new Matrix(ans); + } + /** + * Iteration for Levenberg-Marquardt + * @ignore + * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ] + * @param {Array} 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} + */ + + + function step(data, params, damping, gradientDifference, parameterizedFunction) { + let value = damping * gradientDifference * gradientDifference; + let identity = Matrix.eye(params.length, params.length, value); + const func = parameterizedFunction(params); + let evaluatedData = new Float64Array(data.x.length); + + for (let i = 0; i < data.x.length; i++) { + evaluatedData[i] = func(data.x[i]); + } + + let gradientFunc = gradientFunction(data, evaluatedData, params, gradientDifference, parameterizedFunction); + let matrixFunc = matrixFunction(data, evaluatedData); + let inverseMatrix = inverse(identity.add(gradientFunc.mmul(gradientFunc.transpose()))); + params = new Matrix([params]); + params = params.sub(inverseMatrix.mmul(gradientFunc).mmul(matrixFunc).mul(gradientDifference).transpose()); + return params.to1DArray(); + } + + /** + * Curve fitting algorithm + * @param {{x:Array, y:Array}} 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} [options.minValues] - Minimum allowed values for parameters + * @param {Array} [options.maxValues] - Maximum allowed values for parameters + * @param {Array} [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, parameterError: number, iterations: number}} + */ + + function levenbergMarquardt(data, parameterizedFunction) { + let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let { + maxIterations = 100, + gradientDifference = 10e-2, + damping = 0, + errorTolerance = 10e-3, + minValues, + maxValues, + 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 (!isAnyArray(data.x) || data.x.length < 2 || !isAnyArray(data.y) || data.y.length < 2) { + throw new Error('The data parameter elements must be an array with more than 2 points'); + } else if (data.x.length !== data.y.length) { + throw new Error('The data parameter elements must have the same size'); + } + + let parameters = initialValues || new Array(parameterizedFunction.length).fill(1); + let parLen = parameters.length; + maxValues = maxValues || new Array(parLen).fill(Number.MAX_SAFE_INTEGER); + minValues = minValues || new Array(parLen).fill(Number.MIN_SAFE_INTEGER); + + if (maxValues.length !== minValues.length) { + throw new Error('minValues and maxValues must be the same size'); + } + + if (!isAnyArray(parameters)) { + throw new Error('initialValues must be an array'); + } + + let error = errorCalculation(data, parameters, parameterizedFunction); + let converged = error <= errorTolerance; + let iteration; + + for (iteration = 0; iteration < maxIterations && !converged; iteration++) { + parameters = step(data, parameters, damping, gradientDifference, parameterizedFunction); + + for (let k = 0; k < parLen; k++) { + parameters[k] = Math.min(Math.max(minValues[k], parameters[k]), maxValues[k]); + } + + error = errorCalculation(data, parameters, parameterizedFunction); + if (isNaN(error)) break; + converged = error <= errorTolerance; + } + + return { + parameterValues: parameters, + parameterError: error, + iterations: iteration + }; + } + + /** + * This function calculates the spectrum as a sum of gaussian functions. The Gaussian + * parameters are divided in 3 batches. 1st: centers; 2nd: height; 3th: std's; + * @param t Ordinate values + * @param p Gaussian parameters + * @param c Constant parameters(Not used) + * @returns {*} + */ + function sumOfGaussians(p) { + return function (t) { + let nL = p.length / 3; + let factor; + let rows = t.length; + let result = rows === undefined ? 0 : new Float64Array(rows).fill(0); + + for (let i = 0; i < nL; i++) { + factor = Math.pow(p[i + nL * 2], 2) * 2; + + if (rows === undefined) { + result += p[i + nL] * Math.exp(-Math.pow(t - p[i], 2) / factor); + } else { + for (let j = 0; j < rows; j++) { + result[j] += p[i + nL] * Math.exp(-Math.pow(t[j] - p[i], 2) / factor); + } + } + } + + return result; + }; + } + + /** + * + * @param xy A two column matrix containing the x and y data to be fitted + * @param group A set of initial lorentzian parameters to be optimized [center, heigth, half_width_at_half_height] + * @returns {Array} A set of final lorentzian parameters [center, heigth, hwhh*2] + */ + + function optimizeGaussianSum(xy, group) { + let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let t = xy[0]; + let yData = xy[1]; + let maxY = Math.max(...yData); + yData.forEach((x, i, arr) => arr[i] /= maxY); + let nL = group.length; + let pInit = new Float64Array(nL * 3); + let pMin = new Float64Array(nL * 3); + let pMax = new Float64Array(nL * 3); + let dt = Math.abs(t[0] - t[1]); + + for (let i = 0; i < nL; i++) { + pInit[i] = group[i].x; + pInit[i + nL] = group[i].y / maxY; + pInit[i + 2 * nL] = group[i].width; + pMin[i] = group[i].x - dt; + pMin[i + nL] = 0; + pMin[i + 2 * nL] = group[i].width / 4; + pMax[i] = group[i].x + dt; + pMax[i + nL] = group[i].y * 1.2 / maxY; + pMax[i + 2 * nL] = group[i].width * 4; + } + + let data = { + x: t, + y: yData + }; + let result = new Array(nL); + let lmOptions = { + damping: 1.5, + initialValues: pInit, + minValues: pMin, + maxValues: pMax, + gradientDifference: dt / 10000, + maxIterations: 100, + errorTolerance: 10e-5 + }; + opts = Object.assign({}, lmOptions, opts); + let pFit = levenbergMarquardt(data, sumOfGaussians, opts); + + for (let i = 0; i < nL; i++) { + result[i] = { + parameters: [pFit.parameterValues[i], pFit.parameterValues[i + nL] * maxY, pFit.parameterValues[i + nL * 2]], + error: pFit.parameterError + }; + } + + return result; + } + + /** + * Single 3 parameter gaussian function + * @param t Ordinate values + * @param p Gaussian parameters [mean, height, std] + * @param c Constant parameters(Not used) + * @returns {*} + */ + function singleGaussian(p) { + return function (t) { + let factor2 = p[2] * p[2] / 2; + let rows = t.length; + if (!rows) return p[1] * Math.exp(-(t - p[0]) * (t - p[0]) / factor2); + let result = new Float64Array(t.length); + + for (let i = 0; i < t.length; i++) { + result[i] = p[1] * Math.exp(-(t[i] - p[0]) * (t[i] - p[0]) / factor2); + } + + return result; + }; + } + + /** + * Fits a set of points to a gaussian bell. Returns the mean of the peak, the std and the height of the signal. + * @param data,[y] + * @returns {*[]} + */ + + function optimizeSingleGaussian(xy, peak) { + let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let t = xy[0]; + let yData = xy[1]; + let maxY = Math.max(...yData); + yData.forEach((x, i, arr) => arr[i] /= maxY); + let dt = Math.abs(t[0] - t[1]); + let pInit = new Float64Array([peak.x, 1, peak.width]); + let pMin = new Float64Array([peak.x - dt, 0, peak.width / 4]); + let pMax = new Float64Array([peak.x + dt, 1.25, peak.width * 4]); + let data = { + x: t, + y: yData + }; + let lmOptions = { + damping: 1.5, + initialValues: pInit, + minValues: pMin, + maxValues: pMax, + gradientDifference: dt / 10000, + maxIterations: 100, + errorTolerance: 10e-5 + }; + opts = Object.assign({}, lmOptions, opts); + let pFit = levenbergMarquardt(data, singleGaussian, opts); + return { + parameters: [pFit.parameterValues[0], pFit.parameterValues[1] * maxY, pFit.parameterValues[2]], + error: pFit.parameterError + }; + } + + /** + * This function calculates the spectrum as a sum of lorentzian functions. The Lorentzian + * parameters are divided in 3 batches. 1st: centers; 2nd: heights; 3th: widths; + * @param t Ordinate values + * @param p Lorentzian parameters + * @returns {*} + */ + function sumOfLorentzians(p) { + return function (t) { + let nL = p.length / 3; + let factor; + let p2; + let rows = t.length; + let result = rows === undefined ? 0 : new Float64Array(rows).fill(0); + + for (let i = 0; i < nL; i++) { + p2 = Math.pow(p[i + nL * 2] / 2, 2); + factor = p[i + nL] * p2; + + if (rows === undefined) { + result += factor / (Math.pow(t - p[i], 2) + p2); + } else { + for (let j = 0; j < rows; j++) { + result[j] += factor / (Math.pow(t[j] - p[i], 2) + p2); + } + } + } + + return result; + }; + } + + /** + * + * @param xy A two column matrix containing the x and y data to be fitted + * @param group A set of initial lorentzian parameters to be optimized [center, heigth, half_width_at_half_height] + * @returns {Array} A set of final lorentzian parameters [center, heigth, hwhh*2] + */ + + function optimizeLorentzianSum(xy, group) { + let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let t = xy[0]; + let yData = xy[1]; + let maxY = Math.max(...yData); + yData.forEach((x, i, arr) => arr[i] /= maxY); + let nL = group.length; + let pInit = new Float64Array(nL * 3); + let pMin = new Float64Array(nL * 3); + let pMax = new Float64Array(nL * 3); + let dt = Math.abs(t[0] - t[1]); + + for (let i = 0; i < nL; i++) { + pInit[i] = group[i].x; + pInit[i + nL] = 1; + pInit[i + 2 * nL] = group[i].width; + pMin[i] = group[i].x - dt; + pMin[i + nL] = 0; + pMin[i + 2 * nL] = group[i].width / 4; + pMax[i] = group[i].x + dt; + pMax[i + nL] = 1.5; + pMax[i + 2 * nL] = group[i].width * 4; + } + + let data = { + x: t, + y: yData + }; + let result = new Array(nL); + let lmOptions = { + damping: 1.5, + initialValues: pInit, + minValues: pMin, + maxValues: pMax, + gradientDifference: dt / 10000, + maxIterations: 100, + errorTolerance: 10e-5 + }; + opts = Object.assign({}, lmOptions, opts); + let pFit = levenbergMarquardt(data, sumOfLorentzians, opts); + + for (let i = 0; i < nL; i++) { + result[i] = { + parameters: [pFit.parameterValues[i], pFit.parameterValues[i + nL] * maxY, pFit.parameterValues[i + nL * 2]], + error: pFit.parameterError + }; + } + + return result; + } + + /** + * Single 4 parameter lorentzian function + * @param t Ordinate values + * @param p Lorentzian parameters + * @param c Constant parameters(Not used) + * @returns {*} + */ + function singleLorentzian(p) { + return function (t) { + let factor = p[1] * Math.pow(p[2] / 2, 2); + let rows = t.length; + if (!rows) return factor / (Math.pow(t - p[0], 2) + Math.pow(p[2] / 2, 2)); + let result = new Float64Array(rows); + + for (let i = 0; i < rows; i++) { + result[i] = factor / (Math.pow(t[i] - p[0], 2) + Math.pow(p[2] / 2, 2)); + } + + return result; + }; + } + + /** + * * Fits a set of points to a Lorentzian function. Returns the center of the peak, the width at half height, and the height of the signal. + * @param data,[y] + * @returns {*[]} + */ + + function optimizeSingleLorentzian(xy, peak) { + let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + let t = xy[0]; + let yData = xy[1]; + let maxY = Math.max(...yData); + yData.forEach((x, i, arr) => arr[i] /= maxY); + let dt = Math.abs(t[0] - t[1]); + let pInit = new Float64Array([peak.x, 1, peak.width]); + let pMin = new Float64Array([peak.x - dt, 0.75, peak.width / 4]); + let pMax = new Float64Array([peak.x + dt, 1.25, peak.width * 4]); + let data = { + x: t, + y: yData + }; + let lmOptions = { + damping: 1.5, + initialValues: pInit, + minValues: pMin, + maxValues: pMax, + gradientDifference: dt / 10000, + maxIterations: 100, + errorTolerance: 10e-5 + }; + opts = Object.assign({}, lmOptions, opts); + let pFit = levenbergMarquardt(data, singleLorentzian, opts); + return { + parameters: [pFit.parameterValues[0], pFit.parameterValues[1] * maxY, pFit.parameterValues[2]], + error: pFit.parameterError + }; + } + + function optimizePeaks(peakList, x, y) { + let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; + const { + functionName = 'gaussian', + factorWidth = 4, + optimizationOptions = { + damping: 1.5, + maxIterations: 100, + errorTolerance: 10e-5 + } + } = options; + let lastIndex = [0]; + let groups = groupPeaks(peakList, factorWidth); + let result = []; + let factor = 1; + + if (functionName === 'gaussian') { + factor = 1.17741; + } // From https://en.wikipedia.org/wiki/Gaussian_function#Properties + + + let sampling; + + for (let i = 0; i < groups.length; i++) { + let peaks = groups[i].group; + + if (peaks.length > 1) { + // Multiple peaks + sampling = sampleFunction(groups[i].limits[0] - groups[i].limits[1], groups[i].limits[0] + groups[i].limits[1], x, y, lastIndex); + + if (sampling[0].length > 5) { + let optPeaks = []; + + if (functionName === 'gaussian') { + optPeaks = optimizeGaussianSum(sampling, peaks, optimizationOptions); + } else { + if (functionName === 'lorentzian') { + optPeaks = optimizeLorentzianSum(sampling, peaks, optimizationOptions); + } + } + + for (let j = 0; j < optPeaks.length; j++) { + let { + parameters + } = optPeaks[j]; + result.push({ + x: parameters[0], + y: parameters[1], + width: parameters[2] * factor, + index: peaks[j].index + }); + } + } + } else { + // Single peak + peaks = peaks[0]; + sampling = sampleFunction(peaks.x - factorWidth * peaks.width, peaks.x + factorWidth * peaks.width, x, y, lastIndex); + + if (sampling[0].length > 5) { + let fitResult = []; + + if (functionName === 'gaussian') { + fitResult = optimizeSingleGaussian([sampling[0], sampling[1]], peaks, optimizationOptions); + } else { + if (functionName === 'lorentzian') { + fitResult = optimizeSingleLorentzian([sampling[0], sampling[1]], peaks, optimizationOptions); + } + } + + let { + parameters + } = fitResult; + result.push({ + x: parameters[0], + y: parameters[1], + width: parameters[2] * factor, + index: peaks.index + }); // From https://en.wikipedia.org/wiki/Gaussian_function#Properties} + } + } + } + + return result; + } + + function sampleFunction(from, to, x, y, lastIndex) { + let nbPoints = x.length; + let sampleX = []; + let sampleY = []; + let direction = Math.sign(x[1] - x[0]); // Direction of the derivative + + if (direction === -1) { + lastIndex[0] = x.length - 1; + } + + let delta = Math.abs(to - from) / 2; + let mid = (from + to) / 2; + let stop = false; + let index = lastIndex[0]; + + while (!stop && index < nbPoints && index >= 0) { + if (Math.abs(x[index] - mid) <= delta) { + sampleX.push(x[index]); + sampleY.push(y[index]); + index += direction; + } else { + // It is outside the range. + if (Math.sign(mid - x[index]) === 1) { + // We'll reach the mid going in the current direction + index += direction; + } else { + // There is not more peaks in the current range + stop = true; + } + } + } + + lastIndex[0] = index; + return [sampleX, sampleY]; + } + + function groupPeaks(peakList, nL) { + let group = []; + let groups = []; + let limits = [peakList[0].x, nL * peakList[0].width]; + let upperLimit, lowerLimit; // Merge forward + + for (let i = 0; i < peakList.length; i++) { + // If the 2 things overlaps + if (Math.abs(peakList[i].x - limits[0]) < nL * peakList[i].width + limits[1]) { + // Add the peak to the group + group.push(peakList[i]); // Update the group limits + + upperLimit = limits[0] + limits[1]; + + if (peakList[i].x + nL * peakList[i].width > upperLimit) { + upperLimit = peakList[i].x + nL * peakList[i].width; + } + + lowerLimit = limits[0] - limits[1]; + + if (peakList[i].x - nL * peakList[i].width < lowerLimit) { + lowerLimit = peakList[i].x - nL * peakList[i].width; + } + + limits = [(upperLimit + lowerLimit) / 2, Math.abs(upperLimit - lowerLimit) / 2]; + } else { + groups.push({ + limits: limits, + group: group + }); // var optmimalPeak = fitSpectrum(group,limits,spectrum); + + group = [peakList[i]]; + limits = [peakList[i].x, nL * peakList[i].width]; + } + } + + groups.push({ + limits: limits, + group: group + }); // Merge backward + + for (let i = groups.length - 2; i >= 0; i--) { + // The groups overlaps + if (Math.abs(groups[i].limits[0] - groups[i + 1].limits[0]) < (groups[i].limits[1] + groups[i + 1].limits[1]) / 2) { + for (let j = 0; j < groups[i + 1].group.length; j++) { + groups[i].group.push(groups[i + 1].group[j]); + } + + upperLimit = groups[i].limits[0] + groups[i].limits[1]; + + if (groups[i + 1].limits[0] + groups[i + 1].limits[1] > upperLimit) { + upperLimit = groups[i + 1].limits[0] + groups[i + 1].limits[1]; + } + + lowerLimit = groups[i].limits[0] - groups[i].limits[1]; + + if (groups[i + 1].limits[0] - groups[i + 1].limits[1] < lowerLimit) { + lowerLimit = groups[i + 1].limits[0] - groups[i + 1].limits[1]; + } + + groups[i].limits = [(upperLimit + lowerLimit) / 2, Math.abs(upperLimit - lowerLimit) / 2]; + groups.splice(i + 1, 1); + } + } + + return groups; + } + + /** + * This function try to join the peaks that seems to belong to a broad signal in a single broad peak. + * @param peakList + * @param options + */ + + function joinBroadPeaks(peakList) { + let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + let width = options.width; + let broadLines = []; // Optimize the possible broad lines + + let max = 0; + let maxI = 0; + let count = 1; + + for (let i = peakList.length - 1; i >= 0; i--) { + if (peakList[i].soft) { + broadLines.push(peakList.splice(i, 1)[0]); + } + } // Push a feke peak + + + broadLines.push({ + x: Number.MAX_VALUE + }); + let candidates = [[broadLines[0].x, broadLines[0].y]]; + let indexes = [broadLines[0].index]; + + for (let i = 1; i < broadLines.length; i++) { + // console.log(broadLines[i-1].x+" "+broadLines[i].x); + if (Math.abs(broadLines[i - 1].x - broadLines[i].x) < width) { + candidates.push([broadLines[i].x, broadLines[i].y]); + + if (broadLines[i].y > max) { + max = broadLines[i].y; + maxI = i; + } + + indexes.push(broadLines[i].index); + count++; + } else { + if (count > 2) { + let fitted = optimizeSingleLorentzian(candidates, { + x: broadLines[maxI].x, + y: max, + width: Math.abs(candidates[0][0] - candidates[candidates.length - 1][0]) + }); + let { + parameters + } = fitted; + peakList.push({ + x: parameters[0], + y: parameters[1], + width: parameters[2], + index: Math.floor(indexes.reduce((a, b) => a + b, 0) / indexes.length), + soft: false + }); + } else { + // Put back the candidates to the signals list + indexes.forEach(index => { + peakList.push(broadLines[index]); + }); + } + + candidates = [[broadLines[i].x, broadLines[i].y]]; + indexes = [i]; + max = broadLines[i].y; + maxI = i; + count = 1; + } + } + + peakList.sort(function (a, b) { + return a.x - b.x; + }); + return peakList; + } + + /** + * This method will allow to enlarge peaks and prevent overlap between peaks + * Because peaks may not be symmetric after we add 2 properties, from and to. + * @param {Array} peakList + * @param {object} [options={}] + * @param {number} [factor=2] + * @param {boolean} [overlap=false] by default we don't allow overlap + * @return {Array} peakList + */ + function broadenPeaks(peakList) { + let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + const { + factor = 2, + overlap = false + } = options; + + for (let peak of peakList) { + if (!peak.right || !peak.left) { + peak.from = peak.x - peak.width / 2 * factor; + peak.to = peak.x + peak.width / 2 * factor; + } else { + peak.from = peak.x - (peak.x - peak.left.x) * factor; + peak.to = peak.x + (peak.right.x - peak.x) * factor; + } + } + + if (!overlap) { + for (let i = 0; i < peakList.length - 1; i++) { + let peak = peakList[i]; + let nextPeak = peakList[i + 1]; + + if (peak.to > nextPeak.from) { + peak.to = nextPeak.from = (peak.to + nextPeak.from) / 2; + } + } + } + + for (let peak of peakList) { + peak.width = peak.to - peak.from; + } + + return peakList; + } + + exports.broadenPeaks = broadenPeaks; + exports.gsd = gsd; + exports.joinBroadPeaks = joinBroadPeaks; + exports.optimizePeaks = optimizePeaks; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); +//# sourceMappingURL=ml-gsd.js.map diff --git a/dist/ml-gsd.js.map b/dist/ml-gsd.js.map new file mode 100644 index 0000000..f78494f --- /dev/null +++ b/dist/ml-gsd.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ml-gsd.js","sources":["../node_modules/ml-savitzky-golay-generalized/src/index.js","../src/gsd.js","../node_modules/is-any-array/src/index.js","../node_modules/ml-levenberg-marquardt/src/errorCalculation.js","../node_modules/ml-array-rescale/node_modules/is-any-array/src/index.js","../node_modules/ml-array-max/node_modules/is-any-array/src/index.js","../node_modules/ml-array-max/lib-es6/index.js","../node_modules/ml-array-min/node_modules/is-any-array/src/index.js","../node_modules/ml-array-min/lib-es6/index.js","../node_modules/ml-array-rescale/lib-es6/index.js","../node_modules/ml-matrix/src/inspect.js","../node_modules/ml-matrix/src/mathOperations.js","../node_modules/ml-matrix/src/util.js","../node_modules/ml-matrix/src/stat.js","../node_modules/ml-matrix/src/matrix.js","../node_modules/ml-matrix/src/wrap/WrapperMatrix2D.js","../node_modules/ml-matrix/src/dc/lu.js","../node_modules/ml-matrix/src/dc/util.js","../node_modules/ml-matrix/src/dc/qr.js","../node_modules/ml-matrix/src/dc/svd.js","../node_modules/ml-matrix/src/decompositions.js","../node_modules/ml-levenberg-marquardt/src/step.js","../node_modules/ml-levenberg-marquardt/src/index.js","../node_modules/ml-optimize-lorentzian/src/sumOfGaussians.js","../node_modules/ml-optimize-lorentzian/src/optimizeGaussianSum.js","../node_modules/ml-optimize-lorentzian/src/singleGaussian.js","../node_modules/ml-optimize-lorentzian/src/optimizeSingleGaussian.js","../node_modules/ml-optimize-lorentzian/src/sumOfLorentzians.js","../node_modules/ml-optimize-lorentzian/src/optimizeLorentzianSum.js","../node_modules/ml-optimize-lorentzian/src/singleLorentzian.js","../node_modules/ml-optimize-lorentzian/src/optimizeSingleLorentzian.js","../src/post/optimizePeaks.js","../src/post/joinBroadPeaks.js","../src/post/broadenPeaks.js"],"sourcesContent":["export default function SavitzkyGolay(data, h, options = {}) {\n let { windowSize = 9, derivative = 0, polynomial = 3 } = options;\n\n if (windowSize % 2 === 0 || windowSize < 5 || !Number.isInteger(windowSize)) {\n throw new RangeError(\n 'Invalid window size (should be odd and at least 5 integer number)',\n );\n }\n if (windowSize > data.length) {\n throw new RangeError(\n `Window size is higher than the data length ${windowSize}>${data.length}`,\n );\n }\n if (derivative < 0 || !Number.isInteger(derivative)) {\n throw new RangeError('Derivative should be a positive integer');\n }\n if (polynomial < 1 || !Number.isInteger(polynomial)) {\n throw new RangeError('Polynomial should be a positive integer');\n }\n if (polynomial >= 6) {\n // eslint-disable-next-line no-console\n console.warn(\n 'You should not use polynomial grade higher than 5 if you are' +\n ' not sure that your data arises from such a model. Possible polynomial oscillation problems',\n );\n }\n\n let half = Math.floor(windowSize / 2);\n let np = data.length;\n let ans = new Array(np);\n let weights = fullWeights(windowSize, polynomial, derivative);\n let hs = 0;\n let constantH = true;\n if (Array.isArray(h)) {\n constantH = false;\n } else {\n hs = Math.pow(h, derivative);\n }\n\n //For the borders\n for (let i = 0; i < half; i++) {\n let wg1 = weights[half - i - 1];\n let wg2 = weights[half + i + 1];\n let d1 = 0;\n let d2 = 0;\n for (let l = 0; l < windowSize; l++) {\n d1 += wg1[l] * data[l];\n d2 += wg2[l] * data[np - windowSize + l];\n }\n if (constantH) {\n ans[half - i - 1] = d1 / hs;\n ans[np - half + i] = d2 / hs;\n } else {\n hs = getHs(h, half - i - 1, half, derivative);\n ans[half - i - 1] = d1 / hs;\n hs = getHs(h, np - half + i, half, derivative);\n ans[np - half + i] = d2 / hs;\n }\n }\n\n //For the internal points\n let wg = weights[half];\n for (let i = windowSize; i <= np; i++) {\n let d = 0;\n for (let l = 0; l < windowSize; l++) d += wg[l] * data[l + i - windowSize];\n if (!constantH) hs = getHs(h, i - half - 1, half, derivative);\n ans[i - half - 1] = d / hs;\n }\n return ans;\n}\n\nfunction getHs(h, center, half, derivative) {\n let hs = 0;\n let count = 0;\n for (let i = center - half; i < center + half; i++) {\n if (i >= 0 && i < h.length - 1) {\n hs += h[i + 1] - h[i];\n count++;\n }\n }\n return Math.pow(hs / count, derivative);\n}\n\nfunction GramPoly(i, m, k, s) {\n let Grampoly = 0;\n if (k > 0) {\n Grampoly =\n ((4 * k - 2) / (k * (2 * m - k + 1))) *\n (i * GramPoly(i, m, k - 1, s) + s * GramPoly(i, m, k - 1, s - 1)) -\n (((k - 1) * (2 * m + k)) / (k * (2 * m - k + 1))) *\n GramPoly(i, m, k - 2, s);\n } else {\n if (k === 0 && s === 0) {\n Grampoly = 1;\n } else {\n Grampoly = 0;\n }\n }\n return Grampoly;\n}\n\nfunction GenFact(a, b) {\n let gf = 1;\n if (a >= b) {\n for (let j = a - b + 1; j <= a; j++) {\n gf *= j;\n }\n }\n return gf;\n}\n\nfunction Weight(i, t, m, n, s) {\n let sum = 0;\n for (let k = 0; k <= n; k++) {\n //console.log(k);\n sum +=\n (2 * k + 1) *\n (GenFact(2 * m, k) / GenFact(2 * m + k + 1, k + 1)) *\n GramPoly(i, m, k, 0) *\n GramPoly(t, m, k, s);\n }\n return sum;\n}\n\n/**\n *\n * @param m Number of points\n * @param n Polynomial grade\n * @param s Derivative\n */\nfunction fullWeights(m, n, s) {\n let weights = new Array(m);\n let np = Math.floor(m / 2);\n for (let t = -np; t <= np; t++) {\n weights[t + np] = new Array(m);\n for (let j = -np; j <= np; j++) {\n weights[t + np][j + np] = Weight(j, t, np, n, s);\n }\n }\n return weights;\n}\n\n/*function entropy(data,h,options){\n var trend = SavitzkyGolay(data,h,trendOptions);\n var copy = new Array(data.length);\n var sum = 0;\n var max = 0;\n for(var i=0;i} x - Independent variable\n * @param {Array} yIn - Dependent variable\n * @param {object} [options] - Options object\n * @param {object} [options.sgOptions] - Options object for Savitzky-Golay filter. See https://github.com/mljs/savitzky-golay-generalized#options\n * @param {number} [options.sgOptions.windowSize = 9] - points to use in the approximations\n * @param {number} [options.sgOptions.polynomial = 3] - degree of the polynomial to use in the approximations\n * @param {number} [options.minMaxRatio = 0.00025] - Threshold to determine if a given peak should be considered as a noise\n * @param {number} [options.broadRatio = 0.00] - If `broadRatio` is higher than 0, then all the peaks which second derivative\n * smaller than `broadRatio * maxAbsSecondDerivative` will be marked with the soft mask equal to true.\n * @param {number} [options.noiseLevel = 0] - Noise threshold in spectrum units\n * @param {boolean} [options.maxCriteria = true] - Peaks are local maximum(true) or minimum(false)\n * @param {boolean} [options.smoothY = true] - Select the peak intensities from a smoothed version of the independent variables\n * @param {boolean} [options.realTopDetection = false] - Use a quadratic optimizations with the peak and its 3 closest neighbors\n * to determine the true x,y values of the peak?\n * @param {number} [options.heightFactor = 0] - Factor to multiply the calculated height (usually 2)\n * @param {boolean} [options.boundaries = false] - Return also the inflection points of the peaks\n * @param {number} [options.derivativeThreshold = -1] - Filters based on the amplitude of the first derivative\n * @return {Array}\n */\nexport function gsd(x, yIn, options = {}) {\n let {\n noiseLevel,\n sgOptions = {\n windowSize: 9,\n polynomial: 3,\n },\n smoothY = true,\n heightFactor = 0,\n broadRatio = 0.0,\n maxCriteria = true,\n minMaxRatio = 0.00025,\n derivativeThreshold = -1,\n realTopDetection = false,\n } = options;\n\n const y = yIn.slice();\n let equalSpaced = isEqualSpaced(x);\n\n if (noiseLevel === undefined) {\n noiseLevel = equalSpaced ? getNoiseLevel(y) : 0;\n }\n\n const yCorrection = { m: 1, b: noiseLevel };\n\n if (!maxCriteria) {\n yCorrection.m = -1;\n yCorrection.b *= -1;\n }\n\n for (let i = 0; i < y.length; i++) {\n y[i] = yCorrection.m * y[i] - yCorrection.b;\n }\n\n for (let i = 0; i < y.length; i++) {\n if (y[i] < 0) {\n y[i] = 0;\n }\n }\n // If the max difference between delta x is less than 5%, then,\n // we can assume it to be equally spaced variable\n let Y = y;\n let dY, ddY;\n const { windowSize, polynomial } = sgOptions;\n\n if (equalSpaced) {\n if (smoothY) {\n Y = SG(y, x[1] - x[0], {\n windowSize,\n polynomial,\n derivative: 0,\n });\n }\n dY = SG(y, x[1] - x[0], {\n windowSize,\n polynomial,\n derivative: 1,\n });\n ddY = SG(y, x[1] - x[0], {\n windowSize,\n polynomial,\n derivative: 2,\n });\n } else {\n if (smoothY) {\n Y = SG(y, x, {\n windowSize,\n polynomial,\n derivative: 0,\n });\n }\n dY = SG(y, x, {\n windowSize,\n polynomial,\n derivative: 1,\n });\n ddY = SG(y, x, {\n windowSize,\n polynomial,\n derivative: 2,\n });\n }\n // console.log('this is 2', y)\n const X = x;\n const dx = x[1] - x[0];\n let maxDdy = 0;\n let maxY = 0;\n for (let i = 0; i < Y.length; i++) {\n if (Math.abs(ddY[i]) > maxDdy) {\n maxDdy = Math.abs(ddY[i]);\n }\n if (Math.abs(Y[i]) > maxY) {\n maxY = Math.abs(Y[i]);\n }\n }\n\n let lastMax = null;\n let lastMin = null;\n let minddY = new Array(Y.length - 2);\n let intervalL = new Array(Y.length);\n let intervalR = new Array(Y.length);\n let broadMask = new Array(Y.length - 2);\n let minddYLen = 0;\n let intervalLLen = 0;\n let intervalRLen = 0;\n let broadMaskLen = 0;\n // By the intermediate value theorem We cannot find 2 consecutive maximum or minimum\n for (let i = 1; i < Y.length - 1; ++i) {\n // filter based on derivativeThreshold\n // console.log('pasa', y[i], dY[i], ddY[i]);\n if (Math.abs(dY[i]) > derivativeThreshold) {\n // Minimum in first derivative\n if (\n (dY[i] < dY[i - 1] && dY[i] <= dY[i + 1]) ||\n (dY[i] <= dY[i - 1] && dY[i] < dY[i + 1])\n ) {\n lastMin = {\n x: X[i],\n index: i,\n };\n if (dx > 0 && lastMax !== null) {\n intervalL[intervalLLen++] = lastMax;\n intervalR[intervalRLen++] = lastMin;\n }\n }\n\n // Maximum in first derivative\n if (\n (dY[i] >= dY[i - 1] && dY[i] > dY[i + 1]) ||\n (dY[i] > dY[i - 1] && dY[i] >= dY[i + 1])\n ) {\n lastMax = {\n x: X[i],\n index: i,\n };\n if (dx < 0 && lastMin !== null) {\n intervalL[intervalLLen++] = lastMax;\n intervalR[intervalRLen++] = lastMin;\n }\n }\n }\n\n // Minimum in second derivative\n if (ddY[i] < ddY[i - 1] && ddY[i] < ddY[i + 1]) {\n // TODO should we change this to have 3 arrays ? Huge overhead creating arrays\n minddY[minddYLen++] = i; // ( [X[i], Y[i], i] );\n broadMask[broadMaskLen++] = Math.abs(ddY[i]) <= broadRatio * maxDdy;\n }\n }\n minddY.length = minddYLen;\n intervalL.length = intervalLLen;\n intervalR.length = intervalRLen;\n broadMask.length = broadMaskLen;\n\n let signals = new Array(minddY.length);\n let signalsLen = 0;\n let lastK = -1;\n let possible, frequency, distanceJ, minDistance, gettingCloser;\n for (let j = 0; j < minddY.length; ++j) {\n frequency = X[minddY[j]];\n possible = -1;\n let k = lastK + 1;\n minDistance = Number.MAX_VALUE;\n distanceJ = 0;\n gettingCloser = true;\n while (possible === -1 && k < intervalL.length && gettingCloser) {\n distanceJ = Math.abs(frequency - (intervalL[k].x + intervalR[k].x) / 2);\n\n // Still getting closer?\n if (distanceJ < minDistance) {\n minDistance = distanceJ;\n } else {\n gettingCloser = false;\n }\n if (distanceJ < Math.abs(intervalL[k].x - intervalR[k].x) / 2) {\n possible = k;\n lastK = k;\n }\n ++k;\n }\n\n if (possible !== -1) {\n if (Math.abs(Y[minddY[j]]) > minMaxRatio * maxY) {\n signals[signalsLen++] = {\n index: minddY[j],\n x: frequency,\n y: (Y[minddY[j]] + yCorrection.b) / yCorrection.m,\n width: Math.abs(intervalR[possible].x - intervalL[possible].x), // widthCorrection\n soft: broadMask[j],\n };\n\n signals[signalsLen - 1].left = intervalL[possible];\n signals[signalsLen - 1].right = intervalR[possible];\n\n if (heightFactor) {\n let yLeft = Y[intervalL[possible].index];\n let yRight = Y[intervalR[possible].index];\n signals[signalsLen - 1].height =\n heightFactor * (signals[signalsLen - 1].y - (yLeft + yRight) / 2);\n }\n }\n }\n }\n signals.length = signalsLen;\n\n if (realTopDetection) {\n determineRealTop(signals, X, Y);\n }\n\n // Correct the values to fit the original spectra data\n for (let j = 0; j < signals.length; j++) {\n signals[j].base = noiseLevel;\n }\n\n signals.sort(function (a, b) {\n return a.x - b.x;\n });\n\n return signals;\n}\n\nconst isEqualSpaced = (x) => {\n let tmp;\n let maxDx = 0;\n let minDx = Number.MAX_SAFE_INTEGER;\n for (let i = 0; i < x.length - 1; ++i) {\n tmp = Math.abs(x[i + 1] - x[i]);\n if (tmp < minDx) {\n minDx = tmp;\n }\n if (tmp > maxDx) {\n maxDx = tmp;\n }\n }\n return (maxDx - minDx) / maxDx < 0.05;\n};\n\nconst getNoiseLevel = (y) => {\n let mean = 0;\n\n let stddev = 0;\n let length = y.length;\n for (let i = 0; i < length; ++i) {\n mean += y[i];\n }\n mean /= length;\n let averageDeviations = new Array(length);\n for (let i = 0; i < length; ++i) {\n averageDeviations[i] = Math.abs(y[i] - mean);\n }\n averageDeviations.sort((a, b) => a - b);\n if (length % 2 === 1) {\n stddev = averageDeviations[(length - 1) / 2] / 0.6745;\n } else {\n stddev =\n (0.5 *\n (averageDeviations[length / 2] + averageDeviations[length / 2 - 1])) /\n 0.6745;\n }\n\n return stddev;\n};\n\nconst determineRealTop = (peakList, x, y) => {\n let alpha, beta, gamma, p, currentPoint;\n for (let j = 0; j < peakList.length; j++) {\n currentPoint = peakList[j].index; // peakList[j][2];\n // The detected peak could be moved 1 or 2 units to left or right.\n if (\n y[currentPoint - 1] >= y[currentPoint - 2] &&\n y[currentPoint - 1] >= y[currentPoint]\n ) {\n currentPoint--;\n } else {\n if (\n y[currentPoint + 1] >= y[currentPoint] &&\n y[currentPoint + 1] >= y[currentPoint + 2]\n ) {\n currentPoint++;\n } else {\n if (\n y[currentPoint - 2] >= y[currentPoint - 3] &&\n y[currentPoint - 2] >= y[currentPoint - 1]\n ) {\n currentPoint -= 2;\n } else {\n if (\n y[currentPoint + 2] >= y[currentPoint + 1] &&\n y[currentPoint + 2] >= y[currentPoint + 3]\n ) {\n currentPoint += 2;\n }\n }\n }\n }\n // interpolation to a sin() function\n if (\n y[currentPoint - 1] > 0 &&\n y[currentPoint + 1] > 0 &&\n y[currentPoint] >= y[currentPoint - 1] &&\n y[currentPoint] >= y[currentPoint + 1] &&\n (y[currentPoint] !== y[currentPoint - 1] ||\n y[currentPoint] !== y[currentPoint + 1])\n ) {\n alpha = 20 * Math.log10(y[currentPoint - 1]);\n beta = 20 * Math.log10(y[currentPoint]);\n gamma = 20 * Math.log10(y[currentPoint + 1]);\n p = (0.5 * (alpha - gamma)) / (alpha - 2 * beta + gamma);\n // console.log(alpha, beta, gamma, `p: ${p}`);\n // console.log(x[currentPoint]+\" \"+tmp+\" \"+currentPoint);\n peakList[j].x =\n x[currentPoint] + (x[currentPoint] - x[currentPoint - 1]) * p;\n peakList[j].y =\n y[currentPoint] -\n 0.25 * (y[currentPoint - 1] - y[currentPoint + 1]) * p;\n }\n }\n};\n","const toString = Object.prototype.toString;\n\nexport default function isAnyArray(object) {\n return toString.call(object).endsWith('Array]');\n}\n","/**\n * Calculate current error\n * @ignore\n * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]\n * @param {Array} parameters - Array of current parameter values\n * @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter\n * @return {number}\n */\nexport default function errorCalculation(\n data,\n parameters,\n parameterizedFunction,\n) {\n let error = 0;\n const func = parameterizedFunction(parameters);\n\n for (let i = 0; i < data.x.length; i++) {\n error += Math.abs(data.y[i] - func(data.x[i]));\n }\n\n return error;\n}\n","'use strict';\n\nconst toString = Object.prototype.toString;\n\nfunction isAnyArray(object) {\n return toString.call(object).endsWith('Array]');\n}\n\nmodule.exports = isAnyArray;\n","'use strict';\n\nconst toString = Object.prototype.toString;\n\nfunction isAnyArray(object) {\n return toString.call(object).endsWith('Array]');\n}\n\nmodule.exports = isAnyArray;\n","import isArray from 'is-any-array';\n\n/**\n * Computes the maximum of the given values\n * @param {Array} input\n * @return {number}\n */\n\nfunction max(input) {\n if (!isArray(input)) {\n throw new TypeError('input must be an array');\n }\n\n if (input.length === 0) {\n throw new TypeError('input must not be empty');\n }\n\n var maxValue = input[0];\n\n for (var i = 1; i < input.length; i++) {\n if (input[i] > maxValue) maxValue = input[i];\n }\n\n return maxValue;\n}\n\nexport default max;\n","'use strict';\n\nconst toString = Object.prototype.toString;\n\nfunction isAnyArray(object) {\n return toString.call(object).endsWith('Array]');\n}\n\nmodule.exports = isAnyArray;\n","import isArray from 'is-any-array';\n\n/**\n * Computes the minimum of the given values\n * @param {Array} input\n * @return {number}\n */\n\nfunction min(input) {\n if (!isArray(input)) {\n throw new TypeError('input must be an array');\n }\n\n if (input.length === 0) {\n throw new TypeError('input must not be empty');\n }\n\n var minValue = input[0];\n\n for (var i = 1; i < input.length; i++) {\n if (input[i] < minValue) minValue = input[i];\n }\n\n return minValue;\n}\n\nexport default min;\n","import isArray from 'is-any-array';\nimport max from 'ml-array-max';\nimport min from 'ml-array-min';\n\n/**\n *\n * @param {Array} input\n * @param {object} [options={}]\n * @param {Array} [options.output=[]] specify the output array, can be the input array for in place modification\n */\n\nfunction rescale(input) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n if (!isArray(input)) {\n throw new TypeError('input must be an array');\n } else if (input.length === 0) {\n throw new TypeError('input must not be empty');\n }\n\n var output;\n\n if (options.output !== undefined) {\n if (!isArray(options.output)) {\n throw new TypeError('output option must be an array if specified');\n }\n\n output = options.output;\n } else {\n output = new Array(input.length);\n }\n\n var currentMin = min(input);\n var currentMax = max(input);\n\n if (currentMin === currentMax) {\n throw new RangeError('minimum and maximum input values are equal. Cannot rescale a constant array');\n }\n\n var _options$min = options.min,\n minValue = _options$min === void 0 ? options.autoMinMax ? currentMin : 0 : _options$min,\n _options$max = options.max,\n maxValue = _options$max === void 0 ? options.autoMinMax ? currentMax : 1 : _options$max;\n\n if (minValue >= maxValue) {\n throw new RangeError('min option must be smaller than max option');\n }\n\n var factor = (maxValue - minValue) / (currentMax - currentMin);\n\n for (var i = 0; i < input.length; i++) {\n output[i] = (input[i] - currentMin) * factor + minValue;\n }\n\n return output;\n}\n\nexport default rescale;\n","const indent = ' '.repeat(2);\nconst indentData = ' '.repeat(4);\n\nexport function inspectMatrix() {\n return inspectMatrixWithOptions(this);\n}\n\nexport function inspectMatrixWithOptions(matrix, options = {}) {\n const { maxRows = 15, maxColumns = 10, maxNumSize = 8 } = options;\n return `${matrix.constructor.name} {\n${indent}[\n${indentData}${inspectData(matrix, maxRows, maxColumns, maxNumSize)}\n${indent}]\n${indent}rows: ${matrix.rows}\n${indent}columns: ${matrix.columns}\n}`;\n}\n\nfunction inspectData(matrix, maxRows, maxColumns, maxNumSize) {\n const { rows, columns } = matrix;\n const maxI = Math.min(rows, maxRows);\n const maxJ = Math.min(columns, maxColumns);\n const result = [];\n for (let i = 0; i < maxI; i++) {\n let line = [];\n for (let j = 0; j < maxJ; j++) {\n line.push(formatNumber(matrix.get(i, j), maxNumSize));\n }\n result.push(`${line.join(' ')}`);\n }\n if (maxJ !== columns) {\n result[result.length - 1] += ` ... ${columns - maxColumns} more columns`;\n }\n if (maxI !== rows) {\n result.push(`... ${rows - maxRows} more rows`);\n }\n return result.join(`\\n${indentData}`);\n}\n\nfunction formatNumber(num, maxNumSize) {\n const numStr = String(num);\n if (numStr.length <= maxNumSize) {\n return numStr.padEnd(maxNumSize, ' ');\n }\n const precise = num.toPrecision(maxNumSize - 2);\n if (precise.length <= maxNumSize) {\n return precise;\n }\n const exponential = num.toExponential(maxNumSize - 2);\n const eIndex = exponential.indexOf('e');\n const e = exponential.slice(eIndex);\n return exponential.slice(0, maxNumSize - e.length) + e;\n}\n","export function installMathOperations(AbstractMatrix, Matrix) {\n AbstractMatrix.prototype.add = function add(value) {\n if (typeof value === 'number') return this.addS(value);\n return this.addM(value);\n };\n\n AbstractMatrix.prototype.addS = function addS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) + value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.addM = function addM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) + matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.add = function add(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.add(value);\n };\n\n AbstractMatrix.prototype.sub = function sub(value) {\n if (typeof value === 'number') return this.subS(value);\n return this.subM(value);\n };\n\n AbstractMatrix.prototype.subS = function subS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) - value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.subM = function subM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) - matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.sub = function sub(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.sub(value);\n };\n AbstractMatrix.prototype.subtract = AbstractMatrix.prototype.sub;\n AbstractMatrix.prototype.subtractS = AbstractMatrix.prototype.subS;\n AbstractMatrix.prototype.subtractM = AbstractMatrix.prototype.subM;\n AbstractMatrix.subtract = AbstractMatrix.sub;\n\n AbstractMatrix.prototype.mul = function mul(value) {\n if (typeof value === 'number') return this.mulS(value);\n return this.mulM(value);\n };\n\n AbstractMatrix.prototype.mulS = function mulS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) * value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.mulM = function mulM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) * matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.mul = function mul(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.mul(value);\n };\n AbstractMatrix.prototype.multiply = AbstractMatrix.prototype.mul;\n AbstractMatrix.prototype.multiplyS = AbstractMatrix.prototype.mulS;\n AbstractMatrix.prototype.multiplyM = AbstractMatrix.prototype.mulM;\n AbstractMatrix.multiply = AbstractMatrix.mul;\n\n AbstractMatrix.prototype.div = function div(value) {\n if (typeof value === 'number') return this.divS(value);\n return this.divM(value);\n };\n\n AbstractMatrix.prototype.divS = function divS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) / value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.divM = function divM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) / matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.div = function div(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.div(value);\n };\n AbstractMatrix.prototype.divide = AbstractMatrix.prototype.div;\n AbstractMatrix.prototype.divideS = AbstractMatrix.prototype.divS;\n AbstractMatrix.prototype.divideM = AbstractMatrix.prototype.divM;\n AbstractMatrix.divide = AbstractMatrix.div;\n\n AbstractMatrix.prototype.mod = function mod(value) {\n if (typeof value === 'number') return this.modS(value);\n return this.modM(value);\n };\n\n AbstractMatrix.prototype.modS = function modS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) % value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.modM = function modM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) % matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.mod = function mod(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.mod(value);\n };\n AbstractMatrix.prototype.modulus = AbstractMatrix.prototype.mod;\n AbstractMatrix.prototype.modulusS = AbstractMatrix.prototype.modS;\n AbstractMatrix.prototype.modulusM = AbstractMatrix.prototype.modM;\n AbstractMatrix.modulus = AbstractMatrix.mod;\n\n AbstractMatrix.prototype.and = function and(value) {\n if (typeof value === 'number') return this.andS(value);\n return this.andM(value);\n };\n\n AbstractMatrix.prototype.andS = function andS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) & value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.andM = function andM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) & matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.and = function and(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.and(value);\n };\n\n AbstractMatrix.prototype.or = function or(value) {\n if (typeof value === 'number') return this.orS(value);\n return this.orM(value);\n };\n\n AbstractMatrix.prototype.orS = function orS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) | value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.orM = function orM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) | matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.or = function or(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.or(value);\n };\n\n AbstractMatrix.prototype.xor = function xor(value) {\n if (typeof value === 'number') return this.xorS(value);\n return this.xorM(value);\n };\n\n AbstractMatrix.prototype.xorS = function xorS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) ^ value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.xorM = function xorM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) ^ matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.xor = function xor(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.xor(value);\n };\n\n AbstractMatrix.prototype.leftShift = function leftShift(value) {\n if (typeof value === 'number') return this.leftShiftS(value);\n return this.leftShiftM(value);\n };\n\n AbstractMatrix.prototype.leftShiftS = function leftShiftS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) << value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.leftShiftM = function leftShiftM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) << matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.leftShift = function leftShift(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.leftShift(value);\n };\n\n AbstractMatrix.prototype.signPropagatingRightShift = function signPropagatingRightShift(value) {\n if (typeof value === 'number') return this.signPropagatingRightShiftS(value);\n return this.signPropagatingRightShiftM(value);\n };\n\n AbstractMatrix.prototype.signPropagatingRightShiftS = function signPropagatingRightShiftS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) >> value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.signPropagatingRightShiftM = function signPropagatingRightShiftM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) >> matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.signPropagatingRightShift = function signPropagatingRightShift(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.signPropagatingRightShift(value);\n };\n\n AbstractMatrix.prototype.rightShift = function rightShift(value) {\n if (typeof value === 'number') return this.rightShiftS(value);\n return this.rightShiftM(value);\n };\n\n AbstractMatrix.prototype.rightShiftS = function rightShiftS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) >>> value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.rightShiftM = function rightShiftM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) >>> matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.rightShift = function rightShift(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.rightShift(value);\n };\n AbstractMatrix.prototype.zeroFillRightShift = AbstractMatrix.prototype.rightShift;\n AbstractMatrix.prototype.zeroFillRightShiftS = AbstractMatrix.prototype.rightShiftS;\n AbstractMatrix.prototype.zeroFillRightShiftM = AbstractMatrix.prototype.rightShiftM;\n AbstractMatrix.zeroFillRightShift = AbstractMatrix.rightShift;\n\n AbstractMatrix.prototype.not = function not() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, ~(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.not = function not(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.not();\n };\n\n AbstractMatrix.prototype.abs = function abs() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.abs(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.abs = function abs(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.abs();\n };\n\n AbstractMatrix.prototype.acos = function acos() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.acos(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.acos = function acos(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.acos();\n };\n\n AbstractMatrix.prototype.acosh = function acosh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.acosh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.acosh = function acosh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.acosh();\n };\n\n AbstractMatrix.prototype.asin = function asin() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.asin(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.asin = function asin(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.asin();\n };\n\n AbstractMatrix.prototype.asinh = function asinh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.asinh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.asinh = function asinh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.asinh();\n };\n\n AbstractMatrix.prototype.atan = function atan() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.atan(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.atan = function atan(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.atan();\n };\n\n AbstractMatrix.prototype.atanh = function atanh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.atanh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.atanh = function atanh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.atanh();\n };\n\n AbstractMatrix.prototype.cbrt = function cbrt() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.cbrt(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.cbrt = function cbrt(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.cbrt();\n };\n\n AbstractMatrix.prototype.ceil = function ceil() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.ceil(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.ceil = function ceil(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.ceil();\n };\n\n AbstractMatrix.prototype.clz32 = function clz32() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.clz32(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.clz32 = function clz32(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.clz32();\n };\n\n AbstractMatrix.prototype.cos = function cos() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.cos(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.cos = function cos(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.cos();\n };\n\n AbstractMatrix.prototype.cosh = function cosh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.cosh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.cosh = function cosh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.cosh();\n };\n\n AbstractMatrix.prototype.exp = function exp() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.exp(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.exp = function exp(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.exp();\n };\n\n AbstractMatrix.prototype.expm1 = function expm1() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.expm1(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.expm1 = function expm1(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.expm1();\n };\n\n AbstractMatrix.prototype.floor = function floor() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.floor(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.floor = function floor(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.floor();\n };\n\n AbstractMatrix.prototype.fround = function fround() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.fround(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.fround = function fround(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.fround();\n };\n\n AbstractMatrix.prototype.log = function log() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.log(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.log = function log(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.log();\n };\n\n AbstractMatrix.prototype.log1p = function log1p() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.log1p(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.log1p = function log1p(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.log1p();\n };\n\n AbstractMatrix.prototype.log10 = function log10() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.log10(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.log10 = function log10(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.log10();\n };\n\n AbstractMatrix.prototype.log2 = function log2() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.log2(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.log2 = function log2(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.log2();\n };\n\n AbstractMatrix.prototype.round = function round() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.round(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.round = function round(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.round();\n };\n\n AbstractMatrix.prototype.sign = function sign() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.sign(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.sign = function sign(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.sign();\n };\n\n AbstractMatrix.prototype.sin = function sin() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.sin(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.sin = function sin(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.sin();\n };\n\n AbstractMatrix.prototype.sinh = function sinh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.sinh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.sinh = function sinh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.sinh();\n };\n\n AbstractMatrix.prototype.sqrt = function sqrt() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.sqrt(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.sqrt = function sqrt(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.sqrt();\n };\n\n AbstractMatrix.prototype.tan = function tan() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.tan(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.tan = function tan(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.tan();\n };\n\n AbstractMatrix.prototype.tanh = function tanh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.tanh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.tanh = function tanh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.tanh();\n };\n\n AbstractMatrix.prototype.trunc = function trunc() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.trunc(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.trunc = function trunc(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.trunc();\n };\n\n AbstractMatrix.pow = function pow(matrix, arg0) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.pow(arg0);\n };\n\n AbstractMatrix.prototype.pow = function pow(value) {\n if (typeof value === 'number') return this.powS(value);\n return this.powM(value);\n };\n\n AbstractMatrix.prototype.powS = function powS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.pow(this.get(i, j), value));\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.powM = function powM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.pow(this.get(i, j), matrix.get(i, j)));\n }\n }\n return this;\n };\n}\n","/**\n * @private\n * Check that a row index is not out of bounds\n * @param {Matrix} matrix\n * @param {number} index\n * @param {boolean} [outer]\n */\nexport function checkRowIndex(matrix, index, outer) {\n let max = outer ? matrix.rows : matrix.rows - 1;\n if (index < 0 || index > max) {\n throw new RangeError('Row index out of range');\n }\n}\n\n/**\n * @private\n * Check that a column index is not out of bounds\n * @param {Matrix} matrix\n * @param {number} index\n * @param {boolean} [outer]\n */\nexport function checkColumnIndex(matrix, index, outer) {\n let max = outer ? matrix.columns : matrix.columns - 1;\n if (index < 0 || index > max) {\n throw new RangeError('Column index out of range');\n }\n}\n\n/**\n * @private\n * Check that the provided vector is an array with the right length\n * @param {Matrix} matrix\n * @param {Array|Matrix} vector\n * @return {Array}\n * @throws {RangeError}\n */\nexport function checkRowVector(matrix, vector) {\n if (vector.to1DArray) {\n vector = vector.to1DArray();\n }\n if (vector.length !== matrix.columns) {\n throw new RangeError(\n 'vector size must be the same as the number of columns',\n );\n }\n return vector;\n}\n\n/**\n * @private\n * Check that the provided vector is an array with the right length\n * @param {Matrix} matrix\n * @param {Array|Matrix} vector\n * @return {Array}\n * @throws {RangeError}\n */\nexport function checkColumnVector(matrix, vector) {\n if (vector.to1DArray) {\n vector = vector.to1DArray();\n }\n if (vector.length !== matrix.rows) {\n throw new RangeError('vector size must be the same as the number of rows');\n }\n return vector;\n}\n\nexport function checkIndices(matrix, rowIndices, columnIndices) {\n return {\n row: checkRowIndices(matrix, rowIndices),\n column: checkColumnIndices(matrix, columnIndices),\n };\n}\n\nexport function checkRowIndices(matrix, rowIndices) {\n if (typeof rowIndices !== 'object') {\n throw new TypeError('unexpected type for row indices');\n }\n\n let rowOut = rowIndices.some((r) => {\n return r < 0 || r >= matrix.rows;\n });\n\n if (rowOut) {\n throw new RangeError('row indices are out of range');\n }\n\n if (!Array.isArray(rowIndices)) rowIndices = Array.from(rowIndices);\n\n return rowIndices;\n}\n\nexport function checkColumnIndices(matrix, columnIndices) {\n if (typeof columnIndices !== 'object') {\n throw new TypeError('unexpected type for column indices');\n }\n\n let columnOut = columnIndices.some((c) => {\n return c < 0 || c >= matrix.columns;\n });\n\n if (columnOut) {\n throw new RangeError('column indices are out of range');\n }\n if (!Array.isArray(columnIndices)) columnIndices = Array.from(columnIndices);\n\n return columnIndices;\n}\n\nexport function checkRange(matrix, startRow, endRow, startColumn, endColumn) {\n if (arguments.length !== 5) {\n throw new RangeError('expected 4 arguments');\n }\n checkNumber('startRow', startRow);\n checkNumber('endRow', endRow);\n checkNumber('startColumn', startColumn);\n checkNumber('endColumn', endColumn);\n if (\n startRow > endRow ||\n startColumn > endColumn ||\n startRow < 0 ||\n startRow >= matrix.rows ||\n endRow < 0 ||\n endRow >= matrix.rows ||\n startColumn < 0 ||\n startColumn >= matrix.columns ||\n endColumn < 0 ||\n endColumn >= matrix.columns\n ) {\n throw new RangeError('Submatrix indices are out of range');\n }\n}\n\nexport function newArray(length, value = 0) {\n let array = [];\n for (let i = 0; i < length; i++) {\n array.push(value);\n }\n return array;\n}\n\nfunction checkNumber(name, value) {\n if (typeof value !== 'number') {\n throw new TypeError(`${name} must be a number`);\n }\n}\n","import { newArray } from './util';\n\nexport function sumByRow(matrix) {\n let sum = newArray(matrix.rows);\n for (let i = 0; i < matrix.rows; ++i) {\n for (let j = 0; j < matrix.columns; ++j) {\n sum[i] += matrix.get(i, j);\n }\n }\n return sum;\n}\n\nexport function sumByColumn(matrix) {\n let sum = newArray(matrix.columns);\n for (let i = 0; i < matrix.rows; ++i) {\n for (let j = 0; j < matrix.columns; ++j) {\n sum[j] += matrix.get(i, j);\n }\n }\n return sum;\n}\n\nexport function sumAll(matrix) {\n let v = 0;\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n v += matrix.get(i, j);\n }\n }\n return v;\n}\n\nexport function productByRow(matrix) {\n let sum = newArray(matrix.rows, 1);\n for (let i = 0; i < matrix.rows; ++i) {\n for (let j = 0; j < matrix.columns; ++j) {\n sum[i] *= matrix.get(i, j);\n }\n }\n return sum;\n}\n\nexport function productByColumn(matrix) {\n let sum = newArray(matrix.columns, 1);\n for (let i = 0; i < matrix.rows; ++i) {\n for (let j = 0; j < matrix.columns; ++j) {\n sum[j] *= matrix.get(i, j);\n }\n }\n return sum;\n}\n\nexport function productAll(matrix) {\n let v = 1;\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n v *= matrix.get(i, j);\n }\n }\n return v;\n}\n\nexport function varianceByRow(matrix, unbiased, mean) {\n const rows = matrix.rows;\n const cols = matrix.columns;\n const variance = [];\n\n for (let i = 0; i < rows; i++) {\n let sum1 = 0;\n let sum2 = 0;\n let x = 0;\n for (let j = 0; j < cols; j++) {\n x = matrix.get(i, j) - mean[i];\n sum1 += x;\n sum2 += x * x;\n }\n if (unbiased) {\n variance.push((sum2 - (sum1 * sum1) / cols) / (cols - 1));\n } else {\n variance.push((sum2 - (sum1 * sum1) / cols) / cols);\n }\n }\n return variance;\n}\n\nexport function varianceByColumn(matrix, unbiased, mean) {\n const rows = matrix.rows;\n const cols = matrix.columns;\n const variance = [];\n\n for (let j = 0; j < cols; j++) {\n let sum1 = 0;\n let sum2 = 0;\n let x = 0;\n for (let i = 0; i < rows; i++) {\n x = matrix.get(i, j) - mean[j];\n sum1 += x;\n sum2 += x * x;\n }\n if (unbiased) {\n variance.push((sum2 - (sum1 * sum1) / rows) / (rows - 1));\n } else {\n variance.push((sum2 - (sum1 * sum1) / rows) / rows);\n }\n }\n return variance;\n}\n\nexport function varianceAll(matrix, unbiased, mean) {\n const rows = matrix.rows;\n const cols = matrix.columns;\n const size = rows * cols;\n\n let sum1 = 0;\n let sum2 = 0;\n let x = 0;\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < cols; j++) {\n x = matrix.get(i, j) - mean;\n sum1 += x;\n sum2 += x * x;\n }\n }\n if (unbiased) {\n return (sum2 - (sum1 * sum1) / size) / (size - 1);\n } else {\n return (sum2 - (sum1 * sum1) / size) / size;\n }\n}\n\nexport function centerByRow(matrix, mean) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) - mean[i]);\n }\n }\n}\n\nexport function centerByColumn(matrix, mean) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) - mean[j]);\n }\n }\n}\n\nexport function centerAll(matrix, mean) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) - mean);\n }\n }\n}\n\nexport function getScaleByRow(matrix) {\n const scale = [];\n for (let i = 0; i < matrix.rows; i++) {\n let sum = 0;\n for (let j = 0; j < matrix.columns; j++) {\n sum += Math.pow(matrix.get(i, j), 2) / (matrix.columns - 1);\n }\n scale.push(Math.sqrt(sum));\n }\n return scale;\n}\n\nexport function scaleByRow(matrix, scale) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) / scale[i]);\n }\n }\n}\n\nexport function getScaleByColumn(matrix) {\n const scale = [];\n for (let j = 0; j < matrix.columns; j++) {\n let sum = 0;\n for (let i = 0; i < matrix.rows; i++) {\n sum += Math.pow(matrix.get(i, j), 2) / (matrix.rows - 1);\n }\n scale.push(Math.sqrt(sum));\n }\n return scale;\n}\n\nexport function scaleByColumn(matrix, scale) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) / scale[j]);\n }\n }\n}\n\nexport function getScaleAll(matrix) {\n const divider = matrix.size - 1;\n let sum = 0;\n for (let j = 0; j < matrix.columns; j++) {\n for (let i = 0; i < matrix.rows; i++) {\n sum += Math.pow(matrix.get(i, j), 2) / divider;\n }\n }\n return Math.sqrt(sum);\n}\n\nexport function scaleAll(matrix, scale) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) / scale);\n }\n }\n}\n","import rescale from 'ml-array-rescale';\n\nimport { inspectMatrix, inspectMatrixWithOptions } from './inspect';\nimport { installMathOperations } from './mathOperations';\nimport {\n sumByRow,\n sumByColumn,\n sumAll,\n productByRow,\n productByColumn,\n productAll,\n varianceByRow,\n varianceByColumn,\n varianceAll,\n centerByRow,\n centerByColumn,\n centerAll,\n scaleByRow,\n scaleByColumn,\n scaleAll,\n getScaleByRow,\n getScaleByColumn,\n getScaleAll,\n} from './stat';\nimport {\n checkRowVector,\n checkRowIndex,\n checkColumnIndex,\n checkColumnVector,\n checkRange,\n checkIndices,\n} from './util';\n\nexport class AbstractMatrix {\n static from1DArray(newRows, newColumns, newData) {\n let length = newRows * newColumns;\n if (length !== newData.length) {\n throw new RangeError('data length does not match given dimensions');\n }\n let newMatrix = new Matrix(newRows, newColumns);\n for (let row = 0; row < newRows; row++) {\n for (let column = 0; column < newColumns; column++) {\n newMatrix.set(row, column, newData[row * newColumns + column]);\n }\n }\n return newMatrix;\n }\n\n static rowVector(newData) {\n let vector = new Matrix(1, newData.length);\n for (let i = 0; i < newData.length; i++) {\n vector.set(0, i, newData[i]);\n }\n return vector;\n }\n\n static columnVector(newData) {\n let vector = new Matrix(newData.length, 1);\n for (let i = 0; i < newData.length; i++) {\n vector.set(i, 0, newData[i]);\n }\n return vector;\n }\n\n static zeros(rows, columns) {\n return new Matrix(rows, columns);\n }\n\n static ones(rows, columns) {\n return new Matrix(rows, columns).fill(1);\n }\n\n static rand(rows, columns, options = {}) {\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { random = Math.random } = options;\n let matrix = new Matrix(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n matrix.set(i, j, random());\n }\n }\n return matrix;\n }\n\n static randInt(rows, columns, options = {}) {\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { min = 0, max = 1000, random = Math.random } = options;\n if (!Number.isInteger(min)) throw new TypeError('min must be an integer');\n if (!Number.isInteger(max)) throw new TypeError('max must be an integer');\n if (min >= max) throw new RangeError('min must be smaller than max');\n let interval = max - min;\n let matrix = new Matrix(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n let value = min + Math.round(random() * interval);\n matrix.set(i, j, value);\n }\n }\n return matrix;\n }\n\n static eye(rows, columns, value) {\n if (columns === undefined) columns = rows;\n if (value === undefined) value = 1;\n let min = Math.min(rows, columns);\n let matrix = this.zeros(rows, columns);\n for (let i = 0; i < min; i++) {\n matrix.set(i, i, value);\n }\n return matrix;\n }\n\n static diag(data, rows, columns) {\n let l = data.length;\n if (rows === undefined) rows = l;\n if (columns === undefined) columns = rows;\n let min = Math.min(l, rows, columns);\n let matrix = this.zeros(rows, columns);\n for (let i = 0; i < min; i++) {\n matrix.set(i, i, data[i]);\n }\n return matrix;\n }\n\n static min(matrix1, matrix2) {\n matrix1 = this.checkMatrix(matrix1);\n matrix2 = this.checkMatrix(matrix2);\n let rows = matrix1.rows;\n let columns = matrix1.columns;\n let result = new Matrix(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n result.set(i, j, Math.min(matrix1.get(i, j), matrix2.get(i, j)));\n }\n }\n return result;\n }\n\n static max(matrix1, matrix2) {\n matrix1 = this.checkMatrix(matrix1);\n matrix2 = this.checkMatrix(matrix2);\n let rows = matrix1.rows;\n let columns = matrix1.columns;\n let result = new this(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n result.set(i, j, Math.max(matrix1.get(i, j), matrix2.get(i, j)));\n }\n }\n return result;\n }\n\n static checkMatrix(value) {\n return AbstractMatrix.isMatrix(value) ? value : new Matrix(value);\n }\n\n static isMatrix(value) {\n return value != null && value.klass === 'Matrix';\n }\n\n get size() {\n return this.rows * this.columns;\n }\n\n apply(callback) {\n if (typeof callback !== 'function') {\n throw new TypeError('callback must be a function');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n callback.call(this, i, j);\n }\n }\n return this;\n }\n\n to1DArray() {\n let array = [];\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n array.push(this.get(i, j));\n }\n }\n return array;\n }\n\n to2DArray() {\n let copy = [];\n for (let i = 0; i < this.rows; i++) {\n copy.push([]);\n for (let j = 0; j < this.columns; j++) {\n copy[i].push(this.get(i, j));\n }\n }\n return copy;\n }\n\n toJSON() {\n return this.to2DArray();\n }\n\n isRowVector() {\n return this.rows === 1;\n }\n\n isColumnVector() {\n return this.columns === 1;\n }\n\n isVector() {\n return this.rows === 1 || this.columns === 1;\n }\n\n isSquare() {\n return this.rows === this.columns;\n }\n\n isSymmetric() {\n if (this.isSquare()) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j <= i; j++) {\n if (this.get(i, j) !== this.get(j, i)) {\n return false;\n }\n }\n }\n return true;\n }\n return false;\n }\n\n isEchelonForm() {\n let i = 0;\n let j = 0;\n let previousColumn = -1;\n let isEchelonForm = true;\n let checked = false;\n while (i < this.rows && isEchelonForm) {\n j = 0;\n checked = false;\n while (j < this.columns && checked === false) {\n if (this.get(i, j) === 0) {\n j++;\n } else if (this.get(i, j) === 1 && j > previousColumn) {\n checked = true;\n previousColumn = j;\n } else {\n isEchelonForm = false;\n checked = true;\n }\n }\n i++;\n }\n return isEchelonForm;\n }\n\n isReducedEchelonForm() {\n let i = 0;\n let j = 0;\n let previousColumn = -1;\n let isReducedEchelonForm = true;\n let checked = false;\n while (i < this.rows && isReducedEchelonForm) {\n j = 0;\n checked = false;\n while (j < this.columns && checked === false) {\n if (this.get(i, j) === 0) {\n j++;\n } else if (this.get(i, j) === 1 && j > previousColumn) {\n checked = true;\n previousColumn = j;\n } else {\n isReducedEchelonForm = false;\n checked = true;\n }\n }\n for (let k = j + 1; k < this.rows; k++) {\n if (this.get(i, k) !== 0) {\n isReducedEchelonForm = false;\n }\n }\n i++;\n }\n return isReducedEchelonForm;\n }\n\n echelonForm() {\n let result = this.clone();\n let h = 0;\n let k = 0;\n while (h < result.rows && k < result.columns) {\n let iMax = h;\n for (let i = h; i < result.rows; i++) {\n if (result.get(i, k) > result.get(iMax, k)) {\n iMax = i;\n }\n }\n if (result.get(iMax, k) === 0) {\n k++;\n } else {\n result.swapRows(h, iMax);\n let tmp = result.get(h, k);\n for (let j = k; j < result.columns; j++) {\n result.set(h, j, result.get(h, j) / tmp);\n }\n for (let i = h + 1; i < result.rows; i++) {\n let factor = result.get(i, k) / result.get(h, k);\n result.set(i, k, 0);\n for (let j = k + 1; j < result.columns; j++) {\n result.set(i, j, result.get(i, j) - result.get(h, j) * factor);\n }\n }\n h++;\n k++;\n }\n }\n return result;\n }\n\n reducedEchelonForm() {\n let result = this.echelonForm();\n let m = result.columns;\n let n = result.rows;\n let h = n - 1;\n while (h >= 0) {\n if (result.maxRow(h) === 0) {\n h--;\n } else {\n let p = 0;\n let pivot = false;\n while (p < n && pivot === false) {\n if (result.get(h, p) === 1) {\n pivot = true;\n } else {\n p++;\n }\n }\n for (let i = 0; i < h; i++) {\n let factor = result.get(i, p);\n for (let j = p; j < m; j++) {\n let tmp = result.get(i, j) - factor * result.get(h, j);\n result.set(i, j, tmp);\n }\n }\n h--;\n }\n }\n return result;\n }\n\n set() {\n throw new Error('set method is unimplemented');\n }\n\n get() {\n throw new Error('get method is unimplemented');\n }\n\n repeat(options = {}) {\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { rows = 1, columns = 1 } = options;\n if (!Number.isInteger(rows) || rows <= 0) {\n throw new TypeError('rows must be a positive integer');\n }\n if (!Number.isInteger(columns) || columns <= 0) {\n throw new TypeError('columns must be a positive integer');\n }\n let matrix = new Matrix(this.rows * rows, this.columns * columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n matrix.setSubMatrix(this, this.rows * i, this.columns * j);\n }\n }\n return matrix;\n }\n\n fill(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, value);\n }\n }\n return this;\n }\n\n neg() {\n return this.mulS(-1);\n }\n\n getRow(index) {\n checkRowIndex(this, index);\n let row = [];\n for (let i = 0; i < this.columns; i++) {\n row.push(this.get(index, i));\n }\n return row;\n }\n\n getRowVector(index) {\n return Matrix.rowVector(this.getRow(index));\n }\n\n setRow(index, array) {\n checkRowIndex(this, index);\n array = checkRowVector(this, array);\n for (let i = 0; i < this.columns; i++) {\n this.set(index, i, array[i]);\n }\n return this;\n }\n\n swapRows(row1, row2) {\n checkRowIndex(this, row1);\n checkRowIndex(this, row2);\n for (let i = 0; i < this.columns; i++) {\n let temp = this.get(row1, i);\n this.set(row1, i, this.get(row2, i));\n this.set(row2, i, temp);\n }\n return this;\n }\n\n getColumn(index) {\n checkColumnIndex(this, index);\n let column = [];\n for (let i = 0; i < this.rows; i++) {\n column.push(this.get(i, index));\n }\n return column;\n }\n\n getColumnVector(index) {\n return Matrix.columnVector(this.getColumn(index));\n }\n\n setColumn(index, array) {\n checkColumnIndex(this, index);\n array = checkColumnVector(this, array);\n for (let i = 0; i < this.rows; i++) {\n this.set(i, index, array[i]);\n }\n return this;\n }\n\n swapColumns(column1, column2) {\n checkColumnIndex(this, column1);\n checkColumnIndex(this, column2);\n for (let i = 0; i < this.rows; i++) {\n let temp = this.get(i, column1);\n this.set(i, column1, this.get(i, column2));\n this.set(i, column2, temp);\n }\n return this;\n }\n\n addRowVector(vector) {\n vector = checkRowVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) + vector[j]);\n }\n }\n return this;\n }\n\n subRowVector(vector) {\n vector = checkRowVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) - vector[j]);\n }\n }\n return this;\n }\n\n mulRowVector(vector) {\n vector = checkRowVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) * vector[j]);\n }\n }\n return this;\n }\n\n divRowVector(vector) {\n vector = checkRowVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) / vector[j]);\n }\n }\n return this;\n }\n\n addColumnVector(vector) {\n vector = checkColumnVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) + vector[i]);\n }\n }\n return this;\n }\n\n subColumnVector(vector) {\n vector = checkColumnVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) - vector[i]);\n }\n }\n return this;\n }\n\n mulColumnVector(vector) {\n vector = checkColumnVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) * vector[i]);\n }\n }\n return this;\n }\n\n divColumnVector(vector) {\n vector = checkColumnVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) / vector[i]);\n }\n }\n return this;\n }\n\n mulRow(index, value) {\n checkRowIndex(this, index);\n for (let i = 0; i < this.columns; i++) {\n this.set(index, i, this.get(index, i) * value);\n }\n return this;\n }\n\n mulColumn(index, value) {\n checkColumnIndex(this, index);\n for (let i = 0; i < this.rows; i++) {\n this.set(i, index, this.get(i, index) * value);\n }\n return this;\n }\n\n max() {\n let v = this.get(0, 0);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n if (this.get(i, j) > v) {\n v = this.get(i, j);\n }\n }\n }\n return v;\n }\n\n maxIndex() {\n let v = this.get(0, 0);\n let idx = [0, 0];\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n if (this.get(i, j) > v) {\n v = this.get(i, j);\n idx[0] = i;\n idx[1] = j;\n }\n }\n }\n return idx;\n }\n\n min() {\n let v = this.get(0, 0);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n if (this.get(i, j) < v) {\n v = this.get(i, j);\n }\n }\n }\n return v;\n }\n\n minIndex() {\n let v = this.get(0, 0);\n let idx = [0, 0];\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n if (this.get(i, j) < v) {\n v = this.get(i, j);\n idx[0] = i;\n idx[1] = j;\n }\n }\n }\n return idx;\n }\n\n maxRow(row) {\n checkRowIndex(this, row);\n let v = this.get(row, 0);\n for (let i = 1; i < this.columns; i++) {\n if (this.get(row, i) > v) {\n v = this.get(row, i);\n }\n }\n return v;\n }\n\n maxRowIndex(row) {\n checkRowIndex(this, row);\n let v = this.get(row, 0);\n let idx = [row, 0];\n for (let i = 1; i < this.columns; i++) {\n if (this.get(row, i) > v) {\n v = this.get(row, i);\n idx[1] = i;\n }\n }\n return idx;\n }\n\n minRow(row) {\n checkRowIndex(this, row);\n let v = this.get(row, 0);\n for (let i = 1; i < this.columns; i++) {\n if (this.get(row, i) < v) {\n v = this.get(row, i);\n }\n }\n return v;\n }\n\n minRowIndex(row) {\n checkRowIndex(this, row);\n let v = this.get(row, 0);\n let idx = [row, 0];\n for (let i = 1; i < this.columns; i++) {\n if (this.get(row, i) < v) {\n v = this.get(row, i);\n idx[1] = i;\n }\n }\n return idx;\n }\n\n maxColumn(column) {\n checkColumnIndex(this, column);\n let v = this.get(0, column);\n for (let i = 1; i < this.rows; i++) {\n if (this.get(i, column) > v) {\n v = this.get(i, column);\n }\n }\n return v;\n }\n\n maxColumnIndex(column) {\n checkColumnIndex(this, column);\n let v = this.get(0, column);\n let idx = [0, column];\n for (let i = 1; i < this.rows; i++) {\n if (this.get(i, column) > v) {\n v = this.get(i, column);\n idx[0] = i;\n }\n }\n return idx;\n }\n\n minColumn(column) {\n checkColumnIndex(this, column);\n let v = this.get(0, column);\n for (let i = 1; i < this.rows; i++) {\n if (this.get(i, column) < v) {\n v = this.get(i, column);\n }\n }\n return v;\n }\n\n minColumnIndex(column) {\n checkColumnIndex(this, column);\n let v = this.get(0, column);\n let idx = [0, column];\n for (let i = 1; i < this.rows; i++) {\n if (this.get(i, column) < v) {\n v = this.get(i, column);\n idx[0] = i;\n }\n }\n return idx;\n }\n\n diag() {\n let min = Math.min(this.rows, this.columns);\n let diag = [];\n for (let i = 0; i < min; i++) {\n diag.push(this.get(i, i));\n }\n return diag;\n }\n\n norm(type = 'frobenius') {\n let result = 0;\n if (type === 'max') {\n return this.max();\n } else if (type === 'frobenius') {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n result = result + this.get(i, j) * this.get(i, j);\n }\n }\n return Math.sqrt(result);\n } else {\n throw new RangeError(`unknown norm type: ${type}`);\n }\n }\n\n cumulativeSum() {\n let sum = 0;\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n sum += this.get(i, j);\n this.set(i, j, sum);\n }\n }\n return this;\n }\n\n dot(vector2) {\n if (AbstractMatrix.isMatrix(vector2)) vector2 = vector2.to1DArray();\n let vector1 = this.to1DArray();\n if (vector1.length !== vector2.length) {\n throw new RangeError('vectors do not have the same size');\n }\n let dot = 0;\n for (let i = 0; i < vector1.length; i++) {\n dot += vector1[i] * vector2[i];\n }\n return dot;\n }\n\n mmul(other) {\n other = Matrix.checkMatrix(other);\n\n let m = this.rows;\n let n = this.columns;\n let p = other.columns;\n\n let result = new Matrix(m, p);\n\n let Bcolj = new Float64Array(n);\n for (let j = 0; j < p; j++) {\n for (let k = 0; k < n; k++) {\n Bcolj[k] = other.get(k, j);\n }\n\n for (let i = 0; i < m; i++) {\n let s = 0;\n for (let k = 0; k < n; k++) {\n s += this.get(i, k) * Bcolj[k];\n }\n\n result.set(i, j, s);\n }\n }\n return result;\n }\n\n strassen2x2(other) {\n other = Matrix.checkMatrix(other);\n let result = new Matrix(2, 2);\n const a11 = this.get(0, 0);\n const b11 = other.get(0, 0);\n const a12 = this.get(0, 1);\n const b12 = other.get(0, 1);\n const a21 = this.get(1, 0);\n const b21 = other.get(1, 0);\n const a22 = this.get(1, 1);\n const b22 = other.get(1, 1);\n\n // Compute intermediate values.\n const m1 = (a11 + a22) * (b11 + b22);\n const m2 = (a21 + a22) * b11;\n const m3 = a11 * (b12 - b22);\n const m4 = a22 * (b21 - b11);\n const m5 = (a11 + a12) * b22;\n const m6 = (a21 - a11) * (b11 + b12);\n const m7 = (a12 - a22) * (b21 + b22);\n\n // Combine intermediate values into the output.\n const c00 = m1 + m4 - m5 + m7;\n const c01 = m3 + m5;\n const c10 = m2 + m4;\n const c11 = m1 - m2 + m3 + m6;\n\n result.set(0, 0, c00);\n result.set(0, 1, c01);\n result.set(1, 0, c10);\n result.set(1, 1, c11);\n return result;\n }\n\n strassen3x3(other) {\n other = Matrix.checkMatrix(other);\n let result = new Matrix(3, 3);\n\n const a00 = this.get(0, 0);\n const a01 = this.get(0, 1);\n const a02 = this.get(0, 2);\n const a10 = this.get(1, 0);\n const a11 = this.get(1, 1);\n const a12 = this.get(1, 2);\n const a20 = this.get(2, 0);\n const a21 = this.get(2, 1);\n const a22 = this.get(2, 2);\n\n const b00 = other.get(0, 0);\n const b01 = other.get(0, 1);\n const b02 = other.get(0, 2);\n const b10 = other.get(1, 0);\n const b11 = other.get(1, 1);\n const b12 = other.get(1, 2);\n const b20 = other.get(2, 0);\n const b21 = other.get(2, 1);\n const b22 = other.get(2, 2);\n\n const m1 = (a00 + a01 + a02 - a10 - a11 - a21 - a22) * b11;\n const m2 = (a00 - a10) * (-b01 + b11);\n const m3 = a11 * (-b00 + b01 + b10 - b11 - b12 - b20 + b22);\n const m4 = (-a00 + a10 + a11) * (b00 - b01 + b11);\n const m5 = (a10 + a11) * (-b00 + b01);\n const m6 = a00 * b00;\n const m7 = (-a00 + a20 + a21) * (b00 - b02 + b12);\n const m8 = (-a00 + a20) * (b02 - b12);\n const m9 = (a20 + a21) * (-b00 + b02);\n const m10 = (a00 + a01 + a02 - a11 - a12 - a20 - a21) * b12;\n const m11 = a21 * (-b00 + b02 + b10 - b11 - b12 - b20 + b21);\n const m12 = (-a02 + a21 + a22) * (b11 + b20 - b21);\n const m13 = (a02 - a22) * (b11 - b21);\n const m14 = a02 * b20;\n const m15 = (a21 + a22) * (-b20 + b21);\n const m16 = (-a02 + a11 + a12) * (b12 + b20 - b22);\n const m17 = (a02 - a12) * (b12 - b22);\n const m18 = (a11 + a12) * (-b20 + b22);\n const m19 = a01 * b10;\n const m20 = a12 * b21;\n const m21 = a10 * b02;\n const m22 = a20 * b01;\n const m23 = a22 * b22;\n\n const c00 = m6 + m14 + m19;\n const c01 = m1 + m4 + m5 + m6 + m12 + m14 + m15;\n const c02 = m6 + m7 + m9 + m10 + m14 + m16 + m18;\n const c10 = m2 + m3 + m4 + m6 + m14 + m16 + m17;\n const c11 = m2 + m4 + m5 + m6 + m20;\n const c12 = m14 + m16 + m17 + m18 + m21;\n const c20 = m6 + m7 + m8 + m11 + m12 + m13 + m14;\n const c21 = m12 + m13 + m14 + m15 + m22;\n const c22 = m6 + m7 + m8 + m9 + m23;\n\n result.set(0, 0, c00);\n result.set(0, 1, c01);\n result.set(0, 2, c02);\n result.set(1, 0, c10);\n result.set(1, 1, c11);\n result.set(1, 2, c12);\n result.set(2, 0, c20);\n result.set(2, 1, c21);\n result.set(2, 2, c22);\n return result;\n }\n\n mmulStrassen(y) {\n y = Matrix.checkMatrix(y);\n let x = this.clone();\n let r1 = x.rows;\n let c1 = x.columns;\n let r2 = y.rows;\n let c2 = y.columns;\n if (c1 !== r2) {\n // eslint-disable-next-line no-console\n console.warn(\n `Multiplying ${r1} x ${c1} and ${r2} x ${c2} matrix: dimensions do not match.`,\n );\n }\n\n // Put a matrix into the top left of a matrix of zeros.\n // `rows` and `cols` are the dimensions of the output matrix.\n function embed(mat, rows, cols) {\n let r = mat.rows;\n let c = mat.columns;\n if (r === rows && c === cols) {\n return mat;\n } else {\n let resultat = AbstractMatrix.zeros(rows, cols);\n resultat = resultat.setSubMatrix(mat, 0, 0);\n return resultat;\n }\n }\n\n // Make sure both matrices are the same size.\n // This is exclusively for simplicity:\n // this algorithm can be implemented with matrices of different sizes.\n\n let r = Math.max(r1, r2);\n let c = Math.max(c1, c2);\n x = embed(x, r, c);\n y = embed(y, r, c);\n\n // Our recursive multiplication function.\n function blockMult(a, b, rows, cols) {\n // For small matrices, resort to naive multiplication.\n if (rows <= 512 || cols <= 512) {\n return a.mmul(b); // a is equivalent to this\n }\n\n // Apply dynamic padding.\n if (rows % 2 === 1 && cols % 2 === 1) {\n a = embed(a, rows + 1, cols + 1);\n b = embed(b, rows + 1, cols + 1);\n } else if (rows % 2 === 1) {\n a = embed(a, rows + 1, cols);\n b = embed(b, rows + 1, cols);\n } else if (cols % 2 === 1) {\n a = embed(a, rows, cols + 1);\n b = embed(b, rows, cols + 1);\n }\n\n let halfRows = parseInt(a.rows / 2, 10);\n let halfCols = parseInt(a.columns / 2, 10);\n // Subdivide input matrices.\n let a11 = a.subMatrix(0, halfRows - 1, 0, halfCols - 1);\n let b11 = b.subMatrix(0, halfRows - 1, 0, halfCols - 1);\n\n let a12 = a.subMatrix(0, halfRows - 1, halfCols, a.columns - 1);\n let b12 = b.subMatrix(0, halfRows - 1, halfCols, b.columns - 1);\n\n let a21 = a.subMatrix(halfRows, a.rows - 1, 0, halfCols - 1);\n let b21 = b.subMatrix(halfRows, b.rows - 1, 0, halfCols - 1);\n\n let a22 = a.subMatrix(halfRows, a.rows - 1, halfCols, a.columns - 1);\n let b22 = b.subMatrix(halfRows, b.rows - 1, halfCols, b.columns - 1);\n\n // Compute intermediate values.\n let m1 = blockMult(\n AbstractMatrix.add(a11, a22),\n AbstractMatrix.add(b11, b22),\n halfRows,\n halfCols,\n );\n let m2 = blockMult(AbstractMatrix.add(a21, a22), b11, halfRows, halfCols);\n let m3 = blockMult(a11, AbstractMatrix.sub(b12, b22), halfRows, halfCols);\n let m4 = blockMult(a22, AbstractMatrix.sub(b21, b11), halfRows, halfCols);\n let m5 = blockMult(AbstractMatrix.add(a11, a12), b22, halfRows, halfCols);\n let m6 = blockMult(\n AbstractMatrix.sub(a21, a11),\n AbstractMatrix.add(b11, b12),\n halfRows,\n halfCols,\n );\n let m7 = blockMult(\n AbstractMatrix.sub(a12, a22),\n AbstractMatrix.add(b21, b22),\n halfRows,\n halfCols,\n );\n\n // Combine intermediate values into the output.\n let c11 = AbstractMatrix.add(m1, m4);\n c11.sub(m5);\n c11.add(m7);\n let c12 = AbstractMatrix.add(m3, m5);\n let c21 = AbstractMatrix.add(m2, m4);\n let c22 = AbstractMatrix.sub(m1, m2);\n c22.add(m3);\n c22.add(m6);\n\n // Crop output to the desired size (undo dynamic padding).\n let resultat = AbstractMatrix.zeros(2 * c11.rows, 2 * c11.columns);\n resultat = resultat.setSubMatrix(c11, 0, 0);\n resultat = resultat.setSubMatrix(c12, c11.rows, 0);\n resultat = resultat.setSubMatrix(c21, 0, c11.columns);\n resultat = resultat.setSubMatrix(c22, c11.rows, c11.columns);\n return resultat.subMatrix(0, rows - 1, 0, cols - 1);\n }\n return blockMult(x, y, r, c);\n }\n\n scaleRows(options = {}) {\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { min = 0, max = 1 } = options;\n if (!Number.isFinite(min)) throw new TypeError('min must be a number');\n if (!Number.isFinite(max)) throw new TypeError('max must be a number');\n if (min >= max) throw new RangeError('min must be smaller than max');\n let newMatrix = new Matrix(this.rows, this.columns);\n for (let i = 0; i < this.rows; i++) {\n const row = this.getRow(i);\n rescale(row, { min, max, output: row });\n newMatrix.setRow(i, row);\n }\n return newMatrix;\n }\n\n scaleColumns(options = {}) {\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { min = 0, max = 1 } = options;\n if (!Number.isFinite(min)) throw new TypeError('min must be a number');\n if (!Number.isFinite(max)) throw new TypeError('max must be a number');\n if (min >= max) throw new RangeError('min must be smaller than max');\n let newMatrix = new Matrix(this.rows, this.columns);\n for (let i = 0; i < this.columns; i++) {\n const column = this.getColumn(i);\n rescale(column, {\n min: min,\n max: max,\n output: column,\n });\n newMatrix.setColumn(i, column);\n }\n return newMatrix;\n }\n\n flipRows() {\n const middle = Math.ceil(this.columns / 2);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < middle; j++) {\n let first = this.get(i, j);\n let last = this.get(i, this.columns - 1 - j);\n this.set(i, j, last);\n this.set(i, this.columns - 1 - j, first);\n }\n }\n return this;\n }\n\n flipColumns() {\n const middle = Math.ceil(this.rows / 2);\n for (let j = 0; j < this.columns; j++) {\n for (let i = 0; i < middle; i++) {\n let first = this.get(i, j);\n let last = this.get(this.rows - 1 - i, j);\n this.set(i, j, last);\n this.set(this.rows - 1 - i, j, first);\n }\n }\n return this;\n }\n\n kroneckerProduct(other) {\n other = Matrix.checkMatrix(other);\n\n let m = this.rows;\n let n = this.columns;\n let p = other.rows;\n let q = other.columns;\n\n let result = new Matrix(m * p, n * q);\n for (let i = 0; i < m; i++) {\n for (let j = 0; j < n; j++) {\n for (let k = 0; k < p; k++) {\n for (let l = 0; l < q; l++) {\n result.set(p * i + k, q * j + l, this.get(i, j) * other.get(k, l));\n }\n }\n }\n }\n return result;\n }\n\n transpose() {\n let result = new Matrix(this.columns, this.rows);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n result.set(j, i, this.get(i, j));\n }\n }\n return result;\n }\n\n sortRows(compareFunction = compareNumbers) {\n for (let i = 0; i < this.rows; i++) {\n this.setRow(i, this.getRow(i).sort(compareFunction));\n }\n return this;\n }\n\n sortColumns(compareFunction = compareNumbers) {\n for (let i = 0; i < this.columns; i++) {\n this.setColumn(i, this.getColumn(i).sort(compareFunction));\n }\n return this;\n }\n\n subMatrix(startRow, endRow, startColumn, endColumn) {\n checkRange(this, startRow, endRow, startColumn, endColumn);\n let newMatrix = new Matrix(\n endRow - startRow + 1,\n endColumn - startColumn + 1,\n );\n for (let i = startRow; i <= endRow; i++) {\n for (let j = startColumn; j <= endColumn; j++) {\n newMatrix.set(i - startRow, j - startColumn, this.get(i, j));\n }\n }\n return newMatrix;\n }\n\n subMatrixRow(indices, startColumn, endColumn) {\n if (startColumn === undefined) startColumn = 0;\n if (endColumn === undefined) endColumn = this.columns - 1;\n if (\n startColumn > endColumn ||\n startColumn < 0 ||\n startColumn >= this.columns ||\n endColumn < 0 ||\n endColumn >= this.columns\n ) {\n throw new RangeError('Argument out of range');\n }\n\n let newMatrix = new Matrix(indices.length, endColumn - startColumn + 1);\n for (let i = 0; i < indices.length; i++) {\n for (let j = startColumn; j <= endColumn; j++) {\n if (indices[i] < 0 || indices[i] >= this.rows) {\n throw new RangeError(`Row index out of range: ${indices[i]}`);\n }\n newMatrix.set(i, j - startColumn, this.get(indices[i], j));\n }\n }\n return newMatrix;\n }\n\n subMatrixColumn(indices, startRow, endRow) {\n if (startRow === undefined) startRow = 0;\n if (endRow === undefined) endRow = this.rows - 1;\n if (\n startRow > endRow ||\n startRow < 0 ||\n startRow >= this.rows ||\n endRow < 0 ||\n endRow >= this.rows\n ) {\n throw new RangeError('Argument out of range');\n }\n\n let newMatrix = new Matrix(endRow - startRow + 1, indices.length);\n for (let i = 0; i < indices.length; i++) {\n for (let j = startRow; j <= endRow; j++) {\n if (indices[i] < 0 || indices[i] >= this.columns) {\n throw new RangeError(`Column index out of range: ${indices[i]}`);\n }\n newMatrix.set(j - startRow, i, this.get(j, indices[i]));\n }\n }\n return newMatrix;\n }\n\n setSubMatrix(matrix, startRow, startColumn) {\n matrix = Matrix.checkMatrix(matrix);\n let endRow = startRow + matrix.rows - 1;\n let endColumn = startColumn + matrix.columns - 1;\n checkRange(this, startRow, endRow, startColumn, endColumn);\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n this.set(startRow + i, startColumn + j, matrix.get(i, j));\n }\n }\n return this;\n }\n\n selection(rowIndices, columnIndices) {\n let indices = checkIndices(this, rowIndices, columnIndices);\n let newMatrix = new Matrix(rowIndices.length, columnIndices.length);\n for (let i = 0; i < indices.row.length; i++) {\n let rowIndex = indices.row[i];\n for (let j = 0; j < indices.column.length; j++) {\n let columnIndex = indices.column[j];\n newMatrix.set(i, j, this.get(rowIndex, columnIndex));\n }\n }\n return newMatrix;\n }\n\n trace() {\n let min = Math.min(this.rows, this.columns);\n let trace = 0;\n for (let i = 0; i < min; i++) {\n trace += this.get(i, i);\n }\n return trace;\n }\n\n clone() {\n let newMatrix = new Matrix(this.rows, this.columns);\n for (let row = 0; row < this.rows; row++) {\n for (let column = 0; column < this.columns; column++) {\n newMatrix.set(row, column, this.get(row, column));\n }\n }\n return newMatrix;\n }\n\n sum(by) {\n switch (by) {\n case 'row':\n return sumByRow(this);\n case 'column':\n return sumByColumn(this);\n case undefined:\n return sumAll(this);\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n product(by) {\n switch (by) {\n case 'row':\n return productByRow(this);\n case 'column':\n return productByColumn(this);\n case undefined:\n return productAll(this);\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n mean(by) {\n const sum = this.sum(by);\n switch (by) {\n case 'row': {\n for (let i = 0; i < this.rows; i++) {\n sum[i] /= this.columns;\n }\n return sum;\n }\n case 'column': {\n for (let i = 0; i < this.columns; i++) {\n sum[i] /= this.rows;\n }\n return sum;\n }\n case undefined:\n return sum / this.size;\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n variance(by, options = {}) {\n if (typeof by === 'object') {\n options = by;\n by = undefined;\n }\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { unbiased = true, mean = this.mean(by) } = options;\n if (typeof unbiased !== 'boolean') {\n throw new TypeError('unbiased must be a boolean');\n }\n switch (by) {\n case 'row': {\n if (!Array.isArray(mean)) {\n throw new TypeError('mean must be an array');\n }\n return varianceByRow(this, unbiased, mean);\n }\n case 'column': {\n if (!Array.isArray(mean)) {\n throw new TypeError('mean must be an array');\n }\n return varianceByColumn(this, unbiased, mean);\n }\n case undefined: {\n if (typeof mean !== 'number') {\n throw new TypeError('mean must be a number');\n }\n return varianceAll(this, unbiased, mean);\n }\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n standardDeviation(by, options) {\n if (typeof by === 'object') {\n options = by;\n by = undefined;\n }\n const variance = this.variance(by, options);\n if (by === undefined) {\n return Math.sqrt(variance);\n } else {\n for (let i = 0; i < variance.length; i++) {\n variance[i] = Math.sqrt(variance[i]);\n }\n return variance;\n }\n }\n\n center(by, options = {}) {\n if (typeof by === 'object') {\n options = by;\n by = undefined;\n }\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { center = this.mean(by) } = options;\n switch (by) {\n case 'row': {\n if (!Array.isArray(center)) {\n throw new TypeError('center must be an array');\n }\n centerByRow(this, center);\n return this;\n }\n case 'column': {\n if (!Array.isArray(center)) {\n throw new TypeError('center must be an array');\n }\n centerByColumn(this, center);\n return this;\n }\n case undefined: {\n if (typeof center !== 'number') {\n throw new TypeError('center must be a number');\n }\n centerAll(this, center);\n return this;\n }\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n scale(by, options = {}) {\n if (typeof by === 'object') {\n options = by;\n by = undefined;\n }\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n let scale = options.scale;\n switch (by) {\n case 'row': {\n if (scale === undefined) {\n scale = getScaleByRow(this);\n } else if (!Array.isArray(scale)) {\n throw new TypeError('scale must be an array');\n }\n scaleByRow(this, scale);\n return this;\n }\n case 'column': {\n if (scale === undefined) {\n scale = getScaleByColumn(this);\n } else if (!Array.isArray(scale)) {\n throw new TypeError('scale must be an array');\n }\n scaleByColumn(this, scale);\n return this;\n }\n case undefined: {\n if (scale === undefined) {\n scale = getScaleAll(this);\n } else if (typeof scale !== 'number') {\n throw new TypeError('scale must be a number');\n }\n scaleAll(this, scale);\n return this;\n }\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n toString(options) {\n return inspectMatrixWithOptions(this, options);\n }\n}\n\nAbstractMatrix.prototype.klass = 'Matrix';\nif (typeof Symbol !== 'undefined') {\n AbstractMatrix.prototype[\n Symbol.for('nodejs.util.inspect.custom')\n ] = inspectMatrix;\n}\n\nfunction compareNumbers(a, b) {\n return a - b;\n}\n\n// Synonyms\nAbstractMatrix.random = AbstractMatrix.rand;\nAbstractMatrix.randomInt = AbstractMatrix.randInt;\nAbstractMatrix.diagonal = AbstractMatrix.diag;\nAbstractMatrix.prototype.diagonal = AbstractMatrix.prototype.diag;\nAbstractMatrix.identity = AbstractMatrix.eye;\nAbstractMatrix.prototype.negate = AbstractMatrix.prototype.neg;\nAbstractMatrix.prototype.tensorProduct =\n AbstractMatrix.prototype.kroneckerProduct;\n\nexport default class Matrix extends AbstractMatrix {\n constructor(nRows, nColumns) {\n super();\n if (Matrix.isMatrix(nRows)) {\n return nRows.clone();\n } else if (Number.isInteger(nRows) && nRows > 0) {\n // Create an empty matrix\n this.data = [];\n if (Number.isInteger(nColumns) && nColumns > 0) {\n for (let i = 0; i < nRows; i++) {\n this.data.push(new Float64Array(nColumns));\n }\n } else {\n throw new TypeError('nColumns must be a positive integer');\n }\n } else if (Array.isArray(nRows)) {\n // Copy the values from the 2D array\n const arrayData = nRows;\n nRows = arrayData.length;\n nColumns = arrayData[0].length;\n if (typeof nColumns !== 'number' || nColumns === 0) {\n throw new TypeError(\n 'Data must be a 2D array with at least one element',\n );\n }\n this.data = [];\n for (let i = 0; i < nRows; i++) {\n if (arrayData[i].length !== nColumns) {\n throw new RangeError('Inconsistent array dimensions');\n }\n this.data.push(Float64Array.from(arrayData[i]));\n }\n } else {\n throw new TypeError(\n 'First argument must be a positive number or an array',\n );\n }\n this.rows = nRows;\n this.columns = nColumns;\n return this;\n }\n\n set(rowIndex, columnIndex, value) {\n this.data[rowIndex][columnIndex] = value;\n return this;\n }\n\n get(rowIndex, columnIndex) {\n return this.data[rowIndex][columnIndex];\n }\n\n removeRow(index) {\n checkRowIndex(this, index);\n if (this.rows === 1) {\n throw new RangeError('A matrix cannot have less than one row');\n }\n this.data.splice(index, 1);\n this.rows -= 1;\n return this;\n }\n\n addRow(index, array) {\n if (array === undefined) {\n array = index;\n index = this.rows;\n }\n checkRowIndex(this, index, true);\n array = Float64Array.from(checkRowVector(this, array, true));\n this.data.splice(index, 0, array);\n this.rows += 1;\n return this;\n }\n\n removeColumn(index) {\n checkColumnIndex(this, index);\n if (this.columns === 1) {\n throw new RangeError('A matrix cannot have less than one column');\n }\n for (let i = 0; i < this.rows; i++) {\n const newRow = new Float64Array(this.columns - 1);\n for (let j = 0; j < index; j++) {\n newRow[j] = this.data[i][j];\n }\n for (let j = index + 1; j < this.columns; j++) {\n newRow[j - 1] = this.data[i][j];\n }\n this.data[i] = newRow;\n }\n this.columns -= 1;\n return this;\n }\n\n addColumn(index, array) {\n if (typeof array === 'undefined') {\n array = index;\n index = this.columns;\n }\n checkColumnIndex(this, index, true);\n array = checkColumnVector(this, array);\n for (let i = 0; i < this.rows; i++) {\n const newRow = new Float64Array(this.columns + 1);\n let j = 0;\n for (; j < index; j++) {\n newRow[j] = this.data[i][j];\n }\n newRow[j++] = array[i];\n for (; j < this.columns + 1; j++) {\n newRow[j] = this.data[i][j - 1];\n }\n this.data[i] = newRow;\n }\n this.columns += 1;\n return this;\n }\n}\n\ninstallMathOperations(AbstractMatrix, Matrix);\n","import { AbstractMatrix } from '../matrix';\n\nexport default class WrapperMatrix2D extends AbstractMatrix {\n constructor(data) {\n super();\n this.data = data;\n this.rows = data.length;\n this.columns = data[0].length;\n }\n\n set(rowIndex, columnIndex, value) {\n this.data[rowIndex][columnIndex] = value;\n return this;\n }\n\n get(rowIndex, columnIndex) {\n return this.data[rowIndex][columnIndex];\n }\n}\n","import Matrix from '../matrix';\nimport WrapperMatrix2D from '../wrap/WrapperMatrix2D';\n\nexport default class LuDecomposition {\n constructor(matrix) {\n matrix = WrapperMatrix2D.checkMatrix(matrix);\n\n let lu = matrix.clone();\n let rows = lu.rows;\n let columns = lu.columns;\n let pivotVector = new Float64Array(rows);\n let pivotSign = 1;\n let i, j, k, p, s, t, v;\n let LUcolj, kmax;\n\n for (i = 0; i < rows; i++) {\n pivotVector[i] = i;\n }\n\n LUcolj = new Float64Array(rows);\n\n for (j = 0; j < columns; j++) {\n for (i = 0; i < rows; i++) {\n LUcolj[i] = lu.get(i, j);\n }\n\n for (i = 0; i < rows; i++) {\n kmax = Math.min(i, j);\n s = 0;\n for (k = 0; k < kmax; k++) {\n s += lu.get(i, k) * LUcolj[k];\n }\n LUcolj[i] -= s;\n lu.set(i, j, LUcolj[i]);\n }\n\n p = j;\n for (i = j + 1; i < rows; i++) {\n if (Math.abs(LUcolj[i]) > Math.abs(LUcolj[p])) {\n p = i;\n }\n }\n\n if (p !== j) {\n for (k = 0; k < columns; k++) {\n t = lu.get(p, k);\n lu.set(p, k, lu.get(j, k));\n lu.set(j, k, t);\n }\n\n v = pivotVector[p];\n pivotVector[p] = pivotVector[j];\n pivotVector[j] = v;\n\n pivotSign = -pivotSign;\n }\n\n if (j < rows && lu.get(j, j) !== 0) {\n for (i = j + 1; i < rows; i++) {\n lu.set(i, j, lu.get(i, j) / lu.get(j, j));\n }\n }\n }\n\n this.LU = lu;\n this.pivotVector = pivotVector;\n this.pivotSign = pivotSign;\n }\n\n isSingular() {\n let data = this.LU;\n let col = data.columns;\n for (let j = 0; j < col; j++) {\n if (data.get(j, j) === 0) {\n return true;\n }\n }\n return false;\n }\n\n solve(value) {\n value = Matrix.checkMatrix(value);\n\n let lu = this.LU;\n let rows = lu.rows;\n\n if (rows !== value.rows) {\n throw new Error('Invalid matrix dimensions');\n }\n if (this.isSingular()) {\n throw new Error('LU matrix is singular');\n }\n\n let count = value.columns;\n let X = value.subMatrixRow(this.pivotVector, 0, count - 1);\n let columns = lu.columns;\n let i, j, k;\n\n for (k = 0; k < columns; k++) {\n for (i = k + 1; i < columns; i++) {\n for (j = 0; j < count; j++) {\n X.set(i, j, X.get(i, j) - X.get(k, j) * lu.get(i, k));\n }\n }\n }\n for (k = columns - 1; k >= 0; k--) {\n for (j = 0; j < count; j++) {\n X.set(k, j, X.get(k, j) / lu.get(k, k));\n }\n for (i = 0; i < k; i++) {\n for (j = 0; j < count; j++) {\n X.set(i, j, X.get(i, j) - X.get(k, j) * lu.get(i, k));\n }\n }\n }\n return X;\n }\n\n get determinant() {\n let data = this.LU;\n if (!data.isSquare()) {\n throw new Error('Matrix must be square');\n }\n let determinant = this.pivotSign;\n let col = data.columns;\n for (let j = 0; j < col; j++) {\n determinant *= data.get(j, j);\n }\n return determinant;\n }\n\n get lowerTriangularMatrix() {\n let data = this.LU;\n let rows = data.rows;\n let columns = data.columns;\n let X = new Matrix(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n if (i > j) {\n X.set(i, j, data.get(i, j));\n } else if (i === j) {\n X.set(i, j, 1);\n } else {\n X.set(i, j, 0);\n }\n }\n }\n return X;\n }\n\n get upperTriangularMatrix() {\n let data = this.LU;\n let rows = data.rows;\n let columns = data.columns;\n let X = new Matrix(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n if (i <= j) {\n X.set(i, j, data.get(i, j));\n } else {\n X.set(i, j, 0);\n }\n }\n }\n return X;\n }\n\n get pivotPermutationVector() {\n return Array.from(this.pivotVector);\n }\n}\n","export function hypotenuse(a, b) {\n let r = 0;\n if (Math.abs(a) > Math.abs(b)) {\n r = b / a;\n return Math.abs(a) * Math.sqrt(1 + r * r);\n }\n if (b !== 0) {\n r = a / b;\n return Math.abs(b) * Math.sqrt(1 + r * r);\n }\n return 0;\n}\n","import Matrix from '../matrix';\nimport WrapperMatrix2D from '../wrap/WrapperMatrix2D';\n\nimport { hypotenuse } from './util';\n\nexport default class QrDecomposition {\n constructor(value) {\n value = WrapperMatrix2D.checkMatrix(value);\n\n let qr = value.clone();\n let m = value.rows;\n let n = value.columns;\n let rdiag = new Float64Array(n);\n let i, j, k, s;\n\n for (k = 0; k < n; k++) {\n let nrm = 0;\n for (i = k; i < m; i++) {\n nrm = hypotenuse(nrm, qr.get(i, k));\n }\n if (nrm !== 0) {\n if (qr.get(k, k) < 0) {\n nrm = -nrm;\n }\n for (i = k; i < m; i++) {\n qr.set(i, k, qr.get(i, k) / nrm);\n }\n qr.set(k, k, qr.get(k, k) + 1);\n for (j = k + 1; j < n; j++) {\n s = 0;\n for (i = k; i < m; i++) {\n s += qr.get(i, k) * qr.get(i, j);\n }\n s = -s / qr.get(k, k);\n for (i = k; i < m; i++) {\n qr.set(i, j, qr.get(i, j) + s * qr.get(i, k));\n }\n }\n }\n rdiag[k] = -nrm;\n }\n\n this.QR = qr;\n this.Rdiag = rdiag;\n }\n\n solve(value) {\n value = Matrix.checkMatrix(value);\n\n let qr = this.QR;\n let m = qr.rows;\n\n if (value.rows !== m) {\n throw new Error('Matrix row dimensions must agree');\n }\n if (!this.isFullRank()) {\n throw new Error('Matrix is rank deficient');\n }\n\n let count = value.columns;\n let X = value.clone();\n let n = qr.columns;\n let i, j, k, s;\n\n for (k = 0; k < n; k++) {\n for (j = 0; j < count; j++) {\n s = 0;\n for (i = k; i < m; i++) {\n s += qr.get(i, k) * X.get(i, j);\n }\n s = -s / qr.get(k, k);\n for (i = k; i < m; i++) {\n X.set(i, j, X.get(i, j) + s * qr.get(i, k));\n }\n }\n }\n for (k = n - 1; k >= 0; k--) {\n for (j = 0; j < count; j++) {\n X.set(k, j, X.get(k, j) / this.Rdiag[k]);\n }\n for (i = 0; i < k; i++) {\n for (j = 0; j < count; j++) {\n X.set(i, j, X.get(i, j) - X.get(k, j) * qr.get(i, k));\n }\n }\n }\n\n return X.subMatrix(0, n - 1, 0, count - 1);\n }\n\n isFullRank() {\n let columns = this.QR.columns;\n for (let i = 0; i < columns; i++) {\n if (this.Rdiag[i] === 0) {\n return false;\n }\n }\n return true;\n }\n\n get upperTriangularMatrix() {\n let qr = this.QR;\n let n = qr.columns;\n let X = new Matrix(n, n);\n let i, j;\n for (i = 0; i < n; i++) {\n for (j = 0; j < n; j++) {\n if (i < j) {\n X.set(i, j, qr.get(i, j));\n } else if (i === j) {\n X.set(i, j, this.Rdiag[i]);\n } else {\n X.set(i, j, 0);\n }\n }\n }\n return X;\n }\n\n get orthogonalMatrix() {\n let qr = this.QR;\n let rows = qr.rows;\n let columns = qr.columns;\n let X = new Matrix(rows, columns);\n let i, j, k, s;\n\n for (k = columns - 1; k >= 0; k--) {\n for (i = 0; i < rows; i++) {\n X.set(i, k, 0);\n }\n X.set(k, k, 1);\n for (j = k; j < columns; j++) {\n if (qr.get(k, k) !== 0) {\n s = 0;\n for (i = k; i < rows; i++) {\n s += qr.get(i, k) * X.get(i, j);\n }\n\n s = -s / qr.get(k, k);\n\n for (i = k; i < rows; i++) {\n X.set(i, j, X.get(i, j) + s * qr.get(i, k));\n }\n }\n }\n }\n return X;\n }\n}\n","import Matrix from '../matrix';\nimport WrapperMatrix2D from '../wrap/WrapperMatrix2D';\n\nimport { hypotenuse } from './util';\n\nexport default class SingularValueDecomposition {\n constructor(value, options = {}) {\n value = WrapperMatrix2D.checkMatrix(value);\n\n let m = value.rows;\n let n = value.columns;\n\n const {\n computeLeftSingularVectors = true,\n computeRightSingularVectors = true,\n autoTranspose = false,\n } = options;\n\n let wantu = Boolean(computeLeftSingularVectors);\n let wantv = Boolean(computeRightSingularVectors);\n\n let swapped = false;\n let a;\n if (m < n) {\n if (!autoTranspose) {\n a = value.clone();\n // eslint-disable-next-line no-console\n console.warn(\n 'Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose',\n );\n } else {\n a = value.transpose();\n m = a.rows;\n n = a.columns;\n swapped = true;\n let aux = wantu;\n wantu = wantv;\n wantv = aux;\n }\n } else {\n a = value.clone();\n }\n\n let nu = Math.min(m, n);\n let ni = Math.min(m + 1, n);\n let s = new Float64Array(ni);\n let U = new Matrix(m, nu);\n let V = new Matrix(n, n);\n\n let e = new Float64Array(n);\n let work = new Float64Array(m);\n\n let si = new Float64Array(ni);\n for (let i = 0; i < ni; i++) si[i] = i;\n\n let nct = Math.min(m - 1, n);\n let nrt = Math.max(0, Math.min(n - 2, m));\n let mrc = Math.max(nct, nrt);\n\n for (let k = 0; k < mrc; k++) {\n if (k < nct) {\n s[k] = 0;\n for (let i = k; i < m; i++) {\n s[k] = hypotenuse(s[k], a.get(i, k));\n }\n if (s[k] !== 0) {\n if (a.get(k, k) < 0) {\n s[k] = -s[k];\n }\n for (let i = k; i < m; i++) {\n a.set(i, k, a.get(i, k) / s[k]);\n }\n a.set(k, k, a.get(k, k) + 1);\n }\n s[k] = -s[k];\n }\n\n for (let j = k + 1; j < n; j++) {\n if (k < nct && s[k] !== 0) {\n let t = 0;\n for (let i = k; i < m; i++) {\n t += a.get(i, k) * a.get(i, j);\n }\n t = -t / a.get(k, k);\n for (let i = k; i < m; i++) {\n a.set(i, j, a.get(i, j) + t * a.get(i, k));\n }\n }\n e[j] = a.get(k, j);\n }\n\n if (wantu && k < nct) {\n for (let i = k; i < m; i++) {\n U.set(i, k, a.get(i, k));\n }\n }\n\n if (k < nrt) {\n e[k] = 0;\n for (let i = k + 1; i < n; i++) {\n e[k] = hypotenuse(e[k], e[i]);\n }\n if (e[k] !== 0) {\n if (e[k + 1] < 0) {\n e[k] = 0 - e[k];\n }\n for (let i = k + 1; i < n; i++) {\n e[i] /= e[k];\n }\n e[k + 1] += 1;\n }\n e[k] = -e[k];\n if (k + 1 < m && e[k] !== 0) {\n for (let i = k + 1; i < m; i++) {\n work[i] = 0;\n }\n for (let i = k + 1; i < m; i++) {\n for (let j = k + 1; j < n; j++) {\n work[i] += e[j] * a.get(i, j);\n }\n }\n for (let j = k + 1; j < n; j++) {\n let t = -e[j] / e[k + 1];\n for (let i = k + 1; i < m; i++) {\n a.set(i, j, a.get(i, j) + t * work[i]);\n }\n }\n }\n if (wantv) {\n for (let i = k + 1; i < n; i++) {\n V.set(i, k, e[i]);\n }\n }\n }\n }\n\n let p = Math.min(n, m + 1);\n if (nct < n) {\n s[nct] = a.get(nct, nct);\n }\n if (m < p) {\n s[p - 1] = 0;\n }\n if (nrt + 1 < p) {\n e[nrt] = a.get(nrt, p - 1);\n }\n e[p - 1] = 0;\n\n if (wantu) {\n for (let j = nct; j < nu; j++) {\n for (let i = 0; i < m; i++) {\n U.set(i, j, 0);\n }\n U.set(j, j, 1);\n }\n for (let k = nct - 1; k >= 0; k--) {\n if (s[k] !== 0) {\n for (let j = k + 1; j < nu; j++) {\n let t = 0;\n for (let i = k; i < m; i++) {\n t += U.get(i, k) * U.get(i, j);\n }\n t = -t / U.get(k, k);\n for (let i = k; i < m; i++) {\n U.set(i, j, U.get(i, j) + t * U.get(i, k));\n }\n }\n for (let i = k; i < m; i++) {\n U.set(i, k, -U.get(i, k));\n }\n U.set(k, k, 1 + U.get(k, k));\n for (let i = 0; i < k - 1; i++) {\n U.set(i, k, 0);\n }\n } else {\n for (let i = 0; i < m; i++) {\n U.set(i, k, 0);\n }\n U.set(k, k, 1);\n }\n }\n }\n\n if (wantv) {\n for (let k = n - 1; k >= 0; k--) {\n if (k < nrt && e[k] !== 0) {\n for (let j = k + 1; j < n; j++) {\n let t = 0;\n for (let i = k + 1; i < n; i++) {\n t += V.get(i, k) * V.get(i, j);\n }\n t = -t / V.get(k + 1, k);\n for (let i = k + 1; i < n; i++) {\n V.set(i, j, V.get(i, j) + t * V.get(i, k));\n }\n }\n }\n for (let i = 0; i < n; i++) {\n V.set(i, k, 0);\n }\n V.set(k, k, 1);\n }\n }\n\n let pp = p - 1;\n let iter = 0;\n let eps = Number.EPSILON;\n while (p > 0) {\n let k, kase;\n for (k = p - 2; k >= -1; k--) {\n if (k === -1) {\n break;\n }\n const alpha =\n Number.MIN_VALUE + eps * Math.abs(s[k] + Math.abs(s[k + 1]));\n if (Math.abs(e[k]) <= alpha || Number.isNaN(e[k])) {\n e[k] = 0;\n break;\n }\n }\n if (k === p - 2) {\n kase = 4;\n } else {\n let ks;\n for (ks = p - 1; ks >= k; ks--) {\n if (ks === k) {\n break;\n }\n let t =\n (ks !== p ? Math.abs(e[ks]) : 0) +\n (ks !== k + 1 ? Math.abs(e[ks - 1]) : 0);\n if (Math.abs(s[ks]) <= eps * t) {\n s[ks] = 0;\n break;\n }\n }\n if (ks === k) {\n kase = 3;\n } else if (ks === p - 1) {\n kase = 1;\n } else {\n kase = 2;\n k = ks;\n }\n }\n\n k++;\n\n switch (kase) {\n case 1: {\n let f = e[p - 2];\n e[p - 2] = 0;\n for (let j = p - 2; j >= k; j--) {\n let t = hypotenuse(s[j], f);\n let cs = s[j] / t;\n let sn = f / t;\n s[j] = t;\n if (j !== k) {\n f = -sn * e[j - 1];\n e[j - 1] = cs * e[j - 1];\n }\n if (wantv) {\n for (let i = 0; i < n; i++) {\n t = cs * V.get(i, j) + sn * V.get(i, p - 1);\n V.set(i, p - 1, -sn * V.get(i, j) + cs * V.get(i, p - 1));\n V.set(i, j, t);\n }\n }\n }\n break;\n }\n case 2: {\n let f = e[k - 1];\n e[k - 1] = 0;\n for (let j = k; j < p; j++) {\n let t = hypotenuse(s[j], f);\n let cs = s[j] / t;\n let sn = f / t;\n s[j] = t;\n f = -sn * e[j];\n e[j] = cs * e[j];\n if (wantu) {\n for (let i = 0; i < m; i++) {\n t = cs * U.get(i, j) + sn * U.get(i, k - 1);\n U.set(i, k - 1, -sn * U.get(i, j) + cs * U.get(i, k - 1));\n U.set(i, j, t);\n }\n }\n }\n break;\n }\n case 3: {\n const scale = Math.max(\n Math.abs(s[p - 1]),\n Math.abs(s[p - 2]),\n Math.abs(e[p - 2]),\n Math.abs(s[k]),\n Math.abs(e[k]),\n );\n const sp = s[p - 1] / scale;\n const spm1 = s[p - 2] / scale;\n const epm1 = e[p - 2] / scale;\n const sk = s[k] / scale;\n const ek = e[k] / scale;\n const b = ((spm1 + sp) * (spm1 - sp) + epm1 * epm1) / 2;\n const c = sp * epm1 * (sp * epm1);\n let shift = 0;\n if (b !== 0 || c !== 0) {\n if (b < 0) {\n shift = 0 - Math.sqrt(b * b + c);\n } else {\n shift = Math.sqrt(b * b + c);\n }\n shift = c / (b + shift);\n }\n let f = (sk + sp) * (sk - sp) + shift;\n let g = sk * ek;\n for (let j = k; j < p - 1; j++) {\n let t = hypotenuse(f, g);\n if (t === 0) t = Number.MIN_VALUE;\n let cs = f / t;\n let sn = g / t;\n if (j !== k) {\n e[j - 1] = t;\n }\n f = cs * s[j] + sn * e[j];\n e[j] = cs * e[j] - sn * s[j];\n g = sn * s[j + 1];\n s[j + 1] = cs * s[j + 1];\n if (wantv) {\n for (let i = 0; i < n; i++) {\n t = cs * V.get(i, j) + sn * V.get(i, j + 1);\n V.set(i, j + 1, -sn * V.get(i, j) + cs * V.get(i, j + 1));\n V.set(i, j, t);\n }\n }\n t = hypotenuse(f, g);\n if (t === 0) t = Number.MIN_VALUE;\n cs = f / t;\n sn = g / t;\n s[j] = t;\n f = cs * e[j] + sn * s[j + 1];\n s[j + 1] = -sn * e[j] + cs * s[j + 1];\n g = sn * e[j + 1];\n e[j + 1] = cs * e[j + 1];\n if (wantu && j < m - 1) {\n for (let i = 0; i < m; i++) {\n t = cs * U.get(i, j) + sn * U.get(i, j + 1);\n U.set(i, j + 1, -sn * U.get(i, j) + cs * U.get(i, j + 1));\n U.set(i, j, t);\n }\n }\n }\n e[p - 2] = f;\n iter = iter + 1;\n break;\n }\n case 4: {\n if (s[k] <= 0) {\n s[k] = s[k] < 0 ? -s[k] : 0;\n if (wantv) {\n for (let i = 0; i <= pp; i++) {\n V.set(i, k, -V.get(i, k));\n }\n }\n }\n while (k < pp) {\n if (s[k] >= s[k + 1]) {\n break;\n }\n let t = s[k];\n s[k] = s[k + 1];\n s[k + 1] = t;\n if (wantv && k < n - 1) {\n for (let i = 0; i < n; i++) {\n t = V.get(i, k + 1);\n V.set(i, k + 1, V.get(i, k));\n V.set(i, k, t);\n }\n }\n if (wantu && k < m - 1) {\n for (let i = 0; i < m; i++) {\n t = U.get(i, k + 1);\n U.set(i, k + 1, U.get(i, k));\n U.set(i, k, t);\n }\n }\n k++;\n }\n iter = 0;\n p--;\n break;\n }\n // no default\n }\n }\n\n if (swapped) {\n let tmp = V;\n V = U;\n U = tmp;\n }\n\n this.m = m;\n this.n = n;\n this.s = s;\n this.U = U;\n this.V = V;\n }\n\n solve(value) {\n let Y = value;\n let e = this.threshold;\n let scols = this.s.length;\n let Ls = Matrix.zeros(scols, scols);\n\n for (let i = 0; i < scols; i++) {\n if (Math.abs(this.s[i]) <= e) {\n Ls.set(i, i, 0);\n } else {\n Ls.set(i, i, 1 / this.s[i]);\n }\n }\n\n let U = this.U;\n let V = this.rightSingularVectors;\n\n let VL = V.mmul(Ls);\n let vrows = V.rows;\n let urows = U.rows;\n let VLU = Matrix.zeros(vrows, urows);\n\n for (let i = 0; i < vrows; i++) {\n for (let j = 0; j < urows; j++) {\n let sum = 0;\n for (let k = 0; k < scols; k++) {\n sum += VL.get(i, k) * U.get(j, k);\n }\n VLU.set(i, j, sum);\n }\n }\n\n return VLU.mmul(Y);\n }\n\n solveForDiagonal(value) {\n return this.solve(Matrix.diag(value));\n }\n\n inverse() {\n let V = this.V;\n let e = this.threshold;\n let vrows = V.rows;\n let vcols = V.columns;\n let X = new Matrix(vrows, this.s.length);\n\n for (let i = 0; i < vrows; i++) {\n for (let j = 0; j < vcols; j++) {\n if (Math.abs(this.s[j]) > e) {\n X.set(i, j, V.get(i, j) / this.s[j]);\n }\n }\n }\n\n let U = this.U;\n\n let urows = U.rows;\n let ucols = U.columns;\n let Y = new Matrix(vrows, urows);\n\n for (let i = 0; i < vrows; i++) {\n for (let j = 0; j < urows; j++) {\n let sum = 0;\n for (let k = 0; k < ucols; k++) {\n sum += X.get(i, k) * U.get(j, k);\n }\n Y.set(i, j, sum);\n }\n }\n\n return Y;\n }\n\n get condition() {\n return this.s[0] / this.s[Math.min(this.m, this.n) - 1];\n }\n\n get norm2() {\n return this.s[0];\n }\n\n get rank() {\n let tol = Math.max(this.m, this.n) * this.s[0] * Number.EPSILON;\n let r = 0;\n let s = this.s;\n for (let i = 0, ii = s.length; i < ii; i++) {\n if (s[i] > tol) {\n r++;\n }\n }\n return r;\n }\n\n get diagonal() {\n return Array.from(this.s);\n }\n\n get threshold() {\n return (Number.EPSILON / 2) * Math.max(this.m, this.n) * this.s[0];\n }\n\n get leftSingularVectors() {\n return this.U;\n }\n\n get rightSingularVectors() {\n return this.V;\n }\n\n get diagonalMatrix() {\n return Matrix.diag(this.s);\n }\n}\n","import LuDecomposition from './dc/lu';\nimport QrDecomposition from './dc/qr';\nimport SingularValueDecomposition from './dc/svd';\nimport Matrix from './matrix';\nimport WrapperMatrix2D from './wrap/WrapperMatrix2D';\n\nexport function inverse(matrix, useSVD = false) {\n matrix = WrapperMatrix2D.checkMatrix(matrix);\n if (useSVD) {\n return new SingularValueDecomposition(matrix).inverse();\n } else {\n return solve(matrix, Matrix.eye(matrix.rows));\n }\n}\n\nexport function solve(leftHandSide, rightHandSide, useSVD = false) {\n leftHandSide = WrapperMatrix2D.checkMatrix(leftHandSide);\n rightHandSide = WrapperMatrix2D.checkMatrix(rightHandSide);\n if (useSVD) {\n return new SingularValueDecomposition(leftHandSide).solve(rightHandSide);\n } else {\n return leftHandSide.isSquare()\n ? new LuDecomposition(leftHandSide).solve(rightHandSide)\n : new QrDecomposition(leftHandSide).solve(rightHandSide);\n }\n}\n","import { inverse, Matrix } from 'ml-matrix';\n\n/**\n * Difference of the matrix function over the parameters\n * @ignore\n * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]\n * @param {Array} evaluatedData - Array of previous evaluated function values\n * @param {Array} params - Array of previous parameter values\n * @param {number} gradientDifference - Adjustment for decrease the damping parameter\n * @param {function} paramFunction - The parameters and returns a function with the independent variable as a parameter\n * @return {Matrix}\n */\nfunction gradientFunction(\n data,\n evaluatedData,\n params,\n gradientDifference,\n paramFunction,\n) {\n const n = params.length;\n const m = data.x.length;\n\n let ans = new Array(n);\n\n for (let param = 0; param < n; param++) {\n ans[param] = new Array(m);\n let auxParams = params.slice();\n auxParams[param] += gradientDifference;\n let funcParam = paramFunction(auxParams);\n\n for (let point = 0; point < m; point++) {\n ans[param][point] = evaluatedData[point] - funcParam(data.x[point]);\n }\n }\n return new Matrix(ans);\n}\n\n/**\n * Matrix function over the samples\n * @ignore\n * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]\n * @param {Array} evaluatedData - Array of previous evaluated function values\n * @return {Matrix}\n */\nfunction matrixFunction(data, evaluatedData) {\n const m = data.x.length;\n\n let ans = new Array(m);\n\n for (let point = 0; point < m; point++) {\n ans[point] = [data.y[point] - evaluatedData[point]];\n }\n\n return new Matrix(ans);\n}\n\n/**\n * Iteration for Levenberg-Marquardt\n * @ignore\n * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]\n * @param {Array} params - Array of previous parameter values\n * @param {number} damping - Levenberg-Marquardt parameter\n * @param {number} gradientDifference - Adjustment for decrease the damping parameter\n * @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter\n * @return {Array}\n */\nexport default function step(\n data,\n params,\n damping,\n gradientDifference,\n parameterizedFunction,\n) {\n let value = damping * gradientDifference * gradientDifference;\n let identity = Matrix.eye(params.length, params.length, value);\n\n const func = parameterizedFunction(params);\n\n let evaluatedData = new Float64Array(data.x.length);\n for (let i = 0; i < data.x.length; i++) {\n evaluatedData[i] = func(data.x[i]);\n }\n\n let gradientFunc = gradientFunction(\n data,\n evaluatedData,\n params,\n gradientDifference,\n parameterizedFunction,\n );\n let matrixFunc = matrixFunction(data, evaluatedData);\n let inverseMatrix = inverse(\n identity.add(gradientFunc.mmul(gradientFunc.transpose())),\n );\n\n params = new Matrix([params]);\n params = params.sub(\n inverseMatrix\n .mmul(gradientFunc)\n .mmul(matrixFunc)\n .mul(gradientDifference)\n .transpose(),\n );\n\n return params.to1DArray();\n}\n","import isArray from 'is-any-array';\n\nimport errorCalculation from './errorCalculation';\nimport step from './step';\n\n/**\n * Curve fitting algorithm\n * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]\n * @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter\n * @param {object} [options] - Options object\n * @param {number} [options.damping] - Levenberg-Marquardt parameter\n * @param {number} [options.gradientDifference = 10e-2] - Adjustment for decrease the damping parameter\n * @param {Array} [options.minValues] - Minimum allowed values for parameters\n * @param {Array} [options.maxValues] - Maximum allowed values for parameters\n * @param {Array} [options.initialValues] - Array of initial parameter values\n * @param {number} [options.maxIterations = 100] - Maximum of allowed iterations\n * @param {number} [options.errorTolerance = 10e-3] - Minimum uncertainty allowed for each point\n * @return {{parameterValues: Array, parameterError: number, iterations: number}}\n */\nexport default function levenbergMarquardt(\n data,\n parameterizedFunction,\n options = {},\n) {\n let {\n maxIterations = 100,\n gradientDifference = 10e-2,\n damping = 0,\n errorTolerance = 10e-3,\n minValues,\n maxValues,\n initialValues,\n } = options;\n\n if (damping <= 0) {\n throw new Error('The damping option must be a positive number');\n } else if (!data.x || !data.y) {\n throw new Error('The data parameter must have x and y elements');\n } else if (\n !isArray(data.x) ||\n data.x.length < 2 ||\n !isArray(data.y) ||\n data.y.length < 2\n ) {\n throw new Error(\n 'The data parameter elements must be an array with more than 2 points',\n );\n } else if (data.x.length !== data.y.length) {\n throw new Error('The data parameter elements must have the same size');\n }\n\n let parameters =\n initialValues || new Array(parameterizedFunction.length).fill(1);\n let parLen = parameters.length;\n maxValues = maxValues || new Array(parLen).fill(Number.MAX_SAFE_INTEGER);\n minValues = minValues || new Array(parLen).fill(Number.MIN_SAFE_INTEGER);\n\n if (maxValues.length !== minValues.length) {\n throw new Error('minValues and maxValues must be the same size');\n }\n\n if (!isArray(parameters)) {\n throw new Error('initialValues must be an array');\n }\n\n let error = errorCalculation(data, parameters, parameterizedFunction);\n\n let converged = error <= errorTolerance;\n\n let iteration;\n for (iteration = 0; iteration < maxIterations && !converged; iteration++) {\n parameters = step(\n data,\n parameters,\n damping,\n gradientDifference,\n parameterizedFunction,\n );\n\n for (let k = 0; k < parLen; k++) {\n parameters[k] = Math.min(\n Math.max(minValues[k], parameters[k]),\n maxValues[k],\n );\n }\n\n error = errorCalculation(data, parameters, parameterizedFunction);\n if (isNaN(error)) break;\n converged = error <= errorTolerance;\n }\n\n return {\n parameterValues: parameters,\n parameterError: error,\n iterations: iteration,\n };\n}\n","/**\n * This function calculates the spectrum as a sum of gaussian functions. The Gaussian\n * parameters are divided in 3 batches. 1st: centers; 2nd: height; 3th: std's;\n * @param t Ordinate values\n * @param p Gaussian parameters\n * @param c Constant parameters(Not used)\n * @returns {*}\n */\nexport function sumOfGaussians(p) {\n return function (t) {\n let nL = p.length / 3;\n let factor;\n let rows = t.length;\n let result = rows === undefined ? 0 : new Float64Array(rows).fill(0);\n for (let i = 0; i < nL; i++) {\n factor = Math.pow(p[i + nL * 2], 2) * 2;\n if (rows === undefined) {\n result += p[i + nL] * Math.exp(-Math.pow(t - p[i], 2) / factor);\n } else {\n for (let j = 0; j < rows; j++) {\n result[j] += p[i + nL] * Math.exp(-Math.pow(t[j] - p[i], 2) / factor);\n }\n }\n }\n return result;\n };\n}\n","import LM from 'ml-levenberg-marquardt';\n\nimport { sumOfGaussians } from './sumOfGaussians';\n\n/**\n *\n * @param xy A two column matrix containing the x and y data to be fitted\n * @param group A set of initial lorentzian parameters to be optimized [center, heigth, half_width_at_half_height]\n * @returns {Array} A set of final lorentzian parameters [center, heigth, hwhh*2]\n */\nexport function optimizeGaussianSum(xy, group, opts = {}) {\n let t = xy[0];\n let yData = xy[1];\n let maxY = Math.max(...yData);\n yData.forEach((x, i, arr) => (arr[i] /= maxY));\n let nL = group.length;\n let pInit = new Float64Array(nL * 3);\n let pMin = new Float64Array(nL * 3);\n let pMax = new Float64Array(nL * 3);\n let dt = Math.abs(t[0] - t[1]);\n\n for (let i = 0; i < nL; i++) {\n pInit[i] = group[i].x;\n pInit[i + nL] = group[i].y / maxY;\n pInit[i + 2 * nL] = group[i].width;\n\n pMin[i] = group[i].x - dt;\n pMin[i + nL] = 0;\n pMin[i + 2 * nL] = group[i].width / 4;\n\n pMax[i] = group[i].x + dt;\n pMax[i + nL] = (group[i].y * 1.2) / maxY;\n pMax[i + 2 * nL] = group[i].width * 4;\n }\n\n let data = {\n x: t,\n y: yData,\n };\n let result = new Array(nL);\n\n let lmOptions = {\n damping: 1.5,\n initialValues: pInit,\n minValues: pMin,\n maxValues: pMax,\n gradientDifference: dt / 10000,\n maxIterations: 100,\n errorTolerance: 10e-5,\n };\n\n opts = Object.assign({}, lmOptions, opts);\n\n let pFit = LM(data, sumOfGaussians, opts);\n for (let i = 0; i < nL; i++) {\n result[i] = {\n parameters: [\n pFit.parameterValues[i],\n pFit.parameterValues[i + nL] * maxY,\n pFit.parameterValues[i + nL * 2],\n ],\n error: pFit.parameterError,\n };\n }\n return result;\n}\n","/**\n * Single 3 parameter gaussian function\n * @param t Ordinate values\n * @param p Gaussian parameters [mean, height, std]\n * @param c Constant parameters(Not used)\n * @returns {*}\n */\n\nexport function singleGaussian(p) {\n return function (t) {\n let factor2 = (p[2] * p[2]) / 2;\n let rows = t.length;\n if (!rows) return p[1] * Math.exp((-(t - p[0]) * (t - p[0])) / factor2);\n let result = new Float64Array(t.length);\n for (let i = 0; i < t.length; i++) {\n result[i] = p[1] * Math.exp((-(t[i] - p[0]) * (t[i] - p[0])) / factor2);\n }\n return result;\n };\n}\n","import LM from 'ml-levenberg-marquardt';\n\nimport { singleGaussian } from './singleGaussian';\n\n/**\n * Fits a set of points to a gaussian bell. Returns the mean of the peak, the std and the height of the signal.\n * @param data,[y]\n * @returns {*[]}\n */\nexport function optimizeSingleGaussian(xy, peak, opts = {}) {\n let t = xy[0];\n let yData = xy[1];\n let maxY = Math.max(...yData);\n yData.forEach((x, i, arr) => (arr[i] /= maxY));\n let dt = Math.abs(t[0] - t[1]);\n let pInit = new Float64Array([peak.x, 1, peak.width]);\n let pMin = new Float64Array([peak.x - dt, 0, peak.width / 4]);\n let pMax = new Float64Array([peak.x + dt, 1.25, peak.width * 4]);\n\n let data = {\n x: t,\n y: yData,\n };\n\n let lmOptions = {\n damping: 1.5,\n initialValues: pInit,\n minValues: pMin,\n maxValues: pMax,\n gradientDifference: dt / 10000,\n maxIterations: 100,\n errorTolerance: 10e-5,\n };\n\n opts = Object.assign({}, lmOptions, opts);\n let pFit = LM(data, singleGaussian, opts);\n return {\n parameters: [\n pFit.parameterValues[0],\n pFit.parameterValues[1] * maxY,\n pFit.parameterValues[2],\n ],\n error: pFit.parameterError,\n };\n}\n","/**\n * This function calculates the spectrum as a sum of lorentzian functions. The Lorentzian\n * parameters are divided in 3 batches. 1st: centers; 2nd: heights; 3th: widths;\n * @param t Ordinate values\n * @param p Lorentzian parameters\n * @returns {*}\n */\n\nexport function sumOfLorentzians(p) {\n return function (t) {\n let nL = p.length / 3;\n let factor;\n let p2;\n let rows = t.length;\n let result = rows === undefined ? 0 : new Float64Array(rows).fill(0);\n for (let i = 0; i < nL; i++) {\n p2 = Math.pow(p[i + nL * 2] / 2, 2);\n factor = p[i + nL] * p2;\n if (rows === undefined) {\n result += factor / (Math.pow(t - p[i], 2) + p2);\n } else {\n for (let j = 0; j < rows; j++) {\n result[j] += factor / (Math.pow(t[j] - p[i], 2) + p2);\n }\n }\n }\n return result;\n };\n}\n","import LM from 'ml-levenberg-marquardt';\n\nimport { sumOfLorentzians } from './sumOfLorentzians';\n\n/**\n *\n * @param xy A two column matrix containing the x and y data to be fitted\n * @param group A set of initial lorentzian parameters to be optimized [center, heigth, half_width_at_half_height]\n * @returns {Array} A set of final lorentzian parameters [center, heigth, hwhh*2]\n */\nexport function optimizeLorentzianSum(xy, group, opts = {}) {\n let t = xy[0];\n let yData = xy[1];\n let maxY = Math.max(...yData);\n yData.forEach((x, i, arr) => (arr[i] /= maxY));\n\n let nL = group.length;\n let pInit = new Float64Array(nL * 3);\n let pMin = new Float64Array(nL * 3);\n let pMax = new Float64Array(nL * 3);\n let dt = Math.abs(t[0] - t[1]);\n\n for (let i = 0; i < nL; i++) {\n pInit[i] = group[i].x;\n pInit[i + nL] = 1;\n pInit[i + 2 * nL] = group[i].width;\n\n pMin[i] = group[i].x - dt;\n pMin[i + nL] = 0;\n pMin[i + 2 * nL] = group[i].width / 4;\n\n pMax[i] = group[i].x + dt;\n pMax[i + nL] = 1.5;\n pMax[i + 2 * nL] = group[i].width * 4;\n }\n\n let data = {\n x: t,\n y: yData,\n };\n\n let result = new Array(nL);\n\n let lmOptions = {\n damping: 1.5,\n initialValues: pInit,\n minValues: pMin,\n maxValues: pMax,\n gradientDifference: dt / 10000,\n maxIterations: 100,\n errorTolerance: 10e-5,\n };\n\n opts = Object.assign({}, lmOptions, opts);\n\n let pFit = LM(data, sumOfLorentzians, opts);\n for (let i = 0; i < nL; i++) {\n result[i] = {\n parameters: [\n pFit.parameterValues[i],\n pFit.parameterValues[i + nL] * maxY,\n pFit.parameterValues[i + nL * 2],\n ],\n error: pFit.parameterError,\n };\n }\n return result;\n}\n","/**\n * Single 4 parameter lorentzian function\n * @param t Ordinate values\n * @param p Lorentzian parameters\n * @param c Constant parameters(Not used)\n * @returns {*}\n */\n\nexport function singleLorentzian(p) {\n return function (t) {\n let factor = p[1] * Math.pow(p[2] / 2, 2);\n let rows = t.length;\n if (!rows) return factor / (Math.pow(t - p[0], 2) + Math.pow(p[2] / 2, 2));\n let result = new Float64Array(rows);\n for (let i = 0; i < rows; i++) {\n result[i] = factor / (Math.pow(t[i] - p[0], 2) + Math.pow(p[2] / 2, 2));\n }\n return result;\n };\n}\n","import LM from 'ml-levenberg-marquardt';\n\nimport { singleLorentzian } from './singleLorentzian';\n\n/**\n * * Fits a set of points to a Lorentzian function. Returns the center of the peak, the width at half height, and the height of the signal.\n * @param data,[y]\n * @returns {*[]}\n */\nexport function optimizeSingleLorentzian(xy, peak, opts = {}) {\n let t = xy[0];\n let yData = xy[1];\n let maxY = Math.max(...yData);\n yData.forEach((x, i, arr) => (arr[i] /= maxY));\n let dt = Math.abs(t[0] - t[1]);\n let pInit = new Float64Array([peak.x, 1, peak.width]);\n let pMin = new Float64Array([peak.x - dt, 0.75, peak.width / 4]);\n let pMax = new Float64Array([peak.x + dt, 1.25, peak.width * 4]);\n\n let data = {\n x: t,\n y: yData,\n };\n\n let lmOptions = {\n damping: 1.5,\n initialValues: pInit,\n minValues: pMin,\n maxValues: pMax,\n gradientDifference: dt / 10000,\n maxIterations: 100,\n errorTolerance: 10e-5,\n };\n opts = Object.assign({}, lmOptions, opts);\n let pFit = LM(data, singleLorentzian, opts);\n return {\n parameters: [\n pFit.parameterValues[0],\n pFit.parameterValues[1] * maxY,\n pFit.parameterValues[2],\n ],\n error: pFit.parameterError,\n };\n}\n","import {\n optimizeGaussianSum,\n optimizeLorentzianSum,\n optimizeSingleGaussian,\n optimizeSingleLorentzian,\n} from 'ml-optimize-lorentzian';\n\nexport function optimizePeaks(peakList, x, y, options = {}) {\n const {\n functionName = 'gaussian',\n factorWidth = 4,\n optimizationOptions = {\n damping: 1.5,\n maxIterations: 100,\n errorTolerance: 10e-5,\n },\n } = options;\n\n let lastIndex = [0];\n let groups = groupPeaks(peakList, factorWidth);\n let result = [];\n let factor = 1;\n if (functionName === 'gaussian') {\n factor = 1.17741;\n } // From https://en.wikipedia.org/wiki/Gaussian_function#Properties\n let sampling;\n for (let i = 0; i < groups.length; i++) {\n let peaks = groups[i].group;\n if (peaks.length > 1) {\n // Multiple peaks\n sampling = sampleFunction(\n groups[i].limits[0] - groups[i].limits[1],\n groups[i].limits[0] + groups[i].limits[1],\n x,\n y,\n lastIndex,\n );\n if (sampling[0].length > 5) {\n let optPeaks = [];\n if (functionName === 'gaussian') {\n optPeaks = optimizeGaussianSum(sampling, peaks, optimizationOptions);\n } else {\n if (functionName === 'lorentzian') {\n optPeaks = optimizeLorentzianSum(\n sampling,\n peaks,\n optimizationOptions,\n );\n }\n }\n\n for (let j = 0; j < optPeaks.length; j++) {\n let { parameters } = optPeaks[j];\n result.push({\n x: parameters[0],\n y: parameters[1],\n width: parameters[2] * factor,\n index: peaks[j].index,\n });\n }\n }\n } else {\n // Single peak\n peaks = peaks[0];\n sampling = sampleFunction(\n peaks.x - factorWidth * peaks.width,\n peaks.x + factorWidth * peaks.width,\n x,\n y,\n lastIndex,\n );\n\n if (sampling[0].length > 5) {\n let fitResult = [];\n if (functionName === 'gaussian') {\n fitResult = optimizeSingleGaussian(\n [sampling[0], sampling[1]],\n peaks,\n optimizationOptions,\n );\n } else {\n if (functionName === 'lorentzian') {\n fitResult = optimizeSingleLorentzian(\n [sampling[0], sampling[1]],\n peaks,\n optimizationOptions,\n );\n }\n }\n\n let { parameters } = fitResult;\n result.push({\n x: parameters[0],\n y: parameters[1],\n width: parameters[2] * factor,\n index: peaks.index,\n }); // From https://en.wikipedia.org/wiki/Gaussian_function#Properties}\n }\n }\n }\n return result;\n}\n\nfunction sampleFunction(from, to, x, y, lastIndex) {\n let nbPoints = x.length;\n let sampleX = [];\n let sampleY = [];\n let direction = Math.sign(x[1] - x[0]); // Direction of the derivative\n if (direction === -1) {\n lastIndex[0] = x.length - 1;\n }\n\n let delta = Math.abs(to - from) / 2;\n let mid = (from + to) / 2;\n let stop = false;\n let index = lastIndex[0];\n while (!stop && index < nbPoints && index >= 0) {\n if (Math.abs(x[index] - mid) <= delta) {\n sampleX.push(x[index]);\n sampleY.push(y[index]);\n index += direction;\n } else {\n // It is outside the range.\n if (Math.sign(mid - x[index]) === 1) {\n // We'll reach the mid going in the current direction\n index += direction;\n } else {\n // There is not more peaks in the current range\n stop = true;\n }\n }\n }\n lastIndex[0] = index;\n return [sampleX, sampleY];\n}\n\nfunction groupPeaks(peakList, nL) {\n let group = [];\n let groups = [];\n let limits = [peakList[0].x, nL * peakList[0].width];\n let upperLimit, lowerLimit;\n // Merge forward\n for (let i = 0; i < peakList.length; i++) {\n // If the 2 things overlaps\n if (\n Math.abs(peakList[i].x - limits[0]) <\n nL * peakList[i].width + limits[1]\n ) {\n // Add the peak to the group\n group.push(peakList[i]);\n // Update the group limits\n upperLimit = limits[0] + limits[1];\n if (peakList[i].x + nL * peakList[i].width > upperLimit) {\n upperLimit = peakList[i].x + nL * peakList[i].width;\n }\n lowerLimit = limits[0] - limits[1];\n if (peakList[i].x - nL * peakList[i].width < lowerLimit) {\n lowerLimit = peakList[i].x - nL * peakList[i].width;\n }\n limits = [\n (upperLimit + lowerLimit) / 2,\n Math.abs(upperLimit - lowerLimit) / 2,\n ];\n } else {\n groups.push({ limits: limits, group: group });\n // var optmimalPeak = fitSpectrum(group,limits,spectrum);\n group = [peakList[i]];\n limits = [peakList[i].x, nL * peakList[i].width];\n }\n }\n groups.push({ limits: limits, group: group });\n // Merge backward\n for (let i = groups.length - 2; i >= 0; i--) {\n // The groups overlaps\n if (\n Math.abs(groups[i].limits[0] - groups[i + 1].limits[0]) <\n (groups[i].limits[1] + groups[i + 1].limits[1]) / 2\n ) {\n for (let j = 0; j < groups[i + 1].group.length; j++) {\n groups[i].group.push(groups[i + 1].group[j]);\n }\n upperLimit = groups[i].limits[0] + groups[i].limits[1];\n if (groups[i + 1].limits[0] + groups[i + 1].limits[1] > upperLimit) {\n upperLimit = groups[i + 1].limits[0] + groups[i + 1].limits[1];\n }\n lowerLimit = groups[i].limits[0] - groups[i].limits[1];\n if (groups[i + 1].limits[0] - groups[i + 1].limits[1] < lowerLimit) {\n lowerLimit = groups[i + 1].limits[0] - groups[i + 1].limits[1];\n }\n\n groups[i].limits = [\n (upperLimit + lowerLimit) / 2,\n Math.abs(upperLimit - lowerLimit) / 2,\n ];\n\n groups.splice(i + 1, 1);\n }\n }\n return groups;\n}\n","import { optimizeSingleLorentzian } from 'ml-optimize-lorentzian';\n\n/**\n * This function try to join the peaks that seems to belong to a broad signal in a single broad peak.\n * @param peakList\n * @param options\n */\nexport function joinBroadPeaks(peakList, options = {}) {\n let width = options.width;\n let broadLines = [];\n // Optimize the possible broad lines\n let max = 0;\n\n let maxI = 0;\n\n let count = 1;\n for (let i = peakList.length - 1; i >= 0; i--) {\n if (peakList[i].soft) {\n broadLines.push(peakList.splice(i, 1)[0]);\n }\n }\n // Push a feke peak\n broadLines.push({ x: Number.MAX_VALUE });\n\n let candidates = [[broadLines[0].x, broadLines[0].y]];\n let indexes = [broadLines[0].index];\n\n for (let i = 1; i < broadLines.length; i++) {\n // console.log(broadLines[i-1].x+\" \"+broadLines[i].x);\n if (Math.abs(broadLines[i - 1].x - broadLines[i].x) < width) {\n candidates.push([broadLines[i].x, broadLines[i].y]);\n if (broadLines[i].y > max) {\n max = broadLines[i].y;\n maxI = i;\n }\n indexes.push(broadLines[i].index);\n count++;\n } else {\n if (count > 2) {\n let fitted = optimizeSingleLorentzian(candidates, {\n x: broadLines[maxI].x,\n y: max,\n width: Math.abs(\n candidates[0][0] - candidates[candidates.length - 1][0],\n ),\n });\n let { parameters } = fitted;\n peakList.push({\n x: parameters[0],\n y: parameters[1],\n width: parameters[2],\n index: Math.floor(\n indexes.reduce((a, b) => a + b, 0) / indexes.length,\n ),\n soft: false,\n });\n } else {\n // Put back the candidates to the signals list\n indexes.forEach((index) => {\n peakList.push(broadLines[index]);\n });\n }\n candidates = [[broadLines[i].x, broadLines[i].y]];\n indexes = [i];\n max = broadLines[i].y;\n maxI = i;\n count = 1;\n }\n }\n\n peakList.sort(function (a, b) {\n return a.x - b.x;\n });\n\n return peakList;\n}\n","/**\n * This method will allow to enlarge peaks and prevent overlap between peaks\n * Because peaks may not be symmetric after we add 2 properties, from and to.\n * @param {Array} peakList\n * @param {object} [options={}]\n * @param {number} [factor=2]\n * @param {boolean} [overlap=false] by default we don't allow overlap\n * @return {Array} peakList\n */\nexport function broadenPeaks(peakList, options = {}) {\n const { factor = 2, overlap = false } = options;\n\n for (let peak of peakList) {\n if (!peak.right || !peak.left) {\n peak.from = peak.x - (peak.width / 2) * factor;\n peak.to = peak.x + (peak.width / 2) * factor;\n } else {\n peak.from = peak.x - (peak.x - peak.left.x) * factor;\n peak.to = peak.x + (peak.right.x - peak.x) * factor;\n }\n }\n\n if (!overlap) {\n for (let i = 0; i < peakList.length - 1; i++) {\n let peak = peakList[i];\n let nextPeak = peakList[i + 1];\n if (peak.to > nextPeak.from) {\n peak.to = nextPeak.from = (peak.to + nextPeak.from) / 2;\n }\n }\n }\n\n for (let peak of peakList) {\n peak.width = peak.to - peak.from;\n }\n\n return peakList;\n}\n"],"names":["SavitzkyGolay","data","h","options","windowSize","derivative","polynomial","Number","isInteger","RangeError","length","console","warn","half","Math","floor","np","ans","Array","weights","fullWeights","hs","constantH","isArray","pow","i","wg1","wg2","d1","d2","l","getHs","wg","d","center","count","GramPoly","m","k","s","Grampoly","GenFact","a","b","gf","j","Weight","t","n","sum","gsd","x","yIn","noiseLevel","sgOptions","smoothY","heightFactor","broadRatio","maxCriteria","minMaxRatio","derivativeThreshold","realTopDetection","y","slice","equalSpaced","isEqualSpaced","undefined","getNoiseLevel","yCorrection","Y","dY","ddY","SG","X","dx","maxDdy","maxY","abs","lastMax","lastMin","minddY","intervalL","intervalR","broadMask","minddYLen","intervalLLen","intervalRLen","broadMaskLen","index","signals","signalsLen","lastK","possible","frequency","distanceJ","minDistance","gettingCloser","MAX_VALUE","width","soft","left","right","yLeft","yRight","height","determineRealTop","base","sort","tmp","maxDx","minDx","MAX_SAFE_INTEGER","mean","stddev","averageDeviations","peakList","alpha","beta","gamma","p","currentPoint","log10","toString","Object","prototype","isAnyArray","object","call","endsWith","errorCalculation","parameters","parameterizedFunction","error","func","max","input","TypeError","maxValue","min","minValue","rescale","arguments","output","currentMin","currentMax","_options$min","autoMinMax","_options$max","factor","indent","repeat","indentData","inspectMatrix","inspectMatrixWithOptions","matrix","maxRows","maxColumns","maxNumSize","constructor","name","inspectData","rows","columns","maxI","maxJ","result","line","push","formatNumber","get","join","num","numStr","String","padEnd","precise","toPrecision","exponential","toExponential","eIndex","indexOf","e","installMathOperations","AbstractMatrix","Matrix","add","value","addS","addM","set","checkMatrix","newMatrix","sub","subS","subM","subtract","subtractS","subtractM","mul","mulS","mulM","multiply","multiplyS","multiplyM","div","divS","divM","divide","divideS","divideM","mod","modS","modM","modulus","modulusS","modulusM","and","andS","andM","or","orS","orM","xor","xorS","xorM","leftShift","leftShiftS","leftShiftM","signPropagatingRightShift","signPropagatingRightShiftS","signPropagatingRightShiftM","rightShift","rightShiftS","rightShiftM","zeroFillRightShift","zeroFillRightShiftS","zeroFillRightShiftM","not","acos","acosh","asin","asinh","atan","atanh","cbrt","ceil","clz32","cos","cosh","exp","expm1","fround","log","log1p","log2","round","sign","sin","sinh","sqrt","tan","tanh","trunc","arg0","powS","powM","checkRowIndex","outer","checkColumnIndex","checkRowVector","vector","to1DArray","checkColumnVector","checkIndices","rowIndices","columnIndices","row","checkRowIndices","column","checkColumnIndices","rowOut","some","r","from","columnOut","c","checkRange","startRow","endRow","startColumn","endColumn","checkNumber","newArray","array","sumByRow","sumByColumn","sumAll","v","productByRow","productByColumn","productAll","varianceByRow","unbiased","cols","variance","sum1","sum2","varianceByColumn","varianceAll","size","centerByRow","centerByColumn","centerAll","getScaleByRow","scale","scaleByRow","getScaleByColumn","scaleByColumn","getScaleAll","divider","scaleAll","from1DArray","newRows","newColumns","newData","rowVector","columnVector","zeros","ones","fill","rand","random","randInt","interval","eye","diag","matrix1","matrix2","isMatrix","klass","apply","callback","to2DArray","copy","toJSON","isRowVector","isColumnVector","isVector","isSquare","isSymmetric","isEchelonForm","previousColumn","checked","isReducedEchelonForm","echelonForm","clone","iMax","swapRows","reducedEchelonForm","maxRow","pivot","Error","setSubMatrix","neg","getRow","getRowVector","setRow","row1","row2","temp","getColumn","getColumnVector","setColumn","swapColumns","column1","column2","addRowVector","subRowVector","mulRowVector","divRowVector","addColumnVector","subColumnVector","mulColumnVector","divColumnVector","mulRow","mulColumn","maxIndex","idx","minIndex","maxRowIndex","minRow","minRowIndex","maxColumn","maxColumnIndex","minColumn","minColumnIndex","norm","type","cumulativeSum","dot","vector2","vector1","mmul","other","Bcolj","Float64Array","strassen2x2","a11","b11","a12","b12","a21","b21","a22","b22","m1","m2","m3","m4","m5","m6","m7","c00","c01","c10","c11","strassen3x3","a00","a01","a02","a10","a20","b00","b01","b02","b10","b20","m8","m9","m10","m11","m12","m13","m14","m15","m16","m17","m18","m19","m20","m21","m22","m23","c02","c12","c20","c21","c22","mmulStrassen","r1","c1","r2","c2","embed","mat","resultat","blockMult","halfRows","parseInt","halfCols","subMatrix","scaleRows","isFinite","scaleColumns","flipRows","middle","first","last","flipColumns","kroneckerProduct","q","transpose","sortRows","compareFunction","compareNumbers","sortColumns","subMatrixRow","indices","subMatrixColumn","selection","rowIndex","columnIndex","trace","by","product","standardDeviation","Symbol","for","randomInt","diagonal","identity","negate","tensorProduct","nRows","nColumns","arrayData","removeRow","splice","addRow","removeColumn","newRow","addColumn","WrapperMatrix2D","LuDecomposition","lu","pivotVector","pivotSign","LUcolj","kmax","LU","isSingular","col","solve","determinant","lowerTriangularMatrix","upperTriangularMatrix","pivotPermutationVector","hypotenuse","QrDecomposition","qr","rdiag","nrm","QR","Rdiag","isFullRank","orthogonalMatrix","SingularValueDecomposition","computeLeftSingularVectors","computeRightSingularVectors","autoTranspose","wantu","Boolean","wantv","swapped","aux","nu","ni","U","V","work","si","nct","nrt","mrc","pp","eps","EPSILON","kase","MIN_VALUE","isNaN","ks","f","cs","sn","sp","spm1","epm1","sk","ek","shift","g","iter","threshold","scols","Ls","rightSingularVectors","VL","vrows","urows","VLU","solveForDiagonal","inverse","vcols","ucols","condition","norm2","rank","tol","ii","leftSingularVectors","diagonalMatrix","useSVD","leftHandSide","rightHandSide","gradientFunction","evaluatedData","params","gradientDifference","paramFunction","param","auxParams","funcParam","point","matrixFunction","step","damping","gradientFunc","matrixFunc","inverseMatrix","levenbergMarquardt","maxIterations","errorTolerance","minValues","maxValues","initialValues","parLen","MIN_SAFE_INTEGER","converged","iteration","parameterValues","parameterError","iterations","sumOfGaussians","nL","optimizeGaussianSum","xy","group","opts","yData","forEach","arr","pInit","pMin","pMax","dt","lmOptions","assign","pFit","LM","singleGaussian","factor2","optimizeSingleGaussian","peak","sumOfLorentzians","p2","optimizeLorentzianSum","singleLorentzian","optimizeSingleLorentzian","optimizePeaks","functionName","factorWidth","optimizationOptions","lastIndex","groups","groupPeaks","sampling","peaks","sampleFunction","limits","optPeaks","fitResult","to","nbPoints","sampleX","sampleY","direction","delta","mid","stop","upperLimit","lowerLimit","joinBroadPeaks","broadLines","candidates","indexes","fitted","reduce","broadenPeaks","overlap","nextPeak"],"mappings":";;;;;;;;;;;;EAAe,SAASA,aAAT,CAAuBC,IAAvB,EAA6BC,CAA7B,EAA8C;EAAA,MAAdC,OAAc,uEAAJ,EAAI;EAC3D,MAAI;EAAEC,IAAAA,UAAU,GAAG,CAAf;EAAkBC,IAAAA,UAAU,GAAG,CAA/B;EAAkCC,IAAAA,UAAU,GAAG;EAA/C,MAAqDH,OAAzD;;EAEA,MAAIC,UAAU,GAAG,CAAb,KAAmB,CAAnB,IAAwBA,UAAU,GAAG,CAArC,IAA0C,CAACG,MAAM,CAACC,SAAP,CAAiBJ,UAAjB,CAA/C,EAA6E;EAC3E,UAAM,IAAIK,UAAJ,CACJ,mEADI,CAAN;EAGD;;EACD,MAAIL,UAAU,GAAGH,IAAI,CAACS,MAAtB,EAA8B;EAC5B,UAAM,IAAID,UAAJ,sDAC0CL,UAD1C,cACwDH,IAAI,CAACS,MAD7D,EAAN;EAGD;;EACD,MAAIL,UAAU,GAAG,CAAb,IAAkB,CAACE,MAAM,CAACC,SAAP,CAAiBH,UAAjB,CAAvB,EAAqD;EACnD,UAAM,IAAII,UAAJ,CAAe,yCAAf,CAAN;EACD;;EACD,MAAIH,UAAU,GAAG,CAAb,IAAkB,CAACC,MAAM,CAACC,SAAP,CAAiBF,UAAjB,CAAvB,EAAqD;EACnD,UAAM,IAAIG,UAAJ,CAAe,yCAAf,CAAN;EACD;;EACD,MAAIH,UAAU,IAAI,CAAlB,EAAqB;EACnB;EACAK,IAAAA,OAAO,CAACC,IAAR,CACE,iEACE,6FAFJ;EAID;;EAED,MAAIC,IAAI,GAAGC,IAAI,CAACC,KAAL,CAAWX,UAAU,GAAG,CAAxB,CAAX;EACA,MAAIY,EAAE,GAAGf,IAAI,CAACS,MAAd;EACA,MAAIO,GAAG,GAAG,IAAIC,KAAJ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C5Y,IAAvB,EAA6B;EAC3BuW,QAAAA,IAAI,CAACmB,EAAL,GAAUkB,QAAQ,CAAC5Y,IAAT,GAAgB,CAACuW,IAAI,CAACmB,EAAL,GAAUkB,QAAQ,CAAC5Y,IAApB,IAA4B,CAAtD;EACD;EACF;EACF;;EAED,OAAK,IAAIuW,IAAT,IAAiB/gB,QAAjB,EAA2B;EACzB+gB,IAAAA,IAAI,CAAChiB,KAAL,GAAagiB,IAAI,CAACmB,EAAL,GAAUnB,IAAI,CAACvW,IAA5B;EACD;;EAED,SAAOxK,QAAP;EACD;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/ml-gsd.min.js b/dist/ml-gsd.min.js new file mode 100644 index 0000000..0040f6e --- /dev/null +++ b/dist/ml-gsd.min.js @@ -0,0 +1,2 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).GSD={})}(this,(function(t){"use strict";function e(t,e){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{windowSize:s=9,derivative:i=0,polynomial:l=3}=o;if(s%2==0||s<5||!Number.isInteger(s))throw new RangeError("Invalid window size (should be odd and at least 5 integer number)");if(s>t.length)throw new RangeError("Window size is higher than the data length ".concat(s,">").concat(t.length));if(i<0||!Number.isInteger(i))throw new RangeError("Derivative should be a positive integer");if(l<1||!Number.isInteger(l))throw new RangeError("Polynomial should be a positive integer");l>=6&&console.warn("You should not use polynomial grade higher than 5 if you are not sure that your data arises from such a model. Possible polynomial oscillation problems");let h=Math.floor(s/2),u=t.length,a=new Array(u),f=function(t,e,r){let o=new Array(t),s=Math.floor(t/2);for(let i=-s;i<=s;i++){o[i+s]=new Array(t);for(let t=-s;t<=s;t++)o[i+s][t+s]=n(t,i,s,e,r)}return o}(s,l,i),c=0,m=!0;Array.isArray(e)?m=!1:c=Math.pow(e,i);for(let o=0;o=0&&o0?(4*r-2)/(r*(2*e-r+1))*(t*o(t,e,r-1,s)+s*o(t,e,r-1,s-1))-(r-1)*(2*e+r)/(r*(2*e-r+1))*o(t,e,r-2,s):0===r&&0===s?1:0,n}function s(t,e){let r=1;if(t>=e)for(let o=t-e+1;o<=t;o++)r*=o;return r}function n(t,e,r,n,i){let l=0;for(let h=0;h<=n;h++)l+=(2*h+1)*(s(2*r,h)/s(2*r+h+1,h+1))*o(t,r,h,0)*o(e,r,h,i);return l}const i=t=>{let e,r=0,o=Number.MAX_SAFE_INTEGER;for(let s=0;sr&&(r=e);return(r-o)/r<.05},l=t=>{let e=0,r=0,o=t.length;for(let r=0;rt-e),r=o%2==1?s[(o-1)/2]/.6745:.5*(s[o/2]+s[o/2-1])/.6745,r},h=(t,e,r)=>{let o,s,n,i,l;for(let h=0;h=r[l-2]&&r[l-1]>=r[l]?l--:r[l+1]>=r[l]&&r[l+1]>=r[l+2]?l++:r[l-2]>=r[l-3]&&r[l-2]>=r[l-1]?l-=2:r[l+2]>=r[l+1]&&r[l+2]>=r[l+3]&&(l+=2),r[l-1]>0&&r[l+1]>0&&r[l]>=r[l-1]&&r[l]>=r[l+1]&&(r[l]!==r[l-1]||r[l]!==r[l+1])&&(o=20*Math.log10(r[l-1]),s=20*Math.log10(r[l]),n=20*Math.log10(r[l+1]),i=.5*(o-n)/(o-2*s+n),t[h].x=e[l]+(e[l]-e[l-1])*i,t[h].y=r[l]-.25*(r[l-1]-r[l+1])*i)},u=Object.prototype.toString;function a(t){return u.call(t).endsWith("Array]")}function f(t,e,r){let o=0;const s=r(e);for(let e=0;e1&&void 0!==arguments[1]?arguments[1]:{};if(!m(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!m(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=function(t){if(!d(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");for(var e=t[0],r=1;re&&(e=t[r]);return e}(t);if(o===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=r.min,i=void 0===n?r.autoMinMax?o:0:n,l=r.max,h=void 0===l?r.autoMinMax?s:1:l;if(i>=h)throw new RangeError("min option must be smaller than max option");for(var u=(h-i)/(s-o),a=0;a1&&void 0!==arguments[1]?arguments[1]:{};const{maxRows:r=15,maxColumns:o=10,maxNumSize:s=8}=e;return"".concat(t.constructor.name," {\n").concat(b,"[\n").concat(M).concat(function(t,e,r,o){const{rows:s,columns:n}=t,i=Math.min(s,e),l=Math.min(n,r),h=[];for(let e=0;eo)throw new RangeError("Row index out of range")}function S(t,e,r){let o=r?t.columns:t.columns-1;if(e<0||e>o)throw new RangeError("Column index out of range")}function A(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function R(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function V(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for row indices");if(e.some(e=>e<0||e>=t.rows))throw new RangeError("row indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function T(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for column indices");if(e.some(e=>e<0||e>=t.columns))throw new RangeError("column indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function k(t,e,r,o,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(N("startRow",e),N("endRow",r),N("startColumn",o),N("endColumn",s),e>r||o>s||e<0||e>=t.rows||r<0||r>=t.rows||o<0||o>=t.columns||s<0||s>=t.columns)throw new RangeError("Submatrix indices are out of range")}function F(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=[];for(let o=0;o2&&void 0!==arguments[2]?arguments[2]:{};if("object"!=typeof r)throw new TypeError("options must be an object");const{random:o=Math.random}=r;let s=new j(t,e);for(let r=0;r2&&void 0!==arguments[2]?arguments[2]:{};if("object"!=typeof r)throw new TypeError("options must be an object");const{min:o=0,max:s=1e3,random:n=Math.random}=r;if(!Number.isInteger(o))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(o>=s)throw new RangeError("min must be smaller than max");let i=s-o,l=new j(t,e);for(let r=0;rr?(s=!0,r=e):(o=!1,s=!0);t++}return o}isReducedEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;tr?(s=!0,r=e):(o=!1,s=!0);for(let r=e+1;rt.get(o,r)&&(o=s);if(0===t.get(o,r))r++;else{t.swapRows(e,o);let s=t.get(e,r);for(let o=r;o=0;)if(0===t.maxRow(o))o--;else{let s=0,n=!1;for(;s0&&void 0!==arguments[0]?arguments[0]:{};if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let o=new j(this.rows*e,this.columns*r);for(let t=0;tt&&(t=this.get(e,r));return t}maxIndex(){let t=this.get(0,0),e=[0,0];for(let r=0;rt&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}min(){let t=this.get(0,0);for(let e=0;ee&&(e=this.get(t,r));return e}maxRowIndex(t){E(this,t);let e=this.get(t,0),r=[t,0];for(let o=1;oe&&(e=this.get(t,o),r[1]=o);return r}minRow(t){E(this,t);let e=this.get(t,0);for(let r=1;re&&(e=this.get(r,t));return e}maxColumnIndex(t){S(this,t);let e=this.get(0,t),r=[0,t];for(let o=1;oe&&(e=this.get(o,t),r[0]=o);return r}minColumn(t){S(this,t);let e=this.get(0,t);for(let r=1;r0&&void 0!==arguments[0]?arguments[0]:"frobenius",e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t0&&void 0!==arguments[0]?arguments[0]:{};if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new j(this.rows,this.columns);for(let t=0;t0&&void 0!==arguments[0]?arguments[0]:{};if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new j(this.rows,this.columns);for(let t=0;t0&&void 0!==arguments[0]?arguments[0]:I;for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:I;for(let e=0;er||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let o=new j(t.length,r-e+1);for(let s=0;s=this.rows)throw new RangeError("Row index out of range: ".concat(t[s]));o.set(s,n-e,this.get(t[s],n))}return o}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let o=new j(r-e+1,t.length);for(let s=0;s=this.columns)throw new RangeError("Column index out of range: ".concat(t[s]));o.set(n-e,s,this.get(n,t[s]))}return o}setSubMatrix(t,e,r){k(this,e,e+(t=j.checkMatrix(t)).rows-1,r,r+t.columns-1);for(let o=0;o1&&void 0!==arguments[1]?arguments[1]:{};if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Array.isArray(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i1&&void 0!==arguments[1]?arguments[1]:{};if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!Array.isArray(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r1&&void 0!==arguments[1]?arguments[1]:{};if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r0){if(this.data=[],!(Number.isInteger(e)&&e>0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;tMath.abs(h[s])&&(s=e);if(s!==r){for(o=0;o=0;s--){for(o=0;oe?o.set(s,e,t.get(s,e)):s===e?o.set(s,e,1):o.set(s,e,0);return o}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,o=new j(e,r);for(let s=0;sMath.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class P{constructor(t){let e,r,o,s,n=(t=C.checkMatrix(t)).clone(),i=t.rows,l=t.columns,h=new Float64Array(l);for(o=0;o=0;n--){for(s=0;s=0;r--){for(t=0;t1&&void 0!==arguments[1]?arguments[1]:{},r=(t=C.checkMatrix(t)).rows,o=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:n=!0,autoTranspose:i=!1}=e;let l,h=Boolean(s),u=Boolean(n),a=!1;if(r=0;t--)if(0!==m[t]){for(let e=t+1;e=0;t--){if(t0;){let t,e;for(t=v-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(m[t]+Math.abs(m[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===v-2)e=4;else{let r;for(r=v-1;r>=t&&r!==t;r--){let e=(r!==v?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(m[r])<=S*e){m[r]=0;break}}r===t?e=3:r===v-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[v-2];p[v-2]=0;for(let r=v-2;r>=t;r--){let s=D(m[r],e),n=m[r]/s,i=e/s;if(m[r]=s,r!==t&&(e=-i*p[r-1],p[r-1]=n*p[r-1]),u)for(let t=0;t=m[t+1]);){let e=m[t];if(m[t]=m[t+1],m[t+1]=e,u&&te&&s.set(n,r,t.get(n,r)/this.s[r]);let n=this.U,i=n.rows,l=n.columns,h=new j(r,i);for(let t=0;tt&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return j.diag(this.s)}}function O(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return t=C.checkMatrix(t),e?new L(t).inverse():function(t,e){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return t=C.checkMatrix(t),e=C.checkMatrix(e),r?new L(t).solve(e):t.isSquare()?new q(t).solve(e):new P(t).solve(e)}(t,j.eye(t.rows))}function U(t,e,r,o,s){let n=r*o*o,i=j.eye(e.length,e.length,n);const l=s(e);let h=new Float64Array(t.x.length);for(let e=0;e2&&void 0!==arguments[2]?arguments[2]:{},{maxIterations:o=100,gradientDifference:s=.1,damping:n=0,errorTolerance:i=.01,minValues:l,maxValues:h,initialValues:u}=r;if(n<=0)throw new Error("The damping option must be a positive number");if(!t.x||!t.y)throw new Error("The data parameter must have x and y elements");if(!a(t.x)||t.x.length<2||!a(t.y)||t.y.length<2)throw new Error("The data parameter elements must be an array with more than 2 points");if(t.x.length!==t.y.length)throw new Error("The data parameter elements must have the same size");let c=u||new Array(e.length).fill(1),m=c.length;if(h=h||new Array(m).fill(Number.MAX_SAFE_INTEGER),l=l||new Array(m).fill(Number.MIN_SAFE_INTEGER),h.length!==l.length)throw new Error("minValues and maxValues must be the same size");if(!a(c))throw new Error("initialValues must be an array");let g,w=f(t,c,e),p=w<=i;for(g=0;g2&&void 0!==arguments[2]?arguments[2]:{},o=t[0],s=t[1],n=Math.max(...s);s.forEach((t,e,r)=>r[e]/=n);let i=e.length,l=new Float64Array(3*i),h=new Float64Array(3*i),u=new Float64Array(3*i),a=Math.abs(o[0]-o[1]);for(let t=0;t2&&void 0!==arguments[2]?arguments[2]:{},o=t[0],s=t[1],n=Math.max(...s);s.forEach((t,e,r)=>r[e]/=n);let i=Math.abs(o[0]-o[1]),l={x:o,y:s},h={damping:1.5,initialValues:new Float64Array([e.x,1,e.width]),minValues:new Float64Array([e.x-i,0,e.width/4]),maxValues:new Float64Array([e.x+i,1.25,4*e.width]),gradientDifference:i/1e4,maxIterations:100,errorTolerance:1e-4};r=Object.assign({},h,r);let u=_(l,G,r);return{parameters:[u.parameterValues[0],u.parameterValues[1]*n,u.parameterValues[2]],error:u.parameterError}}function B(t){return function(e){let r,o,s=t.length/3,n=e.length,i=void 0===n?0:new Float64Array(n).fill(0);for(let l=0;l2&&void 0!==arguments[2]?arguments[2]:{},o=t[0],s=t[1],n=Math.max(...s);s.forEach((t,e,r)=>r[e]/=n);let i=e.length,l=new Float64Array(3*i),h=new Float64Array(3*i),u=new Float64Array(3*i),a=Math.abs(o[0]-o[1]);for(let t=0;t2&&void 0!==arguments[2]?arguments[2]:{},o=t[0],s=t[1],n=Math.max(...s);s.forEach((t,e,r)=>r[e]/=n);let i=Math.abs(o[0]-o[1]),l={x:o,y:s},h={damping:1.5,initialValues:new Float64Array([e.x,1,e.width]),minValues:new Float64Array([e.x-i,.75,e.width/4]),maxValues:new Float64Array([e.x+i,1.25,4*e.width]),gradientDifference:i/1e4,maxIterations:100,errorTolerance:1e-4};r=Object.assign({},h,r);let u=_(l,J,r);return{parameters:[u.parameterValues[0],u.parameterValues[1]*n,u.parameterValues[2]],error:u.parameterError}}function K(t,e,r,o,s){let n=r.length,i=[],l=[],h=Math.sign(r[1]-r[0]);-1===h&&(s[0]=r.length-1);let u=Math.abs(e-t)/2,a=(t+e)/2,f=!1,c=s[0];for(;!f&&c=0;)Math.abs(r[c]-a)<=u?(i.push(r[c]),l.push(o[c]),c+=h):1===Math.sign(a-r[c])?c+=h:f=!0;return s[0]=c,[i,l]}t.broadenPeaks=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{factor:r=2,overlap:o=!1}=e;for(let e of t)e.right&&e.left?(e.from=e.x-(e.x-e.left.x)*r,e.to=e.x+(e.right.x-e.x)*r):(e.from=e.x-e.width/2*r,e.to=e.x+e.width/2*r);if(!o)for(let e=0;eo.from&&(r.to=o.from=(r.to+o.from)/2)}for(let e of t)e.width=e.to-e.from;return t},t.gsd=function(t,r){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{noiseLevel:s,sgOptions:n={windowSize:9,polynomial:3},smoothY:u=!0,heightFactor:a=0,broadRatio:f=0,maxCriteria:c=!0,minMaxRatio:m=25e-5,derivativeThreshold:g=-1,realTopDetection:w=!1}=o;const p=r.slice();let d=i(t);void 0===s&&(s=d?l(p):0);const y={m:1,b:s};c||(y.m=-1,y.b*=-1);for(let t=0;tR&&(R=Math.abs(M[t])),Math.abs(x[t])>V&&(V=Math.abs(x[t]));let T=null,k=null,F=new Array(x.length-2),N=new Array(x.length),z=new Array(x.length),I=new Array(x.length-2),j=0,C=0,q=0,D=0;for(let t=1;tg&&((b[t]0&&null!==T&&(N[C++]=T,z[q++]=k)),(b[t]>=b[t-1]&&b[t]>b[t+1]||b[t]>b[t-1]&&b[t]>=b[t+1])&&(T={x:S[t],index:t},A<0&&null!==k&&(N[C++]=T,z[q++]=k))),M[t]m*V&&(W[Q++]={index:F[t],x:L,y:(x[F[t]]+y.b)/y.m,width:Math.abs(z[P].x-N[P].x),soft:I[t]},W[Q-1].left=N[P],W[Q-1].right=z[P],a)){let t=x[N[P].index],e=x[z[P].index];W[Q-1].height=a*(W[Q-1].y-(t+e)/2)}}W.length=Q,w&&h(W,S,x);for(let t=0;t1&&void 0!==arguments[1]?arguments[1]:{}).width,r=[],o=0,s=0,n=1;for(let e=t.length-1;e>=0;e--)t[e].soft&&r.push(t.splice(e,1)[0]);r.push({x:Number.MAX_VALUE});let i=[[r[0].x,r[0].y]],l=[r[0].index];for(let h=1;ho&&(o=r[h].y,s=h),l.push(r[h].index),n++;else{if(n>2){let e=H(i,{x:r[s].x,y:o,width:Math.abs(i[0][0]-i[i.length-1][0])}),{parameters:n}=e;t.push({x:n[0],y:n[1],width:n[2],index:Math.floor(l.reduce((t,e)=>t+e,0)/l.length),soft:!1})}else l.forEach(e=>{t.push(r[e])});i=[[r[h].x,r[h].y]],l=[h],o=r[h].y,s=h,n=1}return t.sort((function(t,e){return t.x-e.x})),t},t.optimizePeaks=function(t,e,r){let o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};const{functionName:s="gaussian",factorWidth:n=4,optimizationOptions:i={damping:1.5,maxIterations:100,errorTolerance:1e-4}}=o;let l,h=[0],u=function(t,e){let r,o,s=[],n=[],i=[t[0].x,e*t[0].width];for(let l=0;lr&&(r=t[l].x+e*t[l].width),o=i[0]-i[1],t[l].x-e*t[l].width=0;t--)if(Math.abs(n[t].limits[0]-n[t+1].limits[0])<(n[t].limits[1]+n[t+1].limits[1])/2){for(let e=0;er&&(r=n[t+1].limits[0]+n[t+1].limits[1]),o=n[t].limits[0]-n[t].limits[1],n[t+1].limits[0]-n[t+1].limits[1]1){if(l=K(u[t].limits[0]-u[t].limits[1],u[t].limits[0]+u[t].limits[1],e,r,h),l[0].length>5){let t=[];"gaussian"===s?t=Q(l,o,i):"lorentzian"===s&&(t=Y(l,o,i));for(let e=0;e5){let t=[];"gaussian"===s?t=X([l[0],l[1]],o,i):"lorentzian"===s&&(t=H([l[0],l[1]],o,i));let{parameters:e}=t;a.push({x:e[0],y:e[1],width:e[2]*f,index:o.index})}}return a},Object.defineProperty(t,"__esModule",{value:!0})})); +//# sourceMappingURL=ml-gsd.min.js.map diff --git a/dist/ml-gsd.min.js.map b/dist/ml-gsd.min.js.map new file mode 100644 index 0000000..cfa7501 --- /dev/null +++ b/dist/ml-gsd.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ml-gsd.min.js","sources":["../node_modules/ml-savitzky-golay-generalized/src/index.js","../src/gsd.js","../node_modules/is-any-array/src/index.js","../node_modules/ml-levenberg-marquardt/src/errorCalculation.js","../node_modules/ml-array-rescale/node_modules/is-any-array/src/index.js","../node_modules/ml-array-max/node_modules/is-any-array/src/index.js","../node_modules/ml-array-min/node_modules/is-any-array/src/index.js","../node_modules/ml-array-rescale/lib-es6/index.js","../node_modules/ml-array-min/lib-es6/index.js","../node_modules/ml-array-max/lib-es6/index.js","../node_modules/ml-matrix/src/inspect.js","../node_modules/ml-matrix/src/util.js","../node_modules/ml-matrix/src/matrix.js","../node_modules/ml-matrix/src/stat.js","../node_modules/ml-matrix/src/mathOperations.js","../node_modules/ml-matrix/src/wrap/WrapperMatrix2D.js","../node_modules/ml-matrix/src/dc/lu.js","../node_modules/ml-matrix/src/dc/util.js","../node_modules/ml-matrix/src/dc/qr.js","../node_modules/ml-matrix/src/dc/svd.js","../node_modules/ml-matrix/src/decompositions.js","../node_modules/ml-levenberg-marquardt/src/step.js","../node_modules/ml-levenberg-marquardt/src/index.js","../node_modules/ml-optimize-lorentzian/src/sumOfGaussians.js","../node_modules/ml-optimize-lorentzian/src/optimizeGaussianSum.js","../node_modules/ml-optimize-lorentzian/src/singleGaussian.js","../node_modules/ml-optimize-lorentzian/src/optimizeSingleGaussian.js","../node_modules/ml-optimize-lorentzian/src/sumOfLorentzians.js","../node_modules/ml-optimize-lorentzian/src/optimizeLorentzianSum.js","../node_modules/ml-optimize-lorentzian/src/singleLorentzian.js","../node_modules/ml-optimize-lorentzian/src/optimizeSingleLorentzian.js","../src/post/optimizePeaks.js","../src/post/broadenPeaks.js","../src/post/joinBroadPeaks.js"],"sourcesContent":["export default function SavitzkyGolay(data, h, options = {}) {\n let { windowSize = 9, derivative = 0, polynomial = 3 } = options;\n\n if (windowSize % 2 === 0 || windowSize < 5 || !Number.isInteger(windowSize)) {\n throw new RangeError(\n 'Invalid window size (should be odd and at least 5 integer number)',\n );\n }\n if (windowSize > data.length) {\n throw new RangeError(\n `Window size is higher than the data length ${windowSize}>${data.length}`,\n );\n }\n if (derivative < 0 || !Number.isInteger(derivative)) {\n throw new RangeError('Derivative should be a positive integer');\n }\n if (polynomial < 1 || !Number.isInteger(polynomial)) {\n throw new RangeError('Polynomial should be a positive integer');\n }\n if (polynomial >= 6) {\n // eslint-disable-next-line no-console\n console.warn(\n 'You should not use polynomial grade higher than 5 if you are' +\n ' not sure that your data arises from such a model. Possible polynomial oscillation problems',\n );\n }\n\n let half = Math.floor(windowSize / 2);\n let np = data.length;\n let ans = new Array(np);\n let weights = fullWeights(windowSize, polynomial, derivative);\n let hs = 0;\n let constantH = true;\n if (Array.isArray(h)) {\n constantH = false;\n } else {\n hs = Math.pow(h, derivative);\n }\n\n //For the borders\n for (let i = 0; i < half; i++) {\n let wg1 = weights[half - i - 1];\n let wg2 = weights[half + i + 1];\n let d1 = 0;\n let d2 = 0;\n for (let l = 0; l < windowSize; l++) {\n d1 += wg1[l] * data[l];\n d2 += wg2[l] * data[np - windowSize + l];\n }\n if (constantH) {\n ans[half - i - 1] = d1 / hs;\n ans[np - half + i] = d2 / hs;\n } else {\n hs = getHs(h, half - i - 1, half, derivative);\n ans[half - i - 1] = d1 / hs;\n hs = getHs(h, np - half + i, half, derivative);\n ans[np - half + i] = d2 / hs;\n }\n }\n\n //For the internal points\n let wg = weights[half];\n for (let i = windowSize; i <= np; i++) {\n let d = 0;\n for (let l = 0; l < windowSize; l++) d += wg[l] * data[l + i - windowSize];\n if (!constantH) hs = getHs(h, i - half - 1, half, derivative);\n ans[i - half - 1] = d / hs;\n }\n return ans;\n}\n\nfunction getHs(h, center, half, derivative) {\n let hs = 0;\n let count = 0;\n for (let i = center - half; i < center + half; i++) {\n if (i >= 0 && i < h.length - 1) {\n hs += h[i + 1] - h[i];\n count++;\n }\n }\n return Math.pow(hs / count, derivative);\n}\n\nfunction GramPoly(i, m, k, s) {\n let Grampoly = 0;\n if (k > 0) {\n Grampoly =\n ((4 * k - 2) / (k * (2 * m - k + 1))) *\n (i * GramPoly(i, m, k - 1, s) + s * GramPoly(i, m, k - 1, s - 1)) -\n (((k - 1) * (2 * m + k)) / (k * (2 * m - k + 1))) *\n GramPoly(i, m, k - 2, s);\n } else {\n if (k === 0 && s === 0) {\n Grampoly = 1;\n } else {\n Grampoly = 0;\n }\n }\n return Grampoly;\n}\n\nfunction GenFact(a, b) {\n let gf = 1;\n if (a >= b) {\n for (let j = a - b + 1; j <= a; j++) {\n gf *= j;\n }\n }\n return gf;\n}\n\nfunction Weight(i, t, m, n, s) {\n let sum = 0;\n for (let k = 0; k <= n; k++) {\n //console.log(k);\n sum +=\n (2 * k + 1) *\n (GenFact(2 * m, k) / GenFact(2 * m + k + 1, k + 1)) *\n GramPoly(i, m, k, 0) *\n GramPoly(t, m, k, s);\n }\n return sum;\n}\n\n/**\n *\n * @param m Number of points\n * @param n Polynomial grade\n * @param s Derivative\n */\nfunction fullWeights(m, n, s) {\n let weights = new Array(m);\n let np = Math.floor(m / 2);\n for (let t = -np; t <= np; t++) {\n weights[t + np] = new Array(m);\n for (let j = -np; j <= np; j++) {\n weights[t + np][j + np] = Weight(j, t, np, n, s);\n }\n }\n return weights;\n}\n\n/*function entropy(data,h,options){\n var trend = SavitzkyGolay(data,h,trendOptions);\n var copy = new Array(data.length);\n var sum = 0;\n var max = 0;\n for(var i=0;i} x - Independent variable\n * @param {Array} yIn - Dependent variable\n * @param {object} [options] - Options object\n * @param {object} [options.sgOptions] - Options object for Savitzky-Golay filter. See https://github.com/mljs/savitzky-golay-generalized#options\n * @param {number} [options.sgOptions.windowSize = 9] - points to use in the approximations\n * @param {number} [options.sgOptions.polynomial = 3] - degree of the polynomial to use in the approximations\n * @param {number} [options.minMaxRatio = 0.00025] - Threshold to determine if a given peak should be considered as a noise\n * @param {number} [options.broadRatio = 0.00] - If `broadRatio` is higher than 0, then all the peaks which second derivative\n * smaller than `broadRatio * maxAbsSecondDerivative` will be marked with the soft mask equal to true.\n * @param {number} [options.noiseLevel = 0] - Noise threshold in spectrum units\n * @param {boolean} [options.maxCriteria = true] - Peaks are local maximum(true) or minimum(false)\n * @param {boolean} [options.smoothY = true] - Select the peak intensities from a smoothed version of the independent variables\n * @param {boolean} [options.realTopDetection = false] - Use a quadratic optimizations with the peak and its 3 closest neighbors\n * to determine the true x,y values of the peak?\n * @param {number} [options.heightFactor = 0] - Factor to multiply the calculated height (usually 2)\n * @param {boolean} [options.boundaries = false] - Return also the inflection points of the peaks\n * @param {number} [options.derivativeThreshold = -1] - Filters based on the amplitude of the first derivative\n * @return {Array}\n */\nexport function gsd(x, yIn, options = {}) {\n let {\n noiseLevel,\n sgOptions = {\n windowSize: 9,\n polynomial: 3,\n },\n smoothY = true,\n heightFactor = 0,\n broadRatio = 0.0,\n maxCriteria = true,\n minMaxRatio = 0.00025,\n derivativeThreshold = -1,\n realTopDetection = false,\n } = options;\n\n const y = yIn.slice();\n let equalSpaced = isEqualSpaced(x);\n\n if (noiseLevel === undefined) {\n noiseLevel = equalSpaced ? getNoiseLevel(y) : 0;\n }\n\n const yCorrection = { m: 1, b: noiseLevel };\n\n if (!maxCriteria) {\n yCorrection.m = -1;\n yCorrection.b *= -1;\n }\n\n for (let i = 0; i < y.length; i++) {\n y[i] = yCorrection.m * y[i] - yCorrection.b;\n }\n\n for (let i = 0; i < y.length; i++) {\n if (y[i] < 0) {\n y[i] = 0;\n }\n }\n // If the max difference between delta x is less than 5%, then,\n // we can assume it to be equally spaced variable\n let Y = y;\n let dY, ddY;\n const { windowSize, polynomial } = sgOptions;\n\n if (equalSpaced) {\n if (smoothY) {\n Y = SG(y, x[1] - x[0], {\n windowSize,\n polynomial,\n derivative: 0,\n });\n }\n dY = SG(y, x[1] - x[0], {\n windowSize,\n polynomial,\n derivative: 1,\n });\n ddY = SG(y, x[1] - x[0], {\n windowSize,\n polynomial,\n derivative: 2,\n });\n } else {\n if (smoothY) {\n Y = SG(y, x, {\n windowSize,\n polynomial,\n derivative: 0,\n });\n }\n dY = SG(y, x, {\n windowSize,\n polynomial,\n derivative: 1,\n });\n ddY = SG(y, x, {\n windowSize,\n polynomial,\n derivative: 2,\n });\n }\n // console.log('this is 2', y)\n const X = x;\n const dx = x[1] - x[0];\n let maxDdy = 0;\n let maxY = 0;\n for (let i = 0; i < Y.length; i++) {\n if (Math.abs(ddY[i]) > maxDdy) {\n maxDdy = Math.abs(ddY[i]);\n }\n if (Math.abs(Y[i]) > maxY) {\n maxY = Math.abs(Y[i]);\n }\n }\n\n let lastMax = null;\n let lastMin = null;\n let minddY = new Array(Y.length - 2);\n let intervalL = new Array(Y.length);\n let intervalR = new Array(Y.length);\n let broadMask = new Array(Y.length - 2);\n let minddYLen = 0;\n let intervalLLen = 0;\n let intervalRLen = 0;\n let broadMaskLen = 0;\n // By the intermediate value theorem We cannot find 2 consecutive maximum or minimum\n for (let i = 1; i < Y.length - 1; ++i) {\n // filter based on derivativeThreshold\n // console.log('pasa', y[i], dY[i], ddY[i]);\n if (Math.abs(dY[i]) > derivativeThreshold) {\n // Minimum in first derivative\n if (\n (dY[i] < dY[i - 1] && dY[i] <= dY[i + 1]) ||\n (dY[i] <= dY[i - 1] && dY[i] < dY[i + 1])\n ) {\n lastMin = {\n x: X[i],\n index: i,\n };\n if (dx > 0 && lastMax !== null) {\n intervalL[intervalLLen++] = lastMax;\n intervalR[intervalRLen++] = lastMin;\n }\n }\n\n // Maximum in first derivative\n if (\n (dY[i] >= dY[i - 1] && dY[i] > dY[i + 1]) ||\n (dY[i] > dY[i - 1] && dY[i] >= dY[i + 1])\n ) {\n lastMax = {\n x: X[i],\n index: i,\n };\n if (dx < 0 && lastMin !== null) {\n intervalL[intervalLLen++] = lastMax;\n intervalR[intervalRLen++] = lastMin;\n }\n }\n }\n\n // Minimum in second derivative\n if (ddY[i] < ddY[i - 1] && ddY[i] < ddY[i + 1]) {\n // TODO should we change this to have 3 arrays ? Huge overhead creating arrays\n minddY[minddYLen++] = i; // ( [X[i], Y[i], i] );\n broadMask[broadMaskLen++] = Math.abs(ddY[i]) <= broadRatio * maxDdy;\n }\n }\n minddY.length = minddYLen;\n intervalL.length = intervalLLen;\n intervalR.length = intervalRLen;\n broadMask.length = broadMaskLen;\n\n let signals = new Array(minddY.length);\n let signalsLen = 0;\n let lastK = -1;\n let possible, frequency, distanceJ, minDistance, gettingCloser;\n for (let j = 0; j < minddY.length; ++j) {\n frequency = X[minddY[j]];\n possible = -1;\n let k = lastK + 1;\n minDistance = Number.MAX_VALUE;\n distanceJ = 0;\n gettingCloser = true;\n while (possible === -1 && k < intervalL.length && gettingCloser) {\n distanceJ = Math.abs(frequency - (intervalL[k].x + intervalR[k].x) / 2);\n\n // Still getting closer?\n if (distanceJ < minDistance) {\n minDistance = distanceJ;\n } else {\n gettingCloser = false;\n }\n if (distanceJ < Math.abs(intervalL[k].x - intervalR[k].x) / 2) {\n possible = k;\n lastK = k;\n }\n ++k;\n }\n\n if (possible !== -1) {\n if (Math.abs(Y[minddY[j]]) > minMaxRatio * maxY) {\n signals[signalsLen++] = {\n index: minddY[j],\n x: frequency,\n y: (Y[minddY[j]] + yCorrection.b) / yCorrection.m,\n width: Math.abs(intervalR[possible].x - intervalL[possible].x), // widthCorrection\n soft: broadMask[j],\n };\n\n signals[signalsLen - 1].left = intervalL[possible];\n signals[signalsLen - 1].right = intervalR[possible];\n\n if (heightFactor) {\n let yLeft = Y[intervalL[possible].index];\n let yRight = Y[intervalR[possible].index];\n signals[signalsLen - 1].height =\n heightFactor * (signals[signalsLen - 1].y - (yLeft + yRight) / 2);\n }\n }\n }\n }\n signals.length = signalsLen;\n\n if (realTopDetection) {\n determineRealTop(signals, X, Y);\n }\n\n // Correct the values to fit the original spectra data\n for (let j = 0; j < signals.length; j++) {\n signals[j].base = noiseLevel;\n }\n\n signals.sort(function (a, b) {\n return a.x - b.x;\n });\n\n return signals;\n}\n\nconst isEqualSpaced = (x) => {\n let tmp;\n let maxDx = 0;\n let minDx = Number.MAX_SAFE_INTEGER;\n for (let i = 0; i < x.length - 1; ++i) {\n tmp = Math.abs(x[i + 1] - x[i]);\n if (tmp < minDx) {\n minDx = tmp;\n }\n if (tmp > maxDx) {\n maxDx = tmp;\n }\n }\n return (maxDx - minDx) / maxDx < 0.05;\n};\n\nconst getNoiseLevel = (y) => {\n let mean = 0;\n\n let stddev = 0;\n let length = y.length;\n for (let i = 0; i < length; ++i) {\n mean += y[i];\n }\n mean /= length;\n let averageDeviations = new Array(length);\n for (let i = 0; i < length; ++i) {\n averageDeviations[i] = Math.abs(y[i] - mean);\n }\n averageDeviations.sort((a, b) => a - b);\n if (length % 2 === 1) {\n stddev = averageDeviations[(length - 1) / 2] / 0.6745;\n } else {\n stddev =\n (0.5 *\n (averageDeviations[length / 2] + averageDeviations[length / 2 - 1])) /\n 0.6745;\n }\n\n return stddev;\n};\n\nconst determineRealTop = (peakList, x, y) => {\n let alpha, beta, gamma, p, currentPoint;\n for (let j = 0; j < peakList.length; j++) {\n currentPoint = peakList[j].index; // peakList[j][2];\n // The detected peak could be moved 1 or 2 units to left or right.\n if (\n y[currentPoint - 1] >= y[currentPoint - 2] &&\n y[currentPoint - 1] >= y[currentPoint]\n ) {\n currentPoint--;\n } else {\n if (\n y[currentPoint + 1] >= y[currentPoint] &&\n y[currentPoint + 1] >= y[currentPoint + 2]\n ) {\n currentPoint++;\n } else {\n if (\n y[currentPoint - 2] >= y[currentPoint - 3] &&\n y[currentPoint - 2] >= y[currentPoint - 1]\n ) {\n currentPoint -= 2;\n } else {\n if (\n y[currentPoint + 2] >= y[currentPoint + 1] &&\n y[currentPoint + 2] >= y[currentPoint + 3]\n ) {\n currentPoint += 2;\n }\n }\n }\n }\n // interpolation to a sin() function\n if (\n y[currentPoint - 1] > 0 &&\n y[currentPoint + 1] > 0 &&\n y[currentPoint] >= y[currentPoint - 1] &&\n y[currentPoint] >= y[currentPoint + 1] &&\n (y[currentPoint] !== y[currentPoint - 1] ||\n y[currentPoint] !== y[currentPoint + 1])\n ) {\n alpha = 20 * Math.log10(y[currentPoint - 1]);\n beta = 20 * Math.log10(y[currentPoint]);\n gamma = 20 * Math.log10(y[currentPoint + 1]);\n p = (0.5 * (alpha - gamma)) / (alpha - 2 * beta + gamma);\n // console.log(alpha, beta, gamma, `p: ${p}`);\n // console.log(x[currentPoint]+\" \"+tmp+\" \"+currentPoint);\n peakList[j].x =\n x[currentPoint] + (x[currentPoint] - x[currentPoint - 1]) * p;\n peakList[j].y =\n y[currentPoint] -\n 0.25 * (y[currentPoint - 1] - y[currentPoint + 1]) * p;\n }\n }\n};\n","const toString = Object.prototype.toString;\n\nexport default function isAnyArray(object) {\n return toString.call(object).endsWith('Array]');\n}\n","/**\n * Calculate current error\n * @ignore\n * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]\n * @param {Array} parameters - Array of current parameter values\n * @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter\n * @return {number}\n */\nexport default function errorCalculation(\n data,\n parameters,\n parameterizedFunction,\n) {\n let error = 0;\n const func = parameterizedFunction(parameters);\n\n for (let i = 0; i < data.x.length; i++) {\n error += Math.abs(data.y[i] - func(data.x[i]));\n }\n\n return error;\n}\n","'use strict';\n\nconst toString = Object.prototype.toString;\n\nfunction isAnyArray(object) {\n return toString.call(object).endsWith('Array]');\n}\n\nmodule.exports = isAnyArray;\n","'use strict';\n\nconst toString = Object.prototype.toString;\n\nfunction isAnyArray(object) {\n return toString.call(object).endsWith('Array]');\n}\n\nmodule.exports = isAnyArray;\n","'use strict';\n\nconst toString = Object.prototype.toString;\n\nfunction isAnyArray(object) {\n return toString.call(object).endsWith('Array]');\n}\n\nmodule.exports = isAnyArray;\n","import isArray from 'is-any-array';\nimport max from 'ml-array-max';\nimport min from 'ml-array-min';\n\n/**\n *\n * @param {Array} input\n * @param {object} [options={}]\n * @param {Array} [options.output=[]] specify the output array, can be the input array for in place modification\n */\n\nfunction rescale(input) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n if (!isArray(input)) {\n throw new TypeError('input must be an array');\n } else if (input.length === 0) {\n throw new TypeError('input must not be empty');\n }\n\n var output;\n\n if (options.output !== undefined) {\n if (!isArray(options.output)) {\n throw new TypeError('output option must be an array if specified');\n }\n\n output = options.output;\n } else {\n output = new Array(input.length);\n }\n\n var currentMin = min(input);\n var currentMax = max(input);\n\n if (currentMin === currentMax) {\n throw new RangeError('minimum and maximum input values are equal. Cannot rescale a constant array');\n }\n\n var _options$min = options.min,\n minValue = _options$min === void 0 ? options.autoMinMax ? currentMin : 0 : _options$min,\n _options$max = options.max,\n maxValue = _options$max === void 0 ? options.autoMinMax ? currentMax : 1 : _options$max;\n\n if (minValue >= maxValue) {\n throw new RangeError('min option must be smaller than max option');\n }\n\n var factor = (maxValue - minValue) / (currentMax - currentMin);\n\n for (var i = 0; i < input.length; i++) {\n output[i] = (input[i] - currentMin) * factor + minValue;\n }\n\n return output;\n}\n\nexport default rescale;\n","import isArray from 'is-any-array';\n\n/**\n * Computes the minimum of the given values\n * @param {Array} input\n * @return {number}\n */\n\nfunction min(input) {\n if (!isArray(input)) {\n throw new TypeError('input must be an array');\n }\n\n if (input.length === 0) {\n throw new TypeError('input must not be empty');\n }\n\n var minValue = input[0];\n\n for (var i = 1; i < input.length; i++) {\n if (input[i] < minValue) minValue = input[i];\n }\n\n return minValue;\n}\n\nexport default min;\n","import isArray from 'is-any-array';\n\n/**\n * Computes the maximum of the given values\n * @param {Array} input\n * @return {number}\n */\n\nfunction max(input) {\n if (!isArray(input)) {\n throw new TypeError('input must be an array');\n }\n\n if (input.length === 0) {\n throw new TypeError('input must not be empty');\n }\n\n var maxValue = input[0];\n\n for (var i = 1; i < input.length; i++) {\n if (input[i] > maxValue) maxValue = input[i];\n }\n\n return maxValue;\n}\n\nexport default max;\n","const indent = ' '.repeat(2);\nconst indentData = ' '.repeat(4);\n\nexport function inspectMatrix() {\n return inspectMatrixWithOptions(this);\n}\n\nexport function inspectMatrixWithOptions(matrix, options = {}) {\n const { maxRows = 15, maxColumns = 10, maxNumSize = 8 } = options;\n return `${matrix.constructor.name} {\n${indent}[\n${indentData}${inspectData(matrix, maxRows, maxColumns, maxNumSize)}\n${indent}]\n${indent}rows: ${matrix.rows}\n${indent}columns: ${matrix.columns}\n}`;\n}\n\nfunction inspectData(matrix, maxRows, maxColumns, maxNumSize) {\n const { rows, columns } = matrix;\n const maxI = Math.min(rows, maxRows);\n const maxJ = Math.min(columns, maxColumns);\n const result = [];\n for (let i = 0; i < maxI; i++) {\n let line = [];\n for (let j = 0; j < maxJ; j++) {\n line.push(formatNumber(matrix.get(i, j), maxNumSize));\n }\n result.push(`${line.join(' ')}`);\n }\n if (maxJ !== columns) {\n result[result.length - 1] += ` ... ${columns - maxColumns} more columns`;\n }\n if (maxI !== rows) {\n result.push(`... ${rows - maxRows} more rows`);\n }\n return result.join(`\\n${indentData}`);\n}\n\nfunction formatNumber(num, maxNumSize) {\n const numStr = String(num);\n if (numStr.length <= maxNumSize) {\n return numStr.padEnd(maxNumSize, ' ');\n }\n const precise = num.toPrecision(maxNumSize - 2);\n if (precise.length <= maxNumSize) {\n return precise;\n }\n const exponential = num.toExponential(maxNumSize - 2);\n const eIndex = exponential.indexOf('e');\n const e = exponential.slice(eIndex);\n return exponential.slice(0, maxNumSize - e.length) + e;\n}\n","/**\n * @private\n * Check that a row index is not out of bounds\n * @param {Matrix} matrix\n * @param {number} index\n * @param {boolean} [outer]\n */\nexport function checkRowIndex(matrix, index, outer) {\n let max = outer ? matrix.rows : matrix.rows - 1;\n if (index < 0 || index > max) {\n throw new RangeError('Row index out of range');\n }\n}\n\n/**\n * @private\n * Check that a column index is not out of bounds\n * @param {Matrix} matrix\n * @param {number} index\n * @param {boolean} [outer]\n */\nexport function checkColumnIndex(matrix, index, outer) {\n let max = outer ? matrix.columns : matrix.columns - 1;\n if (index < 0 || index > max) {\n throw new RangeError('Column index out of range');\n }\n}\n\n/**\n * @private\n * Check that the provided vector is an array with the right length\n * @param {Matrix} matrix\n * @param {Array|Matrix} vector\n * @return {Array}\n * @throws {RangeError}\n */\nexport function checkRowVector(matrix, vector) {\n if (vector.to1DArray) {\n vector = vector.to1DArray();\n }\n if (vector.length !== matrix.columns) {\n throw new RangeError(\n 'vector size must be the same as the number of columns',\n );\n }\n return vector;\n}\n\n/**\n * @private\n * Check that the provided vector is an array with the right length\n * @param {Matrix} matrix\n * @param {Array|Matrix} vector\n * @return {Array}\n * @throws {RangeError}\n */\nexport function checkColumnVector(matrix, vector) {\n if (vector.to1DArray) {\n vector = vector.to1DArray();\n }\n if (vector.length !== matrix.rows) {\n throw new RangeError('vector size must be the same as the number of rows');\n }\n return vector;\n}\n\nexport function checkIndices(matrix, rowIndices, columnIndices) {\n return {\n row: checkRowIndices(matrix, rowIndices),\n column: checkColumnIndices(matrix, columnIndices),\n };\n}\n\nexport function checkRowIndices(matrix, rowIndices) {\n if (typeof rowIndices !== 'object') {\n throw new TypeError('unexpected type for row indices');\n }\n\n let rowOut = rowIndices.some((r) => {\n return r < 0 || r >= matrix.rows;\n });\n\n if (rowOut) {\n throw new RangeError('row indices are out of range');\n }\n\n if (!Array.isArray(rowIndices)) rowIndices = Array.from(rowIndices);\n\n return rowIndices;\n}\n\nexport function checkColumnIndices(matrix, columnIndices) {\n if (typeof columnIndices !== 'object') {\n throw new TypeError('unexpected type for column indices');\n }\n\n let columnOut = columnIndices.some((c) => {\n return c < 0 || c >= matrix.columns;\n });\n\n if (columnOut) {\n throw new RangeError('column indices are out of range');\n }\n if (!Array.isArray(columnIndices)) columnIndices = Array.from(columnIndices);\n\n return columnIndices;\n}\n\nexport function checkRange(matrix, startRow, endRow, startColumn, endColumn) {\n if (arguments.length !== 5) {\n throw new RangeError('expected 4 arguments');\n }\n checkNumber('startRow', startRow);\n checkNumber('endRow', endRow);\n checkNumber('startColumn', startColumn);\n checkNumber('endColumn', endColumn);\n if (\n startRow > endRow ||\n startColumn > endColumn ||\n startRow < 0 ||\n startRow >= matrix.rows ||\n endRow < 0 ||\n endRow >= matrix.rows ||\n startColumn < 0 ||\n startColumn >= matrix.columns ||\n endColumn < 0 ||\n endColumn >= matrix.columns\n ) {\n throw new RangeError('Submatrix indices are out of range');\n }\n}\n\nexport function newArray(length, value = 0) {\n let array = [];\n for (let i = 0; i < length; i++) {\n array.push(value);\n }\n return array;\n}\n\nfunction checkNumber(name, value) {\n if (typeof value !== 'number') {\n throw new TypeError(`${name} must be a number`);\n }\n}\n","import rescale from 'ml-array-rescale';\n\nimport { inspectMatrix, inspectMatrixWithOptions } from './inspect';\nimport { installMathOperations } from './mathOperations';\nimport {\n sumByRow,\n sumByColumn,\n sumAll,\n productByRow,\n productByColumn,\n productAll,\n varianceByRow,\n varianceByColumn,\n varianceAll,\n centerByRow,\n centerByColumn,\n centerAll,\n scaleByRow,\n scaleByColumn,\n scaleAll,\n getScaleByRow,\n getScaleByColumn,\n getScaleAll,\n} from './stat';\nimport {\n checkRowVector,\n checkRowIndex,\n checkColumnIndex,\n checkColumnVector,\n checkRange,\n checkIndices,\n} from './util';\n\nexport class AbstractMatrix {\n static from1DArray(newRows, newColumns, newData) {\n let length = newRows * newColumns;\n if (length !== newData.length) {\n throw new RangeError('data length does not match given dimensions');\n }\n let newMatrix = new Matrix(newRows, newColumns);\n for (let row = 0; row < newRows; row++) {\n for (let column = 0; column < newColumns; column++) {\n newMatrix.set(row, column, newData[row * newColumns + column]);\n }\n }\n return newMatrix;\n }\n\n static rowVector(newData) {\n let vector = new Matrix(1, newData.length);\n for (let i = 0; i < newData.length; i++) {\n vector.set(0, i, newData[i]);\n }\n return vector;\n }\n\n static columnVector(newData) {\n let vector = new Matrix(newData.length, 1);\n for (let i = 0; i < newData.length; i++) {\n vector.set(i, 0, newData[i]);\n }\n return vector;\n }\n\n static zeros(rows, columns) {\n return new Matrix(rows, columns);\n }\n\n static ones(rows, columns) {\n return new Matrix(rows, columns).fill(1);\n }\n\n static rand(rows, columns, options = {}) {\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { random = Math.random } = options;\n let matrix = new Matrix(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n matrix.set(i, j, random());\n }\n }\n return matrix;\n }\n\n static randInt(rows, columns, options = {}) {\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { min = 0, max = 1000, random = Math.random } = options;\n if (!Number.isInteger(min)) throw new TypeError('min must be an integer');\n if (!Number.isInteger(max)) throw new TypeError('max must be an integer');\n if (min >= max) throw new RangeError('min must be smaller than max');\n let interval = max - min;\n let matrix = new Matrix(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n let value = min + Math.round(random() * interval);\n matrix.set(i, j, value);\n }\n }\n return matrix;\n }\n\n static eye(rows, columns, value) {\n if (columns === undefined) columns = rows;\n if (value === undefined) value = 1;\n let min = Math.min(rows, columns);\n let matrix = this.zeros(rows, columns);\n for (let i = 0; i < min; i++) {\n matrix.set(i, i, value);\n }\n return matrix;\n }\n\n static diag(data, rows, columns) {\n let l = data.length;\n if (rows === undefined) rows = l;\n if (columns === undefined) columns = rows;\n let min = Math.min(l, rows, columns);\n let matrix = this.zeros(rows, columns);\n for (let i = 0; i < min; i++) {\n matrix.set(i, i, data[i]);\n }\n return matrix;\n }\n\n static min(matrix1, matrix2) {\n matrix1 = this.checkMatrix(matrix1);\n matrix2 = this.checkMatrix(matrix2);\n let rows = matrix1.rows;\n let columns = matrix1.columns;\n let result = new Matrix(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n result.set(i, j, Math.min(matrix1.get(i, j), matrix2.get(i, j)));\n }\n }\n return result;\n }\n\n static max(matrix1, matrix2) {\n matrix1 = this.checkMatrix(matrix1);\n matrix2 = this.checkMatrix(matrix2);\n let rows = matrix1.rows;\n let columns = matrix1.columns;\n let result = new this(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n result.set(i, j, Math.max(matrix1.get(i, j), matrix2.get(i, j)));\n }\n }\n return result;\n }\n\n static checkMatrix(value) {\n return AbstractMatrix.isMatrix(value) ? value : new Matrix(value);\n }\n\n static isMatrix(value) {\n return value != null && value.klass === 'Matrix';\n }\n\n get size() {\n return this.rows * this.columns;\n }\n\n apply(callback) {\n if (typeof callback !== 'function') {\n throw new TypeError('callback must be a function');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n callback.call(this, i, j);\n }\n }\n return this;\n }\n\n to1DArray() {\n let array = [];\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n array.push(this.get(i, j));\n }\n }\n return array;\n }\n\n to2DArray() {\n let copy = [];\n for (let i = 0; i < this.rows; i++) {\n copy.push([]);\n for (let j = 0; j < this.columns; j++) {\n copy[i].push(this.get(i, j));\n }\n }\n return copy;\n }\n\n toJSON() {\n return this.to2DArray();\n }\n\n isRowVector() {\n return this.rows === 1;\n }\n\n isColumnVector() {\n return this.columns === 1;\n }\n\n isVector() {\n return this.rows === 1 || this.columns === 1;\n }\n\n isSquare() {\n return this.rows === this.columns;\n }\n\n isSymmetric() {\n if (this.isSquare()) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j <= i; j++) {\n if (this.get(i, j) !== this.get(j, i)) {\n return false;\n }\n }\n }\n return true;\n }\n return false;\n }\n\n isEchelonForm() {\n let i = 0;\n let j = 0;\n let previousColumn = -1;\n let isEchelonForm = true;\n let checked = false;\n while (i < this.rows && isEchelonForm) {\n j = 0;\n checked = false;\n while (j < this.columns && checked === false) {\n if (this.get(i, j) === 0) {\n j++;\n } else if (this.get(i, j) === 1 && j > previousColumn) {\n checked = true;\n previousColumn = j;\n } else {\n isEchelonForm = false;\n checked = true;\n }\n }\n i++;\n }\n return isEchelonForm;\n }\n\n isReducedEchelonForm() {\n let i = 0;\n let j = 0;\n let previousColumn = -1;\n let isReducedEchelonForm = true;\n let checked = false;\n while (i < this.rows && isReducedEchelonForm) {\n j = 0;\n checked = false;\n while (j < this.columns && checked === false) {\n if (this.get(i, j) === 0) {\n j++;\n } else if (this.get(i, j) === 1 && j > previousColumn) {\n checked = true;\n previousColumn = j;\n } else {\n isReducedEchelonForm = false;\n checked = true;\n }\n }\n for (let k = j + 1; k < this.rows; k++) {\n if (this.get(i, k) !== 0) {\n isReducedEchelonForm = false;\n }\n }\n i++;\n }\n return isReducedEchelonForm;\n }\n\n echelonForm() {\n let result = this.clone();\n let h = 0;\n let k = 0;\n while (h < result.rows && k < result.columns) {\n let iMax = h;\n for (let i = h; i < result.rows; i++) {\n if (result.get(i, k) > result.get(iMax, k)) {\n iMax = i;\n }\n }\n if (result.get(iMax, k) === 0) {\n k++;\n } else {\n result.swapRows(h, iMax);\n let tmp = result.get(h, k);\n for (let j = k; j < result.columns; j++) {\n result.set(h, j, result.get(h, j) / tmp);\n }\n for (let i = h + 1; i < result.rows; i++) {\n let factor = result.get(i, k) / result.get(h, k);\n result.set(i, k, 0);\n for (let j = k + 1; j < result.columns; j++) {\n result.set(i, j, result.get(i, j) - result.get(h, j) * factor);\n }\n }\n h++;\n k++;\n }\n }\n return result;\n }\n\n reducedEchelonForm() {\n let result = this.echelonForm();\n let m = result.columns;\n let n = result.rows;\n let h = n - 1;\n while (h >= 0) {\n if (result.maxRow(h) === 0) {\n h--;\n } else {\n let p = 0;\n let pivot = false;\n while (p < n && pivot === false) {\n if (result.get(h, p) === 1) {\n pivot = true;\n } else {\n p++;\n }\n }\n for (let i = 0; i < h; i++) {\n let factor = result.get(i, p);\n for (let j = p; j < m; j++) {\n let tmp = result.get(i, j) - factor * result.get(h, j);\n result.set(i, j, tmp);\n }\n }\n h--;\n }\n }\n return result;\n }\n\n set() {\n throw new Error('set method is unimplemented');\n }\n\n get() {\n throw new Error('get method is unimplemented');\n }\n\n repeat(options = {}) {\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { rows = 1, columns = 1 } = options;\n if (!Number.isInteger(rows) || rows <= 0) {\n throw new TypeError('rows must be a positive integer');\n }\n if (!Number.isInteger(columns) || columns <= 0) {\n throw new TypeError('columns must be a positive integer');\n }\n let matrix = new Matrix(this.rows * rows, this.columns * columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n matrix.setSubMatrix(this, this.rows * i, this.columns * j);\n }\n }\n return matrix;\n }\n\n fill(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, value);\n }\n }\n return this;\n }\n\n neg() {\n return this.mulS(-1);\n }\n\n getRow(index) {\n checkRowIndex(this, index);\n let row = [];\n for (let i = 0; i < this.columns; i++) {\n row.push(this.get(index, i));\n }\n return row;\n }\n\n getRowVector(index) {\n return Matrix.rowVector(this.getRow(index));\n }\n\n setRow(index, array) {\n checkRowIndex(this, index);\n array = checkRowVector(this, array);\n for (let i = 0; i < this.columns; i++) {\n this.set(index, i, array[i]);\n }\n return this;\n }\n\n swapRows(row1, row2) {\n checkRowIndex(this, row1);\n checkRowIndex(this, row2);\n for (let i = 0; i < this.columns; i++) {\n let temp = this.get(row1, i);\n this.set(row1, i, this.get(row2, i));\n this.set(row2, i, temp);\n }\n return this;\n }\n\n getColumn(index) {\n checkColumnIndex(this, index);\n let column = [];\n for (let i = 0; i < this.rows; i++) {\n column.push(this.get(i, index));\n }\n return column;\n }\n\n getColumnVector(index) {\n return Matrix.columnVector(this.getColumn(index));\n }\n\n setColumn(index, array) {\n checkColumnIndex(this, index);\n array = checkColumnVector(this, array);\n for (let i = 0; i < this.rows; i++) {\n this.set(i, index, array[i]);\n }\n return this;\n }\n\n swapColumns(column1, column2) {\n checkColumnIndex(this, column1);\n checkColumnIndex(this, column2);\n for (let i = 0; i < this.rows; i++) {\n let temp = this.get(i, column1);\n this.set(i, column1, this.get(i, column2));\n this.set(i, column2, temp);\n }\n return this;\n }\n\n addRowVector(vector) {\n vector = checkRowVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) + vector[j]);\n }\n }\n return this;\n }\n\n subRowVector(vector) {\n vector = checkRowVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) - vector[j]);\n }\n }\n return this;\n }\n\n mulRowVector(vector) {\n vector = checkRowVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) * vector[j]);\n }\n }\n return this;\n }\n\n divRowVector(vector) {\n vector = checkRowVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) / vector[j]);\n }\n }\n return this;\n }\n\n addColumnVector(vector) {\n vector = checkColumnVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) + vector[i]);\n }\n }\n return this;\n }\n\n subColumnVector(vector) {\n vector = checkColumnVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) - vector[i]);\n }\n }\n return this;\n }\n\n mulColumnVector(vector) {\n vector = checkColumnVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) * vector[i]);\n }\n }\n return this;\n }\n\n divColumnVector(vector) {\n vector = checkColumnVector(this, vector);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) / vector[i]);\n }\n }\n return this;\n }\n\n mulRow(index, value) {\n checkRowIndex(this, index);\n for (let i = 0; i < this.columns; i++) {\n this.set(index, i, this.get(index, i) * value);\n }\n return this;\n }\n\n mulColumn(index, value) {\n checkColumnIndex(this, index);\n for (let i = 0; i < this.rows; i++) {\n this.set(i, index, this.get(i, index) * value);\n }\n return this;\n }\n\n max() {\n let v = this.get(0, 0);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n if (this.get(i, j) > v) {\n v = this.get(i, j);\n }\n }\n }\n return v;\n }\n\n maxIndex() {\n let v = this.get(0, 0);\n let idx = [0, 0];\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n if (this.get(i, j) > v) {\n v = this.get(i, j);\n idx[0] = i;\n idx[1] = j;\n }\n }\n }\n return idx;\n }\n\n min() {\n let v = this.get(0, 0);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n if (this.get(i, j) < v) {\n v = this.get(i, j);\n }\n }\n }\n return v;\n }\n\n minIndex() {\n let v = this.get(0, 0);\n let idx = [0, 0];\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n if (this.get(i, j) < v) {\n v = this.get(i, j);\n idx[0] = i;\n idx[1] = j;\n }\n }\n }\n return idx;\n }\n\n maxRow(row) {\n checkRowIndex(this, row);\n let v = this.get(row, 0);\n for (let i = 1; i < this.columns; i++) {\n if (this.get(row, i) > v) {\n v = this.get(row, i);\n }\n }\n return v;\n }\n\n maxRowIndex(row) {\n checkRowIndex(this, row);\n let v = this.get(row, 0);\n let idx = [row, 0];\n for (let i = 1; i < this.columns; i++) {\n if (this.get(row, i) > v) {\n v = this.get(row, i);\n idx[1] = i;\n }\n }\n return idx;\n }\n\n minRow(row) {\n checkRowIndex(this, row);\n let v = this.get(row, 0);\n for (let i = 1; i < this.columns; i++) {\n if (this.get(row, i) < v) {\n v = this.get(row, i);\n }\n }\n return v;\n }\n\n minRowIndex(row) {\n checkRowIndex(this, row);\n let v = this.get(row, 0);\n let idx = [row, 0];\n for (let i = 1; i < this.columns; i++) {\n if (this.get(row, i) < v) {\n v = this.get(row, i);\n idx[1] = i;\n }\n }\n return idx;\n }\n\n maxColumn(column) {\n checkColumnIndex(this, column);\n let v = this.get(0, column);\n for (let i = 1; i < this.rows; i++) {\n if (this.get(i, column) > v) {\n v = this.get(i, column);\n }\n }\n return v;\n }\n\n maxColumnIndex(column) {\n checkColumnIndex(this, column);\n let v = this.get(0, column);\n let idx = [0, column];\n for (let i = 1; i < this.rows; i++) {\n if (this.get(i, column) > v) {\n v = this.get(i, column);\n idx[0] = i;\n }\n }\n return idx;\n }\n\n minColumn(column) {\n checkColumnIndex(this, column);\n let v = this.get(0, column);\n for (let i = 1; i < this.rows; i++) {\n if (this.get(i, column) < v) {\n v = this.get(i, column);\n }\n }\n return v;\n }\n\n minColumnIndex(column) {\n checkColumnIndex(this, column);\n let v = this.get(0, column);\n let idx = [0, column];\n for (let i = 1; i < this.rows; i++) {\n if (this.get(i, column) < v) {\n v = this.get(i, column);\n idx[0] = i;\n }\n }\n return idx;\n }\n\n diag() {\n let min = Math.min(this.rows, this.columns);\n let diag = [];\n for (let i = 0; i < min; i++) {\n diag.push(this.get(i, i));\n }\n return diag;\n }\n\n norm(type = 'frobenius') {\n let result = 0;\n if (type === 'max') {\n return this.max();\n } else if (type === 'frobenius') {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n result = result + this.get(i, j) * this.get(i, j);\n }\n }\n return Math.sqrt(result);\n } else {\n throw new RangeError(`unknown norm type: ${type}`);\n }\n }\n\n cumulativeSum() {\n let sum = 0;\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n sum += this.get(i, j);\n this.set(i, j, sum);\n }\n }\n return this;\n }\n\n dot(vector2) {\n if (AbstractMatrix.isMatrix(vector2)) vector2 = vector2.to1DArray();\n let vector1 = this.to1DArray();\n if (vector1.length !== vector2.length) {\n throw new RangeError('vectors do not have the same size');\n }\n let dot = 0;\n for (let i = 0; i < vector1.length; i++) {\n dot += vector1[i] * vector2[i];\n }\n return dot;\n }\n\n mmul(other) {\n other = Matrix.checkMatrix(other);\n\n let m = this.rows;\n let n = this.columns;\n let p = other.columns;\n\n let result = new Matrix(m, p);\n\n let Bcolj = new Float64Array(n);\n for (let j = 0; j < p; j++) {\n for (let k = 0; k < n; k++) {\n Bcolj[k] = other.get(k, j);\n }\n\n for (let i = 0; i < m; i++) {\n let s = 0;\n for (let k = 0; k < n; k++) {\n s += this.get(i, k) * Bcolj[k];\n }\n\n result.set(i, j, s);\n }\n }\n return result;\n }\n\n strassen2x2(other) {\n other = Matrix.checkMatrix(other);\n let result = new Matrix(2, 2);\n const a11 = this.get(0, 0);\n const b11 = other.get(0, 0);\n const a12 = this.get(0, 1);\n const b12 = other.get(0, 1);\n const a21 = this.get(1, 0);\n const b21 = other.get(1, 0);\n const a22 = this.get(1, 1);\n const b22 = other.get(1, 1);\n\n // Compute intermediate values.\n const m1 = (a11 + a22) * (b11 + b22);\n const m2 = (a21 + a22) * b11;\n const m3 = a11 * (b12 - b22);\n const m4 = a22 * (b21 - b11);\n const m5 = (a11 + a12) * b22;\n const m6 = (a21 - a11) * (b11 + b12);\n const m7 = (a12 - a22) * (b21 + b22);\n\n // Combine intermediate values into the output.\n const c00 = m1 + m4 - m5 + m7;\n const c01 = m3 + m5;\n const c10 = m2 + m4;\n const c11 = m1 - m2 + m3 + m6;\n\n result.set(0, 0, c00);\n result.set(0, 1, c01);\n result.set(1, 0, c10);\n result.set(1, 1, c11);\n return result;\n }\n\n strassen3x3(other) {\n other = Matrix.checkMatrix(other);\n let result = new Matrix(3, 3);\n\n const a00 = this.get(0, 0);\n const a01 = this.get(0, 1);\n const a02 = this.get(0, 2);\n const a10 = this.get(1, 0);\n const a11 = this.get(1, 1);\n const a12 = this.get(1, 2);\n const a20 = this.get(2, 0);\n const a21 = this.get(2, 1);\n const a22 = this.get(2, 2);\n\n const b00 = other.get(0, 0);\n const b01 = other.get(0, 1);\n const b02 = other.get(0, 2);\n const b10 = other.get(1, 0);\n const b11 = other.get(1, 1);\n const b12 = other.get(1, 2);\n const b20 = other.get(2, 0);\n const b21 = other.get(2, 1);\n const b22 = other.get(2, 2);\n\n const m1 = (a00 + a01 + a02 - a10 - a11 - a21 - a22) * b11;\n const m2 = (a00 - a10) * (-b01 + b11);\n const m3 = a11 * (-b00 + b01 + b10 - b11 - b12 - b20 + b22);\n const m4 = (-a00 + a10 + a11) * (b00 - b01 + b11);\n const m5 = (a10 + a11) * (-b00 + b01);\n const m6 = a00 * b00;\n const m7 = (-a00 + a20 + a21) * (b00 - b02 + b12);\n const m8 = (-a00 + a20) * (b02 - b12);\n const m9 = (a20 + a21) * (-b00 + b02);\n const m10 = (a00 + a01 + a02 - a11 - a12 - a20 - a21) * b12;\n const m11 = a21 * (-b00 + b02 + b10 - b11 - b12 - b20 + b21);\n const m12 = (-a02 + a21 + a22) * (b11 + b20 - b21);\n const m13 = (a02 - a22) * (b11 - b21);\n const m14 = a02 * b20;\n const m15 = (a21 + a22) * (-b20 + b21);\n const m16 = (-a02 + a11 + a12) * (b12 + b20 - b22);\n const m17 = (a02 - a12) * (b12 - b22);\n const m18 = (a11 + a12) * (-b20 + b22);\n const m19 = a01 * b10;\n const m20 = a12 * b21;\n const m21 = a10 * b02;\n const m22 = a20 * b01;\n const m23 = a22 * b22;\n\n const c00 = m6 + m14 + m19;\n const c01 = m1 + m4 + m5 + m6 + m12 + m14 + m15;\n const c02 = m6 + m7 + m9 + m10 + m14 + m16 + m18;\n const c10 = m2 + m3 + m4 + m6 + m14 + m16 + m17;\n const c11 = m2 + m4 + m5 + m6 + m20;\n const c12 = m14 + m16 + m17 + m18 + m21;\n const c20 = m6 + m7 + m8 + m11 + m12 + m13 + m14;\n const c21 = m12 + m13 + m14 + m15 + m22;\n const c22 = m6 + m7 + m8 + m9 + m23;\n\n result.set(0, 0, c00);\n result.set(0, 1, c01);\n result.set(0, 2, c02);\n result.set(1, 0, c10);\n result.set(1, 1, c11);\n result.set(1, 2, c12);\n result.set(2, 0, c20);\n result.set(2, 1, c21);\n result.set(2, 2, c22);\n return result;\n }\n\n mmulStrassen(y) {\n y = Matrix.checkMatrix(y);\n let x = this.clone();\n let r1 = x.rows;\n let c1 = x.columns;\n let r2 = y.rows;\n let c2 = y.columns;\n if (c1 !== r2) {\n // eslint-disable-next-line no-console\n console.warn(\n `Multiplying ${r1} x ${c1} and ${r2} x ${c2} matrix: dimensions do not match.`,\n );\n }\n\n // Put a matrix into the top left of a matrix of zeros.\n // `rows` and `cols` are the dimensions of the output matrix.\n function embed(mat, rows, cols) {\n let r = mat.rows;\n let c = mat.columns;\n if (r === rows && c === cols) {\n return mat;\n } else {\n let resultat = AbstractMatrix.zeros(rows, cols);\n resultat = resultat.setSubMatrix(mat, 0, 0);\n return resultat;\n }\n }\n\n // Make sure both matrices are the same size.\n // This is exclusively for simplicity:\n // this algorithm can be implemented with matrices of different sizes.\n\n let r = Math.max(r1, r2);\n let c = Math.max(c1, c2);\n x = embed(x, r, c);\n y = embed(y, r, c);\n\n // Our recursive multiplication function.\n function blockMult(a, b, rows, cols) {\n // For small matrices, resort to naive multiplication.\n if (rows <= 512 || cols <= 512) {\n return a.mmul(b); // a is equivalent to this\n }\n\n // Apply dynamic padding.\n if (rows % 2 === 1 && cols % 2 === 1) {\n a = embed(a, rows + 1, cols + 1);\n b = embed(b, rows + 1, cols + 1);\n } else if (rows % 2 === 1) {\n a = embed(a, rows + 1, cols);\n b = embed(b, rows + 1, cols);\n } else if (cols % 2 === 1) {\n a = embed(a, rows, cols + 1);\n b = embed(b, rows, cols + 1);\n }\n\n let halfRows = parseInt(a.rows / 2, 10);\n let halfCols = parseInt(a.columns / 2, 10);\n // Subdivide input matrices.\n let a11 = a.subMatrix(0, halfRows - 1, 0, halfCols - 1);\n let b11 = b.subMatrix(0, halfRows - 1, 0, halfCols - 1);\n\n let a12 = a.subMatrix(0, halfRows - 1, halfCols, a.columns - 1);\n let b12 = b.subMatrix(0, halfRows - 1, halfCols, b.columns - 1);\n\n let a21 = a.subMatrix(halfRows, a.rows - 1, 0, halfCols - 1);\n let b21 = b.subMatrix(halfRows, b.rows - 1, 0, halfCols - 1);\n\n let a22 = a.subMatrix(halfRows, a.rows - 1, halfCols, a.columns - 1);\n let b22 = b.subMatrix(halfRows, b.rows - 1, halfCols, b.columns - 1);\n\n // Compute intermediate values.\n let m1 = blockMult(\n AbstractMatrix.add(a11, a22),\n AbstractMatrix.add(b11, b22),\n halfRows,\n halfCols,\n );\n let m2 = blockMult(AbstractMatrix.add(a21, a22), b11, halfRows, halfCols);\n let m3 = blockMult(a11, AbstractMatrix.sub(b12, b22), halfRows, halfCols);\n let m4 = blockMult(a22, AbstractMatrix.sub(b21, b11), halfRows, halfCols);\n let m5 = blockMult(AbstractMatrix.add(a11, a12), b22, halfRows, halfCols);\n let m6 = blockMult(\n AbstractMatrix.sub(a21, a11),\n AbstractMatrix.add(b11, b12),\n halfRows,\n halfCols,\n );\n let m7 = blockMult(\n AbstractMatrix.sub(a12, a22),\n AbstractMatrix.add(b21, b22),\n halfRows,\n halfCols,\n );\n\n // Combine intermediate values into the output.\n let c11 = AbstractMatrix.add(m1, m4);\n c11.sub(m5);\n c11.add(m7);\n let c12 = AbstractMatrix.add(m3, m5);\n let c21 = AbstractMatrix.add(m2, m4);\n let c22 = AbstractMatrix.sub(m1, m2);\n c22.add(m3);\n c22.add(m6);\n\n // Crop output to the desired size (undo dynamic padding).\n let resultat = AbstractMatrix.zeros(2 * c11.rows, 2 * c11.columns);\n resultat = resultat.setSubMatrix(c11, 0, 0);\n resultat = resultat.setSubMatrix(c12, c11.rows, 0);\n resultat = resultat.setSubMatrix(c21, 0, c11.columns);\n resultat = resultat.setSubMatrix(c22, c11.rows, c11.columns);\n return resultat.subMatrix(0, rows - 1, 0, cols - 1);\n }\n return blockMult(x, y, r, c);\n }\n\n scaleRows(options = {}) {\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { min = 0, max = 1 } = options;\n if (!Number.isFinite(min)) throw new TypeError('min must be a number');\n if (!Number.isFinite(max)) throw new TypeError('max must be a number');\n if (min >= max) throw new RangeError('min must be smaller than max');\n let newMatrix = new Matrix(this.rows, this.columns);\n for (let i = 0; i < this.rows; i++) {\n const row = this.getRow(i);\n rescale(row, { min, max, output: row });\n newMatrix.setRow(i, row);\n }\n return newMatrix;\n }\n\n scaleColumns(options = {}) {\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { min = 0, max = 1 } = options;\n if (!Number.isFinite(min)) throw new TypeError('min must be a number');\n if (!Number.isFinite(max)) throw new TypeError('max must be a number');\n if (min >= max) throw new RangeError('min must be smaller than max');\n let newMatrix = new Matrix(this.rows, this.columns);\n for (let i = 0; i < this.columns; i++) {\n const column = this.getColumn(i);\n rescale(column, {\n min: min,\n max: max,\n output: column,\n });\n newMatrix.setColumn(i, column);\n }\n return newMatrix;\n }\n\n flipRows() {\n const middle = Math.ceil(this.columns / 2);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < middle; j++) {\n let first = this.get(i, j);\n let last = this.get(i, this.columns - 1 - j);\n this.set(i, j, last);\n this.set(i, this.columns - 1 - j, first);\n }\n }\n return this;\n }\n\n flipColumns() {\n const middle = Math.ceil(this.rows / 2);\n for (let j = 0; j < this.columns; j++) {\n for (let i = 0; i < middle; i++) {\n let first = this.get(i, j);\n let last = this.get(this.rows - 1 - i, j);\n this.set(i, j, last);\n this.set(this.rows - 1 - i, j, first);\n }\n }\n return this;\n }\n\n kroneckerProduct(other) {\n other = Matrix.checkMatrix(other);\n\n let m = this.rows;\n let n = this.columns;\n let p = other.rows;\n let q = other.columns;\n\n let result = new Matrix(m * p, n * q);\n for (let i = 0; i < m; i++) {\n for (let j = 0; j < n; j++) {\n for (let k = 0; k < p; k++) {\n for (let l = 0; l < q; l++) {\n result.set(p * i + k, q * j + l, this.get(i, j) * other.get(k, l));\n }\n }\n }\n }\n return result;\n }\n\n transpose() {\n let result = new Matrix(this.columns, this.rows);\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n result.set(j, i, this.get(i, j));\n }\n }\n return result;\n }\n\n sortRows(compareFunction = compareNumbers) {\n for (let i = 0; i < this.rows; i++) {\n this.setRow(i, this.getRow(i).sort(compareFunction));\n }\n return this;\n }\n\n sortColumns(compareFunction = compareNumbers) {\n for (let i = 0; i < this.columns; i++) {\n this.setColumn(i, this.getColumn(i).sort(compareFunction));\n }\n return this;\n }\n\n subMatrix(startRow, endRow, startColumn, endColumn) {\n checkRange(this, startRow, endRow, startColumn, endColumn);\n let newMatrix = new Matrix(\n endRow - startRow + 1,\n endColumn - startColumn + 1,\n );\n for (let i = startRow; i <= endRow; i++) {\n for (let j = startColumn; j <= endColumn; j++) {\n newMatrix.set(i - startRow, j - startColumn, this.get(i, j));\n }\n }\n return newMatrix;\n }\n\n subMatrixRow(indices, startColumn, endColumn) {\n if (startColumn === undefined) startColumn = 0;\n if (endColumn === undefined) endColumn = this.columns - 1;\n if (\n startColumn > endColumn ||\n startColumn < 0 ||\n startColumn >= this.columns ||\n endColumn < 0 ||\n endColumn >= this.columns\n ) {\n throw new RangeError('Argument out of range');\n }\n\n let newMatrix = new Matrix(indices.length, endColumn - startColumn + 1);\n for (let i = 0; i < indices.length; i++) {\n for (let j = startColumn; j <= endColumn; j++) {\n if (indices[i] < 0 || indices[i] >= this.rows) {\n throw new RangeError(`Row index out of range: ${indices[i]}`);\n }\n newMatrix.set(i, j - startColumn, this.get(indices[i], j));\n }\n }\n return newMatrix;\n }\n\n subMatrixColumn(indices, startRow, endRow) {\n if (startRow === undefined) startRow = 0;\n if (endRow === undefined) endRow = this.rows - 1;\n if (\n startRow > endRow ||\n startRow < 0 ||\n startRow >= this.rows ||\n endRow < 0 ||\n endRow >= this.rows\n ) {\n throw new RangeError('Argument out of range');\n }\n\n let newMatrix = new Matrix(endRow - startRow + 1, indices.length);\n for (let i = 0; i < indices.length; i++) {\n for (let j = startRow; j <= endRow; j++) {\n if (indices[i] < 0 || indices[i] >= this.columns) {\n throw new RangeError(`Column index out of range: ${indices[i]}`);\n }\n newMatrix.set(j - startRow, i, this.get(j, indices[i]));\n }\n }\n return newMatrix;\n }\n\n setSubMatrix(matrix, startRow, startColumn) {\n matrix = Matrix.checkMatrix(matrix);\n let endRow = startRow + matrix.rows - 1;\n let endColumn = startColumn + matrix.columns - 1;\n checkRange(this, startRow, endRow, startColumn, endColumn);\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n this.set(startRow + i, startColumn + j, matrix.get(i, j));\n }\n }\n return this;\n }\n\n selection(rowIndices, columnIndices) {\n let indices = checkIndices(this, rowIndices, columnIndices);\n let newMatrix = new Matrix(rowIndices.length, columnIndices.length);\n for (let i = 0; i < indices.row.length; i++) {\n let rowIndex = indices.row[i];\n for (let j = 0; j < indices.column.length; j++) {\n let columnIndex = indices.column[j];\n newMatrix.set(i, j, this.get(rowIndex, columnIndex));\n }\n }\n return newMatrix;\n }\n\n trace() {\n let min = Math.min(this.rows, this.columns);\n let trace = 0;\n for (let i = 0; i < min; i++) {\n trace += this.get(i, i);\n }\n return trace;\n }\n\n clone() {\n let newMatrix = new Matrix(this.rows, this.columns);\n for (let row = 0; row < this.rows; row++) {\n for (let column = 0; column < this.columns; column++) {\n newMatrix.set(row, column, this.get(row, column));\n }\n }\n return newMatrix;\n }\n\n sum(by) {\n switch (by) {\n case 'row':\n return sumByRow(this);\n case 'column':\n return sumByColumn(this);\n case undefined:\n return sumAll(this);\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n product(by) {\n switch (by) {\n case 'row':\n return productByRow(this);\n case 'column':\n return productByColumn(this);\n case undefined:\n return productAll(this);\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n mean(by) {\n const sum = this.sum(by);\n switch (by) {\n case 'row': {\n for (let i = 0; i < this.rows; i++) {\n sum[i] /= this.columns;\n }\n return sum;\n }\n case 'column': {\n for (let i = 0; i < this.columns; i++) {\n sum[i] /= this.rows;\n }\n return sum;\n }\n case undefined:\n return sum / this.size;\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n variance(by, options = {}) {\n if (typeof by === 'object') {\n options = by;\n by = undefined;\n }\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { unbiased = true, mean = this.mean(by) } = options;\n if (typeof unbiased !== 'boolean') {\n throw new TypeError('unbiased must be a boolean');\n }\n switch (by) {\n case 'row': {\n if (!Array.isArray(mean)) {\n throw new TypeError('mean must be an array');\n }\n return varianceByRow(this, unbiased, mean);\n }\n case 'column': {\n if (!Array.isArray(mean)) {\n throw new TypeError('mean must be an array');\n }\n return varianceByColumn(this, unbiased, mean);\n }\n case undefined: {\n if (typeof mean !== 'number') {\n throw new TypeError('mean must be a number');\n }\n return varianceAll(this, unbiased, mean);\n }\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n standardDeviation(by, options) {\n if (typeof by === 'object') {\n options = by;\n by = undefined;\n }\n const variance = this.variance(by, options);\n if (by === undefined) {\n return Math.sqrt(variance);\n } else {\n for (let i = 0; i < variance.length; i++) {\n variance[i] = Math.sqrt(variance[i]);\n }\n return variance;\n }\n }\n\n center(by, options = {}) {\n if (typeof by === 'object') {\n options = by;\n by = undefined;\n }\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n const { center = this.mean(by) } = options;\n switch (by) {\n case 'row': {\n if (!Array.isArray(center)) {\n throw new TypeError('center must be an array');\n }\n centerByRow(this, center);\n return this;\n }\n case 'column': {\n if (!Array.isArray(center)) {\n throw new TypeError('center must be an array');\n }\n centerByColumn(this, center);\n return this;\n }\n case undefined: {\n if (typeof center !== 'number') {\n throw new TypeError('center must be a number');\n }\n centerAll(this, center);\n return this;\n }\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n scale(by, options = {}) {\n if (typeof by === 'object') {\n options = by;\n by = undefined;\n }\n if (typeof options !== 'object') {\n throw new TypeError('options must be an object');\n }\n let scale = options.scale;\n switch (by) {\n case 'row': {\n if (scale === undefined) {\n scale = getScaleByRow(this);\n } else if (!Array.isArray(scale)) {\n throw new TypeError('scale must be an array');\n }\n scaleByRow(this, scale);\n return this;\n }\n case 'column': {\n if (scale === undefined) {\n scale = getScaleByColumn(this);\n } else if (!Array.isArray(scale)) {\n throw new TypeError('scale must be an array');\n }\n scaleByColumn(this, scale);\n return this;\n }\n case undefined: {\n if (scale === undefined) {\n scale = getScaleAll(this);\n } else if (typeof scale !== 'number') {\n throw new TypeError('scale must be a number');\n }\n scaleAll(this, scale);\n return this;\n }\n default:\n throw new Error(`invalid option: ${by}`);\n }\n }\n\n toString(options) {\n return inspectMatrixWithOptions(this, options);\n }\n}\n\nAbstractMatrix.prototype.klass = 'Matrix';\nif (typeof Symbol !== 'undefined') {\n AbstractMatrix.prototype[\n Symbol.for('nodejs.util.inspect.custom')\n ] = inspectMatrix;\n}\n\nfunction compareNumbers(a, b) {\n return a - b;\n}\n\n// Synonyms\nAbstractMatrix.random = AbstractMatrix.rand;\nAbstractMatrix.randomInt = AbstractMatrix.randInt;\nAbstractMatrix.diagonal = AbstractMatrix.diag;\nAbstractMatrix.prototype.diagonal = AbstractMatrix.prototype.diag;\nAbstractMatrix.identity = AbstractMatrix.eye;\nAbstractMatrix.prototype.negate = AbstractMatrix.prototype.neg;\nAbstractMatrix.prototype.tensorProduct =\n AbstractMatrix.prototype.kroneckerProduct;\n\nexport default class Matrix extends AbstractMatrix {\n constructor(nRows, nColumns) {\n super();\n if (Matrix.isMatrix(nRows)) {\n return nRows.clone();\n } else if (Number.isInteger(nRows) && nRows > 0) {\n // Create an empty matrix\n this.data = [];\n if (Number.isInteger(nColumns) && nColumns > 0) {\n for (let i = 0; i < nRows; i++) {\n this.data.push(new Float64Array(nColumns));\n }\n } else {\n throw new TypeError('nColumns must be a positive integer');\n }\n } else if (Array.isArray(nRows)) {\n // Copy the values from the 2D array\n const arrayData = nRows;\n nRows = arrayData.length;\n nColumns = arrayData[0].length;\n if (typeof nColumns !== 'number' || nColumns === 0) {\n throw new TypeError(\n 'Data must be a 2D array with at least one element',\n );\n }\n this.data = [];\n for (let i = 0; i < nRows; i++) {\n if (arrayData[i].length !== nColumns) {\n throw new RangeError('Inconsistent array dimensions');\n }\n this.data.push(Float64Array.from(arrayData[i]));\n }\n } else {\n throw new TypeError(\n 'First argument must be a positive number or an array',\n );\n }\n this.rows = nRows;\n this.columns = nColumns;\n return this;\n }\n\n set(rowIndex, columnIndex, value) {\n this.data[rowIndex][columnIndex] = value;\n return this;\n }\n\n get(rowIndex, columnIndex) {\n return this.data[rowIndex][columnIndex];\n }\n\n removeRow(index) {\n checkRowIndex(this, index);\n if (this.rows === 1) {\n throw new RangeError('A matrix cannot have less than one row');\n }\n this.data.splice(index, 1);\n this.rows -= 1;\n return this;\n }\n\n addRow(index, array) {\n if (array === undefined) {\n array = index;\n index = this.rows;\n }\n checkRowIndex(this, index, true);\n array = Float64Array.from(checkRowVector(this, array, true));\n this.data.splice(index, 0, array);\n this.rows += 1;\n return this;\n }\n\n removeColumn(index) {\n checkColumnIndex(this, index);\n if (this.columns === 1) {\n throw new RangeError('A matrix cannot have less than one column');\n }\n for (let i = 0; i < this.rows; i++) {\n const newRow = new Float64Array(this.columns - 1);\n for (let j = 0; j < index; j++) {\n newRow[j] = this.data[i][j];\n }\n for (let j = index + 1; j < this.columns; j++) {\n newRow[j - 1] = this.data[i][j];\n }\n this.data[i] = newRow;\n }\n this.columns -= 1;\n return this;\n }\n\n addColumn(index, array) {\n if (typeof array === 'undefined') {\n array = index;\n index = this.columns;\n }\n checkColumnIndex(this, index, true);\n array = checkColumnVector(this, array);\n for (let i = 0; i < this.rows; i++) {\n const newRow = new Float64Array(this.columns + 1);\n let j = 0;\n for (; j < index; j++) {\n newRow[j] = this.data[i][j];\n }\n newRow[j++] = array[i];\n for (; j < this.columns + 1; j++) {\n newRow[j] = this.data[i][j - 1];\n }\n this.data[i] = newRow;\n }\n this.columns += 1;\n return this;\n }\n}\n\ninstallMathOperations(AbstractMatrix, Matrix);\n","import { newArray } from './util';\n\nexport function sumByRow(matrix) {\n let sum = newArray(matrix.rows);\n for (let i = 0; i < matrix.rows; ++i) {\n for (let j = 0; j < matrix.columns; ++j) {\n sum[i] += matrix.get(i, j);\n }\n }\n return sum;\n}\n\nexport function sumByColumn(matrix) {\n let sum = newArray(matrix.columns);\n for (let i = 0; i < matrix.rows; ++i) {\n for (let j = 0; j < matrix.columns; ++j) {\n sum[j] += matrix.get(i, j);\n }\n }\n return sum;\n}\n\nexport function sumAll(matrix) {\n let v = 0;\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n v += matrix.get(i, j);\n }\n }\n return v;\n}\n\nexport function productByRow(matrix) {\n let sum = newArray(matrix.rows, 1);\n for (let i = 0; i < matrix.rows; ++i) {\n for (let j = 0; j < matrix.columns; ++j) {\n sum[i] *= matrix.get(i, j);\n }\n }\n return sum;\n}\n\nexport function productByColumn(matrix) {\n let sum = newArray(matrix.columns, 1);\n for (let i = 0; i < matrix.rows; ++i) {\n for (let j = 0; j < matrix.columns; ++j) {\n sum[j] *= matrix.get(i, j);\n }\n }\n return sum;\n}\n\nexport function productAll(matrix) {\n let v = 1;\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n v *= matrix.get(i, j);\n }\n }\n return v;\n}\n\nexport function varianceByRow(matrix, unbiased, mean) {\n const rows = matrix.rows;\n const cols = matrix.columns;\n const variance = [];\n\n for (let i = 0; i < rows; i++) {\n let sum1 = 0;\n let sum2 = 0;\n let x = 0;\n for (let j = 0; j < cols; j++) {\n x = matrix.get(i, j) - mean[i];\n sum1 += x;\n sum2 += x * x;\n }\n if (unbiased) {\n variance.push((sum2 - (sum1 * sum1) / cols) / (cols - 1));\n } else {\n variance.push((sum2 - (sum1 * sum1) / cols) / cols);\n }\n }\n return variance;\n}\n\nexport function varianceByColumn(matrix, unbiased, mean) {\n const rows = matrix.rows;\n const cols = matrix.columns;\n const variance = [];\n\n for (let j = 0; j < cols; j++) {\n let sum1 = 0;\n let sum2 = 0;\n let x = 0;\n for (let i = 0; i < rows; i++) {\n x = matrix.get(i, j) - mean[j];\n sum1 += x;\n sum2 += x * x;\n }\n if (unbiased) {\n variance.push((sum2 - (sum1 * sum1) / rows) / (rows - 1));\n } else {\n variance.push((sum2 - (sum1 * sum1) / rows) / rows);\n }\n }\n return variance;\n}\n\nexport function varianceAll(matrix, unbiased, mean) {\n const rows = matrix.rows;\n const cols = matrix.columns;\n const size = rows * cols;\n\n let sum1 = 0;\n let sum2 = 0;\n let x = 0;\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < cols; j++) {\n x = matrix.get(i, j) - mean;\n sum1 += x;\n sum2 += x * x;\n }\n }\n if (unbiased) {\n return (sum2 - (sum1 * sum1) / size) / (size - 1);\n } else {\n return (sum2 - (sum1 * sum1) / size) / size;\n }\n}\n\nexport function centerByRow(matrix, mean) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) - mean[i]);\n }\n }\n}\n\nexport function centerByColumn(matrix, mean) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) - mean[j]);\n }\n }\n}\n\nexport function centerAll(matrix, mean) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) - mean);\n }\n }\n}\n\nexport function getScaleByRow(matrix) {\n const scale = [];\n for (let i = 0; i < matrix.rows; i++) {\n let sum = 0;\n for (let j = 0; j < matrix.columns; j++) {\n sum += Math.pow(matrix.get(i, j), 2) / (matrix.columns - 1);\n }\n scale.push(Math.sqrt(sum));\n }\n return scale;\n}\n\nexport function scaleByRow(matrix, scale) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) / scale[i]);\n }\n }\n}\n\nexport function getScaleByColumn(matrix) {\n const scale = [];\n for (let j = 0; j < matrix.columns; j++) {\n let sum = 0;\n for (let i = 0; i < matrix.rows; i++) {\n sum += Math.pow(matrix.get(i, j), 2) / (matrix.rows - 1);\n }\n scale.push(Math.sqrt(sum));\n }\n return scale;\n}\n\nexport function scaleByColumn(matrix, scale) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) / scale[j]);\n }\n }\n}\n\nexport function getScaleAll(matrix) {\n const divider = matrix.size - 1;\n let sum = 0;\n for (let j = 0; j < matrix.columns; j++) {\n for (let i = 0; i < matrix.rows; i++) {\n sum += Math.pow(matrix.get(i, j), 2) / divider;\n }\n }\n return Math.sqrt(sum);\n}\n\nexport function scaleAll(matrix, scale) {\n for (let i = 0; i < matrix.rows; i++) {\n for (let j = 0; j < matrix.columns; j++) {\n matrix.set(i, j, matrix.get(i, j) / scale);\n }\n }\n}\n","export function installMathOperations(AbstractMatrix, Matrix) {\n AbstractMatrix.prototype.add = function add(value) {\n if (typeof value === 'number') return this.addS(value);\n return this.addM(value);\n };\n\n AbstractMatrix.prototype.addS = function addS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) + value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.addM = function addM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) + matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.add = function add(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.add(value);\n };\n\n AbstractMatrix.prototype.sub = function sub(value) {\n if (typeof value === 'number') return this.subS(value);\n return this.subM(value);\n };\n\n AbstractMatrix.prototype.subS = function subS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) - value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.subM = function subM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) - matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.sub = function sub(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.sub(value);\n };\n AbstractMatrix.prototype.subtract = AbstractMatrix.prototype.sub;\n AbstractMatrix.prototype.subtractS = AbstractMatrix.prototype.subS;\n AbstractMatrix.prototype.subtractM = AbstractMatrix.prototype.subM;\n AbstractMatrix.subtract = AbstractMatrix.sub;\n\n AbstractMatrix.prototype.mul = function mul(value) {\n if (typeof value === 'number') return this.mulS(value);\n return this.mulM(value);\n };\n\n AbstractMatrix.prototype.mulS = function mulS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) * value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.mulM = function mulM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) * matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.mul = function mul(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.mul(value);\n };\n AbstractMatrix.prototype.multiply = AbstractMatrix.prototype.mul;\n AbstractMatrix.prototype.multiplyS = AbstractMatrix.prototype.mulS;\n AbstractMatrix.prototype.multiplyM = AbstractMatrix.prototype.mulM;\n AbstractMatrix.multiply = AbstractMatrix.mul;\n\n AbstractMatrix.prototype.div = function div(value) {\n if (typeof value === 'number') return this.divS(value);\n return this.divM(value);\n };\n\n AbstractMatrix.prototype.divS = function divS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) / value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.divM = function divM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) / matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.div = function div(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.div(value);\n };\n AbstractMatrix.prototype.divide = AbstractMatrix.prototype.div;\n AbstractMatrix.prototype.divideS = AbstractMatrix.prototype.divS;\n AbstractMatrix.prototype.divideM = AbstractMatrix.prototype.divM;\n AbstractMatrix.divide = AbstractMatrix.div;\n\n AbstractMatrix.prototype.mod = function mod(value) {\n if (typeof value === 'number') return this.modS(value);\n return this.modM(value);\n };\n\n AbstractMatrix.prototype.modS = function modS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) % value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.modM = function modM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) % matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.mod = function mod(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.mod(value);\n };\n AbstractMatrix.prototype.modulus = AbstractMatrix.prototype.mod;\n AbstractMatrix.prototype.modulusS = AbstractMatrix.prototype.modS;\n AbstractMatrix.prototype.modulusM = AbstractMatrix.prototype.modM;\n AbstractMatrix.modulus = AbstractMatrix.mod;\n\n AbstractMatrix.prototype.and = function and(value) {\n if (typeof value === 'number') return this.andS(value);\n return this.andM(value);\n };\n\n AbstractMatrix.prototype.andS = function andS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) & value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.andM = function andM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) & matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.and = function and(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.and(value);\n };\n\n AbstractMatrix.prototype.or = function or(value) {\n if (typeof value === 'number') return this.orS(value);\n return this.orM(value);\n };\n\n AbstractMatrix.prototype.orS = function orS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) | value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.orM = function orM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) | matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.or = function or(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.or(value);\n };\n\n AbstractMatrix.prototype.xor = function xor(value) {\n if (typeof value === 'number') return this.xorS(value);\n return this.xorM(value);\n };\n\n AbstractMatrix.prototype.xorS = function xorS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) ^ value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.xorM = function xorM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) ^ matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.xor = function xor(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.xor(value);\n };\n\n AbstractMatrix.prototype.leftShift = function leftShift(value) {\n if (typeof value === 'number') return this.leftShiftS(value);\n return this.leftShiftM(value);\n };\n\n AbstractMatrix.prototype.leftShiftS = function leftShiftS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) << value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.leftShiftM = function leftShiftM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) << matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.leftShift = function leftShift(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.leftShift(value);\n };\n\n AbstractMatrix.prototype.signPropagatingRightShift = function signPropagatingRightShift(value) {\n if (typeof value === 'number') return this.signPropagatingRightShiftS(value);\n return this.signPropagatingRightShiftM(value);\n };\n\n AbstractMatrix.prototype.signPropagatingRightShiftS = function signPropagatingRightShiftS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) >> value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.signPropagatingRightShiftM = function signPropagatingRightShiftM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) >> matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.signPropagatingRightShift = function signPropagatingRightShift(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.signPropagatingRightShift(value);\n };\n\n AbstractMatrix.prototype.rightShift = function rightShift(value) {\n if (typeof value === 'number') return this.rightShiftS(value);\n return this.rightShiftM(value);\n };\n\n AbstractMatrix.prototype.rightShiftS = function rightShiftS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) >>> value);\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.rightShiftM = function rightShiftM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) >>> matrix.get(i, j));\n }\n }\n return this;\n };\n\n AbstractMatrix.rightShift = function rightShift(matrix, value) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.rightShift(value);\n };\n AbstractMatrix.prototype.zeroFillRightShift = AbstractMatrix.prototype.rightShift;\n AbstractMatrix.prototype.zeroFillRightShiftS = AbstractMatrix.prototype.rightShiftS;\n AbstractMatrix.prototype.zeroFillRightShiftM = AbstractMatrix.prototype.rightShiftM;\n AbstractMatrix.zeroFillRightShift = AbstractMatrix.rightShift;\n\n AbstractMatrix.prototype.not = function not() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, ~(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.not = function not(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.not();\n };\n\n AbstractMatrix.prototype.abs = function abs() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.abs(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.abs = function abs(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.abs();\n };\n\n AbstractMatrix.prototype.acos = function acos() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.acos(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.acos = function acos(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.acos();\n };\n\n AbstractMatrix.prototype.acosh = function acosh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.acosh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.acosh = function acosh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.acosh();\n };\n\n AbstractMatrix.prototype.asin = function asin() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.asin(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.asin = function asin(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.asin();\n };\n\n AbstractMatrix.prototype.asinh = function asinh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.asinh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.asinh = function asinh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.asinh();\n };\n\n AbstractMatrix.prototype.atan = function atan() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.atan(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.atan = function atan(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.atan();\n };\n\n AbstractMatrix.prototype.atanh = function atanh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.atanh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.atanh = function atanh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.atanh();\n };\n\n AbstractMatrix.prototype.cbrt = function cbrt() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.cbrt(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.cbrt = function cbrt(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.cbrt();\n };\n\n AbstractMatrix.prototype.ceil = function ceil() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.ceil(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.ceil = function ceil(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.ceil();\n };\n\n AbstractMatrix.prototype.clz32 = function clz32() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.clz32(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.clz32 = function clz32(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.clz32();\n };\n\n AbstractMatrix.prototype.cos = function cos() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.cos(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.cos = function cos(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.cos();\n };\n\n AbstractMatrix.prototype.cosh = function cosh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.cosh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.cosh = function cosh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.cosh();\n };\n\n AbstractMatrix.prototype.exp = function exp() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.exp(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.exp = function exp(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.exp();\n };\n\n AbstractMatrix.prototype.expm1 = function expm1() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.expm1(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.expm1 = function expm1(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.expm1();\n };\n\n AbstractMatrix.prototype.floor = function floor() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.floor(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.floor = function floor(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.floor();\n };\n\n AbstractMatrix.prototype.fround = function fround() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.fround(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.fround = function fround(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.fround();\n };\n\n AbstractMatrix.prototype.log = function log() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.log(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.log = function log(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.log();\n };\n\n AbstractMatrix.prototype.log1p = function log1p() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.log1p(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.log1p = function log1p(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.log1p();\n };\n\n AbstractMatrix.prototype.log10 = function log10() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.log10(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.log10 = function log10(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.log10();\n };\n\n AbstractMatrix.prototype.log2 = function log2() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.log2(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.log2 = function log2(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.log2();\n };\n\n AbstractMatrix.prototype.round = function round() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.round(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.round = function round(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.round();\n };\n\n AbstractMatrix.prototype.sign = function sign() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.sign(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.sign = function sign(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.sign();\n };\n\n AbstractMatrix.prototype.sin = function sin() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.sin(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.sin = function sin(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.sin();\n };\n\n AbstractMatrix.prototype.sinh = function sinh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.sinh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.sinh = function sinh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.sinh();\n };\n\n AbstractMatrix.prototype.sqrt = function sqrt() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.sqrt(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.sqrt = function sqrt(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.sqrt();\n };\n\n AbstractMatrix.prototype.tan = function tan() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.tan(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.tan = function tan(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.tan();\n };\n\n AbstractMatrix.prototype.tanh = function tanh() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.tanh(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.tanh = function tanh(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.tanh();\n };\n\n AbstractMatrix.prototype.trunc = function trunc() {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.trunc(this.get(i, j)));\n }\n }\n return this;\n };\n\n AbstractMatrix.trunc = function trunc(matrix) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.trunc();\n };\n\n AbstractMatrix.pow = function pow(matrix, arg0) {\n const newMatrix = new Matrix(matrix);\n return newMatrix.pow(arg0);\n };\n\n AbstractMatrix.prototype.pow = function pow(value) {\n if (typeof value === 'number') return this.powS(value);\n return this.powM(value);\n };\n\n AbstractMatrix.prototype.powS = function powS(value) {\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.pow(this.get(i, j), value));\n }\n }\n return this;\n };\n\n AbstractMatrix.prototype.powM = function powM(matrix) {\n matrix = Matrix.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (let i = 0; i < this.rows; i++) {\n for (let j = 0; j < this.columns; j++) {\n this.set(i, j, Math.pow(this.get(i, j), matrix.get(i, j)));\n }\n }\n return this;\n };\n}\n","import { AbstractMatrix } from '../matrix';\n\nexport default class WrapperMatrix2D extends AbstractMatrix {\n constructor(data) {\n super();\n this.data = data;\n this.rows = data.length;\n this.columns = data[0].length;\n }\n\n set(rowIndex, columnIndex, value) {\n this.data[rowIndex][columnIndex] = value;\n return this;\n }\n\n get(rowIndex, columnIndex) {\n return this.data[rowIndex][columnIndex];\n }\n}\n","import Matrix from '../matrix';\nimport WrapperMatrix2D from '../wrap/WrapperMatrix2D';\n\nexport default class LuDecomposition {\n constructor(matrix) {\n matrix = WrapperMatrix2D.checkMatrix(matrix);\n\n let lu = matrix.clone();\n let rows = lu.rows;\n let columns = lu.columns;\n let pivotVector = new Float64Array(rows);\n let pivotSign = 1;\n let i, j, k, p, s, t, v;\n let LUcolj, kmax;\n\n for (i = 0; i < rows; i++) {\n pivotVector[i] = i;\n }\n\n LUcolj = new Float64Array(rows);\n\n for (j = 0; j < columns; j++) {\n for (i = 0; i < rows; i++) {\n LUcolj[i] = lu.get(i, j);\n }\n\n for (i = 0; i < rows; i++) {\n kmax = Math.min(i, j);\n s = 0;\n for (k = 0; k < kmax; k++) {\n s += lu.get(i, k) * LUcolj[k];\n }\n LUcolj[i] -= s;\n lu.set(i, j, LUcolj[i]);\n }\n\n p = j;\n for (i = j + 1; i < rows; i++) {\n if (Math.abs(LUcolj[i]) > Math.abs(LUcolj[p])) {\n p = i;\n }\n }\n\n if (p !== j) {\n for (k = 0; k < columns; k++) {\n t = lu.get(p, k);\n lu.set(p, k, lu.get(j, k));\n lu.set(j, k, t);\n }\n\n v = pivotVector[p];\n pivotVector[p] = pivotVector[j];\n pivotVector[j] = v;\n\n pivotSign = -pivotSign;\n }\n\n if (j < rows && lu.get(j, j) !== 0) {\n for (i = j + 1; i < rows; i++) {\n lu.set(i, j, lu.get(i, j) / lu.get(j, j));\n }\n }\n }\n\n this.LU = lu;\n this.pivotVector = pivotVector;\n this.pivotSign = pivotSign;\n }\n\n isSingular() {\n let data = this.LU;\n let col = data.columns;\n for (let j = 0; j < col; j++) {\n if (data.get(j, j) === 0) {\n return true;\n }\n }\n return false;\n }\n\n solve(value) {\n value = Matrix.checkMatrix(value);\n\n let lu = this.LU;\n let rows = lu.rows;\n\n if (rows !== value.rows) {\n throw new Error('Invalid matrix dimensions');\n }\n if (this.isSingular()) {\n throw new Error('LU matrix is singular');\n }\n\n let count = value.columns;\n let X = value.subMatrixRow(this.pivotVector, 0, count - 1);\n let columns = lu.columns;\n let i, j, k;\n\n for (k = 0; k < columns; k++) {\n for (i = k + 1; i < columns; i++) {\n for (j = 0; j < count; j++) {\n X.set(i, j, X.get(i, j) - X.get(k, j) * lu.get(i, k));\n }\n }\n }\n for (k = columns - 1; k >= 0; k--) {\n for (j = 0; j < count; j++) {\n X.set(k, j, X.get(k, j) / lu.get(k, k));\n }\n for (i = 0; i < k; i++) {\n for (j = 0; j < count; j++) {\n X.set(i, j, X.get(i, j) - X.get(k, j) * lu.get(i, k));\n }\n }\n }\n return X;\n }\n\n get determinant() {\n let data = this.LU;\n if (!data.isSquare()) {\n throw new Error('Matrix must be square');\n }\n let determinant = this.pivotSign;\n let col = data.columns;\n for (let j = 0; j < col; j++) {\n determinant *= data.get(j, j);\n }\n return determinant;\n }\n\n get lowerTriangularMatrix() {\n let data = this.LU;\n let rows = data.rows;\n let columns = data.columns;\n let X = new Matrix(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n if (i > j) {\n X.set(i, j, data.get(i, j));\n } else if (i === j) {\n X.set(i, j, 1);\n } else {\n X.set(i, j, 0);\n }\n }\n }\n return X;\n }\n\n get upperTriangularMatrix() {\n let data = this.LU;\n let rows = data.rows;\n let columns = data.columns;\n let X = new Matrix(rows, columns);\n for (let i = 0; i < rows; i++) {\n for (let j = 0; j < columns; j++) {\n if (i <= j) {\n X.set(i, j, data.get(i, j));\n } else {\n X.set(i, j, 0);\n }\n }\n }\n return X;\n }\n\n get pivotPermutationVector() {\n return Array.from(this.pivotVector);\n }\n}\n","export function hypotenuse(a, b) {\n let r = 0;\n if (Math.abs(a) > Math.abs(b)) {\n r = b / a;\n return Math.abs(a) * Math.sqrt(1 + r * r);\n }\n if (b !== 0) {\n r = a / b;\n return Math.abs(b) * Math.sqrt(1 + r * r);\n }\n return 0;\n}\n","import Matrix from '../matrix';\nimport WrapperMatrix2D from '../wrap/WrapperMatrix2D';\n\nimport { hypotenuse } from './util';\n\nexport default class QrDecomposition {\n constructor(value) {\n value = WrapperMatrix2D.checkMatrix(value);\n\n let qr = value.clone();\n let m = value.rows;\n let n = value.columns;\n let rdiag = new Float64Array(n);\n let i, j, k, s;\n\n for (k = 0; k < n; k++) {\n let nrm = 0;\n for (i = k; i < m; i++) {\n nrm = hypotenuse(nrm, qr.get(i, k));\n }\n if (nrm !== 0) {\n if (qr.get(k, k) < 0) {\n nrm = -nrm;\n }\n for (i = k; i < m; i++) {\n qr.set(i, k, qr.get(i, k) / nrm);\n }\n qr.set(k, k, qr.get(k, k) + 1);\n for (j = k + 1; j < n; j++) {\n s = 0;\n for (i = k; i < m; i++) {\n s += qr.get(i, k) * qr.get(i, j);\n }\n s = -s / qr.get(k, k);\n for (i = k; i < m; i++) {\n qr.set(i, j, qr.get(i, j) + s * qr.get(i, k));\n }\n }\n }\n rdiag[k] = -nrm;\n }\n\n this.QR = qr;\n this.Rdiag = rdiag;\n }\n\n solve(value) {\n value = Matrix.checkMatrix(value);\n\n let qr = this.QR;\n let m = qr.rows;\n\n if (value.rows !== m) {\n throw new Error('Matrix row dimensions must agree');\n }\n if (!this.isFullRank()) {\n throw new Error('Matrix is rank deficient');\n }\n\n let count = value.columns;\n let X = value.clone();\n let n = qr.columns;\n let i, j, k, s;\n\n for (k = 0; k < n; k++) {\n for (j = 0; j < count; j++) {\n s = 0;\n for (i = k; i < m; i++) {\n s += qr.get(i, k) * X.get(i, j);\n }\n s = -s / qr.get(k, k);\n for (i = k; i < m; i++) {\n X.set(i, j, X.get(i, j) + s * qr.get(i, k));\n }\n }\n }\n for (k = n - 1; k >= 0; k--) {\n for (j = 0; j < count; j++) {\n X.set(k, j, X.get(k, j) / this.Rdiag[k]);\n }\n for (i = 0; i < k; i++) {\n for (j = 0; j < count; j++) {\n X.set(i, j, X.get(i, j) - X.get(k, j) * qr.get(i, k));\n }\n }\n }\n\n return X.subMatrix(0, n - 1, 0, count - 1);\n }\n\n isFullRank() {\n let columns = this.QR.columns;\n for (let i = 0; i < columns; i++) {\n if (this.Rdiag[i] === 0) {\n return false;\n }\n }\n return true;\n }\n\n get upperTriangularMatrix() {\n let qr = this.QR;\n let n = qr.columns;\n let X = new Matrix(n, n);\n let i, j;\n for (i = 0; i < n; i++) {\n for (j = 0; j < n; j++) {\n if (i < j) {\n X.set(i, j, qr.get(i, j));\n } else if (i === j) {\n X.set(i, j, this.Rdiag[i]);\n } else {\n X.set(i, j, 0);\n }\n }\n }\n return X;\n }\n\n get orthogonalMatrix() {\n let qr = this.QR;\n let rows = qr.rows;\n let columns = qr.columns;\n let X = new Matrix(rows, columns);\n let i, j, k, s;\n\n for (k = columns - 1; k >= 0; k--) {\n for (i = 0; i < rows; i++) {\n X.set(i, k, 0);\n }\n X.set(k, k, 1);\n for (j = k; j < columns; j++) {\n if (qr.get(k, k) !== 0) {\n s = 0;\n for (i = k; i < rows; i++) {\n s += qr.get(i, k) * X.get(i, j);\n }\n\n s = -s / qr.get(k, k);\n\n for (i = k; i < rows; i++) {\n X.set(i, j, X.get(i, j) + s * qr.get(i, k));\n }\n }\n }\n }\n return X;\n }\n}\n","import Matrix from '../matrix';\nimport WrapperMatrix2D from '../wrap/WrapperMatrix2D';\n\nimport { hypotenuse } from './util';\n\nexport default class SingularValueDecomposition {\n constructor(value, options = {}) {\n value = WrapperMatrix2D.checkMatrix(value);\n\n let m = value.rows;\n let n = value.columns;\n\n const {\n computeLeftSingularVectors = true,\n computeRightSingularVectors = true,\n autoTranspose = false,\n } = options;\n\n let wantu = Boolean(computeLeftSingularVectors);\n let wantv = Boolean(computeRightSingularVectors);\n\n let swapped = false;\n let a;\n if (m < n) {\n if (!autoTranspose) {\n a = value.clone();\n // eslint-disable-next-line no-console\n console.warn(\n 'Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose',\n );\n } else {\n a = value.transpose();\n m = a.rows;\n n = a.columns;\n swapped = true;\n let aux = wantu;\n wantu = wantv;\n wantv = aux;\n }\n } else {\n a = value.clone();\n }\n\n let nu = Math.min(m, n);\n let ni = Math.min(m + 1, n);\n let s = new Float64Array(ni);\n let U = new Matrix(m, nu);\n let V = new Matrix(n, n);\n\n let e = new Float64Array(n);\n let work = new Float64Array(m);\n\n let si = new Float64Array(ni);\n for (let i = 0; i < ni; i++) si[i] = i;\n\n let nct = Math.min(m - 1, n);\n let nrt = Math.max(0, Math.min(n - 2, m));\n let mrc = Math.max(nct, nrt);\n\n for (let k = 0; k < mrc; k++) {\n if (k < nct) {\n s[k] = 0;\n for (let i = k; i < m; i++) {\n s[k] = hypotenuse(s[k], a.get(i, k));\n }\n if (s[k] !== 0) {\n if (a.get(k, k) < 0) {\n s[k] = -s[k];\n }\n for (let i = k; i < m; i++) {\n a.set(i, k, a.get(i, k) / s[k]);\n }\n a.set(k, k, a.get(k, k) + 1);\n }\n s[k] = -s[k];\n }\n\n for (let j = k + 1; j < n; j++) {\n if (k < nct && s[k] !== 0) {\n let t = 0;\n for (let i = k; i < m; i++) {\n t += a.get(i, k) * a.get(i, j);\n }\n t = -t / a.get(k, k);\n for (let i = k; i < m; i++) {\n a.set(i, j, a.get(i, j) + t * a.get(i, k));\n }\n }\n e[j] = a.get(k, j);\n }\n\n if (wantu && k < nct) {\n for (let i = k; i < m; i++) {\n U.set(i, k, a.get(i, k));\n }\n }\n\n if (k < nrt) {\n e[k] = 0;\n for (let i = k + 1; i < n; i++) {\n e[k] = hypotenuse(e[k], e[i]);\n }\n if (e[k] !== 0) {\n if (e[k + 1] < 0) {\n e[k] = 0 - e[k];\n }\n for (let i = k + 1; i < n; i++) {\n e[i] /= e[k];\n }\n e[k + 1] += 1;\n }\n e[k] = -e[k];\n if (k + 1 < m && e[k] !== 0) {\n for (let i = k + 1; i < m; i++) {\n work[i] = 0;\n }\n for (let i = k + 1; i < m; i++) {\n for (let j = k + 1; j < n; j++) {\n work[i] += e[j] * a.get(i, j);\n }\n }\n for (let j = k + 1; j < n; j++) {\n let t = -e[j] / e[k + 1];\n for (let i = k + 1; i < m; i++) {\n a.set(i, j, a.get(i, j) + t * work[i]);\n }\n }\n }\n if (wantv) {\n for (let i = k + 1; i < n; i++) {\n V.set(i, k, e[i]);\n }\n }\n }\n }\n\n let p = Math.min(n, m + 1);\n if (nct < n) {\n s[nct] = a.get(nct, nct);\n }\n if (m < p) {\n s[p - 1] = 0;\n }\n if (nrt + 1 < p) {\n e[nrt] = a.get(nrt, p - 1);\n }\n e[p - 1] = 0;\n\n if (wantu) {\n for (let j = nct; j < nu; j++) {\n for (let i = 0; i < m; i++) {\n U.set(i, j, 0);\n }\n U.set(j, j, 1);\n }\n for (let k = nct - 1; k >= 0; k--) {\n if (s[k] !== 0) {\n for (let j = k + 1; j < nu; j++) {\n let t = 0;\n for (let i = k; i < m; i++) {\n t += U.get(i, k) * U.get(i, j);\n }\n t = -t / U.get(k, k);\n for (let i = k; i < m; i++) {\n U.set(i, j, U.get(i, j) + t * U.get(i, k));\n }\n }\n for (let i = k; i < m; i++) {\n U.set(i, k, -U.get(i, k));\n }\n U.set(k, k, 1 + U.get(k, k));\n for (let i = 0; i < k - 1; i++) {\n U.set(i, k, 0);\n }\n } else {\n for (let i = 0; i < m; i++) {\n U.set(i, k, 0);\n }\n U.set(k, k, 1);\n }\n }\n }\n\n if (wantv) {\n for (let k = n - 1; k >= 0; k--) {\n if (k < nrt && e[k] !== 0) {\n for (let j = k + 1; j < n; j++) {\n let t = 0;\n for (let i = k + 1; i < n; i++) {\n t += V.get(i, k) * V.get(i, j);\n }\n t = -t / V.get(k + 1, k);\n for (let i = k + 1; i < n; i++) {\n V.set(i, j, V.get(i, j) + t * V.get(i, k));\n }\n }\n }\n for (let i = 0; i < n; i++) {\n V.set(i, k, 0);\n }\n V.set(k, k, 1);\n }\n }\n\n let pp = p - 1;\n let iter = 0;\n let eps = Number.EPSILON;\n while (p > 0) {\n let k, kase;\n for (k = p - 2; k >= -1; k--) {\n if (k === -1) {\n break;\n }\n const alpha =\n Number.MIN_VALUE + eps * Math.abs(s[k] + Math.abs(s[k + 1]));\n if (Math.abs(e[k]) <= alpha || Number.isNaN(e[k])) {\n e[k] = 0;\n break;\n }\n }\n if (k === p - 2) {\n kase = 4;\n } else {\n let ks;\n for (ks = p - 1; ks >= k; ks--) {\n if (ks === k) {\n break;\n }\n let t =\n (ks !== p ? Math.abs(e[ks]) : 0) +\n (ks !== k + 1 ? Math.abs(e[ks - 1]) : 0);\n if (Math.abs(s[ks]) <= eps * t) {\n s[ks] = 0;\n break;\n }\n }\n if (ks === k) {\n kase = 3;\n } else if (ks === p - 1) {\n kase = 1;\n } else {\n kase = 2;\n k = ks;\n }\n }\n\n k++;\n\n switch (kase) {\n case 1: {\n let f = e[p - 2];\n e[p - 2] = 0;\n for (let j = p - 2; j >= k; j--) {\n let t = hypotenuse(s[j], f);\n let cs = s[j] / t;\n let sn = f / t;\n s[j] = t;\n if (j !== k) {\n f = -sn * e[j - 1];\n e[j - 1] = cs * e[j - 1];\n }\n if (wantv) {\n for (let i = 0; i < n; i++) {\n t = cs * V.get(i, j) + sn * V.get(i, p - 1);\n V.set(i, p - 1, -sn * V.get(i, j) + cs * V.get(i, p - 1));\n V.set(i, j, t);\n }\n }\n }\n break;\n }\n case 2: {\n let f = e[k - 1];\n e[k - 1] = 0;\n for (let j = k; j < p; j++) {\n let t = hypotenuse(s[j], f);\n let cs = s[j] / t;\n let sn = f / t;\n s[j] = t;\n f = -sn * e[j];\n e[j] = cs * e[j];\n if (wantu) {\n for (let i = 0; i < m; i++) {\n t = cs * U.get(i, j) + sn * U.get(i, k - 1);\n U.set(i, k - 1, -sn * U.get(i, j) + cs * U.get(i, k - 1));\n U.set(i, j, t);\n }\n }\n }\n break;\n }\n case 3: {\n const scale = Math.max(\n Math.abs(s[p - 1]),\n Math.abs(s[p - 2]),\n Math.abs(e[p - 2]),\n Math.abs(s[k]),\n Math.abs(e[k]),\n );\n const sp = s[p - 1] / scale;\n const spm1 = s[p - 2] / scale;\n const epm1 = e[p - 2] / scale;\n const sk = s[k] / scale;\n const ek = e[k] / scale;\n const b = ((spm1 + sp) * (spm1 - sp) + epm1 * epm1) / 2;\n const c = sp * epm1 * (sp * epm1);\n let shift = 0;\n if (b !== 0 || c !== 0) {\n if (b < 0) {\n shift = 0 - Math.sqrt(b * b + c);\n } else {\n shift = Math.sqrt(b * b + c);\n }\n shift = c / (b + shift);\n }\n let f = (sk + sp) * (sk - sp) + shift;\n let g = sk * ek;\n for (let j = k; j < p - 1; j++) {\n let t = hypotenuse(f, g);\n if (t === 0) t = Number.MIN_VALUE;\n let cs = f / t;\n let sn = g / t;\n if (j !== k) {\n e[j - 1] = t;\n }\n f = cs * s[j] + sn * e[j];\n e[j] = cs * e[j] - sn * s[j];\n g = sn * s[j + 1];\n s[j + 1] = cs * s[j + 1];\n if (wantv) {\n for (let i = 0; i < n; i++) {\n t = cs * V.get(i, j) + sn * V.get(i, j + 1);\n V.set(i, j + 1, -sn * V.get(i, j) + cs * V.get(i, j + 1));\n V.set(i, j, t);\n }\n }\n t = hypotenuse(f, g);\n if (t === 0) t = Number.MIN_VALUE;\n cs = f / t;\n sn = g / t;\n s[j] = t;\n f = cs * e[j] + sn * s[j + 1];\n s[j + 1] = -sn * e[j] + cs * s[j + 1];\n g = sn * e[j + 1];\n e[j + 1] = cs * e[j + 1];\n if (wantu && j < m - 1) {\n for (let i = 0; i < m; i++) {\n t = cs * U.get(i, j) + sn * U.get(i, j + 1);\n U.set(i, j + 1, -sn * U.get(i, j) + cs * U.get(i, j + 1));\n U.set(i, j, t);\n }\n }\n }\n e[p - 2] = f;\n iter = iter + 1;\n break;\n }\n case 4: {\n if (s[k] <= 0) {\n s[k] = s[k] < 0 ? -s[k] : 0;\n if (wantv) {\n for (let i = 0; i <= pp; i++) {\n V.set(i, k, -V.get(i, k));\n }\n }\n }\n while (k < pp) {\n if (s[k] >= s[k + 1]) {\n break;\n }\n let t = s[k];\n s[k] = s[k + 1];\n s[k + 1] = t;\n if (wantv && k < n - 1) {\n for (let i = 0; i < n; i++) {\n t = V.get(i, k + 1);\n V.set(i, k + 1, V.get(i, k));\n V.set(i, k, t);\n }\n }\n if (wantu && k < m - 1) {\n for (let i = 0; i < m; i++) {\n t = U.get(i, k + 1);\n U.set(i, k + 1, U.get(i, k));\n U.set(i, k, t);\n }\n }\n k++;\n }\n iter = 0;\n p--;\n break;\n }\n // no default\n }\n }\n\n if (swapped) {\n let tmp = V;\n V = U;\n U = tmp;\n }\n\n this.m = m;\n this.n = n;\n this.s = s;\n this.U = U;\n this.V = V;\n }\n\n solve(value) {\n let Y = value;\n let e = this.threshold;\n let scols = this.s.length;\n let Ls = Matrix.zeros(scols, scols);\n\n for (let i = 0; i < scols; i++) {\n if (Math.abs(this.s[i]) <= e) {\n Ls.set(i, i, 0);\n } else {\n Ls.set(i, i, 1 / this.s[i]);\n }\n }\n\n let U = this.U;\n let V = this.rightSingularVectors;\n\n let VL = V.mmul(Ls);\n let vrows = V.rows;\n let urows = U.rows;\n let VLU = Matrix.zeros(vrows, urows);\n\n for (let i = 0; i < vrows; i++) {\n for (let j = 0; j < urows; j++) {\n let sum = 0;\n for (let k = 0; k < scols; k++) {\n sum += VL.get(i, k) * U.get(j, k);\n }\n VLU.set(i, j, sum);\n }\n }\n\n return VLU.mmul(Y);\n }\n\n solveForDiagonal(value) {\n return this.solve(Matrix.diag(value));\n }\n\n inverse() {\n let V = this.V;\n let e = this.threshold;\n let vrows = V.rows;\n let vcols = V.columns;\n let X = new Matrix(vrows, this.s.length);\n\n for (let i = 0; i < vrows; i++) {\n for (let j = 0; j < vcols; j++) {\n if (Math.abs(this.s[j]) > e) {\n X.set(i, j, V.get(i, j) / this.s[j]);\n }\n }\n }\n\n let U = this.U;\n\n let urows = U.rows;\n let ucols = U.columns;\n let Y = new Matrix(vrows, urows);\n\n for (let i = 0; i < vrows; i++) {\n for (let j = 0; j < urows; j++) {\n let sum = 0;\n for (let k = 0; k < ucols; k++) {\n sum += X.get(i, k) * U.get(j, k);\n }\n Y.set(i, j, sum);\n }\n }\n\n return Y;\n }\n\n get condition() {\n return this.s[0] / this.s[Math.min(this.m, this.n) - 1];\n }\n\n get norm2() {\n return this.s[0];\n }\n\n get rank() {\n let tol = Math.max(this.m, this.n) * this.s[0] * Number.EPSILON;\n let r = 0;\n let s = this.s;\n for (let i = 0, ii = s.length; i < ii; i++) {\n if (s[i] > tol) {\n r++;\n }\n }\n return r;\n }\n\n get diagonal() {\n return Array.from(this.s);\n }\n\n get threshold() {\n return (Number.EPSILON / 2) * Math.max(this.m, this.n) * this.s[0];\n }\n\n get leftSingularVectors() {\n return this.U;\n }\n\n get rightSingularVectors() {\n return this.V;\n }\n\n get diagonalMatrix() {\n return Matrix.diag(this.s);\n }\n}\n","import LuDecomposition from './dc/lu';\nimport QrDecomposition from './dc/qr';\nimport SingularValueDecomposition from './dc/svd';\nimport Matrix from './matrix';\nimport WrapperMatrix2D from './wrap/WrapperMatrix2D';\n\nexport function inverse(matrix, useSVD = false) {\n matrix = WrapperMatrix2D.checkMatrix(matrix);\n if (useSVD) {\n return new SingularValueDecomposition(matrix).inverse();\n } else {\n return solve(matrix, Matrix.eye(matrix.rows));\n }\n}\n\nexport function solve(leftHandSide, rightHandSide, useSVD = false) {\n leftHandSide = WrapperMatrix2D.checkMatrix(leftHandSide);\n rightHandSide = WrapperMatrix2D.checkMatrix(rightHandSide);\n if (useSVD) {\n return new SingularValueDecomposition(leftHandSide).solve(rightHandSide);\n } else {\n return leftHandSide.isSquare()\n ? new LuDecomposition(leftHandSide).solve(rightHandSide)\n : new QrDecomposition(leftHandSide).solve(rightHandSide);\n }\n}\n","import { inverse, Matrix } from 'ml-matrix';\n\n/**\n * Difference of the matrix function over the parameters\n * @ignore\n * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]\n * @param {Array} evaluatedData - Array of previous evaluated function values\n * @param {Array} params - Array of previous parameter values\n * @param {number} gradientDifference - Adjustment for decrease the damping parameter\n * @param {function} paramFunction - The parameters and returns a function with the independent variable as a parameter\n * @return {Matrix}\n */\nfunction gradientFunction(\n data,\n evaluatedData,\n params,\n gradientDifference,\n paramFunction,\n) {\n const n = params.length;\n const m = data.x.length;\n\n let ans = new Array(n);\n\n for (let param = 0; param < n; param++) {\n ans[param] = new Array(m);\n let auxParams = params.slice();\n auxParams[param] += gradientDifference;\n let funcParam = paramFunction(auxParams);\n\n for (let point = 0; point < m; point++) {\n ans[param][point] = evaluatedData[point] - funcParam(data.x[point]);\n }\n }\n return new Matrix(ans);\n}\n\n/**\n * Matrix function over the samples\n * @ignore\n * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]\n * @param {Array} evaluatedData - Array of previous evaluated function values\n * @return {Matrix}\n */\nfunction matrixFunction(data, evaluatedData) {\n const m = data.x.length;\n\n let ans = new Array(m);\n\n for (let point = 0; point < m; point++) {\n ans[point] = [data.y[point] - evaluatedData[point]];\n }\n\n return new Matrix(ans);\n}\n\n/**\n * Iteration for Levenberg-Marquardt\n * @ignore\n * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]\n * @param {Array} params - Array of previous parameter values\n * @param {number} damping - Levenberg-Marquardt parameter\n * @param {number} gradientDifference - Adjustment for decrease the damping parameter\n * @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter\n * @return {Array}\n */\nexport default function step(\n data,\n params,\n damping,\n gradientDifference,\n parameterizedFunction,\n) {\n let value = damping * gradientDifference * gradientDifference;\n let identity = Matrix.eye(params.length, params.length, value);\n\n const func = parameterizedFunction(params);\n\n let evaluatedData = new Float64Array(data.x.length);\n for (let i = 0; i < data.x.length; i++) {\n evaluatedData[i] = func(data.x[i]);\n }\n\n let gradientFunc = gradientFunction(\n data,\n evaluatedData,\n params,\n gradientDifference,\n parameterizedFunction,\n );\n let matrixFunc = matrixFunction(data, evaluatedData);\n let inverseMatrix = inverse(\n identity.add(gradientFunc.mmul(gradientFunc.transpose())),\n );\n\n params = new Matrix([params]);\n params = params.sub(\n inverseMatrix\n .mmul(gradientFunc)\n .mmul(matrixFunc)\n .mul(gradientDifference)\n .transpose(),\n );\n\n return params.to1DArray();\n}\n","import isArray from 'is-any-array';\n\nimport errorCalculation from './errorCalculation';\nimport step from './step';\n\n/**\n * Curve fitting algorithm\n * @param {{x:Array, y:Array}} data - Array of points to fit in the format [x1, x2, ... ], [y1, y2, ... ]\n * @param {function} parameterizedFunction - The parameters and returns a function with the independent variable as a parameter\n * @param {object} [options] - Options object\n * @param {number} [options.damping] - Levenberg-Marquardt parameter\n * @param {number} [options.gradientDifference = 10e-2] - Adjustment for decrease the damping parameter\n * @param {Array} [options.minValues] - Minimum allowed values for parameters\n * @param {Array} [options.maxValues] - Maximum allowed values for parameters\n * @param {Array} [options.initialValues] - Array of initial parameter values\n * @param {number} [options.maxIterations = 100] - Maximum of allowed iterations\n * @param {number} [options.errorTolerance = 10e-3] - Minimum uncertainty allowed for each point\n * @return {{parameterValues: Array, parameterError: number, iterations: number}}\n */\nexport default function levenbergMarquardt(\n data,\n parameterizedFunction,\n options = {},\n) {\n let {\n maxIterations = 100,\n gradientDifference = 10e-2,\n damping = 0,\n errorTolerance = 10e-3,\n minValues,\n maxValues,\n initialValues,\n } = options;\n\n if (damping <= 0) {\n throw new Error('The damping option must be a positive number');\n } else if (!data.x || !data.y) {\n throw new Error('The data parameter must have x and y elements');\n } else if (\n !isArray(data.x) ||\n data.x.length < 2 ||\n !isArray(data.y) ||\n data.y.length < 2\n ) {\n throw new Error(\n 'The data parameter elements must be an array with more than 2 points',\n );\n } else if (data.x.length !== data.y.length) {\n throw new Error('The data parameter elements must have the same size');\n }\n\n let parameters =\n initialValues || new Array(parameterizedFunction.length).fill(1);\n let parLen = parameters.length;\n maxValues = maxValues || new Array(parLen).fill(Number.MAX_SAFE_INTEGER);\n minValues = minValues || new Array(parLen).fill(Number.MIN_SAFE_INTEGER);\n\n if (maxValues.length !== minValues.length) {\n throw new Error('minValues and maxValues must be the same size');\n }\n\n if (!isArray(parameters)) {\n throw new Error('initialValues must be an array');\n }\n\n let error = errorCalculation(data, parameters, parameterizedFunction);\n\n let converged = error <= errorTolerance;\n\n let iteration;\n for (iteration = 0; iteration < maxIterations && !converged; iteration++) {\n parameters = step(\n data,\n parameters,\n damping,\n gradientDifference,\n parameterizedFunction,\n );\n\n for (let k = 0; k < parLen; k++) {\n parameters[k] = Math.min(\n Math.max(minValues[k], parameters[k]),\n maxValues[k],\n );\n }\n\n error = errorCalculation(data, parameters, parameterizedFunction);\n if (isNaN(error)) break;\n converged = error <= errorTolerance;\n }\n\n return {\n parameterValues: parameters,\n parameterError: error,\n iterations: iteration,\n };\n}\n","/**\n * This function calculates the spectrum as a sum of gaussian functions. The Gaussian\n * parameters are divided in 3 batches. 1st: centers; 2nd: height; 3th: std's;\n * @param t Ordinate values\n * @param p Gaussian parameters\n * @param c Constant parameters(Not used)\n * @returns {*}\n */\nexport function sumOfGaussians(p) {\n return function (t) {\n let nL = p.length / 3;\n let factor;\n let rows = t.length;\n let result = rows === undefined ? 0 : new Float64Array(rows).fill(0);\n for (let i = 0; i < nL; i++) {\n factor = Math.pow(p[i + nL * 2], 2) * 2;\n if (rows === undefined) {\n result += p[i + nL] * Math.exp(-Math.pow(t - p[i], 2) / factor);\n } else {\n for (let j = 0; j < rows; j++) {\n result[j] += p[i + nL] * Math.exp(-Math.pow(t[j] - p[i], 2) / factor);\n }\n }\n }\n return result;\n };\n}\n","import LM from 'ml-levenberg-marquardt';\n\nimport { sumOfGaussians } from './sumOfGaussians';\n\n/**\n *\n * @param xy A two column matrix containing the x and y data to be fitted\n * @param group A set of initial lorentzian parameters to be optimized [center, heigth, half_width_at_half_height]\n * @returns {Array} A set of final lorentzian parameters [center, heigth, hwhh*2]\n */\nexport function optimizeGaussianSum(xy, group, opts = {}) {\n let t = xy[0];\n let yData = xy[1];\n let maxY = Math.max(...yData);\n yData.forEach((x, i, arr) => (arr[i] /= maxY));\n let nL = group.length;\n let pInit = new Float64Array(nL * 3);\n let pMin = new Float64Array(nL * 3);\n let pMax = new Float64Array(nL * 3);\n let dt = Math.abs(t[0] - t[1]);\n\n for (let i = 0; i < nL; i++) {\n pInit[i] = group[i].x;\n pInit[i + nL] = group[i].y / maxY;\n pInit[i + 2 * nL] = group[i].width;\n\n pMin[i] = group[i].x - dt;\n pMin[i + nL] = 0;\n pMin[i + 2 * nL] = group[i].width / 4;\n\n pMax[i] = group[i].x + dt;\n pMax[i + nL] = (group[i].y * 1.2) / maxY;\n pMax[i + 2 * nL] = group[i].width * 4;\n }\n\n let data = {\n x: t,\n y: yData,\n };\n let result = new Array(nL);\n\n let lmOptions = {\n damping: 1.5,\n initialValues: pInit,\n minValues: pMin,\n maxValues: pMax,\n gradientDifference: dt / 10000,\n maxIterations: 100,\n errorTolerance: 10e-5,\n };\n\n opts = Object.assign({}, lmOptions, opts);\n\n let pFit = LM(data, sumOfGaussians, opts);\n for (let i = 0; i < nL; i++) {\n result[i] = {\n parameters: [\n pFit.parameterValues[i],\n pFit.parameterValues[i + nL] * maxY,\n pFit.parameterValues[i + nL * 2],\n ],\n error: pFit.parameterError,\n };\n }\n return result;\n}\n","/**\n * Single 3 parameter gaussian function\n * @param t Ordinate values\n * @param p Gaussian parameters [mean, height, std]\n * @param c Constant parameters(Not used)\n * @returns {*}\n */\n\nexport function singleGaussian(p) {\n return function (t) {\n let factor2 = (p[2] * p[2]) / 2;\n let rows = t.length;\n if (!rows) return p[1] * Math.exp((-(t - p[0]) * (t - p[0])) / factor2);\n let result = new Float64Array(t.length);\n for (let i = 0; i < t.length; i++) {\n result[i] = p[1] * Math.exp((-(t[i] - p[0]) * (t[i] - p[0])) / factor2);\n }\n return result;\n };\n}\n","import LM from 'ml-levenberg-marquardt';\n\nimport { singleGaussian } from './singleGaussian';\n\n/**\n * Fits a set of points to a gaussian bell. Returns the mean of the peak, the std and the height of the signal.\n * @param data,[y]\n * @returns {*[]}\n */\nexport function optimizeSingleGaussian(xy, peak, opts = {}) {\n let t = xy[0];\n let yData = xy[1];\n let maxY = Math.max(...yData);\n yData.forEach((x, i, arr) => (arr[i] /= maxY));\n let dt = Math.abs(t[0] - t[1]);\n let pInit = new Float64Array([peak.x, 1, peak.width]);\n let pMin = new Float64Array([peak.x - dt, 0, peak.width / 4]);\n let pMax = new Float64Array([peak.x + dt, 1.25, peak.width * 4]);\n\n let data = {\n x: t,\n y: yData,\n };\n\n let lmOptions = {\n damping: 1.5,\n initialValues: pInit,\n minValues: pMin,\n maxValues: pMax,\n gradientDifference: dt / 10000,\n maxIterations: 100,\n errorTolerance: 10e-5,\n };\n\n opts = Object.assign({}, lmOptions, opts);\n let pFit = LM(data, singleGaussian, opts);\n return {\n parameters: [\n pFit.parameterValues[0],\n pFit.parameterValues[1] * maxY,\n pFit.parameterValues[2],\n ],\n error: pFit.parameterError,\n };\n}\n","/**\n * This function calculates the spectrum as a sum of lorentzian functions. The Lorentzian\n * parameters are divided in 3 batches. 1st: centers; 2nd: heights; 3th: widths;\n * @param t Ordinate values\n * @param p Lorentzian parameters\n * @returns {*}\n */\n\nexport function sumOfLorentzians(p) {\n return function (t) {\n let nL = p.length / 3;\n let factor;\n let p2;\n let rows = t.length;\n let result = rows === undefined ? 0 : new Float64Array(rows).fill(0);\n for (let i = 0; i < nL; i++) {\n p2 = Math.pow(p[i + nL * 2] / 2, 2);\n factor = p[i + nL] * p2;\n if (rows === undefined) {\n result += factor / (Math.pow(t - p[i], 2) + p2);\n } else {\n for (let j = 0; j < rows; j++) {\n result[j] += factor / (Math.pow(t[j] - p[i], 2) + p2);\n }\n }\n }\n return result;\n };\n}\n","import LM from 'ml-levenberg-marquardt';\n\nimport { sumOfLorentzians } from './sumOfLorentzians';\n\n/**\n *\n * @param xy A two column matrix containing the x and y data to be fitted\n * @param group A set of initial lorentzian parameters to be optimized [center, heigth, half_width_at_half_height]\n * @returns {Array} A set of final lorentzian parameters [center, heigth, hwhh*2]\n */\nexport function optimizeLorentzianSum(xy, group, opts = {}) {\n let t = xy[0];\n let yData = xy[1];\n let maxY = Math.max(...yData);\n yData.forEach((x, i, arr) => (arr[i] /= maxY));\n\n let nL = group.length;\n let pInit = new Float64Array(nL * 3);\n let pMin = new Float64Array(nL * 3);\n let pMax = new Float64Array(nL * 3);\n let dt = Math.abs(t[0] - t[1]);\n\n for (let i = 0; i < nL; i++) {\n pInit[i] = group[i].x;\n pInit[i + nL] = 1;\n pInit[i + 2 * nL] = group[i].width;\n\n pMin[i] = group[i].x - dt;\n pMin[i + nL] = 0;\n pMin[i + 2 * nL] = group[i].width / 4;\n\n pMax[i] = group[i].x + dt;\n pMax[i + nL] = 1.5;\n pMax[i + 2 * nL] = group[i].width * 4;\n }\n\n let data = {\n x: t,\n y: yData,\n };\n\n let result = new Array(nL);\n\n let lmOptions = {\n damping: 1.5,\n initialValues: pInit,\n minValues: pMin,\n maxValues: pMax,\n gradientDifference: dt / 10000,\n maxIterations: 100,\n errorTolerance: 10e-5,\n };\n\n opts = Object.assign({}, lmOptions, opts);\n\n let pFit = LM(data, sumOfLorentzians, opts);\n for (let i = 0; i < nL; i++) {\n result[i] = {\n parameters: [\n pFit.parameterValues[i],\n pFit.parameterValues[i + nL] * maxY,\n pFit.parameterValues[i + nL * 2],\n ],\n error: pFit.parameterError,\n };\n }\n return result;\n}\n","/**\n * Single 4 parameter lorentzian function\n * @param t Ordinate values\n * @param p Lorentzian parameters\n * @param c Constant parameters(Not used)\n * @returns {*}\n */\n\nexport function singleLorentzian(p) {\n return function (t) {\n let factor = p[1] * Math.pow(p[2] / 2, 2);\n let rows = t.length;\n if (!rows) return factor / (Math.pow(t - p[0], 2) + Math.pow(p[2] / 2, 2));\n let result = new Float64Array(rows);\n for (let i = 0; i < rows; i++) {\n result[i] = factor / (Math.pow(t[i] - p[0], 2) + Math.pow(p[2] / 2, 2));\n }\n return result;\n };\n}\n","import LM from 'ml-levenberg-marquardt';\n\nimport { singleLorentzian } from './singleLorentzian';\n\n/**\n * * Fits a set of points to a Lorentzian function. Returns the center of the peak, the width at half height, and the height of the signal.\n * @param data,[y]\n * @returns {*[]}\n */\nexport function optimizeSingleLorentzian(xy, peak, opts = {}) {\n let t = xy[0];\n let yData = xy[1];\n let maxY = Math.max(...yData);\n yData.forEach((x, i, arr) => (arr[i] /= maxY));\n let dt = Math.abs(t[0] - t[1]);\n let pInit = new Float64Array([peak.x, 1, peak.width]);\n let pMin = new Float64Array([peak.x - dt, 0.75, peak.width / 4]);\n let pMax = new Float64Array([peak.x + dt, 1.25, peak.width * 4]);\n\n let data = {\n x: t,\n y: yData,\n };\n\n let lmOptions = {\n damping: 1.5,\n initialValues: pInit,\n minValues: pMin,\n maxValues: pMax,\n gradientDifference: dt / 10000,\n maxIterations: 100,\n errorTolerance: 10e-5,\n };\n opts = Object.assign({}, lmOptions, opts);\n let pFit = LM(data, singleLorentzian, opts);\n return {\n parameters: [\n pFit.parameterValues[0],\n pFit.parameterValues[1] * maxY,\n pFit.parameterValues[2],\n ],\n error: pFit.parameterError,\n };\n}\n","import {\n optimizeGaussianSum,\n optimizeLorentzianSum,\n optimizeSingleGaussian,\n optimizeSingleLorentzian,\n} from 'ml-optimize-lorentzian';\n\nexport function optimizePeaks(peakList, x, y, options = {}) {\n const {\n functionName = 'gaussian',\n factorWidth = 4,\n optimizationOptions = {\n damping: 1.5,\n maxIterations: 100,\n errorTolerance: 10e-5,\n },\n } = options;\n\n let lastIndex = [0];\n let groups = groupPeaks(peakList, factorWidth);\n let result = [];\n let factor = 1;\n if (functionName === 'gaussian') {\n factor = 1.17741;\n } // From https://en.wikipedia.org/wiki/Gaussian_function#Properties\n let sampling;\n for (let i = 0; i < groups.length; i++) {\n let peaks = groups[i].group;\n if (peaks.length > 1) {\n // Multiple peaks\n sampling = sampleFunction(\n groups[i].limits[0] - groups[i].limits[1],\n groups[i].limits[0] + groups[i].limits[1],\n x,\n y,\n lastIndex,\n );\n if (sampling[0].length > 5) {\n let optPeaks = [];\n if (functionName === 'gaussian') {\n optPeaks = optimizeGaussianSum(sampling, peaks, optimizationOptions);\n } else {\n if (functionName === 'lorentzian') {\n optPeaks = optimizeLorentzianSum(\n sampling,\n peaks,\n optimizationOptions,\n );\n }\n }\n\n for (let j = 0; j < optPeaks.length; j++) {\n let { parameters } = optPeaks[j];\n result.push({\n x: parameters[0],\n y: parameters[1],\n width: parameters[2] * factor,\n index: peaks[j].index,\n });\n }\n }\n } else {\n // Single peak\n peaks = peaks[0];\n sampling = sampleFunction(\n peaks.x - factorWidth * peaks.width,\n peaks.x + factorWidth * peaks.width,\n x,\n y,\n lastIndex,\n );\n\n if (sampling[0].length > 5) {\n let fitResult = [];\n if (functionName === 'gaussian') {\n fitResult = optimizeSingleGaussian(\n [sampling[0], sampling[1]],\n peaks,\n optimizationOptions,\n );\n } else {\n if (functionName === 'lorentzian') {\n fitResult = optimizeSingleLorentzian(\n [sampling[0], sampling[1]],\n peaks,\n optimizationOptions,\n );\n }\n }\n\n let { parameters } = fitResult;\n result.push({\n x: parameters[0],\n y: parameters[1],\n width: parameters[2] * factor,\n index: peaks.index,\n }); // From https://en.wikipedia.org/wiki/Gaussian_function#Properties}\n }\n }\n }\n return result;\n}\n\nfunction sampleFunction(from, to, x, y, lastIndex) {\n let nbPoints = x.length;\n let sampleX = [];\n let sampleY = [];\n let direction = Math.sign(x[1] - x[0]); // Direction of the derivative\n if (direction === -1) {\n lastIndex[0] = x.length - 1;\n }\n\n let delta = Math.abs(to - from) / 2;\n let mid = (from + to) / 2;\n let stop = false;\n let index = lastIndex[0];\n while (!stop && index < nbPoints && index >= 0) {\n if (Math.abs(x[index] - mid) <= delta) {\n sampleX.push(x[index]);\n sampleY.push(y[index]);\n index += direction;\n } else {\n // It is outside the range.\n if (Math.sign(mid - x[index]) === 1) {\n // We'll reach the mid going in the current direction\n index += direction;\n } else {\n // There is not more peaks in the current range\n stop = true;\n }\n }\n }\n lastIndex[0] = index;\n return [sampleX, sampleY];\n}\n\nfunction groupPeaks(peakList, nL) {\n let group = [];\n let groups = [];\n let limits = [peakList[0].x, nL * peakList[0].width];\n let upperLimit, lowerLimit;\n // Merge forward\n for (let i = 0; i < peakList.length; i++) {\n // If the 2 things overlaps\n if (\n Math.abs(peakList[i].x - limits[0]) <\n nL * peakList[i].width + limits[1]\n ) {\n // Add the peak to the group\n group.push(peakList[i]);\n // Update the group limits\n upperLimit = limits[0] + limits[1];\n if (peakList[i].x + nL * peakList[i].width > upperLimit) {\n upperLimit = peakList[i].x + nL * peakList[i].width;\n }\n lowerLimit = limits[0] - limits[1];\n if (peakList[i].x - nL * peakList[i].width < lowerLimit) {\n lowerLimit = peakList[i].x - nL * peakList[i].width;\n }\n limits = [\n (upperLimit + lowerLimit) / 2,\n Math.abs(upperLimit - lowerLimit) / 2,\n ];\n } else {\n groups.push({ limits: limits, group: group });\n // var optmimalPeak = fitSpectrum(group,limits,spectrum);\n group = [peakList[i]];\n limits = [peakList[i].x, nL * peakList[i].width];\n }\n }\n groups.push({ limits: limits, group: group });\n // Merge backward\n for (let i = groups.length - 2; i >= 0; i--) {\n // The groups overlaps\n if (\n Math.abs(groups[i].limits[0] - groups[i + 1].limits[0]) <\n (groups[i].limits[1] + groups[i + 1].limits[1]) / 2\n ) {\n for (let j = 0; j < groups[i + 1].group.length; j++) {\n groups[i].group.push(groups[i + 1].group[j]);\n }\n upperLimit = groups[i].limits[0] + groups[i].limits[1];\n if (groups[i + 1].limits[0] + groups[i + 1].limits[1] > upperLimit) {\n upperLimit = groups[i + 1].limits[0] + groups[i + 1].limits[1];\n }\n lowerLimit = groups[i].limits[0] - groups[i].limits[1];\n if (groups[i + 1].limits[0] - groups[i + 1].limits[1] < lowerLimit) {\n lowerLimit = groups[i + 1].limits[0] - groups[i + 1].limits[1];\n }\n\n groups[i].limits = [\n (upperLimit + lowerLimit) / 2,\n Math.abs(upperLimit - lowerLimit) / 2,\n ];\n\n groups.splice(i + 1, 1);\n }\n }\n return groups;\n}\n","/**\n * This method will allow to enlarge peaks and prevent overlap between peaks\n * Because peaks may not be symmetric after we add 2 properties, from and to.\n * @param {Array} peakList\n * @param {object} [options={}]\n * @param {number} [factor=2]\n * @param {boolean} [overlap=false] by default we don't allow overlap\n * @return {Array} peakList\n */\nexport function broadenPeaks(peakList, options = {}) {\n const { factor = 2, overlap = false } = options;\n\n for (let peak of peakList) {\n if (!peak.right || !peak.left) {\n peak.from = peak.x - (peak.width / 2) * factor;\n peak.to = peak.x + (peak.width / 2) * factor;\n } else {\n peak.from = peak.x - (peak.x - peak.left.x) * factor;\n peak.to = peak.x + (peak.right.x - peak.x) * factor;\n }\n }\n\n if (!overlap) {\n for (let i = 0; i < peakList.length - 1; i++) {\n let peak = peakList[i];\n let nextPeak = peakList[i + 1];\n if (peak.to > nextPeak.from) {\n peak.to = nextPeak.from = (peak.to + nextPeak.from) / 2;\n }\n }\n }\n\n for (let peak of peakList) {\n peak.width = peak.to - peak.from;\n }\n\n return peakList;\n}\n","import { optimizeSingleLorentzian } from 'ml-optimize-lorentzian';\n\n/**\n * This function try to join the peaks that seems to belong to a broad signal in a single broad peak.\n * @param peakList\n * @param options\n */\nexport function joinBroadPeaks(peakList, options = {}) {\n let width = options.width;\n let broadLines = [];\n // Optimize the possible broad lines\n let max = 0;\n\n let maxI = 0;\n\n let count = 1;\n for (let i = peakList.length - 1; i >= 0; i--) {\n if (peakList[i].soft) {\n broadLines.push(peakList.splice(i, 1)[0]);\n }\n }\n // Push a feke peak\n broadLines.push({ x: Number.MAX_VALUE });\n\n let candidates = [[broadLines[0].x, broadLines[0].y]];\n let indexes = [broadLines[0].index];\n\n for (let i = 1; i < broadLines.length; i++) {\n // console.log(broadLines[i-1].x+\" \"+broadLines[i].x);\n if (Math.abs(broadLines[i - 1].x - broadLines[i].x) < width) {\n candidates.push([broadLines[i].x, broadLines[i].y]);\n if (broadLines[i].y > max) {\n max = broadLines[i].y;\n maxI = i;\n }\n indexes.push(broadLines[i].index);\n count++;\n } else {\n if (count > 2) {\n let fitted = optimizeSingleLorentzian(candidates, {\n x: broadLines[maxI].x,\n y: max,\n width: Math.abs(\n candidates[0][0] - candidates[candidates.length - 1][0],\n ),\n });\n let { parameters } = fitted;\n peakList.push({\n x: parameters[0],\n y: parameters[1],\n width: parameters[2],\n index: Math.floor(\n indexes.reduce((a, b) => a + b, 0) / indexes.length,\n ),\n soft: false,\n });\n } else {\n // Put back the candidates to the signals list\n indexes.forEach((index) => {\n peakList.push(broadLines[index]);\n });\n }\n candidates = [[broadLines[i].x, broadLines[i].y]];\n indexes = [i];\n max = broadLines[i].y;\n maxI = i;\n count = 1;\n }\n }\n\n peakList.sort(function (a, b) {\n return a.x - b.x;\n });\n\n return peakList;\n}\n"],"names":["SavitzkyGolay","data","h","options","windowSize","derivative","polynomial","Number","isInteger","RangeError","length","console","warn","half","Math","floor","np","ans","Array","weights","m","n","s","t","j","Weight","fullWeights","hs","constantH","isArray","pow","i","wg1","wg2","d1","d2","l","getHs","wg","d","center","count","GramPoly","k","Grampoly","GenFact","a","b","gf","sum","isEqualSpaced","x","tmp","maxDx","minDx","MAX_SAFE_INTEGER","abs","getNoiseLevel","y","mean","stddev","averageDeviations","sort","determineRealTop","peakList","alpha","beta","gamma","p","currentPoint","index","log10","toString","Object","prototype","isAnyArray","object","call","endsWith","errorCalculation","parameters","parameterizedFunction","error","func","rescale","input","output","arguments","undefined","TypeError","currentMin","minValue","min","currentMax","maxValue","max","_options$min","autoMinMax","_options$max","factor","indent","repeat","indentData","inspectMatrixWithOptions","matrix","maxRows","maxColumns","maxNumSize","constructor","name","rows","columns","maxI","maxJ","result","line","push","formatNumber","get","join","inspectData","num","numStr","String","padEnd","precise","toPrecision","exponential","toExponential","eIndex","indexOf","e","slice","checkRowIndex","outer","checkColumnIndex","checkRowVector","vector","to1DArray","checkColumnVector","checkRowIndices","rowIndices","some","r","from","checkColumnIndices","columnIndices","c","checkRange","startRow","endRow","startColumn","endColumn","checkNumber","newArray","value","array","AbstractMatrix","newRows","newColumns","newData","newMatrix","Matrix","row","column","set","fill","random","interval","round","this","zeros","matrix1","matrix2","checkMatrix","isMatrix","klass","apply","callback","to2DArray","copy","toJSON","isRowVector","isColumnVector","isVector","isSquare","isSymmetric","isEchelonForm","previousColumn","checked","isReducedEchelonForm","echelonForm","clone","iMax","swapRows","reducedEchelonForm","maxRow","pivot","Error","setSubMatrix","neg","mulS","getRow","getRowVector","rowVector","setRow","row1","row2","temp","getColumn","getColumnVector","columnVector","setColumn","swapColumns","column1","column2","addRowVector","subRowVector","mulRowVector","divRowVector","addColumnVector","subColumnVector","mulColumnVector","divColumnVector","mulRow","mulColumn","v","maxIndex","idx","minIndex","maxRowIndex","minRow","minRowIndex","maxColumn","maxColumnIndex","minColumn","minColumnIndex","diag","norm","type","sqrt","cumulativeSum","dot","vector2","vector1","mmul","other","Bcolj","Float64Array","strassen2x2","a11","b11","a12","b12","a21","b21","a22","b22","m1","m2","m3","m4","m5","c00","c01","c10","c11","strassen3x3","a00","a01","a02","a10","a20","b00","b01","b02","b10","b20","m6","m7","m8","m9","m12","m13","m14","m15","m16","m17","m18","c02","c12","c20","c21","c22","mmulStrassen","r1","c1","r2","c2","embed","mat","cols","resultat","blockMult","halfRows","parseInt","halfCols","subMatrix","add","sub","scaleRows","isFinite","scaleColumns","flipRows","middle","ceil","first","last","flipColumns","kroneckerProduct","q","transpose","sortRows","compareFunction","compareNumbers","sortColumns","subMatrixRow","indices","subMatrixColumn","selection","checkIndices","rowIndex","columnIndex","trace","by","sumByRow","sumByColumn","sumAll","product","productByRow","productByColumn","productAll","size","variance","unbiased","sum1","sum2","varianceByRow","varianceByColumn","varianceAll","standardDeviation","centerByRow","centerByColumn","centerAll","scale","getScaleByRow","scaleByRow","getScaleByColumn","scaleByColumn","divider","getScaleAll","scaleAll","Symbol","for","rand","randomInt","randInt","diagonal","identity","eye","negate","tensorProduct","nRows","nColumns","arrayData","removeRow","splice","addRow","removeColumn","newRow","addColumn","addS","addM","subS","subM","subtract","subtractS","subtractM","mul","mulM","multiply","multiplyS","multiplyM","div","divS","divM","divide","divideS","divideM","mod","modS","modM","modulus","modulusS","modulusM","and","andS","andM","or","orS","orM","xor","xorS","xorM","leftShift","leftShiftS","leftShiftM","signPropagatingRightShift","signPropagatingRightShiftS","signPropagatingRightShiftM","rightShift","rightShiftS","rightShiftM","zeroFillRightShift","zeroFillRightShiftS","zeroFillRightShiftM","not","acos","acosh","asin","asinh","atan","atanh","cbrt","clz32","cos","cosh","exp","expm1","fround","log","log1p","log2","sign","sin","sinh","tan","tanh","trunc","arg0","powS","powM","installMathOperations","WrapperMatrix2D","LuDecomposition","LUcolj","kmax","lu","pivotVector","pivotSign","LU","isSingular","col","solve","X","determinant","hypotenuse","QrDecomposition","qr","rdiag","nrm","QR","Rdiag","isFullRank","SingularValueDecomposition","computeLeftSingularVectors","computeRightSingularVectors","autoTranspose","wantu","Boolean","wantv","swapped","aux","nu","ni","U","V","work","si","nct","nrt","mrc","pp","eps","EPSILON","kase","MIN_VALUE","isNaN","ks","f","cs","sn","sp","spm1","epm1","sk","ek","shift","g","Y","threshold","scols","Ls","rightSingularVectors","VL","vrows","urows","VLU","solveForDiagonal","inverse","vcols","ucols","tol","ii","useSVD","leftHandSide","rightHandSide","step","params","damping","gradientDifference","evaluatedData","gradientFunc","paramFunction","param","auxParams","funcParam","point","gradientFunction","matrixFunc","matrixFunction","inverseMatrix","levenbergMarquardt","maxIterations","errorTolerance","minValues","maxValues","initialValues","parLen","MIN_SAFE_INTEGER","iteration","converged","parameterValues","parameterError","iterations","sumOfGaussians","nL","optimizeGaussianSum","xy","group","opts","yData","maxY","forEach","arr","pInit","pMin","pMax","dt","width","lmOptions","assign","pFit","LM","singleGaussian","factor2","optimizeSingleGaussian","peak","sumOfLorentzians","p2","optimizeLorentzianSum","singleLorentzian","optimizeSingleLorentzian","sampleFunction","to","lastIndex","nbPoints","sampleX","sampleY","direction","delta","mid","stop","overlap","right","left","nextPeak","yIn","noiseLevel","sgOptions","smoothY","heightFactor","broadRatio","maxCriteria","minMaxRatio","derivativeThreshold","realTopDetection","equalSpaced","yCorrection","dY","ddY","SG","dx","maxDdy","lastMax","lastMin","minddY","intervalL","intervalR","broadMask","minddYLen","intervalLLen","intervalRLen","broadMaskLen","possible","frequency","distanceJ","minDistance","gettingCloser","signals","signalsLen","lastK","MAX_VALUE","soft","yLeft","yRight","height","base","broadLines","candidates","indexes","fitted","reduce","functionName","factorWidth","optimizationOptions","sampling","groups","upperLimit","lowerLimit","limits","groupPeaks","peaks","optPeaks","fitResult"],"mappings":"iMAAe,SAASA,EAAcC,EAAMC,OAAGC,yDAAU,IACnDC,WAAEA,EAAa,EAAfC,WAAkBA,EAAa,EAA/BC,WAAkCA,EAAa,GAAMH,KAErDC,EAAa,GAAM,GAAKA,EAAa,IAAMG,OAAOC,UAAUJ,SACxD,IAAIK,WACR,wEAGAL,EAAaH,EAAKS,aACd,IAAID,gEACsCL,cAAcH,EAAKS,YAGjEL,EAAa,IAAME,OAAOC,UAAUH,SAChC,IAAII,WAAW,8CAEnBH,EAAa,IAAMC,OAAOC,UAAUF,SAChC,IAAIG,WAAW,2CAEnBH,GAAc,GAEhBK,QAAQC,KACN,+JAKAC,EAAOC,KAAKC,MAAMX,EAAa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W,GACdtB,EAAGsB,EAAW,GACdye,MAAOze,EAAW,GAAKmB,EACvB7B,MAAOskB,EAAMtkB,gBAKd4C"} \ No newline at end of file diff --git a/package.json b/package.json index 2fa54ef..f9e57bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ml-gsd", - "version": "5.0.0", + "version": "5.0.1", "description": "Global Spectra Deconvolution", "main": "lib/index.js", "module": "src/index.js",