Skip to content

Commit 2f966e6

Browse files
committed
Fix assertions for parameters of autotuning when it is called with explicit default arguments -1
1 parent c6f5a59 commit 2f966e6

22 files changed

+106
-95
lines changed

cpp/Mrpt.h

+47-44
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ class Mrpt {
164164
* @param depth_min_ minimum depth of trees considered when searching for
165165
* optimal parameters; in the set
166166
* \f$\{1,2, \dots ,\lfloor \log_2 (n) \rfloor \}\f$; a default value -1
167-
* sets this to 5
167+
* sets this to \f$ \mathrm{max}(\lfloor \log_2 (n) \rfloor - 11, 5)\f$
168168
* @param votes_max_ maximum number of votes considered when searching for
169169
* optimal parameters; a default value -1 sets this to
170-
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor, 10) \f$
170+
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor,
171+
* \mathrm{min}(10, \mathrm{trees\_max})) \f$
171172
* @param density expected proportion of non-zero components in the random vectors;
172173
* default value -1.0 sets this to \f$ 1 / \sqrt{d} \f$, where \f$ d\f$ is
173174
* the dimension of data
@@ -201,10 +202,11 @@ class Mrpt {
201202
* @param depth_min_ minimum depth of trees considered when searching for
202203
* optimal parameters; in the set
203204
* \f$\{1,2, \dots ,\lfloor \log_2 (n) \rfloor \}\f$; a default value -1
204-
* sets this to 5
205+
* sets this to \f$ \mathrm{max}(\lfloor \log_2 (n) \rfloor - 11, 5)\f$
205206
* @param votes_max_ maximum number of votes considered when searching for
206207
* optimal parameters; a default value -1 sets this to
207-
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor, 10) \f$
208+
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor,
209+
* \mathrm{min}(10, \mathrm{trees\_max})) \f$
208210
* @param density expected proportion of non-zero components in the random vectors;
209211
* default value -1.0 sets this to \f$ 1 / \sqrt{d} \f$, where \f$ d\f$ is
210212
* the dimension of data
@@ -239,10 +241,11 @@ class Mrpt {
239241
* @param depth_min_ minimum depth of trees considered when searching for
240242
* optimal parameters; in the set
241243
* \f$\{1,2, \dots ,\lfloor \log_2 (n) \rfloor \}\f$; a default value -1
242-
* sets this to 5
244+
* sets this to \f$ \mathrm{max}(\lfloor \log_2 (n) \rfloor - 11, 5)\f$
243245
* @param votes_max_ maximum number of votes considered when searching for
244246
* optimal parameters; a default value -1 sets this to
245-
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor, 10) \f$
247+
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor,
248+
* \mathrm{min}(10, \mathrm{trees\_max})) \f$
246249
* @param density_ expected proportion of non-zero components in the random vectors;
247250
* default value -1.0 sets this to \f$ 1 / \sqrt{d} \f$, where \f$ d\f$ is
248251
* the dimension of data
@@ -325,10 +328,11 @@ class Mrpt {
325328
* @param depth_min_ minimum depth of trees considered when searching for
326329
* optimal parameters; in the set
327330
* \f$\{1,2, \dots ,\lfloor \log_2 (n) \rfloor \}\f$; a default value -1
328-
* sets this to 5
331+
* sets this to \f$ \mathrm{max}(\lfloor \log_2 (n) \rfloor - 11, 5)\f$
329332
* @param votes_max_ maximum number of votes considered when searching for
330333
* optimal parameters; a default value -1 sets this to
331-
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor, 10) \f$
334+
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor,
335+
* \mathrm{min}(10, \mathrm{trees\_max})) \f$
332336
* @param density_ expected proportion of non-zero components in the random vectors;
333337
* default value -1.0 sets this to \f$ 1 / \sqrt{d} \f$, where \f$ d\f$ is
334338
* the dimension of data
@@ -341,6 +345,26 @@ class Mrpt {
341345
int depth_min_ = -1, int votes_max_ = -1, float density_ = -1.0, int seed = 0,
342346
const std::vector<int> &indices_test = {}) {
343347

348+
if (trees_max == - 1) {
349+
trees_max = std::min(std::sqrt(n_samples), 1000.0);
350+
}
351+
352+
if (depth_min_ == -1) {
353+
depth_min_ = std::max(static_cast<int>(std::log2(n_samples) - 11), 5);
354+
}
355+
356+
if (depth_max == -1) {
357+
depth_max = std::max(static_cast<int>(std::log2(n_samples) - 4), depth_min_);
358+
}
359+
360+
if (votes_max_ == -1) {
361+
votes_max_ = std::max(trees_max / 10, std::min(trees_max, 10));
362+
}
363+
364+
if (density_ > -1.0001 && density_ < -0.9999) {
365+
density_ = 1.0 / std::sqrt(dim);
366+
}
367+
344368
if (!empty()) {
345369
throw std::logic_error("The index has already been grown.");
346370
}
@@ -349,60 +373,37 @@ class Mrpt {
349373
throw std::out_of_range("k_ must belong to the set {1, ..., n}.");
350374
}
351375

352-
if (trees_max < -1 || trees_max == 0) {
376+
if (trees_max <= 0) {
353377
throw std::out_of_range("trees_max must be positive.");
354378
}
355379

356-
if (depth_max < -1 || depth_max == 0 || depth_max > std::log2(n_samples)) {
380+
if (depth_max <= 0 || depth_max > std::log2(n_samples)) {
357381
throw std::out_of_range("depth_max must belong to the set {1, ... , log2(n)}.");
358382
}
359383

360-
if (depth_min_ < -1 || depth_min_ == 0 || depth_min_ > depth_max) {
384+
if (depth_min_ <= 0 || depth_min_ > depth_max) {
361385
throw std::out_of_range("depth_min_ must belong to the set {1, ... , depth_max}");
362386
}
363387

364-
if (votes_max_ < -1 || votes_max_ == 0 || votes_max_ > trees_max) {
388+
if (votes_max_ <= 0 || votes_max_ > trees_max) {
365389
throw std::out_of_range("votes_max_ must belong to the set {1, ... , trees_max}.");
366390
}
367391

368-
if (density_ < -1.0001 || density_ > 1.0001 || (density_ > -0.9999 && density_ < -0.0001)) {
392+
if (density_ < 0.0 || density_ > 1.0001) {
369393
throw std::out_of_range("The density must be on the interval (0,1].");
370394
}
371395

372396
if(n_samples < 101) {
373397
throw std::out_of_range("Sample size must be at least 101 to autotune an index.");
374398
}
375399

376-
if (trees_max == - 1) {
377-
trees_max = std::min(std::sqrt(n_samples), 1000.0);
378-
}
379-
380-
if (depth_min_ == -1) {
381-
depth_min = std::max(static_cast<int>(std::log2(n_samples) - 11), 5);
382-
} else {
383-
depth_min = depth_min_;
384-
}
385-
386-
if (depth_max == -1) {
387-
depth_max = std::max(static_cast<int>(std::log2(n_samples) - 4), depth_min);
388-
}
389-
390-
if (votes_max_ == -1) {
391-
votes_max = std::max(trees_max / 10, std::min(trees_max, 10));
392-
} else {
393-
votes_max = votes_max_;
394-
}
395-
396-
if (density_ < 0) {
397-
density = 1.0 / std::sqrt(dim);
398-
} else {
399-
density = density_;
400-
}
401-
400+
depth_min = depth_min_;
401+
votes_max = votes_max_;
402402
k = k_;
403+
403404
const Eigen::Map<const Eigen::MatrixXf> Q(data, dim, n_test);
404405

405-
grow(trees_max, depth_max, density, seed);
406+
grow(trees_max, depth_max, density_, seed);
406407
Eigen::MatrixXi exact(k, n_test);
407408
compute_exact(Q, exact, indices_test);
408409

@@ -453,10 +454,11 @@ class Mrpt {
453454
* @param depth_min_ minimum depth of trees considered when searching for
454455
* optimal parameters on the set
455456
* \f$\{1,2, \dots ,\lfloor \log_2 (n) \rfloor \}\f$; a default value -1
456-
* sets this to 5
457+
* sets this to \f$ \mathrm{max}(\lfloor \log_2 (n) \rfloor - 11, 5)\f$
457458
* @param votes_max_ maximum number of votes considered when searching for
458459
* optimal parameters; a default value -1 sets this to
459-
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor, 10) \f$
460+
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor,
461+
* \mathrm{min}(10, \mathrm{trees\_max})) \f$
460462
* @param density_ expected proportion of non-zero components of random vectors;
461463
* default value -1.0 sets this to \f$ 1 / \sqrt{d} \f$, where \f$ d\f$ is
462464
* the dimension of data
@@ -486,10 +488,11 @@ class Mrpt {
486488
* @param depth_min_ minimum depth of trees considered when searching for
487489
* optimal parameters on the set
488490
* \f$\{1,2, \dots ,\lfloor \log_2 (n) \rfloor \}\f$; a default value -1
489-
* sets this to 5
491+
* sets this to \f$ \mathrm{max}(\lfloor \log_2 (n) \rfloor - 11, 5)\f$
490492
* @param votes_max_ maximum number of votes considered when searching for
491493
* optimal parameters; a default value -1 sets this to
492-
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor, 10) \f$
494+
* \f$ \mathrm{max}(\lfloor \mathrm{trees\_max} / 10 \rfloor,
495+
* \mathrm{min}(10, \mathrm{trees\_max})) \f$
493496
* @param density_ expected proportion of non-zero components of random vectors;
494497
* default value -1.0 sets this to \f$ 1 / \sqrt{d} \f$, where \f$ d\f$ is
495498
* the dimension of data

docs/html/_mrpt_8h_source.html

+23-23
Large diffs are not rendered by default.

docs/html/annotated.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<td id="projectlogo"><img alt="Logo" src="extree3.png"/></td>
2424
<td id="projectalign" style="padding-left: 0.5em;">
2525
<div id="projectname">Mrpt
26-
&#160;<span id="projectnumber">1.0.0</span>
26+
&#160;<span id="projectnumber">1.1.1</span>
2727
</div>
2828
</td>
2929
</tr>

docs/html/class_mrpt-members.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<td id="projectlogo"><img alt="Logo" src="extree3.png"/></td>
2424
<td id="projectalign" style="padding-left: 0.5em;">
2525
<div id="projectname">Mrpt
26-
&#160;<span id="projectnumber">1.0.0</span>
26+
&#160;<span id="projectnumber">1.1.1</span>
2727
</div>
2828
</td>
2929
</tr>

0 commit comments

Comments
 (0)