Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  index.js   Sprache: JAVA

 
/*
 * The MIT License (MIT)
 * 
 * Copyright (c) 2015 ml.js
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
*/

'use strict';

// ml-stat array.js
const MLStatArray = {};
{
    function compareNumbers(a, b) {
        return a - b;
    }

    /**
     * Computes the sum of the given values
     * @param {Array} values
     * @returns {number}
     */

    MLStatArray.sum = function sum(values) {
        var sum = 0;
        for (var i = 0; i < values.length; i++) {
            sum += values[i];
        }
        return sum;
    };

    /**
     * Computes the maximum of the given values
     * @param {Array} values
     * @returns {number}
     */

    MLStatArray.max = function max(values) {
        var max = values[0];
        var l = values.length;
        for (var i = 1; i < l; i++) {
            if (values[i] > max) max = values[i];
        }
        return max;
    };

    /**
     * Computes the minimum of the given values
     * @param {Array} values
     * @returns {number}
     */

    MLStatArray.min = function min(values) {
        var min = values[0];
        var l = values.length;
        for (var i = 1; i < l; i++) {
            if (values[i] < min) min = values[i];
        }
        return min;
    };

    /**
     * Computes the min and max of the given values
     * @param {Array} values
     * @returns {{min: number, max: number}}
     */

    MLStatArray.minMax = function minMax(values) {
        var min = values[0];
        var max = values[0];
        var l = values.length;
        for (var i = 1; i < l; i++) {
            if (values[i] < min) min = values[i];
            if (values[i] > max) max = values[i];
        }
        return {
            min: min,
            max: max
        };
    };

    /**
     * Computes the arithmetic mean of the given values
     * @param {Array} values
     * @returns {number}
     */

    MLStatArray.arithmeticMean = function arithmeticMean(values) {
        var sum = 0;
        var l = values.length;
        for (var i = 0; i < l; i++) {
            sum += values[i];
        }
        return sum / l;
    };

    /**
     * {@link arithmeticMean}
     */

    MLStatArray.mean = MLStatArray.arithmeticMean;

    /**
     * Computes the geometric mean of the given values
     * @param {Array} values
     * @returns {number}
     */

    MLStatArray.geometricMean = function geometricMean(values) {
        var mul = 1;
        var l = values.length;
        for (var i = 0; i < l; i++) {
            mul *= values[i];
        }
        return Math.pow(mul, 1 / l);
    };

    /**
     * Computes the mean of the log of the given values
     * If the return value is exponentiated, it gives the same result as the
     * geometric mean.
     * @param {Array} values
     * @returns {number}
     */

    MLStatArray.logMean = function logMean(values) {
        var lnsum = 0;
        var l = values.length;
        for (var i = 0; i < l; i++) {
            lnsum += Math.log(values[i]);
        }
        return lnsum / l;
    };

    /**
     * Computes the weighted grand mean for a list of means and sample sizes
     * @param {Array} means - Mean values for each set of samples
     * @param {Array} samples - Number of original values for each set of samples
     * @returns {number}
     */

    MLStatArray.grandMean = function grandMean(means, samples) {
        var sum = 0;
        var n = 0;
        var l = means.length;
        for (var i = 0; i < l; i++) {
            sum += samples[i] * means[i];
            n += samples[i];
        }
        return sum / n;
    };

    /**
     * Computes the truncated mean of the given values using a given percentage
     * @param {Array} values
     * @param {number} percent - The percentage of values to keep (range: [0,1])
     * @param {boolean} [alreadySorted=false]
     * @returns {number}
     */

    MLStatArray.truncatedMean = function truncatedMean(values, percent, alreadySorted) {
        if (alreadySorted === undefined) alreadySorted = false;
        if (!alreadySorted) {
            values = [].concat(values).sort(compareNumbers);
        }
        var l = values.length;
        var k = Math.floor(l * percent);
        var sum = 0;
        for (var i = k; i < (l - k); i++) {
            sum += values[i];
        }
        return sum / (l - 2 * k);
    };

    /**
     * Computes the harmonic mean of the given values
     * @param {Array} values
     * @returns {number}
     */

    MLStatArray.harmonicMean = function harmonicMean(values) {
        var sum = 0;
        var l = values.length;
        for (var i = 0; i < l; i++) {
            if (values[i] === 0) {
                throw new RangeError('value at index ' + i + 'is zero');
            }
            sum += 1 / values[i];
        }
        return l / sum;
    };

    /**
     * Computes the contraharmonic mean of the given values
     * @param {Array} values
     * @returns {number}
     */

    MLStatArray.contraHarmonicMean = function contraHarmonicMean(values) {
        var r1 = 0;
        var r2 = 0;
        var l = values.length;
        for (var i = 0; i < l; i++) {
            r1 += values[i] * values[i];
            r2 += values[i];
        }
        if (r2 < 0) {
            throw new RangeError('sum of values is negative');
        }
        return r1 / r2;
    };

    /**
     * Computes the median of the given values
     * @param {Array} values
     * @param {boolean} [alreadySorted=false]
     * @returns {number}
     */

    MLStatArray.median = function median(values, alreadySorted) {
        if (alreadySorted === undefined) alreadySorted = false;
        if (!alreadySorted) {
            values = [].concat(values).sort(compareNumbers);
        }
        var l = values.length;
        var half = Math.floor(l / 2);
        if (l % 2 === 0) {
            return (values[half - 1] + values[half]) * 0.5;
        } else {
            return values[half];
        }
    };

    /**
     * Computes the variance of the given values
     * @param {Array} values
     * @param {boolean} [unbiased=true] - if true, divide by (n-1); if false, divide by n.
     * @returns {number}
     */

    MLStatArray.variance = function variance(values, unbiased) {
        if (unbiased === undefined) unbiased = true;
        var theMean = MLStatArray.mean(values);
        var theVariance = 0;
        var l = values.length;

        for (var i = 0; i < l; i++) {
            var x = values[i] - theMean;
            theVariance += x * x;
        }

        if (unbiased) {
            return theVariance / (l - 1);
        } else {
            return theVariance / l;
        }
    };

    /**
     * Computes the standard deviation of the given values
     * @param {Array} values
     * @param {boolean} [unbiased=true] - if true, divide by (n-1); if false, divide by n.
     * @returns {number}
     */

    MLStatArray.standardDeviation = function standardDeviation(values, unbiased) {
        return Math.sqrt(MLStatArray.variance(values, unbiased));
    };

    MLStatArray.standardError = function standardError(values) {
        return MLStatArray.standardDeviation(values) / Math.sqrt(values.length);
    };

    /**
     * IEEE Transactions on biomedical engineering, vol. 52, no. 1, january 2005, p. 76-
     * Calculate the standard deviation via the Median of the absolute deviation
     *  The formula for the standard deviation only holds for Gaussian random variables.
     * @returns {{mean: number, stdev: number}}
     */

    MLStatArray.robustMeanAndStdev = function robustMeanAndStdev(y) {
        var mean = 0, stdev = 0;
        var length = y.length, i = 0;
        for (i = 0; i < length; i++) {
            mean += y[i];
        }
        mean /= length;
        var averageDeviations = new Array(length);
        for (i = 0; i < length; i++)
            averageDeviations[i] = Math.abs(y[i] - mean);
        averageDeviations.sort(compareNumbers);
        if (length % 2 === 1) {
            stdev = averageDeviations[(length - 1) / 2] / 0.6745;
        } else {
            stdev = 0.5 * (averageDeviations[length / 2] + averageDeviations[length / 2 - 1]) / 0.6745;
        }

        return {
            mean: mean,
            stdev: stdev
        };
    };

    MLStatArray.quartiles = function quartiles(values, alreadySorted) {
        if (typeof (alreadySorted) === 'undefined') alreadySorted = false;
        if (!alreadySorted) {
            values = [].concat(values).sort(compareNumbers);
        }

        var quart = values.length / 4;
        var q1 = values[Math.ceil(quart) - 1];
        var q2 = MLStatArray.median(values, true);
        var q3 = values[Math.ceil(quart * 3) - 1];

        return {q1: q1, q2: q2, q3: q3};
    };

    MLStatArray.pooledStandardDeviation = function pooledStandardDeviation(samples, unbiased) {
        return Math.sqrt(MLStatArray.pooledVariance(samples, unbiased));
    };

    MLStatArray.pooledVariance = function pooledVariance(samples, unbiased) {
        if (typeof (unbiased) === 'undefined') unbiased = true;
        var sum = 0;
        var length = 0, l = samples.length;
        for (var i = 0; i < l; i++) {
            var values = samples[i];
            var vari = MLStatArray.variance(values);

            sum += (values.length - 1) * vari;

            if (unbiased)
                length += values.length - 1;
            else
                length += values.length;
        }
        return sum / length;
    };

    MLStatArray.mode = function mode(values) {
        var l = values.length,
            itemCount = new Array(l),
            i;
        for (i = 0; i < l; i++) {
            itemCount[i] = 0;
        }
        var itemArray = new Array(l);
        var count = 0;

        for (i = 0; i < l; i++) {
            var index = itemArray.indexOf(values[i]);
            if (index >= 0)
                itemCount[index]++;
            else {
                itemArray[count] = values[i];
                itemCount[count] = 1;
                count++;
            }
        }

        var maxValue = 0, maxIndex = 0;
        for (i = 0; i < count; i++) {
            if (itemCount[i] > maxValue) {
                maxValue = itemCount[i];
                maxIndex = i;
            }
        }

        return itemArray[maxIndex];
    };

    MLStatArray.covariance = function covariance(vector1, vector2, unbiased) {
        if (typeof (unbiased) === 'undefined') unbiased = true;
        var mean1 = MLStatArray.mean(vector1);
        var mean2 = MLStatArray.mean(vector2);

        if (vector1.length !== vector2.length)
            throw 'Vectors do not have the same dimensions';

        var cov = 0, l = vector1.length;
        for (var i = 0; i < l; i++) {
            var x = vector1[i] - mean1;
            var y = vector2[i] - mean2;
            cov += x * y;
        }

        if (unbiased)
            return cov / (l - 1);
        else
            return cov / l;
    };

    MLStatArray.skewness = function skewness(values, unbiased) {
        if (typeof (unbiased) === 'undefined') unbiased = true;
        var theMean = MLStatArray.mean(values);

        var s2 = 0, s3 = 0, l = values.length;
        for (var i = 0; i < l; i++) {
            var dev = values[i] - theMean;
            s2 += dev * dev;
            s3 += dev * dev * dev;
        }
        var m2 = s2 / l;
        var m3 = s3 / l;

        var g = m3 / (Math.pow(m2, 3 / 2.0));
        if (unbiased) {
            var a = Math.sqrt(l * (l - 1));
            var b = l - 2;
            return (a / b) * g;
        } else {
            return g;
        }
    };

    MLStatArray.kurtosis = function kurtosis(values, unbiased) {
        if (typeof (unbiased) === 'undefined') unbiased = true;
        var theMean = MLStatArray.mean(values);
        var n = values.length, s2 = 0, s4 = 0;

        for (var i = 0; i < n; i++) {
            var dev = values[i] - theMean;
            s2 += dev * dev;
            s4 += dev * dev * dev * dev;
        }
        var m2 = s2 / n;
        var m4 = s4 / n;

        if (unbiased) {
            var v = s2 / (n - 1);
            var a = (n * (n + 1)) / ((n - 1) * (n - 2) * (n - 3));
            var b = s4 / (v * v);
            var c = ((n - 1) * (n - 1)) / ((n - 2) * (n - 3));

            return a * b - 3 * c;
        } else {
            return m4 / (m2 * m2) - 3;
        }
    };

    MLStatArray.entropy = function entropy(values, eps) {
        if (typeof (eps) === 'undefined') eps = 0;
        var sum = 0, l = values.length;
        for (var i = 0; i < l; i++)
            sum += values[i] * Math.log(values[i] + eps);
        return -sum;
    };

    MLStatArray.weightedMean = function weightedMean(values, weights) {
        var sum = 0, l = values.length;
        for (var i = 0; i < l; i++)
            sum += values[i] * weights[i];
        return sum;
    };

    MLStatArray.weightedStandardDeviation = function weightedStandardDeviation(values, weights) {
        return Math.sqrt(MLStatArray.weightedVariance(values, weights));
    };

    MLStatArray.weightedVariance = function weightedVariance(values, weights) {
        var theMean = MLStatArray.weightedMean(values, weights);
        var vari = 0, l = values.length;
        var a = 0, b = 0;

        for (var i = 0; i < l; i++) {
            var z = values[i] - theMean;
            var w = weights[i];

            vari += w * (z * z);
            b += w;
            a += w * w;
        }

        return vari * (b / (b * b - a));
    };

    MLStatArray.center = function center(values, inPlace) {
        if (typeof (inPlace) === 'undefined') inPlace = false;

        var result = values;
        if (!inPlace)
            result = [].concat(values);

        var theMean = MLStatArray.mean(result), l = result.length;
        for (var i = 0; i < l; i++)
            result[i] -= theMean;
    };

    MLStatArray.standardize = function standardize(values, standardDev, inPlace) {
        if (typeof (standardDev) === 'undefined') standardDev = MLStatArray.standardDeviation(values);
        if (typeof (inPlace) === 'undefined') inPlace = false;
        var l = values.length;
        var result = inPlace ? values : new Array(l);
        for (var i = 0; i < l; i++)
            result[i] = values[i] / standardDev;
        return result;
    };

    MLStatArray.cumulativeSum = function cumulativeSum(array) {
        var l = array.length;
        var result = new Array(l);
        result[0] = array[0];
        for (var i = 1; i < l; i++)
            result[i] = result[i - 1] + array[i];
        return result;
    };
}


// ml-stat matrix.js
const MLStatMatrix = {};
{
    let arrayStat = MLStatArray;

    function compareNumbers(a, b) {
        return a - b;
    }

    MLStatMatrix.max = function max(matrix) {
        var max = -Infinity;
        for (var i = 0; i < matrix.length; i++) {
            for (var j = 0; j < matrix[i].length; j++) {
                if (matrix[i][j] > max) max = matrix[i][j];
            }
        }
        return max;
    };

    MLStatMatrix.min = function min(matrix) {
        var min = Infinity;
        for (var i = 0; i < matrix.length; i++) {
            for (var j = 0; j < matrix[i].length; j++) {
                if (matrix[i][j] < min) min = matrix[i][j];
            }
        }
        return min;
    };

    MLStatMatrix.minMax = function minMax(matrix) {
        var min = Infinity;
        var max = -Infinity;
        for (var i = 0; i < matrix.length; i++) {
            for (var j = 0; j < matrix[i].length; j++) {
                if (matrix[i][j] < min) min = matrix[i][j];
                if (matrix[i][j] > max) max = matrix[i][j];
            }
        }
        return {
            min:min,
            max:max
        };
    };

    MLStatMatrix.entropy = function entropy(matrix, eps) {
        if (typeof (eps) === 'undefined') {
            eps = 0;
        }
        var sum = 0,
            l1 = matrix.length,
            l2 = matrix[0].length;
        for (var i = 0; i < l1; i++) {
            for (var j = 0; j < l2; j++) {
                sum += matrix[i][j] * Math.log(matrix[i][j] + eps);
            }
        }
        return -sum;
    };

    MLStatMatrix.mean = function mean(matrix, dimension) {
        if (typeof (dimension) === 'undefined') {
            dimension = 0;
        }
        var rows = matrix.length,
            cols = matrix[0].length,
            theMean, N, i, j;

        if (dimension === -1) {
            theMean = [0];
            N = rows * cols;
            for (i = 0; i < rows; i++) {
                for (j = 0; j < cols; j++) {
                    theMean[0] += matrix[i][j];
                }
            }
            theMean[0] /= N;
        } else if (dimension === 0) {
            theMean = new Array(cols);
            N = rows;
            for (j = 0; j < cols; j++) {
                theMean[j] = 0;
                for (i = 0; i < rows; i++) {
                    theMean[j] += matrix[i][j];
                }
                theMean[j] /= N;
            }
        } else if (dimension === 1) {
            theMean = new Array(rows);
            N = cols;
            for (j = 0; j < rows; j++) {
                theMean[j] = 0;
                for (i = 0; i < cols; i++) {
                    theMean[j] += matrix[j][i];
                }
                theMean[j] /= N;
            }
        } else {
            throw new Error('Invalid dimension');
        }
        return theMean;
    };

    MLStatMatrix.sum = function sum(matrix, dimension) {
        if (typeof (dimension) === 'undefined') {
            dimension = 0;
        }
        var rows = matrix.length,
            cols = matrix[0].length,
            theSum, i, j;

        if (dimension === -1) {
            theSum = [0];
            for (i = 0; i < rows; i++) {
                for (j = 0; j < cols; j++) {
                    theSum[0] += matrix[i][j];
                }
            }
        } else if (dimension === 0) {
            theSum = new Array(cols);
            for (j = 0; j < cols; j++) {
                theSum[j] = 0;
                for (i = 0; i < rows; i++) {
                    theSum[j] += matrix[i][j];
                }
            }
        } else if (dimension === 1) {
            theSum = new Array(rows);
            for (j = 0; j < rows; j++) {
                theSum[j] = 0;
                for (i = 0; i < cols; i++) {
                    theSum[j] += matrix[j][i];
                }
            }
        } else {
            throw new Error('Invalid dimension');
        }
        return theSum;
    };

    MLStatMatrix.product = function product(matrix, dimension) {
        if (typeof (dimension) === 'undefined') {
            dimension = 0;
        }
        var rows = matrix.length,
            cols = matrix[0].length,
            theProduct, i, j;

        if (dimension === -1) {
            theProduct = [1];
            for (i = 0; i < rows; i++) {
                for (j = 0; j < cols; j++) {
                    theProduct[0] *= matrix[i][j];
                }
            }
        } else if (dimension === 0) {
            theProduct = new Array(cols);
            for (j = 0; j < cols; j++) {
                theProduct[j] = 1;
                for (i = 0; i < rows; i++) {
                    theProduct[j] *= matrix[i][j];
                }
            }
        } else if (dimension === 1) {
            theProduct = new Array(rows);
            for (j = 0; j < rows; j++) {
                theProduct[j] = 1;
                for (i = 0; i < cols; i++) {
                    theProduct[j] *= matrix[j][i];
                }
            }
        } else {
            throw new Error('Invalid dimension');
        }
        return theProduct;
    };

    MLStatMatrix.standardDeviation = function standardDeviation(matrix, means, unbiased) {
        var vari = MLStatMatrix.variance(matrix, means, unbiased), l = vari.length;
        for (var i = 0; i < l; i++) {
            vari[i] = Math.sqrt(vari[i]);
        }
        return vari;
    };

    MLStatMatrix.variance = function variance(matrix, means, unbiased) {
        if (typeof (unbiased) === 'undefined') {
            unbiased = true;
        }
        means = means || MLStatMatrix.mean(matrix);
        var rows = matrix.length;
        if (rows === 0) return [];
        var cols = matrix[0].length;
        var vari = new Array(cols);

        for (var j = 0; j < cols; j++) {
            var sum1 = 0, sum2 = 0, x = 0;
            for (var i = 0; i < rows; i++) {
                x = matrix[i][j] - means[j];
                sum1 += x;
                sum2 += x * x;
            }
            if (unbiased) {
                vari[j] = (sum2 - ((sum1 * sum1) / rows)) / (rows - 1);
            } else {
                vari[j] = (sum2 - ((sum1 * sum1) / rows)) / rows;
            }
        }
        return vari;
    };

    MLStatMatrix.median = function median(matrix) {
        var rows = matrix.length, cols = matrix[0].length;
        var medians = new Array(cols);

        for (var i = 0; i < cols; i++) {
            var data = new Array(rows);
            for (var j = 0; j < rows; j++) {
                data[j] = matrix[j][i];
            }
            data.sort(compareNumbers);
            var N = data.length;
            if (N % 2 === 0) {
                medians[i] = (data[N / 2] + data[(N / 2) - 1]) * 0.5;
            } else {
                medians[i] = data[Math.floor(N / 2)];
            }
        }
        return medians;
    };

    MLStatMatrix.mode = function mode(matrix) {
        var rows = matrix.length,
            cols = matrix[0].length,
            modes = new Array(cols),
            i, j;
        for (i = 0; i < cols; i++) {
            var itemCount = new Array(rows);
            for (var k = 0; k < rows; k++) {
                itemCount[k] = 0;
            }
            var itemArray = new Array(rows);
            var count = 0;

            for (j = 0; j < rows; j++) {
                var index = itemArray.indexOf(matrix[j][i]);
                if (index >= 0) {
                    itemCount[index]++;
                } else {
                    itemArray[count] = matrix[j][i];
                    itemCount[count] = 1;
                    count++;
                }
            }

            var maxValue = 0, maxIndex = 0;
            for (j = 0; j < count; j++) {
                if (itemCount[j] > maxValue) {
                    maxValue = itemCount[j];
                    maxIndex = j;
                }
            }

            modes[i] = itemArray[maxIndex];
        }
        return modes;
    };

    MLStatMatrix.skewness = function skewness(matrix, unbiased) {
        if (typeof (unbiased) === 'undefined') unbiased = true;
        var means = MLStatMatrix.mean(matrix);
        var n = matrix.length, l = means.length;
        var skew = new Array(l);

        for (var j = 0; j < l; j++) {
            var s2 = 0, s3 = 0;
            for (var i = 0; i < n; i++) {
                var dev = matrix[i][j] - means[j];
                s2 += dev * dev;
                s3 += dev * dev * dev;
            }

            var m2 = s2 / n;
            var m3 = s3 / n;
            var g = m3 / Math.pow(m2, 3 / 2);

            if (unbiased) {
                var a = Math.sqrt(n * (n - 1));
                var b = n - 2;
                skew[j] = (a / b) * g;
            } else {
                skew[j] = g;
            }
        }
        return skew;
    };

    MLStatMatrix.kurtosis = function kurtosis(matrix, unbiased) {
        if (typeof (unbiased) === 'undefined') unbiased = true;
        var means = MLStatMatrix.mean(matrix);
        var n = matrix.length, m = matrix[0].length;
        var kurt = new Array(m);

        for (var j = 0; j < m; j++) {
            var s2 = 0, s4 = 0;
            for (var i = 0; i < n; i++) {
                var dev = matrix[i][j] - means[j];
                s2 += dev * dev;
                s4 += dev * dev * dev * dev;
            }
            var m2 = s2 / n;
            var m4 = s4 / n;

            if (unbiased) {
                var v = s2 / (n - 1);
                var a = (n * (n + 1)) / ((n - 1) * (n - 2) * (n - 3));
                var b = s4 / (v * v);
                var c = ((n - 1) * (n - 1)) / ((n - 2) * (n - 3));
                kurt[j] = a * b - 3 * c;
            } else {
                kurt[j] = m4 / (m2 * m2) - 3;
            }
        }
        return kurt;
    };

    MLStatMatrix.standardError = function standardError(matrix) {
        var samples = matrix.length;
        var standardDeviations = MLStatMatrix.standardDeviation(matrix);
        var l = standardDeviations.length;
        var standardErrors = new Array(l);
        var sqrtN = Math.sqrt(samples);

        for (var i = 0; i < l; i++) {
            standardErrors[i] = standardDeviations[i] / sqrtN;
        }
        return standardErrors;
    };

    MLStatMatrix.covariance = function covariance(matrix, dimension) {
        return MLStatMatrix.scatter(matrix, undefined, dimension);
    };

    MLStatMatrix.scatter = function scatter(matrix, divisor, dimension) {
        if (typeof (dimension) === 'undefined') {
            dimension = 0;
        }
        if (typeof (divisor) === 'undefined') {
            if (dimension === 0) {
                divisor = matrix.length - 1;
            } else if (dimension === 1) {
                divisor = matrix[0].length - 1;
            }
        }
        var means = MLStatMatrix.mean(matrix, dimension);
        var rows = matrix.length;
        if (rows === 0) {
            return [[]];
        }
        var cols = matrix[0].length,
            cov, i, j, s, k;

        if (dimension === 0) {
            cov = new Array(cols);
            for (i = 0; i < cols; i++) {
                cov[i] = new Array(cols);
            }
            for (i = 0; i < cols; i++) {
                for (j = i; j < cols; j++) {
                    s = 0;
                    for (k = 0; k < rows; k++) {
                        s += (matrix[k][j] - means[j]) * (matrix[k][i] - means[i]);
                    }
                    s /= divisor;
                    cov[i][j] = s;
                    cov[j][i] = s;
                }
            }
        } else if (dimension === 1) {
            cov = new Array(rows);
            for (i = 0; i < rows; i++) {
                cov[i] = new Array(rows);
            }
            for (i = 0; i < rows; i++) {
                for (j = i; j < rows; j++) {
                    s = 0;
                    for (k = 0; k < cols; k++) {
                        s += (matrix[j][k] - means[j]) * (matrix[i][k] - means[i]);
                    }
                    s /= divisor;
                    cov[i][j] = s;
                    cov[j][i] = s;
                }
            }
        } else {
            throw new Error('Invalid dimension');
        }

        return cov;
    };

    MLStatMatrix.correlation = function correlation(matrix) {
        var means = MLStatMatrix.mean(matrix),
            standardDeviations = MLStatMatrix.standardDeviation(matrix, true, means),
            scores = MLStatMatrix.zScores(matrix, means, standardDeviations),
            rows = matrix.length,
            cols = matrix[0].length,
            i, j;

        var cor = new Array(cols);
        for (i = 0; i < cols; i++) {
            cor[i] = new Array(cols);
        }
        for (i = 0; i < cols; i++) {
            for (j = i; j < cols; j++) {
                var c = 0;
                for (var k = 0, l = scores.length; k < l; k++) {
                    c += scores[k][j] * scores[k][i];
                }
                c /= rows - 1;
                cor[i][j] = c;
                cor[j][i] = c;
            }
        }
        return cor;
    };

    MLStatMatrix.zScores = function zScores(matrix, means, standardDeviations) {
        means = means || MLStatMatrix.mean(matrix);
        if (typeof (standardDeviations) === 'undefined') standardDeviations = MLStatMatrix.standardDeviation(matrix, true, means);
        return MLStatMatrix.standardize(MLStatMatrix.center(matrix, means, false), standardDeviations, true);
    };

    MLStatMatrix.center = function center(matrix, means, inPlace) {
        means = means || MLStatMatrix.mean(matrix);
        var result = matrix,
            l = matrix.length,
            i, j, jj;

        if (!inPlace) {
            result = new Array(l);
            for (i = 0; i < l; i++) {
                result[i] = new Array(matrix[i].length);
            }
        }

        for (i = 0; i < l; i++) {
            var row = result[i];
            for (j = 0, jj = row.length; j < jj; j++) {
                row[j] = matrix[i][j] - means[j];
            }
        }
        return result;
    };

    MLStatMatrix.standardize = function standardize(matrix, standardDeviations, inPlace) {
        if (typeof (standardDeviations) === 'undefined') standardDeviations = MLStatMatrix.standardDeviation(matrix);
        var result = matrix,
            l = matrix.length,
            i, j, jj;

        if (!inPlace) {
            result = new Array(l);
            for (i = 0; i < l; i++) {
                result[i] = new Array(matrix[i].length);
            }
        }

        for (i = 0; i < l; i++) {
            var resultRow = result[i];
            var sourceRow = matrix[i];
            for (j = 0, jj = resultRow.length; j < jj; j++) {
                if (standardDeviations[j] !== 0 && !isNaN(standardDeviations[j])) {
                    resultRow[j] = sourceRow[j] / standardDeviations[j];
                }
            }
        }
        return result;
    };

    MLStatMatrix.weightedVariance = function weightedVariance(matrix, weights) {
        var means = MLStatMatrix.mean(matrix);
        var rows = matrix.length;
        if (rows === 0) return [];
        var cols = matrix[0].length;
        var vari = new Array(cols);

        for (var j = 0; j < cols; j++) {
            var sum = 0;
            var a = 0, b = 0;

            for (var i = 0; i < rows; i++) {
                var z = matrix[i][j] - means[j];
                var w = weights[i];

                sum += w * (z * z);
                b += w;
                a += w * w;
            }

            vari[j] = sum * (b / (b * b - a));
        }

        return vari;
    };

    MLStatMatrix.weightedMean = function weightedMean(matrix, weights, dimension) {
        if (typeof (dimension) === 'undefined') {
            dimension = 0;
        }
        var rows = matrix.length;
        if (rows === 0) return [];
        var cols = matrix[0].length,
            means, i, ii, j, w, row;

        if (dimension === 0) {
            means = new Array(cols);
            for (i = 0; i < cols; i++) {
                means[i] = 0;
            }
            for (i = 0; i < rows; i++) {
                row = matrix[i];
                w = weights[i];
                for (j = 0; j < cols; j++) {
                    means[j] += row[j] * w;
                }
            }
        } else if (dimension === 1) {
            means = new Array(rows);
            for (i = 0; i < rows; i++) {
                means[i] = 0;
            }
            for (j = 0; j < rows; j++) {
                row = matrix[j];
                w = weights[j];
                for (i = 0; i < cols; i++) {
                    means[j] += row[i] * w;
                }
            }
        } else {
            throw new Error('Invalid dimension');
        }

        var weightSum = arrayStat.sum(weights);
        if (weightSum !== 0) {
            for (i = 0, ii = means.length; i < ii; i++) {
                means[i] /= weightSum;
            }
        }
        return means;
    };

    MLStatMatrix.weightedCovariance = function weightedCovariance(matrix, weights, means, dimension) {
        dimension = dimension || 0;
        means = means || MLStatMatrix.weightedMean(matrix, weights, dimension);
        var s1 = 0, s2 = 0;
        for (var i = 0, ii = weights.length; i < ii; i++) {
            s1 += weights[i];
            s2 += weights[i] * weights[i];
        }
        var factor = s1 / (s1 * s1 - s2);
        return MLStatMatrix.weightedScatter(matrix, weights, means, factor, dimension);
    };

    MLStatMatrix.weightedScatter = function weightedScatter(matrix, weights, means, factor, dimension) {
        dimension = dimension || 0;
        means = means || MLStatMatrix.weightedMean(matrix, weights, dimension);
        if (typeof (factor) === 'undefined') {
            factor = 1;
        }
        var rows = matrix.length;
        if (rows === 0) {
            return [[]];
        }
        var cols = matrix[0].length,
            cov, i, j, k, s;

        if (dimension === 0) {
            cov = new Array(cols);
            for (i = 0; i < cols; i++) {
                cov[i] = new Array(cols);
            }
            for (i = 0; i < cols; i++) {
                for (j = i; j < cols; j++) {
                    s = 0;
                    for (k = 0; k < rows; k++) {
                        s += weights[k] * (matrix[k][j] - means[j]) * (matrix[k][i] - means[i]);
                    }
                    cov[i][j] = s * factor;
                    cov[j][i] = s * factor;
                }
            }
        } else if (dimension === 1) {
            cov = new Array(rows);
            for (i = 0; i < rows; i++) {
                cov[i] = new Array(rows);
            }
            for (i = 0; i < rows; i++) {
                for (j = i; j < rows; j++) {
                    s = 0;
                    for (k = 0; k < cols; k++) {
                        s += weights[k] * (matrix[j][k] - means[j]) * (matrix[i][k] - means[i]);
                    }
                    cov[i][j] = s * factor;
                    cov[j][i] = s * factor;
                }
            }
        } else {
            throw new Error('Invalid dimension');
        }

        return cov;
    };
}

// ml-stat index.js
const MLStat = {};
{
    MLStat.array = MLStatArray;
    MLStat.matrix = MLStatMatrix;
}


// ml-array-utils ArrayUtils.js
const MLArrayUtilsArrayUtils = {};
{
    const Stat = MLStat.array;
    /**
     * Function that returns an array of points given 1D array as follows:
     *
     * [x1, y1, .. , x2, y2, ..]
     *
     * And receive the number of dimensions of each point.
     * @param array
     * @param dimensions
     * @returns {Array} - Array of points.
     */

    function coordArrayToPoints(array, dimensions) {
        if(array.length % dimensions !== 0) {
            throw new RangeError('Dimensions number must be accordance with the size of the array.');
        }

        var length = array.length / dimensions;
        var pointsArr = new Array(length);

        var k = 0;
        for(var i = 0; i < array.length; i += dimensions) {
            var point = new Array(dimensions);
            for(var j = 0; j < dimensions; ++j) {
                point[j] = array[i + j];
            }

            pointsArr[k] = point;
            k++;
        }

        return pointsArr;
    }


    /**
     * Function that given an array as follows:
     * [x1, y1, .. , x2, y2, ..]
     *
     * Returns an array as follows:
     * [[x1, x2, ..], [y1, y2, ..], [ .. ]]
     *
     * And receives the number of dimensions of each coordinate.
     * @param array
     * @param dimensions
     * @returns {Array} - Matrix of coordinates
     */

    function coordArrayToCoordMatrix(array, dimensions) {
        if(array.length % dimensions !== 0) {
            throw new RangeError('Dimensions number must be accordance with the size of the array.');
        }

        var coordinatesArray = new Array(dimensions);
        var points = array.length / dimensions;
        for (var i = 0; i < coordinatesArray.length; i++) {
            coordinatesArray[i] = new Array(points);
        }

        for(i = 0; i < array.length; i += dimensions) {
            for(var j = 0; j < dimensions; ++j) {
                var currentPoint = Math.floor(i / dimensions);
                coordinatesArray[j][currentPoint] = array[i + j];
            }
        }

        return coordinatesArray;
    }

    /**
     * Function that receives a coordinate matrix as follows:
     * [[x1, x2, ..], [y1, y2, ..], [ .. ]]
     *
     * Returns an array of coordinates as follows:
     * [x1, y1, .. , x2, y2, ..]
     *
     * @param coordMatrix
     * @returns {Array}
     */

    function coordMatrixToCoordArray(coordMatrix) {
        var coodinatesArray = new Array(coordMatrix.length * coordMatrix[0].length);
        var k = 0;
        for(var i = 0; i < coordMatrix[0].length; ++i) {
            for(var j = 0; j < coordMatrix.length; ++j) {
                coodinatesArray[k] = coordMatrix[j][i];
                ++k;
            }
        }

        return coodinatesArray;
    }

    /**
     * Tranpose a matrix, this method is for coordMatrixToPoints and
     * pointsToCoordMatrix, that because only transposing the matrix
     * you can change your representation.
     *
     * @param matrix
     * @returns {Array}
     */

    function transpose(matrix) {
        var resultMatrix = new Array(matrix[0].length);
        for(var i = 0; i < resultMatrix.length; ++i) {
            resultMatrix[i] = new Array(matrix.length);
        }

        for (i = 0; i < matrix.length; ++i) {
            for(var j = 0; j < matrix[0].length; ++j) {
                resultMatrix[j][i] = matrix[i][j];
            }
        }

        return resultMatrix;
    }

    /**
     * Function that transform an array of points into a coordinates array
     * as follows:
     * [x1, y1, .. , x2, y2, ..]
     *
     * @param points
     * @returns {Array}
     */

    function pointsToCoordArray(points) {
        var coodinatesArray = new Array(points.length * points[0].length);
        var k = 0;
        for(var i = 0; i < points.length; ++i) {
            for(var j = 0; j < points[0].length; ++j) {
                coodinatesArray[k] = points[i][j];
                ++k;
            }
        }

        return coodinatesArray;
    }

    /**
     * Apply the dot product between the smaller vector and a subsets of the
     * largest one.
     *
     * @param firstVector
     * @param secondVector
     * @returns {Array} each dot product of size of the difference between the
     *                  larger and the smallest one.
     */

    function applyDotProduct(firstVector, secondVector) {
        var largestVector, smallestVector;
        if(firstVector.length <= secondVector.length) {
            smallestVector = firstVector;
            largestVector = secondVector;
        } else {
            smallestVector = secondVector;
            largestVector = firstVector;
        }

        var difference = largestVector.length - smallestVector.length + 1;
        var dotProductApplied = new Array(difference);

        for (var i = 0; i < difference; ++i) {
            var sum = 0;
            for (var j = 0; j < smallestVector.length; ++j) {
                sum += smallestVector[j] * largestVector[i + j];
            }
            dotProductApplied[i] = sum;
        }

        return dotProductApplied;
    }
    /**
     * To scale the input array between the specified min and max values. The operation is performed inplace
     * if the options.inplace is specified. If only one of the min or max parameters is specified, then the scaling
     * will multiply the input array by min/min(input) or max/max(input)
     * @param input
     * @param options
     * @returns {*}
     */

    function scale(input, options){
        var y;
        if(options.inPlace){
            y = input;
        }
        else{
            y = new Array(input.length);
        }
        const max = options.max;
        const min = options.min;
        if(typeof max === "number"){
            if(typeof min === "number"){
                var minMax = Stat.minMax(input);
                var factor = (max - min)/(minMax.max-minMax.min);
                for(var i=0;i< y.length;i++){
                    y[i]=(input[i]-minMax.min)*factor+min;
                }
            }
            else{
                var currentMin = Stat.max(input);
                var factor = max/currentMin;
                for(var i=0;i< y.length;i++){
                    y[i] = input[i]*factor;
                }
            }
        }
        else{
            if(typeof min === "number"){
                var currentMin = Stat.min(input);
                var factor = min/currentMin;
                for(var i=0;i< y.length;i++){
                    y[i] = input[i]*factor;
                }
            }
        }
        return y;
    }

    MLArrayUtilsArrayUtils.coordArrayToPoints = coordArrayToPoints;
    MLArrayUtilsArrayUtils.coordArrayToCoordMatrix = coordArrayToCoordMatrix;
    MLArrayUtilsArrayUtils.coordMatrixToCoordArray = coordMatrixToCoordArray;
    MLArrayUtilsArrayUtils.coordMatrixToPoints = transpose;
    MLArrayUtilsArrayUtils.pointsToCoordArray = pointsToCoordArray;
    MLArrayUtilsArrayUtils.pointsToCoordMatrix = transpose;
    MLArrayUtilsArrayUtils.applyDotProduct = applyDotProduct;
    MLArrayUtilsArrayUtils.scale = scale;
}


// ml-array-utils getEquallySpaced.js
const MLArrayUtilsGetEquallySpaced = {};
{
    /**
     *
     * Function that returns a Number array of equally spaced numberOfPoints
     * containing a representation of intensities of the spectra arguments x
     * and y.
     *
     * The options parameter contains an object in the following form:
     * from: starting point
     * to: last point
     * numberOfPoints: number of points between from and to
     * variant: "slot" or "smooth" - smooth is the default option
     *
     * The slot variant consist that each point in the new array is calculated
     * averaging the existing points between the slot that belongs to the current
     * value. The smooth variant is the same but takes the integral of the range
     * of the slot and divide by the step size between two points in the new array.
     *
     * @param x - sorted increasing x values
     * @param y
     * @param options
     * @returns {Array} new array with the equally spaced data.
     *
     */

    function getEquallySpacedData(x, y, options) {
        if (x.length>1 && x[0]>x[1]) {
            x=x.slice().reverse();
            y=y.slice().reverse();
        }

        var xLength = x.length;
        if(xLength !== y.length)
            throw new RangeError("the x and y vector doesn't have the same size.");

        if (options === undefined) options = {};

        var from = options.from === undefined ? x[0] : options.from
        if (isNaN(from) || !isFinite(from)) {
            throw new RangeError("'From' value must be a number");
        }
        var to = options.to === undefined ? x[x.length - 1] : options.to;
        if (isNaN(to) || !isFinite(to)) {
            throw new RangeError("'To' value must be a number");
        }

        var reverse = from > to;
        if(reverse) {
            var temp = from;
            from = to;
            to = temp;
        }

        var numberOfPoints = options.numberOfPoints === undefined ? 100 : options.numberOfPoints;
        if (isNaN(numberOfPoints) || !isFinite(numberOfPoints)) {
            throw new RangeError("'Number of points' value must be a number");
        }
        if(numberOfPoints < 1)
            throw new RangeError("the number of point must be higher than 1");

        var algorithm = options.variant === "slot" ? "slot" : "smooth"// default value: smooth

        var output = algorithm === "slot" ? getEquallySpacedSlot(x, y, from, to, numberOfPoints) : getEquallySpacedSmooth(x, y, from, to, numberOfPoints);

        return reverse ? output.reverse() : output;
    }

    /**
     * function that retrieves the getEquallySpacedData with the variant "smooth"
     *
     * @param x
     * @param y
     * @param from - Initial point
     * @param to - Final point
     * @param numberOfPoints
     * @returns {Array} - Array of y's equally spaced with the variant "smooth"
     */

    function getEquallySpacedSmooth(x, y, from, to, numberOfPoints) {
        var xLength = x.length;

        var step = (to - from) / (numberOfPoints - 1);
        var halfStep = step / 2;

        var start = from - halfStep;
        var output = new Array(numberOfPoints);

        var initialOriginalStep = x[1] - x[0];
        var lastOriginalStep = x[x.length - 1] - x[x.length - 2];

        // Init main variables
        var min = start;
        var max = start + step;

        var previousX = Number.MIN_VALUE;
        var previousY = 0;
        var nextX = x[0] - initialOriginalStep;
        var nextY = 0;

        var currentValue = 0;
        var slope = 0;
        var intercept = 0;
        var sumAtMin = 0;
        var sumAtMax = 0;

        var i = 0; // index of input
        var j = 0; // index of output

        function getSlope(x0, y0, x1, y1) {
            return (y1 - y0) / (x1 - x0);
        }

        main: while(true) {
            while (nextX - max >= 0) {
                // no overlap with original point, just consume current value
                var add = integral(0, max - previousX, slope, previousY);
                sumAtMax = currentValue + add;

                output[j] = (sumAtMax - sumAtMin) / step;
                j++;

                if (j === numberOfPoints)
                    break main;

                min = max;
                max += step;
                sumAtMin = sumAtMax;
            }

            if(previousX <= min && min <= nextX) {
                add = integral(0, min - previousX, slope, previousY);
                sumAtMin = currentValue + add;
            }

            currentValue += integral(previousX, nextX, slope, intercept);

            previousX = nextX;
            previousY = nextY;

            if (i < xLength) {
                nextX = x[i];
                nextY = y[i];
                i++;
            } else if (i === xLength) {
                nextX += lastOriginalStep;
                nextY = 0;
            }
            // updating parameters
            slope = getSlope(previousX, previousY, nextX, nextY);
            intercept = -slope*previousX + previousY;
        }

        return output;
    }

    /**
     * function that retrieves the getEquallySpacedData with the variant "slot"
     *
     * @param x
     * @param y
     * @param from - Initial point
     * @param to - Final point
     * @param numberOfPoints
     * @returns {Array} - Array of y's equally spaced with the variant "slot"
     */

    function getEquallySpacedSlot(x, y, from, to, numberOfPoints) {
        var xLength = x.length;

        var step = (to - from) / (numberOfPoints - 1);
        var halfStep = step / 2;
        var lastStep = x[x.length - 1] - x[x.length - 2];

        var start = from - halfStep;
        var output = new Array(numberOfPoints);

        // Init main variables
        var min = start;
        var max = start + step;

        var previousX = -Number.MAX_VALUE;
        var previousY = 0;
        var nextX = x[0];
        var nextY = y[0];
        var frontOutsideSpectra = 0;
        var backOutsideSpectra = true;

        var currentValue = 0;

        // for slot algorithm
        var currentPoints = 0;

        var i = 1; // index of input
        var j = 0; // index of output

        main: while(true) {
            if (previousX>=nextX) throw (new Error('x must be an increasing serie'));
            while (previousX - max > 0) {
                // no overlap with original point, just consume current value
                if(backOutsideSpectra) {
                    currentPoints++;
                    backOutsideSpectra = false;
                }

                output[j] = currentPoints <= 0 ? 0 : currentValue / currentPoints;
                j++;

                if (j === numberOfPoints)
                    break main;

                min = max;
                max += step;
                currentValue = 0;
                currentPoints = 0;
            }

            if(previousX > min) {
                currentValue += previousY;
                currentPoints++;
            }

            if(previousX === -Number.MAX_VALUE || frontOutsideSpectra > 1)
                currentPoints--;

            previousX = nextX;
            previousY = nextY;

            if (i < xLength) {
                nextX = x[i];
                nextY = y[i];
                i++;
            } else {
                nextX += lastStep;
                nextY = 0;
                frontOutsideSpectra++;
            }
        }

        return output;
    }
    /**
     * Function that calculates the integral of the line between two
     * x-coordinates, given the slope and intercept of the line.
     *
     * @param x0
     * @param x1
     * @param slope
     * @param intercept
     * @returns {number} integral value.
     */

    function integral(x0, x1, slope, intercept) {
        return (0.5 * slope * x1 * x1 + intercept * x1) - (0.5 * slope * x0 * x0 + intercept * x0);
    }

    MLArrayUtilsGetEquallySpaced.getEquallySpacedData = getEquallySpacedData;
    MLArrayUtilsGetEquallySpaced.integral = integral;
}


// ml-array-utils snv.js
const MLArrayUtilsSNV = {};
{
    MLArrayUtilsSNV.SNV = SNV;
    let Stat = MLStat.array;

    /**
     * Function that applies the standard normal variate (SNV) to an array of values.
     *
     * @param data - Array of values.
     * @returns {Array} - applied the SNV.
     */

    function SNV(data) {
        var mean = Stat.mean(data);
        var std = Stat.standardDeviation(data);
        var result = data.slice();
        for (var i = 0; i < data.length; i++) {
            result[i] = (result[i] - mean) / std;
        }
        return result;
    }
}

// ml-array-utils index.js
const MLArrayUtils = {};
{
    MLArrayUtils.getEquallySpacedData = MLArrayUtilsGetEquallySpaced.getEquallySpacedData;
    MLArrayUtils.SNV = MLArrayUtilsSNV.SNV;
}



// do this early so things can use it. This is from ml-matrix src/matrix.js
const MLMatrixMatrix = {};

// ml-matrix src/util.js
const MLMatrixUtil = {};
{
    let exports = MLMatrixUtil;
    let Matrix = MLMatrixMatrix;

    /**
     * @private
     * Check that a row index is not out of bounds
     * @param {Matrix} matrix
     * @param {number} index
     * @param {boolean} [outer]
     */

    exports.checkRowIndex = function checkRowIndex(matrix, index, outer) {
        var 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]
     */

    exports.checkColumnIndex = function checkColumnIndex(matrix, index, outer) {
        var 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}
     */

    exports.checkRowVector = 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}
     */

    exports.checkColumnVector = 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;
    };

    exports.checkIndices = function checkIndices(matrix, rowIndices, columnIndices) {
        var rowOut = rowIndices.some(r => {
            return r < 0 || r >= matrix.rows;

        });

        var columnOut = columnIndices.some(c => {
            return c < 0 || c >= matrix.columns;
        });

        if (rowOut || columnOut) {
            throw new RangeError('Indices are out of range');
        }

        if (typeof rowIndices !== 'object' || typeof columnIndices !== 'object') {
            throw new TypeError('Unexpected type for row/column indices');
        }
        if (!Array.isArray(rowIndices)) rowIndices = Array.from(rowIndices);
        if (!Array.isArray(columnIndices)) rowIndices = Array.from(columnIndices);

        return {
            row: rowIndices,
            column: columnIndices
        };
    };

    exports.checkRange = function checkRange(matrix, startRow, endRow, startColumn, endColumn) {
        if (arguments.length !== 5) throw new TypeError('Invalid argument type');
        var notAllNumbers = Array.from(arguments).slice(1).some(function (arg) {
            return typeof arg !== 'number';
        });
        if (notAllNumbers) throw new TypeError('Invalid argument type');
        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');
        }
    };

    exports.getRange = function getRange(from, to) {
        var arr = new Array(to - from + 1);
        for (var i = 0; i < arr.length; i++) {
            arr[i] = from + i;
        }
        return arr;
    };

    exports.sumByRow = function sumByRow(matrix) {
        var sum = Matrix.Matrix.zeros(matrix.rows, 1);
        for (var i = 0; i < matrix.rows; ++i) {
            for (var j = 0; j < matrix.columns; ++j) {
                sum.set(i, 0, sum.get(i, 0) + matrix.get(i, j));
            }
        }
        return sum;
    };

    exports.sumByColumn = function sumByColumn(matrix) {
        var sum = Matrix.Matrix.zeros(1, matrix.columns);
        for (var i = 0; i < matrix.rows; ++i) {
            for (var j = 0; j < matrix.columns; ++j) {
                sum.set(0, j, sum.get(0, j) + matrix.get(i, j));
            }
        }
        return sum;
    };

    exports.sumAll = function sumAll(matrix) {
        var v = 0;
        for (var i = 0; i < matrix.rows; i++) {
            for (var j = 0; j < matrix.columns; j++) {
                v += matrix.get(i, j);
            }
        }
        return v;
    };
}

// ml-matrix symbolsspecies.js
if (!Symbol.species) {
    Symbol.species = Symbol.for('@@species');
}


// ml-matrix src/dc/util.js
const MLMatrixDCUtil = {};
{
    let exports = MLMatrixDCUtil;
    exports.hypotenuse = function hypotenuse(a, b) {
        var r;
        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;
    };

    // For use in the decomposition algorithms. With big matrices, access time is
    // too long on elements from array subclass
    // todo check when it is fixed in v8
    // http://jsperf.com/access-and-write-array-subclass
    exports.getEmpty2DArray = function (rows, columns) {
        var array = new Array(rows);
        for (var i = 0; i < rows; i++) {
            array[i] = new Array(columns);
        }
        return array;
    };

    exports.getFilled2DArray = function (rows, columns, value) {
        var array = new Array(rows);
        for (var i = 0; i < rows; i++) {
            array[i] = new Array(columns);
            for (var j = 0; j < columns; j++) {
                array[i][j] = value;
            }
        }
        return array;
    };
}

// ml-matrix src/dc/lu.js
let MLMatrixDCLU = {};
{
    let Matrix = MLMatrixMatrix;

    // https://github.com/lutzroeder/Mapack/blob/master/Source/LuDecomposition.cs
    function LuDecomposition(matrix) {
        if (!(this instanceof LuDecomposition)) {
            return new LuDecomposition(matrix);
        }

        matrix = Matrix.Matrix.checkMatrix(matrix);

        var lu = matrix.clone(),
            rows = lu.rows,
            columns = lu.columns,
            pivotVector = new Array(rows),
            pivotSign = 1,
            i, j, k, p, s, t, v,
            LUrowi, LUcolj, kmax;

        for (i = 0; i < rows; i++) {
            pivotVector[i] = i;
        }

        LUcolj = new Array(rows);

        for (j = 0; j < columns; j++) {

            for (i = 0; i < rows; i++) {
                LUcolj[i] = lu[i][j];
            }

            for (i = 0; i < rows; i++) {
                LUrowi = lu[i];
                kmax = Math.min(i, j);
                s = 0;
                for (k = 0; k < kmax; k++) {
                    s += LUrowi[k] * LUcolj[k];
                }
                LUrowi[j] = LUcolj[i] -= s;
            }

            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[p][k];
                    lu[p][k] = lu[j][k];
                    lu[j][k] = t;
                }

                v = pivotVector[p];
                pivotVector[p] = pivotVector[j];
                pivotVector[j] = v;

                pivotSign = -pivotSign;
            }

            if (j < rows && lu[j][j] !== 0) {
                for (i = j + 1; i < rows; i++) {
                    lu[i][j] /= lu[j][j];
                }
            }
        }

        this.LU = lu;
        this.pivotVector = pivotVector;
        this.pivotSign = pivotSign;
    }

    LuDecomposition.prototype = {
        isSingular: function () {
            var data = this.LU,
                col = data.columns;
            for (var j = 0; j < col; j++) {
                if (data[j][j] === 0) {
                    return true;
                }
            }
            return false;
        },
        get determinant() {
            var data = this.LU;
            if (!data.isSquare()) {
                throw new Error('Matrix must be square');
            }
            var determinant = this.pivotSign, col = data.columns;
            for (var j = 0; j < col; j++) {
                determinant *= data[j][j];
            }
            return determinant;
        },
        get lowerTriangularMatrix() {
            var data = this.LU,
                rows = data.rows,
                columns = data.columns,
                X = new Matrix.Matrix(rows, columns);
            for (var i = 0; i < rows; i++) {
                for (var j = 0; j < columns; j++) {
                    if (i > j) {
                        X[i][j] = data[i][j];
                    } else if (i === j) {
                        X[i][j] = 1;
                    } else {
                        X[i][j] = 0;
                    }
                }
            }
            return X;
        },
        get upperTriangularMatrix() {
            var data = this.LU,
                rows = data.rows,
                columns = data.columns,
                X = new Matrix.Matrix(rows, columns);
            for (var i = 0; i < rows; i++) {
                for (var j = 0; j < columns; j++) {
                    if (i <= j) {
                        X[i][j] = data[i][j];
                    } else {
                        X[i][j] = 0;
                    }
                }
            }
            return X;
        },
        get pivotPermutationVector() {
            return this.pivotVector.slice();
        },
        solve: function (value) {
            value = Matrix.Matrix.checkMatrix(value);

            var lu = this.LU,
                rows = lu.rows;

            if (rows !== value.rows) {
                throw new Error('Invalid matrix dimensions');
            }
            if (this.isSingular()) {
                throw new Error('LU matrix is singular');
            }

            var count = value.columns;
            var X = value.subMatrixRow(this.pivotVector, 0, count - 1);
            var columns = lu.columns;
            var i, j, k;

            for (k = 0; k < columns; k++) {
                for (i = k + 1; i < columns; i++) {
                    for (j = 0; j < count; j++) {
                        X[i][j] -= X[k][j] * lu[i][k];
                    }
                }
            }
            for (k = columns - 1; k >= 0; k--) {
                for (j = 0; j < count; j++) {
                    X[k][j] /= lu[k][k];
                }
                for (i = 0; i < k; i++) {
                    for (j = 0; j < count; j++) {
                        X[i][j] -= X[k][j] * lu[i][k];
                    }
                }
            }
            return X;
        }
    };

    MLMatrixDCLU = LuDecomposition;
}


// ml-matrix src/dc/svd.js
let MLMatrixDCSVD = {};
{
    let Matrix = MLMatrixMatrix;
    let util = MLMatrixDCUtil;
    let hypotenuse = util.hypotenuse;
    let getFilled2DArray = util.getFilled2DArray;

    // https://github.com/lutzroeder/Mapack/blob/master/Source/SingularValueDecomposition.cs
    function SingularValueDecomposition(value, options) {
        if (!(this instanceof SingularValueDecomposition)) {
            return new SingularValueDecomposition(value, options);
        }
        value = Matrix.Matrix.checkMatrix(value);

        options = options || {};

        var m = value.rows,
            n = value.columns,
            nu = Math.min(m, n);

        var wantu = true, wantv = true;
        if (options.computeLeftSingularVectors === false) wantu = false;
        if (options.computeRightSingularVectors === false) wantv = false;
        var autoTranspose = options.autoTranspose === true;

        var swapped = false;
        var 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;
                var aux = wantu;
                wantu = wantv;
                wantv = aux;
            }
        } else {
            a = value.clone();
        }

        var s = new Array(Math.min(m + 1, n)),
            U = getFilled2DArray(m, nu, 0),
            V = getFilled2DArray(n, n, 0),
            e = new Array(n),
            work = new Array(m);

        var nct = Math.min(m - 1, n);
        var nrt = Math.max(0, Math.min(n - 2, m));

        var i, j, k, p, t, ks, f, cs, sn, max, kase,
            scale, sp, spm1, epm1, sk, ek, b, c, shift, g;

        for (k = 0, max = Math.max(nct, nrt); k < max; k++) {
            if (k < nct) {
                s[k] = 0;
                for (i = k; i < m; i++) {
                    s[k] = hypotenuse(s[k], a[i][k]);
                }
                if (s[k] !== 0) {
                    if (a[k][k] < 0) {
                        s[k] = -s[k];
                    }
                    for (i = k; i < m; i++) {
                        a[i][k] /= s[k];
                    }
                    a[k][k] += 1;
                }
                s[k] = -s[k];
            }

            for (j = k + 1; j < n; j++) {
                if ((k < nct) && (s[k] !== 0)) {
                    t = 0;
                    for (i = k; i < m; i++) {
                        t += a[i][k] * a[i][j];
                    }
                    t = -t / a[k][k];
                    for (i = k; i < m; i++) {
                        a[i][j] += t * a[i][k];
                    }
                }
                e[j] = a[k][j];
            }

--> --------------------

--> maximum size reached

--> --------------------

Messung V0.5
C=95 H=69 G=82

¤ Dauer der Verarbeitung: 0.27 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge