Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scikit-learn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ian Johnson
scikit-learn
Commits
b4a6b576
Commit
b4a6b576
authored
14 years ago
by
Fabian Pedregosa
Browse files
Options
Downloads
Patches
Plain Diff
DOC: add docstrings to BallTree.
parent
0ea7d895
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scikits/learn/src/ball_tree.pyx
+57
-1
57 additions, 1 deletion
scikits/learn/src/ball_tree.pyx
with
57 additions
and
1 deletion
scikits/learn/src/ball_tree.pyx
+
57
−
1
View file @
b4a6b576
"""
Cython bindings for the C++ BallTree code.
A Ball Tree is a data structure which can be used
to perform fast neighbor searches in data sets of
low to medium dimensionality.
"""
# Author: Thouis Jones
# License: BSD
...
...
@@ -35,6 +39,28 @@ cdef Point *make_point(vals):
################################################################################
# Cython wrapper
cdef
class
BallTree
:
"""
Ball Tree for fast nearest-neighbor searches :
BallTree(M, leafsize=20)
Parameters
----------
M : array-like, shape = [N,D]
N is the number of points in the data set, and
D is the dimension of the parameter space.
Note: if M is an aligned array of doubles (not
necessarily contiguous) then data will not be
copied. Otherwise, an internal copy will be made.
leafsize : positive integer (default = 20)
number of points at which to switch to brute-force. Currently not
implemented.
Notes
-----
brute-force search was removed. docs should be accordingly.
"""
cdef
cBallTree
*
bt_ptr
cdef
vector
[
Point_p
]
*
ptdata
cdef
size_t
num_points
...
...
@@ -65,6 +91,36 @@ cdef class BallTree:
del
self
.
bt_ptr
def
query
(
self
,
x
,
k
=
1
,
return_distance
=
True
):
"""
query(x, k=1, return_distance=True)
query the Ball Tree for the k nearest neighbors
Parameters
----------
x : array-like, last dimension self.dim
An array of points to query
k : integer (default = 1)
The number of nearest neighbors to return
return_distance : boolean (default = True)
if True, return a tuple (d,i)
if False, return array i
Returns
-------
i : if return_distance == False
(d,i) : if return_distance == True
d : array of doubles - shape: x.shape[:-1] + (k,)
each entry gives the list of distances to the
neighbors of the corresponding point
(note that distances are not sorted)
i : array of integers - shape: x.shape[:-1] + (k,)
each entry gives the list of indices of
neighbors of the corresponding point
(note that neighbors are not sorted)
"""
x
=
np
.
atleast_2d
(
x
)
assert
x
.
shape
[
-
1
]
==
self
.
num_dims
assert
k
<=
self
.
num_points
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment