Java Code Examples for org.apache.commons.math.exception.util.LocalizedFormats#TOO_LARGE_CUTOFF_SINGULAR_VALUE

The following examples show how to use org.apache.commons.math.exception.util.LocalizedFormats#TOO_LARGE_CUTOFF_SINGULAR_VALUE . 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: SingularValueDecompositionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public RealMatrix getCovariance(final double minSingularValue) {
    // get the number of singular values to consider
    final int p = singularValues.length;
    int dimension = 0;
    while ((dimension < p) && (singularValues[dimension] >= minSingularValue)) {
        ++dimension;
    }

    if (dimension == 0) {
        throw new NumberIsTooLargeException(LocalizedFormats.TOO_LARGE_CUTOFF_SINGULAR_VALUE,
                                            minSingularValue, singularValues[0], true);
    }

    final double[][] data = new double[dimension][p];
    getVT().walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {
        /** {@inheritDoc} */
        @Override
        public void visit(final int row, final int column,
                final double value) {
            data[row][column] = value / singularValues[row];
        }
    }, 0, dimension - 1, 0, p - 1);

    RealMatrix jv = new Array2DRowRealMatrix(data, false);
    return jv.transpose().multiply(jv);
}
 
Example 2
Source File: SingularValueDecompositionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public RealMatrix getCovariance(final double minSingularValue) {
    // get the number of singular values to consider
    final int p = singularValues.length;
    int dimension = 0;
    while ((dimension < p) && (singularValues[dimension] >= minSingularValue)) {
        ++dimension;
    }

    if (dimension == 0) {
        throw new NumberIsTooLargeException(LocalizedFormats.TOO_LARGE_CUTOFF_SINGULAR_VALUE,
                                            minSingularValue, singularValues[0], true);
    }

    final double[][] data = new double[dimension][p];
    getVT().walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {
        /** {@inheritDoc} */
        @Override
        public void visit(final int row, final int column,
                final double value) {
            data[row][column] = value / singularValues[row];
        }
    }, 0, dimension - 1, 0, p - 1);

    RealMatrix jv = new Array2DRowRealMatrix(data, false);
    return jv.transpose().multiply(jv);
}
 
Example 3
Source File: SingularValueDecompositionImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public RealMatrix getCovariance(final double minSingularValue) {
    // get the number of singular values to consider
    final int p = singularValues.length;
    int dimension = 0;
    while ((dimension < p) && (singularValues[dimension] >= minSingularValue)) {
        ++dimension;
    }

    if (dimension == 0) {
        throw new NumberIsTooLargeException(LocalizedFormats.TOO_LARGE_CUTOFF_SINGULAR_VALUE,
                                            minSingularValue, singularValues[0], true);
    }

    final double[][] data = new double[dimension][p];
    getVT().walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {
        /** {@inheritDoc} */
        @Override
        public void visit(final int row, final int column,
                final double value) {
            data[row][column] = value / singularValues[row];
        }
    }, 0, dimension - 1, 0, p - 1);

    RealMatrix jv = new Array2DRowRealMatrix(data, false);
    return jv.transpose().multiply(jv);
}