Skip to content

Commit cadce18

Browse files
Merge pull request #154 from swift-nav/seth/ransac_metric_group_count
Minor ransac fixes. Changes default GP consensus metric to a feature count
2 parents 0e0c62f + f10af08 commit cadce18

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

include/albatross/src/models/ransac.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,13 @@ ransac(const RansacFunctions<FitType> &ransac_functions,
8080
random_without_replacement(groups, random_sample_size, gen);
8181
const auto fit = ransac_functions.fitter(candidate_groups);
8282

83-
std::vector<FoldName> candidate_consensus;
83+
// Any group that's part of the candidate set is automatically an inlier.
84+
std::vector<FoldName> candidate_consensus = candidate_groups;
85+
8486
// Find which of the other groups agree with the reference model
8587
// which gives us a consensus (set of inliers).
8688
for (const auto &possible_inlier : groups) {
87-
if (contains_group(candidate_groups, possible_inlier)) {
88-
// Any group that's part of the candidate set is automatically an
89-
// inlier.
90-
candidate_consensus.emplace_back(possible_inlier);
91-
} else {
89+
if (!contains_group(candidate_groups, possible_inlier)) {
9290
double metric_value =
9391
ransac_functions.inlier_metric(possible_inlier, fit);
9492
if (metric_value < inlier_threshold) {
@@ -99,7 +97,7 @@ ransac(const RansacFunctions<FitType> &ransac_functions,
9997

10098
// If there is enough agreement, consider this random set of inliers
10199
// as a candidate model.
102-
if (candidate_consensus.size() + random_sample_size >= min_consensus_size) {
100+
if (candidate_consensus.size() >= min_consensus_size) {
103101
double consensus_metric_value =
104102
ransac_functions.consensus_metric(candidate_consensus);
105103
if (consensus_metric_value < best_consensus_metric) {

include/albatross/src/models/ransac_gp.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ get_gp_ransac_inlier_metric(const RegressionDataset<FeatureType> &dataset,
6666
};
6767
}
6868

69+
/*
6970
template <typename ModelType, typename FeatureType>
7071
inline typename RansacFunctions<
7172
FitAndIndices<ModelType, FeatureType>>::ConsensusMetric
@@ -77,6 +78,17 @@ get_gp_ransac_model_entropy_metric(const FoldIndexer &indexer,
7778
return differential_entropy(consensus_cov);
7879
};
7980
}
81+
*/
82+
83+
template <typename ModelType, typename FeatureType>
84+
inline typename RansacFunctions<
85+
FitAndIndices<ModelType, FeatureType>>::ConsensusMetric
86+
get_gp_ransac_feature_count_consensus_metric(const FoldIndexer &indexer) {
87+
return [&, indexer](const std::vector<FoldName> &groups) {
88+
auto inds = indices_from_names(indexer, groups);
89+
return (-1.0 * static_cast<double>(inds.size()));
90+
};
91+
}
8092

8193
template <typename ModelType, typename FeatureType, typename InlierMetric>
8294
inline RansacFunctions<FitAndIndices<ModelType, FeatureType>>
@@ -97,12 +109,12 @@ get_gp_ransac_functions(const ModelType &model,
97109
get_gp_ransac_inlier_metric<ModelType, FeatureType, InlierMetric>(
98110
dataset, indexer, full_cov, model, inlier_metric);
99111

100-
const auto consensus_metric_from_gorup =
101-
get_gp_ransac_model_entropy_metric<ModelType, FeatureType>(indexer,
102-
full_cov);
112+
const auto consensus_metric_from_group =
113+
get_gp_ransac_feature_count_consensus_metric<ModelType, FeatureType>(
114+
indexer);
103115

104116
return RansacFunctions<FitAndIndices<ModelType, FeatureType>>(
105-
fitter, inlier_metric_from_group, consensus_metric_from_gorup);
117+
fitter, inlier_metric_from_group, consensus_metric_from_group);
106118
};
107119

108120
template <typename InlierMetric, typename IndexingFunction>

0 commit comments

Comments
 (0)