From cdc7f6ddf9e3c69a0c01215724cf370b9f81d176 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Karam=C3=A9?=
 <frederic.karame@univ-lemans.fr>
Date: Fri, 2 Oct 2015 16:02:49 +0200
Subject: [PATCH] Modify the weights to prevent crash in the cholesky of the
 covariance.

---
 src/gaussian_filter.m | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/gaussian_filter.m b/src/gaussian_filter.m
index 5500ea8..9ec83a0 100644
--- a/src/gaussian_filter.m
+++ b/src/gaussian_filter.m
@@ -92,14 +92,14 @@ if isempty(H)
     H = 0;
     H_lower_triangular_cholesky = 0;
 else
-    H_lower_triangular_cholesky = reduced_rank_cholesky(H)';
+    H_lower_triangular_cholesky = chol(H)' ; %reduced_rank_cholesky(H)';
 end
 
 % Get initial condition for the state vector.
 StateVectorMean = ReducedForm.StateVectorMean;
-StateVectorVarianceSquareRoot = reduced_rank_cholesky(ReducedForm.StateVectorVariance)';
+StateVectorVarianceSquareRoot = chol(ReducedForm.StateVectorVariance)';%reduced_rank_cholesky(ReducedForm.StateVectorVariance)';
 state_variance_rank = size(StateVectorVarianceSquareRoot,2);
-Q_lower_triangular_cholesky = reduced_rank_cholesky(Q)';
+Q_lower_triangular_cholesky = chol(Q)'; %reduced_rank_cholesky(Q)';
 
 % Initialization of the likelihood.
 const_lik = (2*pi)^(number_of_observed_variables/2) ;
@@ -126,12 +126,16 @@ for t=1:sample_size
                                         1/number_of_particles,1/number_of_particles,ReducedForm,ThreadsOptions) ;
         SampleWeights = IncrementalWeights/number_of_particles ;
     end
+    SampleWeights = SampleWeights + 1e-6*ones(size(SampleWeights,1),1) ;
     SumSampleWeights = sum(SampleWeights) ;
     lik(t) = log(SumSampleWeights) ;
     SampleWeights = SampleWeights./SumSampleWeights ;
     StateVectorMean = StateParticles*SampleWeights ;
     temp = bsxfun(@minus,StateParticles,StateVectorMean) ;
-    StateVectorVarianceSquareRoot = reduced_rank_cholesky( bsxfun(@times,SampleWeights',temp)*temp' )';
+    %disp(SampleWeights)
+    %disp(StateParticles) 
+    %disp(StateVectorMean)
+    StateVectorVarianceSquareRoot = chol( bsxfun(@times,SampleWeights',temp)*temp' )';%reduced_rank_cholesky( bsxfun(@times,SampleWeights',temp)*temp' )';
 end
 
 LIK = -sum(lik(start:end));
-- 
GitLab