View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.math3.filter;
18  
19  import org.apache.commons.math3.exception.DimensionMismatchException;
20  import org.apache.commons.math3.exception.NoDataException;
21  import org.apache.commons.math3.exception.NullArgumentException;
22  import org.apache.commons.math3.linear.Array2DRowRealMatrix;
23  import org.apache.commons.math3.linear.RealMatrix;
24  
25  /**
26   * Default implementation of a {@link MeasurementModel} for the use with a {@link KalmanFilter}.
27   *
28   * @since 3.0
29   */
30  public class DefaultMeasurementModel implements MeasurementModel {
31  
32      /**
33       * The measurement matrix, used to associate the measurement vector to the
34       * internal state estimation vector.
35       */
36      private RealMatrix measurementMatrix;
37  
38      /**
39       * The measurement noise covariance matrix.
40       */
41      private RealMatrix measurementNoise;
42  
43      /**
44       * Create a new {@link MeasurementModel}, taking double arrays as input parameters for the
45       * respective measurement matrix and noise.
46       *
47       * @param measMatrix
48       *            the measurement matrix
49       * @param measNoise
50       *            the measurement noise matrix
51       * @throws NullArgumentException
52       *             if any of the input matrices is {@code null}
53       * @throws NoDataException
54       *             if any row / column dimension of the input matrices is zero
55       * @throws DimensionMismatchException
56       *             if any of the input matrices is non-rectangular
57       */
58      public DefaultMeasurementModel(final double[][] measMatrix, final double[][] measNoise)
59              throws NullArgumentException, NoDataException, DimensionMismatchException {
60          this(new Array2DRowRealMatrix(measMatrix), new Array2DRowRealMatrix(measNoise));
61      }
62  
63      /**
64       * Create a new {@link MeasurementModel}, taking {@link RealMatrix} objects
65       * as input parameters for the respective measurement matrix and noise.
66       *
67       * @param measMatrix the measurement matrix
68       * @param measNoise the measurement noise matrix
69       */
70      public DefaultMeasurementModel(final RealMatrix measMatrix, final RealMatrix measNoise) {
71          this.measurementMatrix = measMatrix;
72          this.measurementNoise = measNoise;
73      }
74  
75      /** {@inheritDoc} */
76      public RealMatrix getMeasurementMatrix() {
77          return measurementMatrix;
78      }
79  
80      /** {@inheritDoc} */
81      public RealMatrix getMeasurementNoise() {
82          return measurementNoise;
83      }
84  }