Example usage for org.apache.commons.math.linear EigenDecomposition getV

List of usage examples for org.apache.commons.math.linear EigenDecomposition getV

Introduction

In this page you can find the example usage for org.apache.commons.math.linear EigenDecomposition getV.

Prototype

RealMatrix getV();

Source Link

Document

Returns the matrix V of the decomposition.

Usage

From source file:com.opengamma.analytics.math.matrix.CommonsMatrixAlgebra.java

/**
 * Returns a real matrix raised to some real power 
 * Currently this method is limited to symmetric matrices only as Commons Math does not support the diagonalization of asymmetric matrices  
 * @param m The <strong>symmetric</strong> matrix to take the power of. 
 * @param p The power to raise to matrix to
 * @return The result/*from w w w  .j  av  a2 s.  c  o m*/
 */
@Override
public DoubleMatrix2D getPower(final Matrix<?> m, final double p) {
    if (m instanceof DoubleMatrix2D) {
        final RealMatrix temp = CommonsMathWrapper.wrap((DoubleMatrix2D) m);
        final EigenDecomposition eigen = new EigenDecompositionImpl(temp, 0.0);
        final double[] rEigenValues = eigen.getRealEigenvalues();
        final double[] iEigenValues = eigen.getImagEigenvalues();
        final int n = rEigenValues.length;
        final double[][] d = new double[n][n];
        for (int i = n - 1; i >= 0; --i) {
            d[i][i] = Math.pow(rEigenValues[i], p);
            if (iEigenValues[i] != 0.0) {
                throw new NotImplementedException("Cannot handle complex eigenvalues in getPower");
            }
        }
        final RealMatrix res = eigen.getV().multiply((new Array2DRowRealMatrix(d)).multiply(eigen.getVT()));
        return CommonsMathWrapper.unwrap(res);
    }
    throw new IllegalArgumentException("Can only find pow of DoubleMatrix2D; have " + m.getClass());
}

From source file:org.apache.mahout.math.ssvd.EigenSolverWrapper.java

public EigenSolverWrapper(double[][] bbt) {
    int dim = bbt.length;
    EigenDecomposition evd2 = new EigenDecompositionImpl(new Array2DRowRealMatrix(bbt), 0);
    eigenvalues = evd2.getRealEigenvalues();
    RealMatrix uHatrm = evd2.getV();
    uHat = new double[dim][];
    for (int i = 0; i < dim; i++) {
        uHat[i] = uHatrm.getRow(i);//from  w  w  w  .  j  av a2 s .  c o m
    }
}