Java Code Examples for org.apache.commons.math.linear.RealVector#toArray()

The following examples show how to use org.apache.commons.math.linear.RealVector#toArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Nopol2017_0070_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Get the -1 times the sum of all coefficients in the given array.
 * @param coefficients coefficients to sum
 * @return the -1 times the sum of all coefficients in the given array.
 */
protected static double getInvertedCoefficientSum(final RealVector coefficients) {
    double sum = 0;
    for (double coefficient : coefficients.toArray()) {
        sum -= coefficient;
    }
    return sum;
}
 
Example 2
Source File: Nopol2017_0070_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Get the -1 times the sum of all coefficients in the given array.
 * @param coefficients coefficients to sum
 * @return the -1 times the sum of all coefficients in the given array.
 */
protected static double getInvertedCoefficientSum(final RealVector coefficients) {
    double sum = 0;
    for (double coefficient : coefficients.toArray()) {
        sum -= coefficient;
    }
    return sum;
}
 
Example 3
Source File: patch1-Math-42-Nopol2017_patch1-Math-42-Nopol2017_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Get the -1 times the sum of all coefficients in the given array.
 * @param coefficients coefficients to sum
 * @return the -1 times the sum of all coefficients in the given array.
 */
protected static double getInvertedCoefficientSum(final RealVector coefficients) {
    double sum = 0;
    for (double coefficient : coefficients.toArray()) {
        sum -= coefficient;
    }
    return sum;
}
 
Example 4
Source File: patch1-Math-42-Nopol2017_patch1-Math-42-Nopol2017_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Get the -1 times the sum of all coefficients in the given array.
 * @param coefficients coefficients to sum
 * @return the -1 times the sum of all coefficients in the given array.
 */
protected static double getInvertedCoefficientSum(final RealVector coefficients) {
    double sum = 0;
    for (double coefficient : coefficients.toArray()) {
        sum -= coefficient;
    }
    return sum;
}
 
Example 5
Source File: Math_42_SimplexTableau_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Get the -1 times the sum of all coefficients in the given array.
 * @param coefficients coefficients to sum
 * @return the -1 times the sum of all coefficients in the given array.
 */
protected static double getInvertedCoefficientSum(final RealVector coefficients) {
    double sum = 0;
    for (double coefficient : coefficients.toArray()) {
        sum -= coefficient;
    }
    return sum;
}
 
Example 6
Source File: Math_42_SimplexTableau_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Get the -1 times the sum of all coefficients in the given array.
 * @param coefficients coefficients to sum
 * @return the -1 times the sum of all coefficients in the given array.
 */
protected static double getInvertedCoefficientSum(final RealVector coefficients) {
    double sum = 0;
    for (double coefficient : coefficients.toArray()) {
        sum -= coefficient;
    }
    return sum;
}
 
Example 7
Source File: MatrixZoomData.java    From JuiceboxLegacy with MIT License 4 votes vote down vote up
/**
 * Computes eigenvector from Pearson's.
 *
 * @param df    Expected values, needed to get Pearson's
 * @param which Which eigenvector; 0 is principal.
 * @return Eigenvector
 */
public double[] computeEigenvector(ExpectedValueFunction df, int which) {
    BasicMatrix pearsons = getPearsons(df);
    if (pearsons == null) {
        return null;
    }

    int dim = pearsons.getRowDimension();
    double[][] data = new double[dim][dim];
    BitSet bitSet = new BitSet(dim);
    for (int i = 0; i < dim; i++) {
        for (int j = 0; j < dim; j++) {
            float tmp = pearsons.getEntry(i, j);
            data[i][j] = tmp;
            if (data[i][j] != 0 && !Float.isNaN(tmp)) {
                bitSet.set(i);
            }
        }
    }

    int[] nonCentromereColumns = new int[bitSet.cardinality()];
    int count = 0;
    for (int i = 0; i < dim; i++) {
        if (bitSet.get(i)) nonCentromereColumns[count++] = i;
    }

    RealMatrix subMatrix = new Array2DRowRealMatrix(data).getSubMatrix(nonCentromereColumns, nonCentromereColumns);
    RealVector rv = (new EigenDecompositionImpl(subMatrix, 0)).getEigenvector(which);

    double[] ev = rv.toArray();

    int size = pearsons.getColumnDimension();
    double[] eigenvector = new double[size];
    int num = 0;
    for (int i = 0; i < size; i++) {
        if (num < nonCentromereColumns.length && i == nonCentromereColumns[num]) {
            eigenvector[i] = ev[num];
            num++;
        } else {
            eigenvector[i] = Double.NaN;
        }
    }
    return eigenvector;

}
 
Example 8
Source File: MatrixZoomData.java    From Juicebox with MIT License 4 votes vote down vote up
/**
 * Computes eigenvector from Pearson's.
 *
 * @param df    Expected values, needed to get Pearson's
 * @param which Which eigenvector; 0 is principal.
 * @return Eigenvector
 */
public double[] computeEigenvector(ExpectedValueFunction df, int which) {
    BasicMatrix pearsons = getPearsons(df);
    if (pearsons == null) {
        return null;
    }

    int dim = pearsons.getRowDimension();
    double[][] data = new double[dim][dim];
    BitSet bitSet = new BitSet(dim);
    for (int i = 0; i < dim; i++) {
        for (int j = 0; j < dim; j++) {
            float tmp = pearsons.getEntry(i, j);
            data[i][j] = tmp;
            if (data[i][j] != 0 && !Float.isNaN(tmp)) {
                bitSet.set(i);
            }
        }
    }

    int[] nonCentromereColumns = new int[bitSet.cardinality()];
    int count = 0;
    for (int i = 0; i < dim; i++) {
        if (bitSet.get(i)) nonCentromereColumns[count++] = i;
    }

    RealMatrix subMatrix = new Array2DRowRealMatrix(data).getSubMatrix(nonCentromereColumns, nonCentromereColumns);
    RealVector rv = (new EigenDecompositionImpl(subMatrix, 0)).getEigenvector(which);

    double[] ev = rv.toArray();

    int size = pearsons.getColumnDimension();
    double[] eigenvector = new double[size];
    int num = 0;
    for (int i = 0; i < size; i++) {
        if (num < nonCentromereColumns.length && i == nonCentromereColumns[num]) {
            eigenvector[i] = ev[num];
            num++;
        } else {
            eigenvector[i] = Double.NaN;
        }
    }
    return eigenvector;

}