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

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

Introduction

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

Prototype

public boolean hasComplexEigenvalues() 

Source Link

Document

Returns whether the calculated eigen values are complex or real.

Usage

From source file:lanchester.MultiArena.java

public void step() {
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    setFloor(i1, i2);/*  ww w .  ja  v a 2  s .  c  o  m*/
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    //        for(int i1=0;i1<eVals.length;i1++){
    //            System.out.println("eVals["+i1+"] = "+eVals[i1]);
    //        }
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            AthenaForce f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getForceSize() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    MultiTimeStep currentStep = new MultiTimeStep(numFoes);
    currentTime += timeStep;
    currentStep.setTime(currentTime);
    for (int i1 = 0; i1 < numFoes; i1++) {
        double updatedForce = 0.;
        for (int i2 = 0; i2 < numFoes; i2++) {
            updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
            //                updatedForce+=coeffs[i2]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i2]*timeStep);
            //                updatedForce+=coeffs[i1]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i1]*timeStep);
        }
        forces.get(i1).updateForce(updatedForce);
        currentStep.setForceNumber(updatedForce, i1);
    }
    history.add(currentStep);
    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (true) {
        //            System.out.println("time = " + time);
    }
}

From source file:lanchester.MultiArena3.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        currentCeiling = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                    currentCeiling[i1][i2] = 100.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    setFloor(i1, i2);//from ww  w .j  av a  2 s.  c  om
                    setCeiling(i1, i2);
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            MultiForce f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getNumber() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    aboveFloor = true;
    boolean belowCeiling = true;
    int cntr = 0;
    int numGone;
    do {
        timeStep = determineTimeStep();
        MultiTimeStep currentStep = new MultiTimeStep(numFoes);
        currentTime += timeStep;
        currentCycle += timeStep;
        currentStep.setTime(currentTime);
        numGone = 0;
        for (int i1 = 0; i1 < numFoes; i1++) {
            double updatedForce = 0.;
            if (stillAlive[i1]) {
                for (int i2 = 0; i2 < numFoes; i2++) {
                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * currentCycle);
                }
                if (updatedForce < 1.) {
                    updatedForce = lb;
                    stillAlive[i1] = false;
                    numGone++;
                }
            } else {
                numGone++;
                updatedForce = lb;
            }
            forces.get(i1).updateForce(updatedForce);
            currentStep.setForceNumber(updatedForce, i1);
        }
        history.add(currentStep);
        aboveFloor = checkAboveFloors();
        belowCeiling = checkBelowCeilings();
        cntr++;
    } while (aboveFloor && belowCeiling && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setFloor(i1, i2);
            }
        }
    }

    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

From source file:lanchester.MultiArena2.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    setFloor(i1, i2);/*from ww  w  . ja  v a2  s . com*/
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    //        for(int i1=0;i1<eVals.length;i1++){
    //            System.out.println("eVals["+i1+"] = "+eVals[i1]);
    //        }
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            AthenaForce f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getForceSize() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    aboveFloor = true;
    int cntr = 0;
    int numGone;
    do {
        MultiTimeStep currentStep = new MultiTimeStep(numFoes);
        currentTime += timeStep;
        currentCycle += timeStep;
        currentStep.setTime(currentTime);
        numGone = 0;
        for (int i1 = 0; i1 < numFoes; i1++) {
            double updatedForce = 0.;
            if (forces.get(i1).getForceSize() > lb) {
                for (int i2 = 0; i2 < numFoes; i2++) {
                    //                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * currentCycle);
                    if (updatedForce < 1.) {
                        updatedForce = 0.;
                        numGone++;
                    }
                    //                updatedForce+=coeffs[i2]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i2]*timeStep);
                    //                updatedForce+=coeffs[i1]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i1]*timeStep);
                }
            } else {
                updatedForce = lb / 2.;
                numGone++;
            }
            forces.get(i1).updateForce(updatedForce);
            currentStep.setForceNumber(updatedForce, i1);
        }
        history.add(currentStep);
        aboveFloor = checkAboveFloors();
        cntr++;
    } while (aboveFloor && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setFloor(i1, i2);
            }
        }
    }

    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

From source file:lanchester.MultiArena4.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        currentCeiling = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            //                int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                //                    int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                    currentCeiling[i1][i2] = 1000000.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    //                        setStances(i1,i2);
                    setFloor(i1, i2);//from   w  ww . j a v  a 2 s.  c o  m
                    setCeiling(i1, i2);
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            MultiForce f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getNumber() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    aboveFloor = true;
    boolean belowCeiling = true;
    int cntr = 0;
    int numGone;
    do {
        timeStep = determineTimeStep();
        MultiTimeStep currentStep = new MultiTimeStep(numFoes);
        currentTime += timeStep;
        currentCycle += timeStep;
        currentStep.setTime(currentTime);
        numGone = 0;
        for (int i1 = 0; i1 < numFoes; i1++) {
            double updatedForce = 0.;
            //                if (forces.get(i1).getForceSize() > lb) {
            if (stillAlive[i1]) {
                for (int i2 = 0; i2 < numFoes; i2++) {
                    //                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * currentCycle);

                    //                updatedForce+=coeffs[i2]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i2]*timeStep);
                    //                updatedForce+=coeffs[i1]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i1]*timeStep);
                }
                if (updatedForce < 1.) {
                    updatedForce = lb;
                    stillAlive[i1] = false;
                    numGone++;
                }
            } else {
                updatedForce = lb;
                numGone++;
            }
            forces.get(i1).updateForce(updatedForce);
            currentStep.setForceNumber(updatedForce, i1);
            //                for (int i2 = 0; i2 < numFoes; i1++) {
            //                    if (i1 != i2) {
            //
            //                    }
            //                }
        }
        history.add(currentStep);
        aboveFloor = checkAboveFloors();
        belowCeiling = checkBelowCeilings();
        cntr++;
    } while (aboveFloor && belowCeiling && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                //                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setStances(i1, i2);
                setFloor(i1, i2);
                setCeiling(i1, i2);
            }
        }
    }

    //        eVectors.
    //        this.currentTime++;
    //                Truncator truncator = new Truncator();
    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

From source file:net2.N2MultiArena.java

public void step() {
    boolean aboveFloor = true;
    double currentCycle = 0.;
    int numFoes = forces.size();
    System.out.println("Num foes = " + numFoes);
    if (isMyTurn == null) {
        isMyTurn = new boolean[numFoes][numFoes];
        stanceArray = new int[numFoes][numFoes];
        currentFloor = new double[numFoes][numFoes];
        currentCeiling = new double[numFoes][numFoes];
        for (int i1 = 0; i1 < numFoes; i1++) {
            //                int ind1 = forceMap.get(forces.get(i1));
            for (int i2 = 0; i2 < numFoes; i2++) {
                //                    int ind2 = forceMap.get(forces.get(i2));
                isMyTurn[i1][i2] = true;
                if (i1 == i2) {
                    stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                    currentFloor[i1][i2] = 0.;
                    currentCeiling[i1][i2] = 1000000.;
                } else {
                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                    setFloor(i1, i2);//from  w w  w. j a  v  a 2 s. co m
                    setCeiling(i1, i2);
                }
            }
        }
    }
    Array2DRowRealMatrix mat = getMat();
    EigenDecomposition eigen = new EigenDecomposition(mat);
    double det = eigen.getDeterminant();
    double[] eVals = eigen.getRealEigenvalues();
    if (eigen.hasComplexEigenvalues()) {
        System.out.println("Complex eigenvalues");
        for (int i1 = 0; i1 < forces.size(); i1++) {
            N2ForceUnit f = forces.get(i1);
            System.out.println(f.getName() + " has " + f.getNumber() + " forces remaining");
        }
    }
    double[] initialNums = getInitialNumbers(forces);
    Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV();
    LUDecomposition lu = new LUDecomposition(eVectors);
    double det2 = lu.getDeterminant();
    double[] coeffs = new double[numFoes];
    for (int i1 = 0; i1 < numFoes; i1++) {
        Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy();
        tmpMat.setColumn(i1, initialNums);
        LUDecomposition tmpLU = new LUDecomposition(tmpMat);
        double tmpDet = tmpLU.getDeterminant();
        coeffs[i1] = tmpDet / det2;
    }
    aboveFloor = true;
    boolean belowCeiling = true;
    //        int cntr = 0;
    int numGone;
    //        do {
    timeStep = determineTimeStep();
    MultiTimeStep currentStep = new MultiTimeStep(numFoes);
    currentTime += timeStep;
    currentCycle += timeStep;
    currentStep.setTime(currentTime);
    numGone = 0;
    for (int i1 = 0; i1 < numFoes; i1++) {
        double updatedForce = 0.;
        //                if (forces.get(i1).getForceSize() > lb) {
        if (stillAlive[i1]) {
            for (int i2 = 0; i2 < numFoes; i2++) {
                //                    updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep);
                updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * currentCycle);

            }
            if (updatedForce < 1.) {
                updatedForce = lb;
                stillAlive[i1] = false;
                numGone++;
            }
        } else {
            updatedForce = lb;
            numGone++;
        }
        forces.get(i1).updateForce(updatedForce);
        currentStep.setForceNumber(updatedForce, i1);
    }
    history.add(currentStep);
    aboveFloor = checkAboveFloors();
    belowCeiling = checkBelowCeilings();
    //            cntr++;
    //        } while (aboveFloor && belowCeiling && cntr < 2000 && (numFoes - numGone) > 1);
    for (int i1 = 0; i1 < numFoes; i1++) {
        for (int i2 = 0; i2 < numFoes; i2++) {
            if (i1 == i2) {
                stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE;
                currentFloor[i1][i2] = 0.;
            } else {
                //                    stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2));
                setStances(i1, i2);
                setFloor(i1, i2);
                setCeiling(i1, i2);
            }
        }
    }

    if (numFoes - numGone == 1) {
        loneSurvivor = true;
        //            System.out.println("time = " + time);
    }
}

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

/**
 * @param a//from w  ww  .  ja va 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 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//from  ww  w  .ja va2 s  .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] = 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 ww .j a va  2s  . co 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  w  w .  j  ava  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./*  w w  w.j a  v  a2  s  . co  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 };
}