23 #include <gsl/gsl_vector.h>
24 #include <gsl/gsl_matrix.h>
35 inline double min(
double a,
double b)
40 inline double max(
double a,
double b)
47 return x <= 0.0 ? -1.0 : 1.0;
52 return fabs(x - y) <= 1e-10;
56 return fabs(x - y) >= 1e-10;
85 if (sigmaTheta->size1 != sigmaTheta->size2)
86 std::cout<<
"ERROR ukf::math::choleskyUpdate Cannot use CholeskyUpdate on non-squared matrices"<<std::endl ;
88 int i,j,n= sigmaTheta->size1 ;
90 gsl_matrix *U = gsl_matrix_alloc(n,n) ;
91 gsl_vector *D = gsl_vector_alloc(n) ;
92 gsl_vector *y = gsl_vector_alloc(n) ;
96 gsl_matrix_set_zero(U) ;
98 gsl_vector_set(D,i,gsl_matrix_get(sigmaTheta,i,i));
100 gsl_matrix_set(U,j,i,gsl_matrix_get(sigmaTheta,i,j));
105 for (j=0; j<=i; j++){
106 tmp = gsl_matrix_get(sigmaTheta,i,j);
107 tmp /= gsl_vector_get(D,j);
108 gsl_matrix_set(sigmaTheta,i,j,tmp);
109 tmp = gsl_matrix_get(U,j,i);
110 tmp *= gsl_vector_get(D,j);
111 gsl_matrix_set(U,j,i,tmp);
116 gsl_vector_memcpy(y,x) ;
117 gsl_vector_scale(y,alpha) ;
123 tmp = gsl_matrix_get(U,i,i) +
124 gsl_vector_get(x,i)*gsl_vector_get(y,i);
125 gsl_matrix_set(U,i,i,tmp);
126 tmp = gsl_vector_get(y,i);
127 tmp /= gsl_matrix_get(U,i,i);
128 gsl_vector_set(y,i,tmp);
130 for (j=i+1; j<n; j++){
132 tmp = gsl_vector_get(x,j) -
133 gsl_vector_get(x,i)*gsl_matrix_get(sigmaTheta,j,i);
134 gsl_vector_set(x,j,tmp) ;
135 tmp = gsl_matrix_get(sigmaTheta,j,i) + gsl_vector_get(y,i) * gsl_vector_get(x,j);
136 gsl_matrix_set(sigmaTheta,j,i,tmp);
139 for (j=i+1; j<n; j++) {
141 tmp = gsl_matrix_get(U,i,j) +
142 gsl_vector_get(x,i)*gsl_vector_get(y,j);
143 gsl_matrix_set(U,i,j,tmp) ;
144 tmp = gsl_vector_get(y,j) -
145 gsl_vector_get(y,i) * gsl_matrix_get(U,i,j);
146 gsl_vector_set(y,j,tmp) ;
153 tmp = gsl_matrix_get(U,i,i) ;
155 if (tmp<=0){std::cout<<
"WARNING ukf::math::choleskyUpdate::matrix not positive definite : " << tmp << std::endl;}
156 gsl_vector_set(D,i,sqrt(tmp)) ;
159 for (i=0; i<n; i++) {
160 for (j=0; j<n; j++) {
161 tmp = gsl_matrix_get(sigmaTheta,i,j) * gsl_vector_get(D,j);
162 gsl_matrix_set(sigmaTheta,i,j,tmp);
double min(double a, double b)
Definition: ukf_math.h:35
bool cmp_diff(double x, double y)
Definition: ukf_math.h:54
void choleskyUpdate(gsl_matrix *sigmaTheta, double alpha, gsl_vector *x)
This function performs a cholesky update according to Strange et al.(2007)
Definition: ukf_math.h:64
double max(double a, double b)
Definition: ukf_math.h:40
double signof(double x)
Definition: ukf_math.h:45
bool cmp_equal(double x, double y)
Definition: ukf_math.h:50