当前位置: 首页>>代码示例>>Java>>正文


Java MathArrays.copyOf方法代码示例

本文整理汇总了Java中org.apache.commons.math3.util.MathArrays.copyOf方法的典型用法代码示例。如果您正苦于以下问题:Java MathArrays.copyOf方法的具体用法?Java MathArrays.copyOf怎么用?Java MathArrays.copyOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.util.MathArrays的用法示例。


在下文中一共展示了MathArrays.copyOf方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MultivariateNormalMixtureExpectationMaximization

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Creates an object to fit a multivariate normal mixture model to data.
 *
 * @param data Data to use in fitting procedure
 * @throws NotStrictlyPositiveException if data has no rows
 * @throws DimensionMismatchException if rows of data have different numbers
 *             of columns
 * @throws NumberIsTooSmallException if the number of columns in the data is
 *             less than 2
 */
public MultivariateNormalMixtureExpectationMaximization(double[][] data)
    throws NotStrictlyPositiveException,
           DimensionMismatchException,
           NumberIsTooSmallException {
    if (data.length < 1) {
        throw new NotStrictlyPositiveException(data.length);
    }

    this.data = new double[data.length][data[0].length];

    for (int i = 0; i < data.length; i++) {
        if (data[i].length != data[0].length) {
            // Jagged arrays not allowed
            throw new DimensionMismatchException(data[i].length,
                                                 data[0].length);
        }
        if (data[i].length < 2) {
            throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_TOO_SMALL,
                                                data[i].length, 2, true);
        }
        this.data[i] = MathArrays.copyOf(data[i], data[i].length);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:34,代码来源:MultivariateNormalMixtureExpectationMaximization.java

示例2: StepFunction

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Builds a step function from a list of arguments and the corresponding
 * values. Specifically, returns the function h(x) defined by <pre><code>
 * h(x) = y[0] for all x &lt; x[1]
 *        y[1] for x[1] &le; x &lt; x[2]
 *        ...
 *        y[y.length - 1] for x &ge; x[x.length - 1]
 * </code></pre>
 * The value of {@code x[0]} is ignored, but it must be strictly less than
 * {@code x[1]}.
 *
 * @param x Domain values where the function changes value.
 * @param y Values of the function.
 * @throws NonMonotonicSequenceException
 * if the {@code x} array is not sorted in strictly increasing order.
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 * @throws DimensionMismatchException if {@code x} and {@code y} do not
 * have the same length.
 */
public StepFunction(double[] x,
                    double[] y)
    throws NullArgumentException, NoDataException,
           DimensionMismatchException, NonMonotonicSequenceException {
    if (x == null ||
        y == null) {
        throw new NullArgumentException();
    }
    if (x.length == 0 ||
        y.length == 0) {
        throw new NoDataException();
    }
    if (y.length != x.length) {
        throw new DimensionMismatchException(y.length, x.length);
    }
    MathArrays.checkOrder(x);

    abscissa = MathArrays.copyOf(x);
    ordinate = MathArrays.copyOf(y);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:41,代码来源:StepFunction.java

示例3: nextPermutation

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * This method calls {@link MathArrays#shuffle(int[],RandomGenerator)
 * MathArrays.shuffle} in order to create a random shuffle of the set
 * of natural numbers {@code { 0, 1, ..., n - 1 }}.
 *
 * @throws NumberIsTooLargeException if {@code k > n}.
 * @throws NotStrictlyPositiveException if {@code k <= 0}.
 */
public int[] nextPermutation(int n, int k)
    throws NumberIsTooLargeException, NotStrictlyPositiveException {
    if (k > n) {
        throw new NumberIsTooLargeException(LocalizedFormats.PERMUTATION_EXCEEDS_N,
                                            k, n, true);
    }
    if (k <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.PERMUTATION_SIZE,
                                               k);
    }

    int[] index = MathArrays.natural(n);
    MathArrays.shuffle(index, getRandomGenerator());

    // Return a new array containing the first "k" entries of "index".
    return MathArrays.copyOf(index, k);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:28,代码来源:RandomDataGenerator.java

示例4: transform

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Returns the (forward, inverse) transform of the specified real data set.
 *
 * @param f the real data array to be transformed
 * @param type the type of transform (forward, inverse) to be performed
 * @return the complex transformed array
 * @throws MathIllegalArgumentException if the length of the data array is not a power of two
 */
public Complex[] transform(final double[] f, final TransformType type) {
    final double[][] dataRI = new double[][] {
        MathArrays.copyOf(f, f.length), new double[f.length]
    };

    transformInPlace(dataRI, normalization, type);

    return TransformUtils.createComplexArray(dataRI);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:18,代码来源:FastFourierTransformer.java

示例5: integralKolmogorovSmirnovStatistic

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Computes the two-sample Kolmogorov-Smirnov test statistic, \(D_{n,m}=\sup_x |F_n(x)-F_m(x)|\)
 * where \(n\) is the length of {@code x}, \(m\) is the length of {@code y}, \(F_n\) is the
 * empirical distribution that puts mass \(1/n\) at each of the values in {@code x} and \(F_m\)
 * is the empirical distribution of the {@code y} values. Finally \(n m D_{n,m}\) is returned
 * as long value.
 *
 * @param x first sample
 * @param y second sample
 * @return test statistic \(n m D_{n,m}\) used to evaluate the null hypothesis that {@code x} and
 *         {@code y} represent samples from the same underlying distribution
 * @throws InsufficientDataException if either {@code x} or {@code y} does not have length at
 *         least 2
 * @throws NullArgumentException if either {@code x} or {@code y} is null
 */
private long integralKolmogorovSmirnovStatistic(double[] x, double[] y) {
    checkArray(x);
    checkArray(y);
    // Copy and sort the sample arrays
    final double[] sx = MathArrays.copyOf(x);
    final double[] sy = MathArrays.copyOf(y);
    Arrays.sort(sx);
    Arrays.sort(sy);
    final int n = sx.length;
    final int m = sy.length;

    int rankX = 0;
    int rankY = 0;
    long curD = 0l;

    // Find the max difference between cdf_x and cdf_y
    long supD = 0l;
    do {
        double z = Double.compare(sx[rankX], sy[rankY]) <= 0 ? sx[rankX] : sy[rankY];
        while(rankX < n && Double.compare(sx[rankX], z) == 0) {
            rankX += 1;
            curD += m;
        }
        while(rankY < m && Double.compare(sy[rankY], z) == 0) {
            rankY += 1;
            curD -= n;
        }
        if (curD > supD) {
            supD = curD;
        }
        else if (-curD > supD) {
            supD = -curD;
        }
    } while(rankX < n && rankY < m);
    return supD;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:52,代码来源:KolmogorovSmirnovTest.java

示例6: MultivariateNormalDistribution

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Creates a multivariate normal distribution with the given mean vector and
 * covariance matrix.
 * <br/>
 * The number of dimensions is equal to the length of the mean vector
 * and to the number of rows and columns of the covariance matrix.
 * It is frequently written as "p" in formulae.
 *
 * @param rng Random Number Generator.
 * @param means Vector of means.
 * @param covariances Covariance matrix.
 * @throws DimensionMismatchException if the arrays length are
 * inconsistent.
 * @throws SingularMatrixException if the eigenvalue decomposition cannot
 * be performed on the provided covariance matrix.
 * @throws NonPositiveDefiniteMatrixException if any of the eigenvalues is
 * negative.
 */
public MultivariateNormalDistribution(RandomGenerator rng,
                                      final double[] means,
                                      final double[][] covariances)
        throws SingularMatrixException,
               DimensionMismatchException,
               NonPositiveDefiniteMatrixException {
    super(rng, means.length);

    final int dim = means.length;

    if (covariances.length != dim) {
        throw new DimensionMismatchException(covariances.length, dim);
    }

    for (int i = 0; i < dim; i++) {
        if (dim != covariances[i].length) {
            throw new DimensionMismatchException(covariances[i].length, dim);
        }
    }

    this.means = MathArrays.copyOf(means);

    covarianceMatrix = new Array2DRowRealMatrix(covariances);

    // Covariance matrix eigen decomposition.
    final EigenDecomposition covMatDec = new EigenDecomposition(covarianceMatrix);

    // Compute and store the inverse.
    covarianceMatrixInverse = covMatDec.getSolver().getInverse();
    // Compute and store the determinant.
    covarianceMatrixDeterminant = covMatDec.getDeterminant();

    // Eigenvalues of the covariance matrix.
    final double[] covMatEigenvalues = covMatDec.getRealEigenvalues();

    for (int i = 0; i < covMatEigenvalues.length; i++) {
        if (covMatEigenvalues[i] < 0) {
            throw new NonPositiveDefiniteMatrixException(covMatEigenvalues[i], i, 0);
        }
    }

    // Matrix where each column is an eigenvector of the covariance matrix.
    final Array2DRowRealMatrix covMatEigenvectors = new Array2DRowRealMatrix(dim, dim);
    for (int v = 0; v < dim; v++) {
        final double[] evec = covMatDec.getEigenvector(v).toArray();
        covMatEigenvectors.setColumn(v, evec);
    }

    final RealMatrix tmpMatrix = covMatEigenvectors.transpose();

    // Scale each eigenvector by the square root of its eigenvalue.
    for (int row = 0; row < dim; row++) {
        final double factor = FastMath.sqrt(covMatEigenvalues[row]);
        for (int col = 0; col < dim; col++) {
            tmpMatrix.multiplyEntry(row, col, factor);
        }
    }

    samplingMatrix = covMatEigenvectors.multiply(tmpMatrix);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:79,代码来源:MultivariateNormalDistribution.java

示例7: kolmogorovSmirnovTest

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Computes the <i>p-value</i>, or <i>observed significance level</i>, of a two-sample <a
 * href="http://en.wikipedia.org/wiki/Kolmogorov-Smirnov_test"> Kolmogorov-Smirnov test</a>
 * evaluating the null hypothesis that {@code x} and {@code y} are samples drawn from the same
 * probability distribution. Specifically, what is returned is an estimate of the probability
 * that the {@link #kolmogorovSmirnovStatistic(double[], double[])} associated with a randomly
 * selected partition of the combined sample into subsamples of sizes {@code x.length} and
 * {@code y.length} will strictly exceed (if {@code strict} is {@code true}) or be at least as
 * large as {@code strict = false}) as {@code kolmogorovSmirnovStatistic(x, y)}.
 * <ul>
 * <li>For small samples (where the product of the sample sizes is less than
 * {@value #LARGE_SAMPLE_PRODUCT}), the exact p-value is computed using the method presented
 * in [4], implemented in {@link #exactP(double, int, int, boolean)}. </li>
 * <li>When the product of the sample sizes exceeds {@value #LARGE_SAMPLE_PRODUCT}, the
 * asymptotic distribution of \(D_{n,m}\) is used. See {@link #approximateP(double, int, int)}
 * for details on the approximation.</li>
 * </ul><p>
 * If {@code x.length * y.length} < {@value #LARGE_SAMPLE_PRODUCT} and the combined set of values in
 * {@code x} and {@code y} contains ties, random jitter is added to {@code x} and {@code y} to
 * break ties before computing \(D_{n,m}\) and the p-value. The jitter is uniformly distributed
 * on (-minDelta / 2, minDelta / 2) where minDelta is the smallest pairwise difference between
 * values in the combined sample.</p>
 * <p>
 * If ties are known to be present in the data, {@link #bootstrap(double[], double[], int, boolean)}
 * may be used as an alternative method for estimating the p-value.</p>
 *
 * @param x first sample dataset
 * @param y second sample dataset
 * @param strict whether or not the probability to compute is expressed as a strict inequality
 *        (ignored for large samples)
 * @return p-value associated with the null hypothesis that {@code x} and {@code y} represent
 *         samples from the same distribution
 * @throws InsufficientDataException if either {@code x} or {@code y} does not have length at
 *         least 2
 * @throws NullArgumentException if either {@code x} or {@code y} is null
 * @see #bootstrap(double[], double[], int, boolean)
 */
public double kolmogorovSmirnovTest(double[] x, double[] y, boolean strict) {
    final long lengthProduct = (long) x.length * y.length;
    double[] xa = null;
    double[] ya = null;
    if (lengthProduct < LARGE_SAMPLE_PRODUCT && hasTies(x,y)) {
        xa = MathArrays.copyOf(x);
        ya = MathArrays.copyOf(y);
        fixTies(xa, ya);
    } else {
        xa = x;
        ya = y;
    }
    if (lengthProduct < LARGE_SAMPLE_PRODUCT) {
        return exactP(kolmogorovSmirnovStatistic(xa, ya), x.length, y.length, strict);
    }
    return approximateP(kolmogorovSmirnovStatistic(x, y), x.length, y.length);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:55,代码来源:KolmogorovSmirnovTest.java

示例8: RegressionResults

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Constructor for Regression Results.
 *
 * @param parameters a double array with the regression slope estimates
 * @param varcov the variance covariance matrix, stored either in a square matrix
 * or as a compressed
 * @param isSymmetricCompressed a flag which denotes that the variance covariance
 * matrix is in symmetric compressed format
 * @param nobs the number of observations of the regression estimation
 * @param rank the number of independent variables in the regression
 * @param sumy the sum of the independent variable
 * @param sumysq the sum of the squared independent variable
 * @param sse sum of squared errors
 * @param containsConstant true model has constant,  false model does not have constant
 * @param copyData if true a deep copy of all input data is made, if false only references
 * are copied and the RegressionResults become mutable
 */
public RegressionResults(
        final double[] parameters, final double[][] varcov,
        final boolean isSymmetricCompressed,
        final long nobs, final int rank,
        final double sumy, final double sumysq, final double sse,
        final boolean containsConstant,
        final boolean copyData) {
    if (copyData) {
        this.parameters = MathArrays.copyOf(parameters);
        this.varCovData = new double[varcov.length][];
        for (int i = 0; i < varcov.length; i++) {
            this.varCovData[i] = MathArrays.copyOf(varcov[i]);
        }
    } else {
        this.parameters = parameters;
        this.varCovData = varcov;
    }
    this.isSymmetricVCD = isSymmetricCompressed;
    this.nobs = nobs;
    this.rank = rank;
    this.containsConstant = containsConstant;
    this.globalFitInfo = new double[5];
    Arrays.fill(this.globalFitInfo, Double.NaN);

    if (rank > 0) {
        this.globalFitInfo[SST_IDX] = containsConstant ?
                (sumysq - sumy * sumy / nobs) : sumysq;
    }

    this.globalFitInfo[SSE_IDX] = sse;
    this.globalFitInfo[MSE_IDX] = this.globalFitInfo[SSE_IDX] /
            (nobs - rank);
    this.globalFitInfo[RSQ_IDX] = 1.0 -
            this.globalFitInfo[SSE_IDX] /
            this.globalFitInfo[SST_IDX];

    if (!containsConstant) {
        this.globalFitInfo[ADJRSQ_IDX] = 1.0-
                (1.0 - this.globalFitInfo[RSQ_IDX]) *
                ( (double) nobs / ( (double) (nobs - rank)));
    } else {
        this.globalFitInfo[ADJRSQ_IDX] = 1.0 - (sse * (nobs - 1.0)) /
                (globalFitInfo[SST_IDX] * (nobs - rank));
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:63,代码来源:RegressionResults.java

示例9: getVals

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * @return the computed function values
 */
public double[] getVals() {
    return MathArrays.copyOf(vals, vals.length);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:7,代码来源:BesselJ.java

示例10: StepFunction

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Builds a step function from a list of arguments and the corresponding
 * values. Specifically, returns the function h(x) defined by <pre><code>
 * h(x) = y[0] for all x < x[1]
 *        y[1] for x[1] <= x < x[2]
 *        ...
 *        y[y.length - 1] for x >= x[x.length - 1]
 * </code></pre>
 * The value of {@code x[0]} is ignored, but it must be strictly less than
 * {@code x[1]}.
 *
 * @param x Domain values where the function changes value.
 * @param y Values of the function.
 * @throws org.apache.commons.math3.exception.NonMonotonicSequenceException
 * if the {@code x} array is not sorted in strictly increasing order.
 * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
 * @throws NoDataException if {@code x} or {@code y} are zero-length.
 * @throws DimensionMismatchException if {@code x} and {@code y} do not
 * have the same length.
 */
public StepFunction(double[] x,
                    double[] y) {
    if (x == null ||
        y == null) {
        throw new NullArgumentException();
    }
    if (x.length == 0 ||
        y.length == 0) {
        throw new NoDataException();
    }
    if (y.length != x.length) {
        throw new DimensionMismatchException(y.length, x.length);
    }
    MathArrays.checkOrder(x);

    abscissa = MathArrays.copyOf(x);
    ordinate = MathArrays.copyOf(y);
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:39,代码来源:StepFunction.java

示例11: getParameterEstimates

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * <p>Returns a copy of the regression parameters estimates.</p>
 *
 * <p>The parameter estimates are returned in the natural order of the data.</p>
 *
 * <p>A redundant regressor will have its redundancy flag set, as will
 *  a parameter estimate equal to {@code Double.NaN}.</p>
 *
 * @return array of parameter estimates, null if no estimation occurred
 */
public double[] getParameterEstimates() {
    if (this.parameters == null) {
        return null;
    }
    return MathArrays.copyOf(parameters);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:17,代码来源:RegressionResults.java

示例12: getMeans

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Gets the mean vector.
 *
 * @return the mean vector.
 */
public double[] getMeans() {
    return MathArrays.copyOf(means);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:9,代码来源:MultivariateNormalDistribution.java

示例13: getOrderOfRegressors

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Gets the order of the regressors, useful if some type of reordering
 * has been called. Calling regress with int[]{} args will trigger
 * a reordering.
 *
 * @return int[] with the current order of the regressors
 */
public int[] getOrderOfRegressors(){
    return MathArrays.copyOf(vorder);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:11,代码来源:MillerUpdatingRegression.java

示例14: BesselJResult

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Create a new BesselJResult with the given values and valid value count.
 *
 * @param b values
 * @param n count of valid values
 */
public BesselJResult(double[] b, int n) {
    vals = MathArrays.copyOf(b, b.length);
    nVals = n;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:11,代码来源:BesselJ.java


注:本文中的org.apache.commons.math3.util.MathArrays.copyOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。