Java Code Examples for org.apache.commons.math3.linear.EigenDecomposition#getImagEigenvalues()
The following examples show how to use
org.apache.commons.math3.linear.EigenDecomposition#getImagEigenvalues() .
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: LinalgUtil.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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. * @return Result W/V arrays. */ public static Array[] eigen_bak(Array a) { int m = a.getShape()[0]; Array Wa; Array Va = Array.factory(DataType.DOUBLE, new int[]{m, m}); double[][] aa = (double[][]) ArrayUtil.copyToNDJavaArray_Double(a); RealMatrix matrix = new Array2DRowRealMatrix(aa, false); EigenDecomposition decomposition = new EigenDecomposition(matrix); if (decomposition.hasComplexEigenvalues()) { Wa = Array.factory(DataType.OBJECT, new int[]{m}); double[] rev = decomposition.getRealEigenvalues(); double[] iev = decomposition.getImagEigenvalues(); 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(j * m + i, v.getEntry(j)); } } } else { RealMatrix V = decomposition.getV(); RealMatrix D = decomposition.getD(); Wa = Array.factory(DataType.DOUBLE, new int[]{m}); for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { Va.setDouble(i * m + (m - j - 1), V.getEntry(i, j)); if (i == j) { Wa.setDouble(m - i - 1, D.getEntry(i, j)); } } } } return new Array[]{Wa, Va}; }
Example 2
Source File: LinearAlgebra.java From january with Eclipse Public License 1.0 | 5 votes |
/** * @param a * @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); }
Example 3
Source File: LinearAlgebra.java From january with Eclipse Public License 1.0 | 5 votes |
/** * Calculate eigen-decomposition {@code A = V D V^T} * @param a * @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; }