46 double alpha_slow,
double alpha_fast,
56 pf = calloc(1,
sizeof(
pf_t));
77 for (j = 0; j < 2; j++)
82 set->samples = calloc(max_samples,
sizeof(
pf_sample_t));
84 for (i = 0; i <
set->sample_count; i++)
86 sample =
set->samples + i;
87 sample->
pose.
v[0] = 0.0;
88 sample->
pose.
v[1] = 0.0;
89 sample->
pose.
v[2] = 0.0;
90 sample->
weight = 1.0 / max_samples;
96 set->cluster_count = 0;
97 set->cluster_max_count = max_samples;
123 for (i = 0; i < 2; i++)
152 for (i = 0; i <
set->sample_count; i++)
154 sample =
set->samples + i;
191 for (i = 0; i <
set->sample_count; i++)
193 sample =
set->samples + i;
195 sample->
pose = (*init_fn) (init_data);
227 double mean_x = 0, mean_y = 0;
229 for (i = 0; i <
set->sample_count; i++){
230 sample =
set->samples + i;
232 mean_x += sample->
pose.
v[0];
233 mean_y += sample->
pose.
v[1];
235 mean_x /=
set->sample_count;
236 mean_y /=
set->sample_count;
238 for (i = 0; i <
set->sample_count; i++){
239 sample =
set->samples + i;
259 (*action_fn) (action_data,
set);
277 total = (*sensor_fn) (sensor_data,
set);
279 set->n_effective = 0;
285 for (i = 0; i <
set->sample_count; i++)
287 sample =
set->samples + i;
293 w_avg /=
set->sample_count;
308 for (i = 0; i <
set->sample_count; i++)
310 sample =
set->samples + i;
311 sample->
weight = 1.0 /
set->sample_count;
315 set->n_effective = 1.0/
set->n_effective;
339 assert(sample_a->
weight > 0);
345 total += sample_b->
weight;
355 sample_b->
weight /= total;
398 c = (
double*)malloc(
sizeof(
double)*(set_a->
sample_count+1));
429 if(drand48() < w_diff)
462 if((c[i] <= r) && (r < c[i+1]))
465 assert(i<set_a->sample_count);
469 assert(sample_a->
weight > 0);
476 total += sample_b->
weight;
496 sample_b->
weight /= total;
535 b = 2 / (9 * ((double) k - 1));
536 c = sqrt(2 / (9 * ((
double) k - 1))) * pf->
pop_z;
539 n = (int) ceil((k - 1) / (2 * pf->
pop_err) * x * x * x);
541 if (n < pf->min_samples)
565 double m[4], c[2][2];
573 set->cluster_count = 0;
575 for (i = 0; i <
set->cluster_max_count; i++)
577 cluster =
set->clusters + i;
583 for (j = 0; j < 4; j++)
585 for (j = 0; j < 2; j++)
586 for (k = 0; k < 2; k++)
587 cluster->
c[j][k] = 0.0;
595 for (j = 0; j < 4; j++)
597 for (j = 0; j < 2; j++)
598 for (k = 0; k < 2; k++)
602 for (i = 0; i <
set->sample_count; i++)
604 sample =
set->samples + i;
611 if (cidx >=
set->cluster_max_count)
613 if (cidx + 1 >
set->cluster_count)
614 set->cluster_count = cidx + 1;
616 cluster =
set->clusters + cidx;
627 cluster->
m[2] += sample->
weight * cos(sample->
pose.
v[2]);
628 cluster->
m[3] += sample->
weight * sin(sample->
pose.
v[2]);
636 for (j = 0; j < 2; j++)
637 for (k = 0; k < 2; k++)
645 for (i = 0; i <
set->cluster_count; i++)
647 cluster =
set->clusters + i;
651 cluster->
mean.
v[2] = atan2(cluster->
m[3], cluster->
m[2]);
656 for (j = 0; j < 2; j++)
657 for (k = 0; k < 2; k++)
658 cluster->
cov.
m[j][k] = cluster->
c[j][k] / cluster->
weight -
663 cluster->
cov.
m[2][2] = -2 * log(sqrt(cluster->
m[2] * cluster->
m[2] +
664 cluster->
m[3] * cluster->
m[3]));
672 set->mean.v[0] = m[0] / weight;
673 set->mean.v[1] = m[1] / weight;
674 set->mean.v[2] = atan2(m[3], m[2]);
677 for (j = 0; j < 2; j++)
678 for (k = 0; k < 2; k++)
679 set->cov.m[j][k] = c[j][k] / weight -
set->mean.v[j] *
set->mean.v[k];
683 set->cov.m[2][2] = -2 * log(sqrt(m[2] * m[2] + m[3] * m[3]));
697 double mn, mx, my, mrr;
708 for (i = 0; i <
set->sample_count; i++)
710 sample =
set->samples + i;
719 mean->
v[0] = mx / mn;
720 mean->
v[1] = my / mn;
723 *var = mrr / mn - (mx * mx / (mn * mn) + my * my / (mn * mn));
738 if (clabel >=
set->cluster_count)
740 cluster =
set->clusters + clabel;
742 *weight = cluster->
weight;
743 *mean = cluster->
mean;
pf_init_model_fn_t random_pose_fn
double(* pf_sensor_model_fn_t)(void *sensor_data, struct _pf_sample_set_t *set)
static int pf_resample_limit(pf_t *pf, int k)
void pf_update_sensor(pf_t *pf, pf_sensor_model_fn_t sensor_fn, void *sensor_data)
void pf_get_cep_stats(pf_t *pf, pf_vector_t *mean, double *var)
void pf_kdtree_clear(pf_kdtree_t *self)
void pf_kdtree_insert(pf_kdtree_t *self, pf_vector_t pose, double value)
pf_vector_t(* pf_init_model_fn_t)(void *init_data)
void pf_init_converged(pf_t *pf)
pf_vector_t pf_vector_zero()
void pf_update_resample(pf_t *pf)
void copy_set(pf_sample_set_t *set_a, pf_sample_set_t *set_b)
pf_t * pf_alloc(int min_samples, int max_samples, double alpha_slow, double alpha_fast, pf_init_model_fn_t random_pose_fn, void *random_pose_data)
void pf_init_model(pf_t *pf, pf_init_model_fn_t init_fn, void *init_data)
void pf_kdtree_free(pf_kdtree_t *self)
ROSCPP_DECL void set(const std::string &key, const XmlRpc::XmlRpcValue &v)
void pf_set_selective_resampling(pf_t *pf, int selective_resampling)
void pf_pdf_gaussian_free(pf_pdf_gaussian_t *pdf)
void pf_update_action(pf_t *pf, pf_action_model_fn_t action_fn, void *action_data)
int pf_update_converged(pf_t *pf)
pf_matrix_t pf_matrix_zero()
TFSIMD_FORCE_INLINE const tfScalar & x() const
pf_pdf_gaussian_t * pf_pdf_gaussian_alloc(pf_vector_t x, pf_matrix_t cx)
void pf_cluster_stats(pf_t *pf, pf_sample_set_t *set)
void(* pf_action_model_fn_t)(void *action_data, struct _pf_sample_set_t *set)
int pf_get_cluster_stats(pf_t *pf, int clabel, double *weight, pf_vector_t *mean, pf_matrix_t *cov)
void pf_init(pf_t *pf, pf_vector_t mean, pf_matrix_t cov)
pf_kdtree_t * pf_kdtree_alloc(int max_size)
int pf_kdtree_get_cluster(pf_kdtree_t *self, pf_vector_t pose)
void pf_kdtree_cluster(pf_kdtree_t *self)
pf_vector_t pf_pdf_gaussian_sample(pf_pdf_gaussian_t *pdf)