DefaultMeasurementModel.java

  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.math4.legacy.filter;

  18. import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
  19. import org.apache.commons.math4.legacy.exception.NoDataException;
  20. import org.apache.commons.math4.legacy.exception.NullArgumentException;
  21. import org.apache.commons.math4.legacy.linear.Array2DRowRealMatrix;
  22. import org.apache.commons.math4.legacy.linear.RealMatrix;

  23. /**
  24.  * Default implementation of a {@link MeasurementModel} for the use with a {@link KalmanFilter}.
  25.  *
  26.  * @since 3.0
  27.  */
  28. public class DefaultMeasurementModel implements MeasurementModel {

  29.     /**
  30.      * The measurement matrix, used to associate the measurement vector to the
  31.      * internal state estimation vector.
  32.      */
  33.     private final RealMatrix measurementMatrix;

  34.     /**
  35.      * The measurement noise covariance matrix.
  36.      */
  37.     private final RealMatrix measurementNoise;

  38.     /**
  39.      * Create a new {@link MeasurementModel}, taking double arrays as input parameters for the
  40.      * respective measurement matrix and noise.
  41.      *
  42.      * @param measMatrix
  43.      *            the measurement matrix
  44.      * @param measNoise
  45.      *            the measurement noise matrix
  46.      * @throws NullArgumentException
  47.      *             if any of the input matrices is {@code null}
  48.      * @throws NoDataException
  49.      *             if any row / column dimension of the input matrices is zero
  50.      * @throws DimensionMismatchException
  51.      *             if any of the input matrices is non-rectangular
  52.      */
  53.     public DefaultMeasurementModel(final double[][] measMatrix, final double[][] measNoise)
  54.             throws NullArgumentException, NoDataException, DimensionMismatchException {
  55.         this(new Array2DRowRealMatrix(measMatrix), new Array2DRowRealMatrix(measNoise));
  56.     }

  57.     /**
  58.      * Create a new {@link MeasurementModel}, taking {@link RealMatrix} objects
  59.      * as input parameters for the respective measurement matrix and noise.
  60.      *
  61.      * @param measMatrix the measurement matrix
  62.      * @param measNoise the measurement noise matrix
  63.      */
  64.     public DefaultMeasurementModel(final RealMatrix measMatrix, final RealMatrix measNoise) {
  65.         this.measurementMatrix = measMatrix;
  66.         this.measurementNoise = measNoise;
  67.     }

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public RealMatrix getMeasurementMatrix() {
  71.         return measurementMatrix;
  72.     }

  73.     /** {@inheritDoc} */
  74.     @Override
  75.     public RealMatrix getMeasurementNoise() {
  76.         return measurementNoise;
  77.     }
  78. }