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 
27 
28 #include <omp.h>
29 
30 #include <stdio.h>
31 
32 namespace visionx
33 {
34  CParticleFilterFrameworkParallelized::CParticleFilterFrameworkParallelized(int nParticles, int nDimension, int nNumParallelThreads) : CParticleFilterFramework(nParticles, nDimension)
35  {
36  m_nNumParallelThreads = nNumParallelThreads;
37  }
38 
39 
40  double CParticleFilterFrameworkParallelized::ParticleFilter(double* pResultMeanConfiguration, double dSigmaFactor, int nNumParticlesToUse)
41  {
42  // if desired, use only a smaller number of particles
43  const int nRealNumParticles = m_nParticles;
44  if (nNumParticlesToUse > 0 && nNumParticlesToUse < m_nParticles)
45  {
46  m_nParticles = nNumParticlesToUse;
47  }
48 
49  // push previous state through process model
50  // use dynamic model and add noise
51  PredictNewBases(dSigmaFactor);
52 
53  // apply bayesian measurement weighting
54  #pragma omp parallel for num_threads(m_nNumParallelThreads) schedule(guided, 10)
55  for (int i = 0; i < m_nParticles; i++)
56  {
57  const int nThreadNumber = omp_get_thread_num();
58  // update model (calculate forward kinematics)
59  UpdateModel(i, nThreadNumber);
60 
61  // evaluate likelihood function (compare edges,...)
62  pi[i] = CalculateProbability(i, nThreadNumber);
63  }
64 
65  CalculateFinalProbabilities();
66 
67  c_total = 0;
68  for (int i = 0; i < m_nParticles; i++)
69  {
70  c[i] = c_total;
71  c_total += pi[i];
72  if (c_total < 0)
73  {
74  ARMARX_WARNING_S << "CParticleFilterFrameworkParallelized::ParticleFilter(): Error: double values has overrun!";
75  }
76  }
77 
78  // normalize
79  const double factor = 1 / c_total;
80  for (int i = 0; i < m_nParticles; i++)
81  {
82  pi[i] *= factor;
83  }
84 
85  CalculateMean();
86 
87  GetMeanConfiguration(pResultMeanConfiguration);
88 
89  m_nParticles = nRealNumParticles;
90 
91  return CalculateProbabilityForConfiguration(pResultMeanConfiguration);
92  }
93 }
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
pi
#define pi
Definition: Transition.cpp:37
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
visionx::CParticleFilterFrameworkParallelized::CParticleFilterFrameworkParallelized
CParticleFilterFrameworkParallelized(int nParticles, int nDimension, int nNumParallelThreads=1)
Definition: ParticleFilterFrameworkParallelized.cpp:34
visionx::CParticleFilterFrameworkParallelized::m_nNumParallelThreads
int m_nNumParallelThreads
Definition: ParticleFilterFrameworkParallelized.h:50
ParticleFilterFrameworkParallelized.h
Logging.h
visionx::CParticleFilterFrameworkParallelized::ParticleFilter
double ParticleFilter(double *pResultMeanConfiguration, double dSigmaFactor, int nNumParticlesToUse=-1)
Definition: ParticleFilterFrameworkParallelized.cpp:40