Author: tn
Date: Fri Oct 11 21:39:09 2013
New Revision: 1531430

URL: http://svn.apache.org/r1531430
Log:
[MATH-1033] Fix input parameter check in KalmanFilter. Thanks to Yuan Qu.

Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/filter/KalmanFilter.java

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1531430&r1=1531429&r2=1531430&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Fri Oct 11 21:39:09 2013
@@ -51,6 +51,10 @@ If the output is not quite correct, chec
   </properties>
   <body>
     <release version="x.y" date="TBD" description="TBD">
+      <action dev="tn" type="fix" issue="MATH-1033" due-to="Yuan Qu">
+        The "KalmanFilter" wrongly enforced a column dimension of 1 for
+        the provided control and measurement noise matrix.
+      </action>
       <action dev="tn" type="fix" issue="MATH-1037" due-to="Aleksei Dievskii">
         Fix a typo in the "GeometricDistributionTest" and ensure that a 
meaningful
         tolerance value is used when comparing test results with expected 
values.

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/filter/KalmanFilter.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/filter/KalmanFilter.java?rev=1531430&r1=1531429&r2=1531430&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/filter/KalmanFilter.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/filter/KalmanFilter.java
 Fri Oct 11 21:39:09 2013
@@ -182,14 +182,15 @@ public class KalmanFilter {
         }
 
         // row dimension of B must be equal to A
+        // if no control matrix is available, the row and column dimension 
will be 0
         if (controlMatrix != null &&
             controlMatrix.getRowDimension() > 0 &&
             controlMatrix.getColumnDimension() > 0 &&
-            (controlMatrix.getRowDimension() != 
transitionMatrix.getRowDimension() ||
-             controlMatrix.getColumnDimension() != 1)) {
+            controlMatrix.getRowDimension() != 
transitionMatrix.getRowDimension()) {
             throw new 
MatrixDimensionMismatchException(controlMatrix.getRowDimension(),
                                                        
controlMatrix.getColumnDimension(),
-                                                       
transitionMatrix.getRowDimension(), 1);
+                                                       
transitionMatrix.getRowDimension(),
+                                                       
controlMatrix.getColumnDimension());
         }
 
         // Q must be equal to A
@@ -204,11 +205,11 @@ public class KalmanFilter {
         }
 
         // row dimension of R must be equal to row dimension of H
-        if (measNoise.getRowDimension() != measurementMatrix.getRowDimension() 
||
-            measNoise.getColumnDimension() != 1) {
+        if (measNoise.getRowDimension() != 
measurementMatrix.getRowDimension()) {
             throw new 
MatrixDimensionMismatchException(measNoise.getRowDimension(),
                                                        
measNoise.getColumnDimension(),
-                                                       
measurementMatrix.getRowDimension(), 1);
+                                                       
measurementMatrix.getRowDimension(),
+                                                       
measNoise.getColumnDimension());
         }
     }
 
@@ -356,7 +357,7 @@ public class KalmanFilter {
                                                  
measurementMatrix.getRowDimension());
         }
 
-        // S = H * P(k) - * H' + R
+        // S = H * P(k) * H' + R
         RealMatrix s = measurementMatrix.multiply(errorCovariance)
             .multiply(measurementMatrixT)
             .add(measurementModel.getMeasurementNoise());


Reply via email to