TestSetSelection.cpp
Go to the documentation of this file.
1 
19 
21 
23  mEvaluator(pEvaluator), mPrintHelper('=')
24  { }
25 
27  { }
28 
29  void TestSetSelection::removeUnusableTestSets(double& pMinValidProbability, double& pMaxInvalidProbability)
30  {
31  double minValidProbability = 1.0;
32  double maxInvalidProbability = 0.0;
33  unsigned int size = mEvaluator->getValidTestSets().size() + mEvaluator->getInvalidTestSets().size();
34  for (unsigned int counter = 0; counter < size; counter++)
35  {
36  minValidProbability = 1.0;
37  maxInvalidProbability = 0.0;
38 
39  unsigned int minValidIndex = mEvaluator->getValidTestSets().size();
40  for (unsigned int i = 0; i < mEvaluator->getValidTestSets().size(); i++)
41  {
42  double validProbability = mEvaluator->getValidTestSets()[i]->getFullyMeshedProbability();
43  if (validProbability <= minValidProbability)
44  {
45  ROS_INFO_STREAM("Found smaller valid probability " << validProbability);
46  minValidProbability = validProbability;
47  minValidIndex = i;
48  }
49  }
50  if (minValidIndex == mEvaluator->getValidTestSets().size())
51  throw std::runtime_error("In TestSetSelection::removeUnusableTestSets(): No minimum valid probability could be found.");
52 
53  unsigned int maxInvalidIndex = mEvaluator->getInvalidTestSets().size();
54  for (unsigned int i = 0; i < mEvaluator->getInvalidTestSets().size(); i++) {
55  double invalidProbability = mEvaluator->getInvalidTestSets()[i]->getFullyMeshedProbability();
56  if (invalidProbability >= maxInvalidProbability)
57  {
58  maxInvalidProbability = invalidProbability;
59  maxInvalidIndex = i;
60  }
61  }
62  if (maxInvalidIndex == mEvaluator->getInvalidTestSets().size())
63  throw std::runtime_error("In TestSetSelection::removeUnusableTestSets(): No maximum invalid probability could be found.");
64 
65  mPrintHelper.printAsHeader("Minimum valid probability: " + boost::lexical_cast<std::string>(minValidProbability) + ", Maximum invalid probability: " + boost::lexical_cast<std::string>(maxInvalidProbability));
66 
67  double below = 0;
68  for (boost::shared_ptr<TestSet> valid: mEvaluator->getValidTestSets())
69  {
70  double validProbability = valid->getFullyMeshedProbability();
71  if (validProbability < maxInvalidProbability)
72  below++;
73  }
74 
75  double above = 0.0;
76  for (boost::shared_ptr<TestSet> invalid: mEvaluator->getInvalidTestSets())
77  {
78  double invalidProbability = invalid->getFullyMeshedProbability();
79  if (invalidProbability > minValidProbability)
80  above++;
81  }
82 
83  ROS_INFO_STREAM("Valid probabilities below maximum invalid probability: " << below << "/" << mEvaluator->getValidTestSets().size());
84  ROS_INFO_STREAM("Invalid probabilities above minimum valid probability: " << above << "/" << mEvaluator->getInvalidTestSets().size());
85 
86  if (minValidProbability <= maxInvalidProbability)
87  {
88  ROS_INFO_STREAM("Minimum valid probability smaller than maximum invalid probability.");
89 
90  if (below/((double) mEvaluator->getValidTestSets().size()) > above/((double) mEvaluator->getInvalidTestSets().size()))
91  {
92  ROS_INFO_STREAM("Ratio of valid probabilities worse. Removing maximum invalid probability.");
93  mEvaluator->eraseInvalidTestSet(maxInvalidIndex);
94  }
95  else
96  {
97  ROS_INFO_STREAM("Ratio of invalid probabilities worse. Removing minimum valid probability.");
98  mEvaluator->eraseValidTestSet(minValidIndex);
99  }
100  ROS_INFO_STREAM("There are " << mEvaluator->getValidTestSets().size() << " valid and " << mEvaluator->getInvalidTestSets().size() << " invalid test sets left.");
101  }
102  else
103  {
104  ROS_INFO_STREAM("All unusable test sets removed after " << counter << "/" << size << " steps.");
105  ROS_INFO_STREAM("Test sets remanining: " << mEvaluator->getValidTestSets().size() << " valid, " << mEvaluator->getInvalidTestSets().size() << " invalid.");
106  break;
107  }
108  }
109  // in the worst case scenario, all test sets from one of the two lists have been removed (or one was empty to begin with):
110  if (mEvaluator->getValidTestSets().empty() || mEvaluator->getInvalidTestSets().empty())
111  ROS_INFO_STREAM("NOTE: One of the two test set lists is empty. This will impede performance.");
112 
113  if (mEvaluator->getValidTestSets().empty() && mEvaluator->getInvalidTestSets().empty())
114  throw std::runtime_error("After TestSetSelection::removeUnusableTestSets(): Both test sets are now empty.");
115 
116  // Set output parameters:
117  pMinValidProbability = minValidProbability;
118  pMaxInvalidProbability = maxInvalidProbability;
119  }
120 
121  void TestSetSelection::removeMisclassifiedTestSets(double pRecognitionThreshold)
122  {
123  unsigned int validTestSetNumberBefore = mEvaluator->getValidTestSets().size();
124  unsigned int i = 0;
125  while (i < mEvaluator->getValidTestSets().size())
126  {
127  if (mEvaluator->getValidTestSets()[i]->getFullyMeshedProbability() <= pRecognitionThreshold)
128  mEvaluator->eraseValidTestSet(i);
129  else i++;
130  }
131 
132  unsigned int invalidTestSetNumberBefore = mEvaluator->getInvalidTestSets().size();
133  unsigned int j = 0;
134  while (j < mEvaluator->getInvalidTestSets().size())
135  {
136  if (mEvaluator->getInvalidTestSets()[j]->getFullyMeshedProbability() > pRecognitionThreshold)
137  mEvaluator->eraseInvalidTestSet(j);
138  else j++;
139  }
140 
141  ROS_INFO_STREAM("Removed " << validTestSetNumberBefore - mEvaluator->getValidTestSets().size() << " valid and "
142  << invalidTestSetNumberBefore - mEvaluator->getInvalidTestSets().size() << " invalid misclassified test sets.");
143  }
144 
145  void TestSetSelection::takeXTestSets(unsigned int pTestSetCount)
146  {
147  // Take only as many test sets as asked for, according to the fraction of the complete number of test sets each subset represents:
148  double fullTestSetCount = mEvaluator->getValidTestSets().size() + mEvaluator->getInvalidTestSets().size();
149  if (fullTestSetCount > pTestSetCount)
150  {
151  double validFraction = ((double) mEvaluator->getValidTestSets().size()) / fullTestSetCount;
152  double invalidFraction = ((double) mEvaluator->getInvalidTestSets().size()) / fullTestSetCount;
153  unsigned int validTestSetCount = std::floor(validFraction * ((double) pTestSetCount));
154  unsigned int invalidTestSetCount = std::floor(invalidFraction * ((double) pTestSetCount));
155  unsigned int sum = validTestSetCount + invalidTestSetCount;
156  // Fill up the smaller subset so that the pTestSetCount is exactly reached:
157  if (sum < pTestSetCount)
158  {
159  if (validTestSetCount < invalidTestSetCount) validTestSetCount += pTestSetCount - sum;
160  else invalidTestSetCount += pTestSetCount - sum;
161  }
162 
163  std::vector<boost::shared_ptr<TestSet>> validTestSets = mEvaluator->getValidTestSets();
164  validTestSets.resize(validTestSetCount);
165  mEvaluator->setValidTestSets(validTestSets);
166 
167  std::vector<boost::shared_ptr<TestSet>> invalidTestSets = mEvaluator->getInvalidTestSets();
168  invalidTestSets.resize(invalidTestSetCount);
169  mEvaluator->setInvalidTestSets(invalidTestSets);
170 
171  ROS_INFO_STREAM("Reset number of test sets to " << mEvaluator->getValidTestSets().size() << " valid and " << mEvaluator->getInvalidTestSets().size() << " invalid sets "
172  << "(" << mEvaluator->getValidTestSets().size() + mEvaluator->getInvalidTestSets().size() << "/" << pTestSetCount << ")");
173  }
174  }
175 
176 }
177 
boost::shared_ptr< AbstractTopologyEvaluator > mEvaluator
void takeXTestSets(unsigned int pTestSetCount)
void removeUnusableTestSets(double &pMinValidProbability, double &pMaxInvalidProbability)
void removeMisclassifiedTestSets(double pRecognitionThreshold)
#define ROS_INFO_STREAM(args)
TestSetSelection(boost::shared_ptr< AbstractTopologyEvaluator > pEvaluator)


asr_psm
Author(s): Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meißner Pascal
autogenerated on Fri Nov 15 2019 04:00:08