001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.math4.filter;
018
019import org.apache.commons.math4.exception.DimensionMismatchException;
020import org.apache.commons.math4.exception.NoDataException;
021import org.apache.commons.math4.exception.NullArgumentException;
022import org.apache.commons.math4.linear.Array2DRowRealMatrix;
023import org.apache.commons.math4.linear.RealMatrix;
024
025/**
026 * Default implementation of a {@link MeasurementModel} for the use with a {@link KalmanFilter}.
027 *
028 * @since 3.0
029 */
030public class DefaultMeasurementModel implements MeasurementModel {
031
032    /**
033     * The measurement matrix, used to associate the measurement vector to the
034     * internal state estimation vector.
035     */
036    private final RealMatrix measurementMatrix;
037
038    /**
039     * The measurement noise covariance matrix.
040     */
041    private final RealMatrix measurementNoise;
042
043    /**
044     * Create a new {@link MeasurementModel}, taking double arrays as input parameters for the
045     * respective measurement matrix and noise.
046     *
047     * @param measMatrix
048     *            the measurement matrix
049     * @param measNoise
050     *            the measurement noise matrix
051     * @throws NullArgumentException
052     *             if any of the input matrices is {@code null}
053     * @throws NoDataException
054     *             if any row / column dimension of the input matrices is zero
055     * @throws DimensionMismatchException
056     *             if any of the input matrices is non-rectangular
057     */
058    public DefaultMeasurementModel(final double[][] measMatrix, final double[][] measNoise)
059            throws NullArgumentException, NoDataException, DimensionMismatchException {
060        this(new Array2DRowRealMatrix(measMatrix), new Array2DRowRealMatrix(measNoise));
061    }
062
063    /**
064     * Create a new {@link MeasurementModel}, taking {@link RealMatrix} objects
065     * as input parameters for the respective measurement matrix and noise.
066     *
067     * @param measMatrix the measurement matrix
068     * @param measNoise the measurement noise matrix
069     */
070    public DefaultMeasurementModel(final RealMatrix measMatrix, final RealMatrix measNoise) {
071        this.measurementMatrix = measMatrix;
072        this.measurementNoise = measNoise;
073    }
074
075    /** {@inheritDoc} */
076    @Override
077    public RealMatrix getMeasurementMatrix() {
078        return measurementMatrix;
079    }
080
081    /** {@inheritDoc} */
082    @Override
083    public RealMatrix getMeasurementNoise() {
084        return measurementNoise;
085    }
086}