Currently, we have created a function for searching for cocoons recently using the API
kd_treeto improve search efficiency
I can't confirm how the kd tree is built.
I can get the value stored internally in
KDTree (X) .__ getstate __ (), but I don't know what it means.
I want to see how the tree is divided even if I can't visualize it ...
I'm sorry for being thrown away, but please give me your answer.
Answer # 1
Looking at the source code comments, the tree structure seems to be managed by a one-dimensional array stored in the
node_dataattribute of the
According to the comment, KDTree.node_data  is the root node and the two child nodes of node KDTree.node_data [i] are KDTree.node_data [2 * i + 1] and KDTree.node_data [2 * i + See 2].
See the source code comments for the meaning of each element of KDTree.node_data. (There are about 3000 lines and I don't read all of them, so I don't know the details of the implementation.)
The KDTree class inherits the BinaryTree class, so the following two codes are applicable.
Code to store and confirm 1D array as tree structure
# In a typical KD Tree or Ball Tree implementation, the nodes are implemented # as dynamically allocated structures with pointers linking them.Here we # take a different approach, storing all relevant data in a set of arrays # so that the entire tree object can be saved in a pickle file.For efficiency, # the data can be stored in such a way that explicit pointers are not # necessary: for node data stored at index i, the two child nodes are at # index (2 * i + 1) and (2 * i + 2);the parent node is (i-1) // 2 # (where // indicates integer division).
# An external library called anytree is used to visualize the tree structure. You can install with # pip install anytree. import numpy as np from anytree import Node, RenderTree from sklearn.neighbors import KDTree np.random.seed (0) X = np.random.randint (0, 101, (20, 2)) tree = KDTree (X, leaf_size = 2) def tarverse (i = 0, parent = None): node = Node (i, parent) if i * 2 + 1
Node ('/ 0') ├── Node ('/ 0/1') │ ├── Node ('/ 0/1/3') │ │ ├── Node ('/ 0/1/3/7') │ │ └── Node ('/ 0/1/3/8') │ └── Node ('/ 0/1/4') │ ├── Node ('/ 0/1/4/9') │ └── Node ('/ 0/1/4/10') └── Node ('/ 0/2') ├── Node ('/ 0/2/5') │ ├── Node ('/ 0/2/5/11') │ └── Node ('/ 0/2/5/12') └── Node ('/ 0/2/6') ├── Node ('/ 0/2/6/13') └── Node ('/ 0/2/6/14')
- python 3x - i want to list the strings as they are
- python - i want to speed up the for statement
- python - i want to scrape the contents of java in (web) html
- python - how to check the character code on mac
- python - i want the block to disappear when the ball hits the block
- python - i want to ignore the header and loop
- i want to pass the python path in bash
- i want to get the full text of rt with tweepy in python
- python - i want to get the elements in the linked site
- python - i want to find the mode of a pixel with a pixel value of 1 or more
- python - i want to determine if the channel is a text channel
- python - i want to set the user name logged in with django to url and jump to my page
- ruby on rails - i want to display the details page
- python - i want to read an image and display it
- python - i want to avoid line breaks in the file path
- python 3x - how to get the value of scrolledtext
- python - i want to know how to keep outputting to csv
- python - delete bom on the command line
- i want to upload the code to github
- python 3x - about the calculation of cross entropy in pytorch
- python 3x - i don't know how to tune when doing image classification problem with vgg16 with [pytorch] (i want to get 90% accura
- python - optuna light-library import error in gbm parameter tuning
- python 3x - i get a runtimeerror: size mismatch, in the image classification of pytorch what should i do?
- python - attributeerror: module'chainerfunction' has no attribute'max_pooling_2d'
- python 3x - inflating table data using gan
- python 3x - cnn-what is the average pooling process?
- python - pedestrian age group discrimination using opencv
- python 3x - i want to display the importance extracted by evaluating with random forest as a column graph
- python - tensorflow-gpu recognition takes time