20 #ifndef UKF_PARAMETER_SCALAR_H
21 #define UKF_PARAMETER_SCALAR_H
23 #include <gsl/gsl_linalg.h>
24 #include <gsl/gsl_math.h>
25 #include <gsl/gsl_blas.h>
50 s.
Kk = gsl_vector_alloc(p.
n);
51 gsl_vector_set_zero(s.
Kk);
53 s.
Kk_mat = gsl_matrix_alloc(p.
n,1);
54 gsl_matrix_set_zero(s.
Kk_mat);
59 s.
Pwdk = gsl_vector_alloc(p.
n);
60 gsl_vector_set_zero(s.
Pwdk);
63 s.
Prrk = gsl_matrix_alloc(p.
n,p.
n);
70 s.
w = gsl_vector_alloc(p.
n);
71 gsl_vector_set_zero(s.
w);
73 s.
wk = gsl_vector_alloc(p.
n);
74 gsl_vector_set_zero(s.
wk);
76 s.
Pk = gsl_matrix_alloc(p.
n,p.
n);
77 gsl_matrix_set_identity(s.
Pk);
80 s.
Sk = gsl_matrix_alloc(p.
n,p.
n);
82 gsl_matrix_memcpy(s.
Sk, s.
Pk);
83 gsl_linalg_cholesky_decomp(s.
Sk);
85 for(
int k = 0 ; k < p.
n ; k++)
86 for(
int j = 0 ; j < k ; j++)
87 gsl_matrix_set(s.
Sk,j,k,0.0);
89 s.
cSk = gsl_vector_alloc(p.
n);
90 gsl_vector_set_zero(s.
cSk);
100 gsl_vector_set(s.
wm, j, 1.0 / (2.0 * (p.
n + p.
lambda)));
101 gsl_vector_set(s.
wc, j, 1.0 / (2.0 * (p.
n + p.
lambda)));
105 gsl_vector_set_zero(s.
dk);
112 s.
temp_n = gsl_vector_alloc(p.
n);
113 gsl_vector_set_zero(s.
temp_n);
125 gsl_vector_free(s.
Kk);
126 gsl_matrix_free(s.
Kk_mat);
128 gsl_vector_free(s.
Pwdk);
129 gsl_matrix_free(s.
Prrk);
131 gsl_vector_free(s.
w);
132 gsl_vector_free(s.
wk);
134 gsl_matrix_free(s.
Pk);
135 gsl_matrix_free(s.
Sk);
136 gsl_vector_free(s.
cSk);
138 gsl_vector_free(s.
wm);
139 gsl_vector_free(s.
wc);
141 gsl_vector_free(s.
dk);
145 gsl_vector_free(s.
temp_n);
153 template <
typename FunctObj>
163 gsl_matrix_add(s.
Pk, s.
Prrk);
174 gsl_matrix_memcpy(s.
Sk, s.
Pk);
175 gsl_linalg_cholesky_decomp(s.
Sk);
177 for(
int k = 0 ; k < p.
n ; k++)
178 for(
int j = 0 ; j < k ; j++)
179 gsl_matrix_set(s.
Sk,j,k,0.0);
182 for(
int j = 1 ; j < p.
n+1 ; ++j)
183 for(
int i = 0 ; i < p.
n ; ++i)
184 gsl_matrix_set(s.
sigmaPoints, i, j, gsl_vector_get(s.
w, i) + p.
gamma * gsl_matrix_get(s.
Sk,i,j-1));
187 for(
int i = 0 ; i < p.
n ; ++i)
188 gsl_matrix_set(s.
sigmaPoints, i, j, gsl_vector_get(s.
w, i) - p.
gamma * gsl_matrix_get(s.
Sk,i,j-(p.
n+1)));
197 gsl_vector_set_zero(s.
dk);
202 s.
dk->data[j] = g(s.
wk,xk);
213 gsl_vector_set_zero(s.
Pwdk);
222 for(
int i = 0 ; i < p.
n ; ++i)
237 for(
int i = 0 ; i < p.
n ; ++i)
243 for(
int i = 0 ; i < p.
n ; ++i)
244 s.
w->data[i] = s.
w->data[i] + s.
Kk->data[i] * s.
ino_dk;
248 for(
int i = 0 ; i < p.
n ; ++i)
250 gsl_matrix_set(s.
Kk_mat, i, 0, s.
Kk->data[i]);
251 gsl_matrix_set(s.
Kk_mat_T, 0, i, s.
Kk->data[i]);
263 template <
typename FunctObj>
272 gsl_linalg_cholesky_decomp(s.
temp_n_n);
275 for(
int k = 0 ; k < p.
n ; k++)
276 for(
int j = 0 ; j < k ; j++)
286 for(
int j = 1 ; j < p.
n+1 ; j++)
287 for(
int i = 0 ; i < p.
n ; ++i)
291 for(
int i = 0 ; i < p.
n ; ++i)
305 dk += gsl_vector_get(s.
wm,j) * g(s.
wk,xk);
312 #endif // UKF_PARAMETER_SCALAR_H
void ukf_scalar_init(ukf_param &p, ukf_scalar_state &s)
Allocation of the vectors/matrices and initialization.
Definition: ukf_parameter_scalar.h:42
EvolutionNoise * evolution_noise
Parameter used for the evolution noise.
Definition: ukf_types.h:96
gsl_vector * cSk
Vector holding one column of Sk, of size .
Definition: ukf_types.h:196
gsl_vector * w
Parameter vector, of size .
Definition: ukf_types.h:176
gsl_vector * Pwdk
Covariance of : , of size .
Definition: ukf_types.h:156
gsl_vector * dk
Temporary vector holding the image of the sigma points, of size .
Definition: ukf_types.h:215
double Peek
Covariance of the observation noise.
Definition: ukf_types.h:166
Pointer to the function to approximate in the scalar case.
Definition: ukf_types.h:136
double kpa
, is a good choice. According to van der Merwe, its value is not critical
Definition: ukf_types.h:60
gsl_vector * wk
Temporary vector, holding a sigma-point.
Definition: ukf_types.h:181
gsl_matrix * Sk
Matrix holding the Cholesky decomposition of , of size .
Definition: ukf_types.h:191
gsl_matrix * Pk
Covariance matrix of the parameters, of size .
Definition: ukf_types.h:186
double d_mean
Variable holding the mean of the sigma points image.
Definition: ukf_types.h:225
double observation_noise
Covariance of the observation noise.
Definition: ukf_types.h:101
Structure holding the parameters of the Unscented Kalman Filter.
Definition: ukf_types.h:55
double beta
Non negative weights used to introduce knowledge about the higher order moments of the distribution...
Definition: ukf_types.h:70
gsl_matrix * temp_n_n
Temporary matrix.
Definition: ukf_types.h:240
int n
Number of parameters to estimate.
Definition: ukf_types.h:111
void init(ukf_param &p, ukf_state &s)
Definition: ukf_types.h:395
gsl_vector * wm
Weights used to compute the mean of the sigma points' images.
Definition: ukf_types.h:203
double ino_dk
Innovation.
Definition: ukf_types.h:220
double alpha
: "Size" of sigma-point distribution. Should be small if the function is strongly non-linear ...
Definition: ukf_types.h:65
void ukf_scalar_iterate(ukf_param &p, ukf_scalar_state &s, FunctObj g, gsl_vector *xk, double dk)
Iteration for UKF for parameter estimation, in case of a scalar output.
Definition: ukf_parameter_scalar.h:154
gsl_matrix * Prrk
Covariance of the evolution noise.
Definition: ukf_types.h:161
void ukf_scalar_free(ukf_param &p, ukf_scalar_state &s)
Free of memory allocation.
Definition: ukf_parameter_scalar.h:123
gsl_matrix * Kk_mat
Temporary matrix for the kalman gain, a matrix of size .
Definition: ukf_types.h:146
double lambda
Definition: ukf_types.h:75
virtual void updateEvolutionNoise(ukf_param &p, ukf_state &s)=0
gsl_matrix * Kk_mat_T
Temporary matrix for the transpose of the kalman gain, a matrix of size .
Definition: ukf_types.h:151
gsl_vector * wc
Weights used to update the covariance matrices.
Definition: ukf_types.h:210
void ukf_scalar_evaluate(ukf_param &p, ukf_scalar_state &s, FunctObj g, gsl_vector *xk, double &dk)
Evaluation of the output from the sigma points.
Definition: ukf_parameter_scalar.h:264
gsl_vector * Kk
Kalman gain, a vector of size .
Definition: ukf_types.h:141
gsl_vector * temp_n
Temporary vector.
Definition: ukf_types.h:235
double prior_pi
Prior estimate of the covariance matrix.
Definition: ukf_types.h:106
double Pddk
Covariance of the output.
Definition: ukf_types.h:171
double gamma
Definition: ukf_types.h:80
gsl_matrix * sigmaPoints
Matrix holding the sigma points in the columns, of size .
Definition: ukf_types.h:230
int nbSamples
Number of sigma-points
Definition: ukf_types.h:116