You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2008/12/07 16:36:32 UTC
svn commit: r724144 - in /commons/proper/math/trunk/src:
java/org/apache/commons/math/linear/AbstractRealMatrix.java
java/org/apache/commons/math/linear/RealMatrix.java site/xdoc/changes.xml
test/org/apache/commons/math/linear/RealMatrixImplTest.java
Author: luc
Date: Sun Dec 7 07:36:32 2008
New Revision: 724144
URL: http://svn.apache.org/viewvc?rev=724144&view=rev
Log:
added Frobenius matrix norm
JIRA: MATH-232
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrix.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java?rev=724144&r1=724143&r2=724144&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/AbstractRealMatrix.java Sun Dec 7 07:36:32 2008
@@ -217,6 +217,20 @@
}
/** {@inheritDoc} */
+ public double getFrobeniusNorm() {
+ final int rowCount = getRowDimension();
+ final int columnCount = getColumnDimension();
+ double sum2 = 0;
+ for (int col = 0; col < columnCount; ++col) {
+ for (int row = 0; row < rowCount; ++row) {
+ final double mij = getEntry(row, col);
+ sum2 += mij * mij;
+ }
+ }
+ return Math.sqrt(sum2);
+ }
+
+ /** {@inheritDoc} */
public RealMatrix getSubMatrix(final int startRow, final int endRow,
final int startColumn, final int endColumn)
throws MatrixIndexException {
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrix.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrix.java?rev=724144&r1=724143&r2=724144&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrix.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/RealMatrix.java Sun Dec 7 07:36:32 2008
@@ -114,6 +114,14 @@
double getNorm();
/**
+ * Returns the <a href="http://mathworld.wolfram.com/FrobeniusNorm.html">
+ * Frobenius norm</a> of the matrix.
+ *
+ * @return norm
+ */
+ double getFrobeniusNorm();
+
+ /**
* Gets a submatrix. Rows and columns are indicated
* counting from 0 to n-1.
*
Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=724144&r1=724143&r2=724144&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Dec 7 07:36:32 2008
@@ -39,6 +39,9 @@
</properties>
<body>
<release version="2.0" date="TBD" description="TBD">
+ <action dev="luc" type="add" issue="MATH-232" >
+ Added Frobenius matrix norm.
+ </action>
<action dev="luc" type="add" issue="MATH-231" >
Added an abstract matrix implementation simplifying extension by users.
</action>
Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java?rev=724144&r1=724143&r2=724144&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java Sun Dec 7 07:36:32 2008
@@ -159,6 +159,14 @@
assertEquals("testData2 norm",7d,m2.getNorm(),entryTolerance);
}
+ /** test Frobenius norm */
+ public void testFrobeniusNorm() {
+ RealMatrixImpl m = new RealMatrixImpl(testData);
+ RealMatrixImpl m2 = new RealMatrixImpl(testData2);
+ assertEquals("testData Frobenius norm", Math.sqrt(117.0), m.getFrobeniusNorm(), entryTolerance);
+ assertEquals("testData2 Frobenius norm", Math.sqrt(52.0), m2.getFrobeniusNorm(), entryTolerance);
+ }
+
/** test m-n = m + -n */
public void testPlusMinus() {
RealMatrixImpl m = new RealMatrixImpl(testData);