Commit ddc5b5b6 authored by Johannes Pfeifer 's avatar Johannes Pfeifer Committed by GitHub

Properly terminate nonlinear_kalman_filter if non-positive definite matrices are encountered

Otherwise, crashes can happen during mode-finding
parent 285d5c17
......@@ -152,8 +152,18 @@ for t=1:sample_size
KalmanFilterGain = PredictedStateAndObservedCovariance/PredictedObservedVariance;
StateVectorMean = PredictedStateMean + KalmanFilterGain*PredictionError;
StateVectorVariance = PredictedStateVariance - KalmanFilterGain*PredictedObservedVariance*KalmanFilterGain';
StateVectorVarianceSquareRoot = chol(StateVectorVariance)';
PredictedObservedVarianceSquareRoot = chol(PredictedObservedVariance)' ;
[StateVectorVarianceSquareRoot, p]= chol(StateVectorVariance,'lower');
if p
LIK=-Inf;
lik(t)=-Inf;
return
end
[PredictedObservedVarianceSquareRoot, p]= chol(PredictedObservedVariance,'lower');
if p
LIK=-Inf;
lik(t)=-Inf;
return
end
end
lik(t) = log( probability2(0,PredictedObservedVarianceSquareRoot,PredictionError) ) ;
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment