measurementMatrixT = measurementMatrix.transpose();
// check that the process and measurement noise matrices are not null
// they will be directly accessed from the model as they may change
// over time
RealMatrix processNoise = processModel.getProcessNoise();
MathUtils.checkNotNull(processNoise);
RealMatrix measNoise = measurementModel.getMeasurementNoise();
MathUtils.checkNotNull(measNoise);
// set the initial state estimate to a zero vector if it is not
// available from the process model
if (processModel.getInitialStateEstimate() == null) {
stateEstimation = new ArrayRealVector(transitionMatrix.getColumnDimension());
} else {
stateEstimation = processModel.getInitialStateEstimate();
}
if (transitionMatrix.getColumnDimension() != stateEstimation.getDimension()) {
throw new DimensionMismatchException(transitionMatrix.getColumnDimension(),
stateEstimation.getDimension());
}
// initialize the error covariance to the process noise if it is not
// available from the process model
if (processModel.getInitialErrorCovariance() == null) {
errorCovariance = processNoise.copy();
} else {
errorCovariance = processModel.getInitialErrorCovariance();
}
// sanity checks, the control matrix B may be null
// A must be a square matrix
if (!transitionMatrix.isSquare()) {
throw new NonSquareMatrixException(
transitionMatrix.getRowDimension(),
transitionMatrix.getColumnDimension());
}
// row dimension of B must be equal to A
// if no control matrix is available, the row and column dimension will be 0
if (controlMatrix != null &&
controlMatrix.getRowDimension() > 0 &&
controlMatrix.getColumnDimension() > 0 &&
controlMatrix.getRowDimension() != transitionMatrix.getRowDimension()) {
throw new MatrixDimensionMismatchException(controlMatrix.getRowDimension(),
controlMatrix.getColumnDimension(),
transitionMatrix.getRowDimension(),
controlMatrix.getColumnDimension());
}
// Q must be equal to A
MatrixUtils.checkAdditionCompatible(transitionMatrix, processNoise);
// column dimension of H must be equal to row dimension of A
if (measurementMatrix.getColumnDimension() != transitionMatrix.getRowDimension()) {
throw new MatrixDimensionMismatchException(measurementMatrix.getRowDimension(),
measurementMatrix.getColumnDimension(),
measurementMatrix.getRowDimension(),
transitionMatrix.getRowDimension());
}
// row dimension of R must be equal to row dimension of H
if (measNoise.getRowDimension() != measurementMatrix.getRowDimension()) {
throw new MatrixDimensionMismatchException(measNoise.getRowDimension(),
measNoise.getColumnDimension(),
measurementMatrix.getRowDimension(),
measNoise.getColumnDimension());
}
}