Example usage for org.apache.commons.math3.linear EigenDecomposition getImagEigenvalues

List of usage examples for org.apache.commons.math3.linear EigenDecomposition getImagEigenvalues

Introduction

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

Prototype

public double[] getImagEigenvalues() 

Source Link

Document

Gets a copy of the imaginary parts of the eigenvalues of the original matrix.

Usage

From source file:net.sf.dsp4j.octave_3_2_4.Eig.java

public static Complex[] eig(RealMatrix d) {
    EigenDecomposition eig = new EigenDecomposition(d);
    double[] realEigenvalues = eig.getRealEigenvalues();
    double[] imagEigenvalues = eig.getImagEigenvalues();

    final Complex[] result = new Complex[realEigenvalues.length];
    for (int i = 0; i < realEigenvalues.length; i++) {
        result[i] = new Complex(realEigenvalues[i], imagEigenvalues[i]);
    }// ww  w.  j a va2  s .c  o  m
    return result;
}

From source file:edu.cmu.tetrad.search.TimeSeriesUtils.java

public static boolean allEigenvaluesAreSmallerThanOneInModulus(TetradMatrix mat) {

    double[] realEigenvalues = new double[0];
    double[] imagEigenvalues = new double[0];
    try {/* w w  w  . j av  a  2s .c o  m*/
        EigenDecomposition dec = new EigenDecomposition(mat.getRealMatrix());
        realEigenvalues = dec.getRealEigenvalues();
        imagEigenvalues = dec.getImagEigenvalues();
    } catch (MaxCountExceededException e) {
        e.printStackTrace();
    }

    for (int i = 0; i < realEigenvalues.length; i++) {
        double realEigenvalue = realEigenvalues[i];
        double imagEigenvalue = imagEigenvalues[i];
        System.out.println("Real eigenvalues are : " + realEigenvalue + " and imag part : " + imagEigenvalue);
        double modulus = Math.sqrt(Math.pow(realEigenvalue, 2) + Math.pow(imagEigenvalue, 2));

        if (modulus >= 1.0) {
            return false;
        }
    }
    return true;
}

From source file:org.eclipse.dataset.LinearAlgebra.java

/**
 * @param a/*from w w  w  . j av  a2 s . c  o m*/
 * @return dataset of eigenvalues (can be double or complex double)
 */
public static Dataset calcEigenvalues(Dataset a) {
    EigenDecomposition evd = new EigenDecomposition(createRealMatrix(a));
    double[] rev = evd.getRealEigenvalues();

    if (evd.hasComplexEigenvalues()) {
        double[] iev = evd.getImagEigenvalues();
        return new ComplexDoubleDataset(rev, iev);
    }
    return new DoubleDataset(rev);
}

From source file:org.eclipse.dataset.LinearAlgebra.java

/**
 * Calculate eigen-decomposition A = V D V^T
 * @param a/*  w w  w  .j  av a2  s . c  o  m*/
 * @return array of D eigenvalues (can be double or complex double) and V eigenvectors
 */
public static Dataset[] calcEigenDecomposition(Dataset a) {
    EigenDecomposition evd = new EigenDecomposition(createRealMatrix(a));
    Dataset[] results = new Dataset[2];

    double[] rev = evd.getRealEigenvalues();
    if (evd.hasComplexEigenvalues()) {
        double[] iev = evd.getImagEigenvalues();
        results[0] = new ComplexDoubleDataset(rev, iev);
    } else {
        results[0] = new DoubleDataset(rev);
    }
    results[1] = createDataset(evd.getV());
    return results;
}

From source file:org.eclipse.january.dataset.LinearAlgebra.java

/**
 * @param a// w  w w.  java  2  s  .c  o m
 * @return dataset of eigenvalues (can be double or complex double)
 */
public static Dataset calcEigenvalues(Dataset a) {
    EigenDecomposition evd = new EigenDecomposition(createRealMatrix(a));
    double[] rev = evd.getRealEigenvalues();

    if (evd.hasComplexEigenvalues()) {
        double[] iev = evd.getImagEigenvalues();
        return DatasetFactory.createComplexDataset(ComplexDoubleDataset.class, rev, iev);
    }
    return DatasetFactory.createFromObject(rev);
}

From source file:org.eclipse.january.dataset.LinearAlgebra.java

/**
 * Calculate eigen-decomposition A = V D V^T
 * @param a//from   w  ww . j  av a  2s.  c om
 * @return array of D eigenvalues (can be double or complex double) and V eigenvectors
 */
public static Dataset[] calcEigenDecomposition(Dataset a) {
    EigenDecomposition evd = new EigenDecomposition(createRealMatrix(a));
    Dataset[] results = new Dataset[2];

    double[] rev = evd.getRealEigenvalues();
    if (evd.hasComplexEigenvalues()) {
        double[] iev = evd.getImagEigenvalues();
        results[0] = DatasetFactory.createComplexDataset(ComplexDoubleDataset.class, rev, iev);
    } else {
        results[0] = DatasetFactory.createFromObject(rev);
    }
    results[1] = createDataset(evd.getV());
    return results;
}

From source file:org.meteoinfo.math.linalg.LinalgUtil.java

/**
 * Calculates the eigen decomposition of a real matrix.
 * The eigen decomposition of matrix A is a set of two matrices: V and D such that 
 * A = V  D  VT. A, V and D are all m  m matrices.
 * @param a Given matrix./*from   ww  w  .  ja  v  a 2s.c o m*/
 * @return Result W/V arrays.
 */
public static Array[] eigen(Array a) {
    int m = a.getShape()[0];
    Array Wa;
    Array Va = Array.factory(DataType.DOUBLE, new int[] { m, m });
    double[][] aa = (double[][]) ArrayUtil.copyToNDJavaArray(a);
    RealMatrix matrix = new Array2DRowRealMatrix(aa, false);
    EigenDecomposition decomposition = new EigenDecomposition(matrix);
    double[] rev = decomposition.getRealEigenvalues();
    double[] iev = decomposition.getImagEigenvalues();
    if (decomposition.hasComplexEigenvalues()) {
        Wa = Array.factory(DataType.OBJECT, new int[] { m });
        for (int i = 0; i < m; i++) {
            Wa.setObject(i, new Complex(rev[i], iev[i]));
            RealVector v = decomposition.getEigenvector(i);
            for (int j = 0; j < v.getDimension(); j++) {
                Va.setDouble(i * m + j, v.getEntry(j));
            }
        }
    } else {
        Wa = Array.factory(DataType.DOUBLE, new int[] { m });
        for (int i = 0; i < m; i++) {
            Wa.setDouble(i, rev[i]);
            RealVector v = decomposition.getEigenvector(i);
            for (int j = 0; j < v.getDimension(); j++) {
                Va.setDouble(i * m + j, v.getEntry(j));
            }
        }
    }

    return new Array[] { Wa, Va };
}

From source file:org.rhwlab.dispim.nucleus.NucleusData.java

static public boolean intersect(NucleusData nuc1, NucleusData nuc2) {
    RealMatrix qs1 = nuc1.quadraticSurfaceMatrix();
    RealMatrix qs2 = nuc2.quadraticSurfaceMatrix();

    LUDecomposition lu = new LUDecomposition(qs1);
    RealMatrix qs1Inv = lu.getSolver().getInverse();

    EigenDecomposition ed = new EigenDecomposition(qs1Inv.multiply(qs2));
    double[] realValues = ed.getRealEigenvalues();
    double[] imagValues = ed.getImagEigenvalues();

    // are there two distinct negative real eigenvalues

    for (int i = 0; i < realValues.length - 1; ++i) {
        for (int j = i; j < realValues.length; ++j) {
            if (realValues[i] < 0.0 && realValues[j] < 0.0 && imagValues[i] == 0.0 && imagValues[j] == 0.0
                    && realValues[i] != realValues[j]) {
                return false;
            }//from  ww  w  .  j  av  a 2s . c  o  m
        }
    }
    int sahdfuihs = 0;

    return true;
}