BackgroundInferenceAlgorithm.cpp
Go to the documentation of this file.
1 
19 
21 
24  {
25  }
26 
28  {
29  }
30 
31  void BackgroundInferenceAlgorithm::load(boost::property_tree::ptree& pPt)
32  {
33  mNumberOfObjectClasses = pPt.get<int>("description.<xmlattr>.objects");
34  mVolumeOfWorkspace = pPt.get<double>("description.<xmlattr>.volume");
35  }
36 
37  double BackgroundInferenceAlgorithm::calculateProbabilityOfBackgroundSceneObject(unsigned int pNumberOfEvidence, unsigned int pNumberOfSlots)
38  {
39  // NOTE We assume here that the number of slots equals the number of evidences, so that all evidences have a place in the calculation.
40 
41  // The probability of the background scene object.
42  double probability = 0.0;
43 
44  // The number of valid hypothesis, therefore hypotheses where the root node is not occluded and no object is assigned more than one times.
45  unsigned int numberOfValidHypotheses = 0;
46 
47  // The number of evidence is the given number of evidence +1 for the null object.
48  unsigned int numberOfEvidence = pNumberOfEvidence + 1;
49 
50  // Now we iterate over all combinations of hypotheses 'h'.
51  for(unsigned int h = 0; h < pow(numberOfEvidence, pNumberOfSlots); h++)
52  {
53  // A marker that becomes true, when hypothesis contains double assignments and should be dropped.
54  bool dropped = false;
55 
56  // A vector holding the assignments of parts to slots.
57  std::vector<unsigned int> assignments;
58 
59  // The number of filled slots.
60  unsigned int numberOfFilledSlots = 0;
61 
62  // Calculate the assignments of parts to slots. Drop hypotheses with double assignments of parts to slots.
63  for(unsigned int s = 0; s < pNumberOfSlots; s++)
64  {
65  // Calculates which part should be associated with the 's'th slot, based on the 'h'th hypothesis.
66  unsigned int part = (h / ((unsigned int) pow(numberOfEvidence, s)) ) % numberOfEvidence;
67 
68  // If part is not zero-object and is already assigned, we drop this hypothesis and continue with the next one.
69  if(part > 0 && std::find(assignments.begin(), assignments.end(), part) != assignments.end())
70  dropped = true;
71 
72  // Root object is occluded? Drop hypothesis!
73  if(s == 0 && part == 0)
74  dropped = true;
75 
76  // Assign the calculated part to the next slot in the row.
77  // Even if we don't use the vector we have to do it so we can drop double assignments.
78  assignments.push_back(part);
79 
80  // Used to calculate the number of filled slots.
81  if(part > 0)
82  numberOfFilledSlots++;
83  }
84 
85  // Calculate the background probability.
86  if(!dropped)
87  {
88  // Calculate the variables requried by the poisson distribution of the object occlusion term.
89  // The plus one is required to fix an anomaly in the distributions.
90  double lambda = pNumberOfEvidence + 1;
91 
92  double faculty = 1;
93  for(unsigned int i = 2; i <= numberOfFilledSlots; i++)
94  faculty *= i;
95 
96  // Calculate the probability for the background based on (in order of appearance):
97  // - an equal distributed shape over all three position dimensions and four orientation dimensions for every slot
98  // - an equal distributed appearance
99  // - an equal distributed occlusion term
100  // - hypothesis weight by poisson distribution
101  probability += pow(1.0 / (mVolumeOfWorkspace * 2.0 * pow(M_PI, 2.0)), numberOfFilledSlots)
102  * pow(1.0 / mNumberOfObjectClasses, numberOfFilledSlots)
103  * pow(0.5, numberOfFilledSlots)
104  * (pow(lambda, numberOfFilledSlots) / faculty) * exp(-lambda);
105 
106  // +1 for this valid hypothesis.
107  numberOfValidHypotheses++;
108  }
109  }
110  // Apply normalization term by dividing by the number of VALID (!) hypotheses.
111  if(numberOfValidHypotheses > 0)
112  probability /= numberOfValidHypotheses;
113 
114  // return the probability for the background scene object.
115  return probability;
116  }
117 
118 }
XmlRpcServer s
bool find(const std::vector< double > &in, double toFind)
Definition: validator.cpp:128
double calculateProbabilityOfBackgroundSceneObject(unsigned int pNumberOfEvidence, unsigned int pNumberOfSlots)


asr_psm
Author(s): Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meißner Pascal
autogenerated on Fri Nov 15 2019 03:57:54