23 mEvaluator(pEvaluator), mPrintHelper(
'=')
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++)
36 minValidProbability = 1.0;
37 maxInvalidProbability = 0.0;
39 unsigned int minValidIndex =
mEvaluator->getValidTestSets().size();
40 for (
unsigned int i = 0; i <
mEvaluator->getValidTestSets().size(); i++)
42 double validProbability =
mEvaluator->getValidTestSets()[i]->getFullyMeshedProbability();
43 if (validProbability <= minValidProbability)
45 ROS_INFO_STREAM(
"Found smaller valid probability " << validProbability);
46 minValidProbability = validProbability;
50 if (minValidIndex ==
mEvaluator->getValidTestSets().size())
51 throw std::runtime_error(
"In TestSetSelection::removeUnusableTestSets(): No minimum valid probability could be found.");
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)
58 maxInvalidProbability = invalidProbability;
62 if (maxInvalidIndex ==
mEvaluator->getInvalidTestSets().size())
63 throw std::runtime_error(
"In TestSetSelection::removeUnusableTestSets(): No maximum invalid probability could be found.");
65 mPrintHelper.
printAsHeader(
"Minimum valid probability: " + boost::lexical_cast<std::string>(minValidProbability) +
", Maximum invalid probability: " + boost::lexical_cast<std::string>(maxInvalidProbability));
70 double validProbability = valid->getFullyMeshedProbability();
71 if (validProbability < maxInvalidProbability)
78 double invalidProbability = invalid->getFullyMeshedProbability();
79 if (invalidProbability > minValidProbability)
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());
86 if (minValidProbability <= maxInvalidProbability)
88 ROS_INFO_STREAM(
"Minimum valid probability smaller than maximum invalid probability.");
90 if (below/((
double)
mEvaluator->getValidTestSets().size()) > above/((
double)
mEvaluator->getInvalidTestSets().size()))
92 ROS_INFO_STREAM(
"Ratio of valid probabilities worse. Removing maximum invalid probability.");
93 mEvaluator->eraseInvalidTestSet(maxInvalidIndex);
97 ROS_INFO_STREAM(
"Ratio of invalid probabilities worse. Removing minimum valid probability.");
104 ROS_INFO_STREAM(
"All unusable test sets removed after " << counter <<
"/" << size <<
" steps.");
111 ROS_INFO_STREAM(
"NOTE: One of the two test set lists is empty. This will impede performance.");
114 throw std::runtime_error(
"After TestSetSelection::removeUnusableTestSets(): Both test sets are now empty.");
117 pMinValidProbability = minValidProbability;
118 pMaxInvalidProbability = maxInvalidProbability;
123 unsigned int validTestSetNumberBefore =
mEvaluator->getValidTestSets().size();
125 while (i < mEvaluator->getValidTestSets().size())
127 if (
mEvaluator->getValidTestSets()[i]->getFullyMeshedProbability() <= pRecognitionThreshold)
132 unsigned int invalidTestSetNumberBefore =
mEvaluator->getInvalidTestSets().size();
134 while (j < mEvaluator->getInvalidTestSets().size())
136 if (
mEvaluator->getInvalidTestSets()[j]->getFullyMeshedProbability() > pRecognitionThreshold)
142 << invalidTestSetNumberBefore -
mEvaluator->getInvalidTestSets().size() <<
" invalid misclassified test sets.");
148 double fullTestSetCount =
mEvaluator->getValidTestSets().size() +
mEvaluator->getInvalidTestSets().size();
149 if (fullTestSetCount > pTestSetCount)
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;
157 if (sum < pTestSetCount)
159 if (validTestSetCount < invalidTestSetCount) validTestSetCount += pTestSetCount - sum;
160 else invalidTestSetCount += pTestSetCount - sum;
163 std::vector<boost::shared_ptr<TestSet>> validTestSets =
mEvaluator->getValidTestSets();
164 validTestSets.resize(validTestSetCount);
167 std::vector<boost::shared_ptr<TestSet>> invalidTestSets =
mEvaluator->getInvalidTestSets();
168 invalidTestSets.resize(invalidTestSetCount);
169 mEvaluator->setInvalidTestSets(invalidTestSets);
172 <<
"(" <<
mEvaluator->getValidTestSets().size() +
mEvaluator->getInvalidTestSets().size() <<
"/" << pTestSetCount <<
")");
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)