You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2012/10/30 01:38:45 UTC
svn commit: r1403591 -
/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java
Author: erans
Date: Tue Oct 30 00:38:44 2012
New Revision: 1403591
URL: http://svn.apache.org/viewvc?rev=1403591&view=rev
Log:
Use the "isSymmetric" utility method from "MatrixUtils" (copied from
"EigenDecomposition" in MATH-884).
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java?rev=1403591&r1=1403590&r2=1403591&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java Tue Oct 30 00:38:44 2012
@@ -115,7 +115,8 @@ public class EigenDecomposition {
*/
public EigenDecomposition(final RealMatrix matrix)
throws MathArithmeticException {
- isSymmetric = isSymmetric(matrix, false);
+ final double symTol = 10 * matrix.getRowDimension() * matrix.getColumnDimension() * Precision.EPSILON;
+ isSymmetric = MatrixUtils.isSymmetric(matrix, symTol);
if (isSymmetric) {
transformToTridiagonal(matrix);
findEigenVectors(transformer.getQ().getData());
@@ -182,37 +183,6 @@ public class EigenDecomposition {
}
/**
- * Check if a matrix is symmetric.
- *
- * @param matrix Matrix to check.
- * @param raiseException If {@code true}, the method will throw an
- * exception if {@code matrix} is not symmetric.
- * @return {@code true} if {@code matrix} is symmetric.
- * @throws NonSymmetricMatrixException if the matrix is not symmetric and
- * {@code raiseException} is {@code true}.
- */
- private boolean isSymmetric(final RealMatrix matrix,
- boolean raiseException) {
- final int rows = matrix.getRowDimension();
- final int columns = matrix.getColumnDimension();
- final double eps = 10 * rows * columns * Precision.EPSILON;
- for (int i = 0; i < rows; ++i) {
- for (int j = i + 1; j < columns; ++j) {
- final double mij = matrix.getEntry(i, j);
- final double mji = matrix.getEntry(j, i);
- if (FastMath.abs(mij - mji) >
- (FastMath.max(FastMath.abs(mij), FastMath.abs(mji)) * eps)) {
- if (raiseException) {
- throw new NonSymmetricMatrixException(i, j, eps);
- }
- return false;
- }
- }
- }
- return true;
- }
-
- /**
* Gets the matrix V of the decomposition.
* V is an orthogonal matrix, i.e. its transpose is also its inverse.
* The columns of V are the eigenvectors of the original matrix.