Skip to content

Commit

Permalink
Don't throw an error if the required number of neighbors is too high.
Browse files Browse the repository at this point in the history
This is none of our business - if the user requests a certain perplexity
for a dataset, then we'll respect it and proceed with compute.
  • Loading branch information
LTLA committed Oct 15, 2024
1 parent 5196f09 commit 5b10c7d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions include/qdtsne/initialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <vector>
#include <stdexcept>
#include <algorithm>

#include "Status.hpp"
#include "Options.hpp"
Expand Down Expand Up @@ -108,12 +109,9 @@ Status<num_dim_, Index_, Float_> initialize(NeighborList<Index_, Float_> neighbo
*/
template<int num_dim_, typename Dim_, typename Index_, typename Float_>
Status<num_dim_, Index_, Float_> initialize(const knncolle::Prebuilt<Dim_, Index_, Float_>& prebuilt, const Options& options) {
const Index_ K = perplexity_to_k(options.perplexity);
Index_ N = prebuilt.num_observations();
if (K >= N) {
throw std::runtime_error("number of observations should be greater than 3 * perplexity");
}

// TODO: replace max_neighbors with knncolle::cap_nearest_neighbors().
const int max_neighbors = std::max(1, static_cast<int>(prebuilt.num_observations())) - 1;
const int K = std::min(perplexity_to_k(options.perplexity), max_neighbors);
auto neighbors = find_nearest_neighbors(prebuilt, K, options.num_threads);
return internal::initialize<num_dim_>(std::move(neighbors), options.perplexity, options);
}
Expand Down

0 comments on commit 5b10c7d

Please sign in to comment.