MCPcopy Create free account
hub / github.com/colmap/colmap / Sample

Method Sample

src/colmap/optim/progressive_sampler.cc:68–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68void ProgressiveSampler::Sample(std::vector<size_t>* sampled_idxs) {
69 t_ += 1;
70
71 sampled_idxs->clear();
72 sampled_idxs->reserve(num_samples_);
73
74 // Compute T_n_p_ using recurrent relation in equation 3 (second part).
75 if (t_ == T_n_p_ && n_ < total_num_samples_) {
76 const double T_n_plus_1 = T_n_ * (n_ + 1.0) / (n_ + 1.0 - num_samples_);
77 T_n_p_ += std::ceil(T_n_plus_1 - T_n_);
78 T_n_ = T_n_plus_1;
79 n_ += 1;
80 }
81
82 // Decide how many samples to draw from which part of the data as
83 // specified in equation 5.
84 size_t num_random_samples = num_samples_;
85 size_t max_random_sample_idx = n_ - 1;
86 if (T_n_p_ >= t_) {
87 num_random_samples -= 1;
88 max_random_sample_idx -= 1;
89 }
90
91 // Draw semi-random samples as described in algorithm 1.
92 for (size_t i = 0; i < num_random_samples; ++i) {
93 while (true) {
94 const size_t random_idx =
95 RandomUniformInteger<uint32_t>(0, max_random_sample_idx);
96 if (!VectorContainsValue(*sampled_idxs, random_idx)) {
97 sampled_idxs->push_back(random_idx);
98 break;
99 }
100 }
101 }
102
103 // In progressive sampling mode, the last element is mandatory.
104 if (T_n_p_ >= t_) {
105 sampled_idxs->push_back(n_);
106 }
107}
108
109} // namespace colmap

Callers

nothing calls this directly

Calls 1

VectorContainsValueFunction · 0.85

Tested by

no test coverage detected