ProcessEstimate.java

  1. /*
  2.  * Licensed to the Hipparchus project 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 Hipparchus project 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.  *      https://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.hipparchus.filtering.kalman;

  18. import org.hipparchus.linear.RealMatrix;
  19. import org.hipparchus.linear.RealVector;

  20. /**
  21.  * Holder for process state and covariance.
  22.  * <p>
  23.  * The estimate always contains time, state and covariance. These data are
  24.  * the only ones needed to start a Kalman filter. Once a filter has been
  25.  * started and produces new estimates, these new estimates will always
  26.  * contain a state transition matrix and if the measurement has not been
  27.  * ignored, they will also contain measurement Jacobian, innovation covariance
  28.  * and Kalman gain.
  29.  * </p>
  30.  * @since 1.3
  31.  */
  32. public class ProcessEstimate {

  33.     /** Process time (typically the time or index of a measurement). */
  34.     private final double time;

  35.     /** State vector. */
  36.     private final RealVector state;

  37.     /** State covariance. */
  38.     private final RealMatrix covariance;

  39.     /** State transition matrix, may be null.
  40.      * @since 1.4
  41.      */
  42.     private final RealMatrix stateTransitionMatrix;

  43.     /** Jacobian of the measurement with respect to the state (h matrix), may be null.
  44.      * @since 1.4
  45.      */
  46.     private final RealMatrix measurementJacobian;

  47.     /** Innovation covariance matrix, defined as \(h.P.h^T + r\), may be null.
  48.      * @since 1.4
  49.      */
  50.     private final RealMatrix innovationCovarianceMatrix;

  51.     /** Kalman gain (k matrix), may be null.
  52.      * @since 1.4
  53.      */
  54.     private final RealMatrix kalmanGain;

  55.     /** Simple constructor.
  56.      * <p>
  57.      * This constructor sets state transition matrix, covariance matrix H,
  58.      * innovation covariance matrix and Kalman gain k to null.
  59.      * </p>
  60.      * @param time process time (typically the time or index of a measurement)
  61.      * @param state state vector
  62.      * @param covariance state covariance
  63.      */
  64.     public ProcessEstimate(final double time, final RealVector state, final RealMatrix covariance) {
  65.         this(time, state, covariance, null, null, null, null);
  66.     }

  67.     /** Simple constructor.
  68.      * @param time process time (typically the time or index of a measurement)
  69.      * @param state state vector
  70.      * @param covariance state covariance
  71.      * @param stateTransitionMatrix state transition matrix between previous state and estimated (but not yet corrected) state
  72.      * @param measurementJacobian Jacobian of the measurement with respect to the state
  73.      * @param innovationCovariance innovation covariance matrix, defined as \(h.P.h^T + r\), may be null
  74.      * @param kalmanGain Kalman Gain matrix, may be null
  75.      * @since 1.4
  76.      */
  77.     public ProcessEstimate(final double time, final RealVector state, final RealMatrix covariance,
  78.                            final RealMatrix stateTransitionMatrix, final RealMatrix measurementJacobian,
  79.                            final RealMatrix innovationCovariance, final RealMatrix kalmanGain) {
  80.         this.time                       = time;
  81.         this.state                      = state;
  82.         this.covariance                 = covariance;
  83.         this.stateTransitionMatrix      = stateTransitionMatrix;
  84.         this.measurementJacobian        = measurementJacobian;
  85.         this.innovationCovarianceMatrix = innovationCovariance;
  86.         this.kalmanGain                 = kalmanGain;
  87.     }

  88.     /** Get the process time.
  89.      * @return process time (typically the time or index of a measurement)
  90.      */
  91.     public double getTime() {
  92.         return time;
  93.     }

  94.     /** Get the state vector.
  95.      * @return state vector
  96.      */
  97.     public RealVector getState() {
  98.         return state;
  99.     }

  100.     /** Get the state covariance.
  101.      * @return state covariance
  102.      */
  103.     public RealMatrix getCovariance() {
  104.         return covariance;
  105.     }

  106.     /** Get state transition matrix between previous state and estimated (but not yet corrected) state.
  107.      * @return state transition matrix between previous state and estimated state (but not yet corrected)
  108.      * (may be null for initial process estimate)
  109.      * @since 1.4
  110.      */
  111.     public RealMatrix getStateTransitionMatrix() {
  112.         return stateTransitionMatrix;
  113.     }

  114.     /** Get the Jacobian of the measurement with respect to the state (H matrix).
  115.      * @return Jacobian of the measurement with respect to the state (may be null for initial
  116.      * process estimate or if the measurement has been ignored)
  117.      * @since 1.4
  118.      */
  119.     public RealMatrix getMeasurementJacobian() {
  120.         return measurementJacobian;
  121.     }

  122.     /** Get the innovation covariance matrix.
  123.      * @return innovation covariance matrix (may be null for initial
  124.      * process estimate or if the measurement has been ignored)
  125.      * @since 1.4
  126.      */
  127.     public RealMatrix getInnovationCovariance() {
  128.         return innovationCovarianceMatrix;
  129.     }

  130.     /** Get the Kalman gain matrix.
  131.      * @return Kalman gain matrix (may be null for initial
  132.      * process estimate or if the measurement has been ignored)
  133.      * @since 1.4
  134.      */
  135.     public RealMatrix getKalmanGain() {
  136.         return kalmanGain;
  137.     }

  138. }