20 #define DEBUGMODE true
22 #ifndef UKF_SR_STATE_NDIM_H
23 #define UKF_SR_STATE_NDIM_H
25 #include <gsl/gsl_linalg.h>
26 #include <gsl/gsl_math.h>
27 #include <gsl/gsl_blas.h>
34 for(
unsigned int i = 0 ; i < A->size1 ; ++i)
36 for(
unsigned int j = 0 ; j < A ->size2 ; ++j)
37 printf(
"%e ", gsl_matrix_get(A,i,j));
45 for(
unsigned int i = 0 ; i < A->size ; ++i)
47 printf(
"%e ", gsl_vector_get(A,i));
78 s.
xi = gsl_vector_alloc(p.
n);
79 gsl_vector_set_zero(s.
xi);
89 s.
Sxi = gsl_matrix_alloc(p.
n,p.
n);
90 gsl_matrix_set_identity(s.
Sxi);
94 s.
Svi = gsl_matrix_alloc(p.
n,p.
n);
95 gsl_matrix_set_identity(s.
Svi);
102 gsl_vector_set_zero(s.
yi_mean);
105 gsl_vector_set_zero(s.
ino_yi);
108 s.
Syi = gsl_matrix_alloc(p.
no, p.
no);
109 gsl_matrix_set_zero(s.
Syi);
111 s.
Sni = gsl_matrix_alloc(p.
no,p.
no);
112 gsl_matrix_set_identity(s.
Sni);
115 s.
Pxyi = gsl_matrix_alloc(p.
n, p.
no);
116 gsl_matrix_set_zero(s.
Pxyi);
130 s.
U = gsl_matrix_alloc(p.
n, p.
no);
131 gsl_matrix_set_zero(s.
U);
142 gsl_vector_set(s.
wm_j, j, 1.0 / (2.0 * (p.
n + p.
lambda)));
143 gsl_vector_set(s.
wc_j, j, 1.0 / (2.0 * (p.
n + p.
lambda)));
157 s.
Ki = gsl_matrix_alloc(p.
n, p.
no);
158 s.
Ki_T = gsl_matrix_alloc(p.
no, p.
n);
161 s.
temp_n = gsl_vector_alloc(p.
n);
182 gsl_vector_free(s.
xi);
185 gsl_matrix_free(s.
Sxi);
186 gsl_matrix_free(s.
Svi);
190 gsl_vector_free(s.
ino_yi);
191 gsl_matrix_free(s.
Syi);
192 gsl_matrix_free(s.
Sni);
194 gsl_matrix_free(s.
Pxyi);
202 gsl_matrix_free(s.
U);
204 gsl_vector_free(s.
wm_j);
205 gsl_vector_free(s.
wc_j);
210 gsl_matrix_free(s.
Ki);
211 gsl_matrix_free(s.
Ki_T);
213 gsl_vector_free(s.
temp_n);
233 template <
typename FunctProcess,
typename FunctObservation>
237 gsl_matrix_view mat_view;
238 gsl_vector_view vec_view;
249 for(j = 1 ; j < p.
n + 1 ; ++j)
250 for(i = 0 ; i < p.
n ; ++i)
262 gsl_vector_set_zero(s.
xi_mean);
272 for(i = 0 ; i < p.
n ; ++i)
282 for(i = 0 ; i < p.
n ; ++i)
288 for(j = 0 ; j < p.
n ; ++j)
291 gsl_matrix_memcpy(&mat_view.matrix, s.
Svi);
296 for( j = 0 ; j < p.
n ; ++j)
298 for(i = 0 ; i < j+1 ; ++i)
299 gsl_matrix_set(s.
Sxi, i, j, gsl_matrix_get(s.
temp_3n_n, i, j));
301 for(i = j+1 ; i < p.
n ; ++i)
302 gsl_matrix_set(s.
Sxi, i, j, 0.0);
310 for(i = 0 ; i < p.
n ; ++i)
313 if(
DEBUGMODE) printf(
"Before cholupdate 1 \n");
314 gsl_matrix_transpose(s.
Sxi);
320 if(
DEBUGMODE) printf(
"Sxi after cholupdate : \n");
330 for(j = 0 ; j < p.
n ; ++j)
332 for(i = 0 ; i < p.
n ; ++i)
341 gsl_vector_set_zero(s.
yi_mean);
349 for(i = 0 ; i < p.
no ; ++i)
360 for(j = 0 ; j < 2*p.
n ; ++j)
361 for(i = 0 ; i < p.
no ; ++i)
366 gsl_matrix_memcpy(&mat_view.matrix, s.
Sni);
371 for( j = 0 ; j < p.
no ; ++j)
373 for(i = 0 ; i < j+1 ; ++i)
376 for(i = j+1 ; i < p.
no ; ++i)
377 gsl_matrix_set(s.
Syi, i, j, 0.0);
387 for(i = 0 ; i < p.
no ; ++i)
390 if(
DEBUGMODE) printf(
"Before cholupdate 2 \n");
391 gsl_matrix_transpose(s.
Syi);
396 if(
DEBUGMODE) printf(
"Syi after cholupdate : \n");
402 gsl_matrix_set_zero(s.
Pxyi);
405 for(i = 0 ; i < p.
n ; ++i)
408 for(i = 0 ; i < p.
no ; ++i)
435 for(
int i = 0 ; i < p.
n ; ++i)
437 vec_view = gsl_matrix_row(s.
Pxyi, i);
438 gsl_vector_memcpy(s.
temp_no, &vec_view.vector);
439 gsl_blas_dtrsv(CblasLower,CblasNoTrans,CblasNonUnit,s.
Syi,s.
temp_no);
440 gsl_blas_dtrsv(CblasLower,CblasTrans,CblasNonUnit,s.
Syi,s.
temp_no);
442 vec_view = gsl_matrix_row(s.
Ki, i);
443 gsl_vector_memcpy(&vec_view.vector, s.
temp_no);
451 for(i = 0 ; i < p.
no ; ++i)
454 gsl_blas_dgemv(CblasNoTrans, 1.0, s.
Ki, s.
ino_yi, 1.0, s.
xi);
457 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0 , s.
Ki, s.
Syi, 0, s.
U);
463 if(
DEBUGMODE) printf(
"Before cholupdate 3 \n");
464 for(i = 0 ; i < p.
no ; ++i)
466 vec_view = gsl_matrix_column(s.
U, i);
467 gsl_vector_memcpy(s.
temp_n, &vec_view.vector);
469 if(
DEBUGMODE) printf(
"After cholupdate %i\n", i);
504 template <
typename FunctProcess,
typename FunctObservation>
596 #endif // UKF_SR_STATE_NDIM_H
gsl_matrix * Sxi
Definition: ukf_types.h:832
gsl_matrix * xi_prediction
Definition: ukf_types.h:830
void ukf_free(ukf_param &p, ukf_state &s)
Free of memory allocation.
Definition: ukf_sr_state_ndim.h:180
gsl_vector * yi_mean
Definition: ukf_types.h:836
gsl_vector * temp_n
Definition: ukf_types.h:860
gsl_matrix * U
Definition: ukf_types.h:849
gsl_matrix * Sni
Definition: ukf_types.h:839
void print_mat(const gsl_matrix *A)
Definition: ukf_sr_state_ndim.h:32
gsl_vector * wm_aug_j
Definition: ukf_types.h:854
double measurement_noise
Covariance of the observation noise.
Definition: ukf_types.h:816
void print_vec(const gsl_vector *A)
Definition: ukf_sr_state_ndim.h:43
gsl_matrix * Pxyi
Definition: ukf_types.h:841
Structure holding the parameters of the statistical linearization.
Definition: ukf_types.h:749
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
gsl_vector * wc_aug_j
Definition: ukf_types.h:855
gsl_matrix * temp_no_1
Definition: ukf_types.h:870
void ukf_init(ukf_param &p, ukf_state &s)
Allocation of the vectors/matrices and initialization.
Definition: ukf_sr_state_ndim.h:65
gsl_matrix * sigmaPoints
Definition: ukf_types.h:844
#define DEBUGMODE
Definition: ukf_sr_state_ndim.h:20
gsl_vector * temp_no
Definition: ukf_types.h:861
double beta
Non negative weights used to introduce knowledge about the higher order moments of the distribution...
Definition: ukf_types.h:764
gsl_matrix * temp_1_no
Definition: ukf_types.h:871
void ukf_evaluate(ukf_param &p, ukf_state &s, FunctProcess f, FunctObservation h, gsl_vector *yi)
Evaluation of the output from the sigma points.
Definition: ukf_sr_state_ndim.h:505
gsl_matrix * temp_n_1
Definition: ukf_types.h:864
double lambda_aug
Definition: ukf_types.h:770
gsl_matrix * temp_n_no
Definition: ukf_types.h:867
gsl_matrix * temp_1_n
Definition: ukf_types.h:865
gsl_vector * wc_j
Definition: ukf_types.h:852
gsl_vector * sigmaPoint
Definition: ukf_types.h:843
double process_noise
Parameter used for the evolution noise.
Definition: ukf_types.h:811
Structure holding the matrices manipulated by the statistical linearization in the vectorial case for...
Definition: ukf_types.h:825
double kpa
, is a good choice. According to van der Merwe, its value is not critical
Definition: ukf_types.h:754
gsl_matrix * Ki
Definition: ukf_types.h:857
gsl_matrix * temp_no_no
Definition: ukf_types.h:869
int nbSamplesMeasure
Number of sigma-points
Definition: ukf_types.h:791
double gamma
Definition: ukf_types.h:775
gsl_vector * xi_mean
Definition: ukf_types.h:831
gsl_vector * params
Definition: ukf_types.h:827
double alpha
: "Size" of sigma-point distribution. Should be small if the function is strongly non-linear ...
Definition: ukf_types.h:759
int nbSamples
Number of sigma-points
Definition: ukf_types.h:786
gsl_matrix * temp_2nno_no
Definition: ukf_types.h:874
gsl_matrix * temp_n_n
Definition: ukf_types.h:863
int no
Dimension of the output : the measurements.
Definition: ukf_types.h:796
gsl_matrix * yi_prediction
Definition: ukf_types.h:835
gsl_vector * sigmaPointMeasure
Definition: ukf_types.h:846
gsl_vector * wm_j
Definition: ukf_types.h:851
double lambda
Definition: ukf_types.h:769
double signof(double x)
Definition: ukf_math.h:45
int n
Size of the state vector.
Definition: ukf_types.h:781
gsl_vector * xi
Definition: ukf_types.h:829
double prior_x
Prior estimate of the covariance matrix of the state.
Definition: ukf_types.h:801
gsl_matrix * Syi
Definition: ukf_types.h:838
gsl_matrix * Svi
Definition: ukf_types.h:833
void ukf_iterate(ukf_param &p, ukf_state &s, FunctProcess f, FunctObservation h, gsl_vector *yi)
UKF-additive (zero-mean) noise case, "Kalman Filtering and Neural Networks", p.233.
Definition: ukf_sr_state_ndim.h:234
gsl_matrix * temp_3n_n
Definition: ukf_types.h:873
gsl_matrix * Ki_T
Definition: ukf_types.h:858
gsl_vector * ino_yi
Definition: ukf_types.h:837
double gamma_aug
Definition: ukf_types.h:776
gsl_matrix * sigmaPointsMeasure
Definition: ukf_types.h:847