Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying when tree_init=False #103

Closed
jlmelville opened this issue Nov 29, 2020 · 1 comment
Closed

Querying when tree_init=False #103

jlmelville opened this issue Nov 29, 2020 · 1 comment

Comments

@jlmelville
Copy link
Collaborator

Is there an easy way to query an index built when tree_init=False (I haven't looked at the latest source, but I am assuming it should default to random initialization for the nearest neighbor descent part).

I hoped the following would work (using random data as input):

import numpy as np
from numpy.random import default_rng
import pynndescent

rng = default_rng()

nrows = 1000
ncols = 2
data = np.array(rng.standard_normal(nrows * ncols)).reshape(nrows, ncols)

nn_index = pynndescent.NNDescent(data, n_neighbors=15, tree_init=False)
neighbors = nn_index.query(data, k=15)

but I get:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-40-16461a0356f0> in <module>
----> 1 neighbors = nn_index.query(data, k=15)

~/dev/pynndescent/venv/lib/python3.8/site-packages/pynndescent/pynndescent_.py in query(self, query_data, k, epsilon)
   1584         """
   1585         if not hasattr(self, "_search_graph"):
-> 1586             self._init_search_graph()
   1587 
   1588         if not self._is_sparse:

~/dev/pynndescent/venv/lib/python3.8/site-packages/pynndescent/pynndescent_.py in _init_search_graph(self)
    953 
    954         if not hasattr(self, "_search_forest"):
--> 955             tree_scores = [
    956                 score_linked_tree(tree, self._neighbor_graph[0])
    957                 for tree in self._rp_forest

TypeError: 'NoneType' object is not iterable

This is with version 0.5.1.

@jlmelville
Copy link
Collaborator Author

This no longer causes an error with 0.5.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant