Skip to content

Commit

Permalink
MATH-485
Browse files Browse the repository at this point in the history
New "filter" package. Initial implementation of Kalman filter provided
by Thomas Neidhart.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1134779 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Gilles Sadowski committed Jun 11, 2011
1 parent 6e9f1d3 commit 58d1885
Show file tree
Hide file tree
Showing 7 changed files with 805 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math.filter;

import org.apache.commons.math.linear.Array2DRowRealMatrix;
import org.apache.commons.math.linear.RealMatrix;

/**
* Default implementation of a {@link MeasurementModel} for the use with a
* {@link KalmanFilter}.
*
* @version $Id$
*/
public class DefaultMeasurementModel implements MeasurementModel {

private RealMatrix measurementMatrix;
private RealMatrix measurementNoise;

/**
* Create a new {@link MeasurementModel}, taking double arrays as input
* parameters for the respective measurement matrix and noise.
*
* @param measurementMatrix
* the measurement matrix
* @param measurementNoise
* the measurement noise matrix
*/
public DefaultMeasurementModel(final double[][] measurementMatrix,
final double[][] measurementNoise) {
this(new Array2DRowRealMatrix(measurementMatrix),
new Array2DRowRealMatrix(measurementNoise));
}

/**
* Create a new {@link MeasurementModel}, taking {@link RealMatrix} objects
* as input parameters for the respective measurement matrix and noise.
*
* @param measurementMatrix
* @param measurementNoise
*/
public DefaultMeasurementModel(final RealMatrix measurementMatrix,
final RealMatrix measurementNoise) {
this.measurementMatrix = measurementMatrix;
this.measurementNoise = measurementNoise;
}

/**
* {@inheritDoc}
*/
public RealMatrix getMeasurementMatrix() {
return measurementMatrix;
}

/**
* {@inheritDoc}
*/
public RealMatrix getMeasurementNoise() {
return measurementNoise;
}
}
143 changes: 143 additions & 0 deletions src/main/java/org/apache/commons/math/filter/DefaultProcessModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math.filter;

import org.apache.commons.math.linear.Array2DRowRealMatrix;
import org.apache.commons.math.linear.ArrayRealVector;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.RealVector;

/**
* Default implementation of a {@link ProcessModel} for the use with a
* {@link KalmanFilter}.
*
* @version $Id$
*/
public class DefaultProcessModel implements ProcessModel {

private RealMatrix stateTransitionMatrix;
private RealMatrix controlMatrix;
private RealMatrix processNoise;
private RealVector initialStateEstimate;
private RealMatrix initialErrorCovariance;

/**
* Create a new {@link ProcessModel}, taking double arrays as input
* parameters.
*
* @param stateTransitionMatrix
* the state transition matrix
* @param controlMatrix
* the control matrix
* @param processNoise
* the process noise matrix
* @param initialStateEstimate
* the initial state estimate vector
* @param initialErrorCovariance
* the initial error covariance matrix
*/
public DefaultProcessModel(final double[][] stateTransitionMatrix,
final double[][] controlMatrix, final double[][] processNoise,
final double[] initialStateEstimate,
final double[][] initialErrorCovariance) {
this(new Array2DRowRealMatrix(stateTransitionMatrix),
new Array2DRowRealMatrix(controlMatrix),
new Array2DRowRealMatrix(processNoise), new ArrayRealVector(
initialStateEstimate), new Array2DRowRealMatrix(
initialErrorCovariance));
}

/**
* Create a new {@link ProcessModel}, taking double arrays as input
* parameters. The initial state estimate and error covariance are omitted
* and will be initialized by the {@link KalmanFilter} to default values.
*
* @param stateTransitionMatrix
* the state transition matrix
* @param controlMatrix
* the control matrix
* @param processNoise
* the process noise matrix
*/
public DefaultProcessModel(final double[][] stateTransitionMatrix,
final double[][] controlMatrix, final double[][] processNoise) {
this(new Array2DRowRealMatrix(stateTransitionMatrix),
new Array2DRowRealMatrix(controlMatrix),
new Array2DRowRealMatrix(processNoise), null, null);
}

/**
* Create a new {@link ProcessModel}, taking double arrays as input
* parameters.
*
* @param stateTransitionMatrix
* the state transition matrix
* @param controlMatrix
* the control matrix
* @param processNoise
* the process noise matrix
* @param initialStateEstimate
* the initial state estimate vector
* @param initialErrorCovariance
* the initial error covariance matrix
*/
public DefaultProcessModel(final RealMatrix stateTransitionMatrix,
final RealMatrix controlMatrix, final RealMatrix processNoise,
final RealVector initialStateEstimate,
final RealMatrix initialErrorCovariance) {
this.stateTransitionMatrix = stateTransitionMatrix;
this.controlMatrix = controlMatrix;
this.processNoise = processNoise;
this.initialStateEstimate = initialStateEstimate;
this.initialErrorCovariance = initialErrorCovariance;
}

/**
* {@inheritDoc}
*/
public RealMatrix getStateTransitionMatrix() {
return stateTransitionMatrix;
}

/**
* {@inheritDoc}
*/
public RealMatrix getControlMatrix() {
return controlMatrix;
}

/**
* {@inheritDoc}
*/
public RealMatrix getProcessNoise() {
return processNoise;
}

/**
* {@inheritDoc}
*/
public RealVector getInitialStateEstimate() {
return initialStateEstimate;
}

/**
* {@inheritDoc}
*/
public RealMatrix getInitialErrorCovariance() {
return initialErrorCovariance;
}
}

0 comments on commit 58d1885

Please sign in to comment.