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

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

Introduction

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

Prototype

double[] getRealEigenvalues();

Source Link

Document

Returns a copy of the real parts of the eigenvalues of the original matrix.

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   ww  w . j  a v  a2 s  .com*/
 */
@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();/*  w  ww  . j a va  2 s . c  o m*/
    uHat = new double[dim][];
    for (int i = 0; i < dim; i++) {
        uHat[i] = uHatrm.getRow(i);
    }
}