@@ -41,25 +41,18 @@ inline
41
41
};
42
42
}
43
43
44
- template <typename ModelType, typename FeatureType>
44
+ template <typename ModelType, typename FeatureType,
45
+ typename IsValidCandidateMetric>
45
46
inline typename RansacFunctions<
46
47
FitAndIndices<ModelType, FeatureType>>::IsValidCandidate
47
48
get_gp_ransac_is_valid_candidate (const RegressionDataset<FeatureType> &dataset,
48
49
const FoldIndexer &indexer,
49
- const Eigen::MatrixXd &cov) {
50
- return [&, indexer, cov, dataset](const std::vector<FoldName> &groups) {
51
- auto inds = indices_from_names (indexer, groups);
52
- const auto train_dataset = subset (dataset, inds);
53
- const auto train_cov = symmetric_subset (cov, inds);
50
+ const Eigen::MatrixXd &cov,
51
+ const IsValidCandidateMetric &metric) {
54
52
55
- const JointDistribution prior (Eigen::VectorXd::Zero (train_cov.rows ()),
56
- train_cov);
57
- // These thresholds are under the assumption of a perfectly
58
- // representative prior.
59
- const double probability_prior_exceeded =
60
- chi_squared_cdf (prior, train_dataset.targets );
61
- const double skip_every_1000th_candidate = 0.999 ;
62
- return (probability_prior_exceeded < skip_every_1000th_candidate);
53
+ return [&, indexer, cov, dataset](const std::vector<FoldName> &groups) {
54
+ const auto inds = indices_from_names (indexer, groups);
55
+ return metric (inds, dataset, cov);
63
56
};
64
57
}
65
58
@@ -145,14 +138,43 @@ class ChiSquaredConsensusMetric {
145
138
Eigen::MatrixXd cov_;
146
139
};
147
140
141
+ struct ChiSquaredIsValidCandidateMetric {
142
+
143
+ template <typename FeatureType>
144
+ bool operator ()(const FoldIndices &inds,
145
+ const RegressionDataset<FeatureType> &dataset,
146
+ const Eigen::MatrixXd &cov) const {
147
+ const auto train_dataset = subset (dataset, inds);
148
+ const auto train_cov = symmetric_subset (cov, inds);
149
+
150
+ const JointDistribution prior (Eigen::VectorXd::Zero (train_cov.rows ()),
151
+ train_cov);
152
+ // These thresholds are under the assumption of a perfectly
153
+ // representative prior.
154
+ const double probability_prior_exceeded =
155
+ chi_squared_cdf (prior, train_dataset.targets );
156
+ const double skip_every_1000th_candidate = 0.999 ;
157
+ return (probability_prior_exceeded < skip_every_1000th_candidate);
158
+ };
159
+ };
160
+
161
+ struct AlwaysAcceptCandidateMetric {
162
+ template <typename FeatureType>
163
+ bool operator ()(const FoldIndices &inds,
164
+ const RegressionDataset<FeatureType> &dataset,
165
+ const Eigen::MatrixXd &cov) const {
166
+ return true ;
167
+ }
168
+ };
169
+
148
170
template <typename ModelType, typename FeatureType, typename InlierMetric,
149
- typename ConsensusMetric>
171
+ typename ConsensusMetric, typename IsValidCandidateMetric >
150
172
inline RansacFunctions<FitAndIndices<ModelType, FeatureType>>
151
- get_gp_ransac_functions (const ModelType &model,
152
- const RegressionDataset<FeatureType> &dataset,
153
- const FoldIndexer &indexer ,
154
- const InlierMetric &inlier_metric ,
155
- const ConsensusMetric &consensus_metric ) {
173
+ get_gp_ransac_functions (
174
+ const ModelType &model, const RegressionDataset<FeatureType> &dataset,
175
+ const FoldIndexer &indexer, const InlierMetric &inlier_metric ,
176
+ const ConsensusMetric &consensus_metric ,
177
+ const IsValidCandidateMetric &is_valid_candidate_metric ) {
156
178
157
179
static_assert (is_prediction_metric<InlierMetric>::value,
158
180
" InlierMetric must be an PredictionMetric." );
@@ -170,16 +192,16 @@ get_gp_ransac_functions(const ModelType &model,
170
192
full_cov);
171
193
172
194
const auto is_valid_candidate =
173
- get_gp_ransac_is_valid_candidate<ModelType, FeatureType>(dataset, indexer,
174
- full_cov);
195
+ get_gp_ransac_is_valid_candidate<ModelType, FeatureType>(
196
+ dataset, indexer, full_cov, is_valid_candidate_metric );
175
197
176
198
return RansacFunctions<FitAndIndices<ModelType, FeatureType>>(
177
199
fitter, inlier_metric_from_group, consensus_metric_from_group,
178
200
is_valid_candidate);
179
201
};
180
202
181
203
template <typename InlierMetric, typename ConsensusMetric,
182
- typename IndexingFunction>
204
+ typename IndexingFunction, typename IsValidCandidateMetric >
183
205
struct GaussianProcessRansacStrategy {
184
206
185
207
GaussianProcessRansacStrategy () = default ;
@@ -188,15 +210,15 @@ struct GaussianProcessRansacStrategy {
188
210
const ConsensusMetric &consensus_metric,
189
211
const IndexingFunction &indexing_function)
190
212
: inlier_metric_(inlier_metric), consensus_metric_(consensus_metric),
191
- indexing_function_ (indexing_function){};
213
+ indexing_function_ (indexing_function), is_valid_candidate_() {};
192
214
193
215
template <typename ModelType, typename FeatureType>
194
216
RansacFunctions<FitAndIndices<ModelType, FeatureType>>
195
217
operator ()(const ModelType &model,
196
218
const RegressionDataset<FeatureType> &dataset) const {
197
219
const auto indexer = get_indexer (dataset);
198
220
return get_gp_ransac_functions (model, dataset, indexer, inlier_metric_,
199
- consensus_metric_);
221
+ consensus_metric_, is_valid_candidate_ );
200
222
}
201
223
202
224
template <typename FeatureType>
@@ -208,6 +230,7 @@ struct GaussianProcessRansacStrategy {
208
230
InlierMetric inlier_metric_;
209
231
ConsensusMetric consensus_metric_;
210
232
IndexingFunction indexing_function_;
233
+ IsValidCandidateMetric is_valid_candidate_;
211
234
};
212
235
213
236
using DefaultGPRansacStrategy =
0 commit comments