ParticleFilterFrameworkParallelized.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
25
26#include <stdio.h>
27
29
30#include <omp.h>
31
32namespace visionx
33{
35 int nParticles,
36 int nDimension,
37 int nNumParallelThreads) :
38 CParticleFilterFramework(nParticles, nDimension)
39 {
40 m_nNumParallelThreads = nNumParallelThreads;
41 }
42
43 double
45 double dSigmaFactor,
46 int nNumParticlesToUse)
47 {
48 // if desired, use only a smaller number of particles
49 const int nRealNumParticles = m_nParticles;
50 if (nNumParticlesToUse > 0 && nNumParticlesToUse < m_nParticles)
51 {
52 m_nParticles = nNumParticlesToUse;
53 }
54
55 // push previous state through process model
56 // use dynamic model and add noise
57 PredictNewBases(dSigmaFactor);
58
59// apply bayesian measurement weighting
60#pragma omp parallel for num_threads(m_nNumParallelThreads) schedule(guided, 10)
61 for (int i = 0; i < m_nParticles; i++)
62 {
63 const int nThreadNumber = omp_get_thread_num();
64 // update model (calculate forward kinematics)
65 UpdateModel(i, nThreadNumber);
66
67 // evaluate likelihood function (compare edges,...)
68 pi[i] = CalculateProbability(i, nThreadNumber);
69 }
70
71 CalculateFinalProbabilities();
72
73 c_total = 0;
74 for (int i = 0; i < m_nParticles; i++)
75 {
76 c[i] = c_total;
77 c_total += pi[i];
78 if (c_total < 0)
79 {
80 ARMARX_WARNING_S << "CParticleFilterFrameworkParallelized::ParticleFilter(): "
81 "Error: double values has overrun!";
82 }
83 }
84
85 // normalize
86 const double factor = 1 / c_total;
87 for (int i = 0; i < m_nParticles; i++)
88 {
89 pi[i] *= factor;
90 }
91
92 CalculateMean();
93
94 GetMeanConfiguration(pResultMeanConfiguration);
95
96 m_nParticles = nRealNumParticles;
97
98 return CalculateProbabilityForConfiguration(pResultMeanConfiguration);
99 }
100} // namespace visionx
#define pi
constexpr T c
CParticleFilterFrameworkParallelized(int nParticles, int nDimension, int nNumParallelThreads=1)
double ParticleFilter(double *pResultMeanConfiguration, double dSigmaFactor, int nNumParticlesToUse=-1)
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:213
ArmarX headers.