pyflann package¶
Submodules¶
pyflann.flann_ctypes module¶
-
class
pyflann.flann_ctypes.
CustomStructure
[source]¶ Bases:
_ctypes.Structure
This class extends the functionality of the ctype’s structure class by adding custom default values to the fields and a way of translating field types.
-
class
pyflann.flann_ctypes.
FLANNParameters
[source]¶ Bases:
pyflann.flann_ctypes.CustomStructure
-
algorithm
¶ Structure/Union member
-
branching
¶ Structure/Union member
-
build_weight
¶ Structure/Union member
-
cb_index
¶ Structure/Union member
-
centers_init
¶ Structure/Union member
-
checks
¶ Structure/Union member
-
cores
¶ Structure/Union member
-
eps
¶ Structure/Union member
-
iterations
¶ Structure/Union member
-
key_size_
¶ Structure/Union member
-
leaf_max_size
¶ Structure/Union member
-
log_level
¶ Structure/Union member
-
max_neighbors
¶ Structure/Union member
-
memory_weight
¶ Structure/Union member
-
multi_probe_level_
¶ Structure/Union member
-
random_seed
¶ Structure/Union member
-
sample_fraction
¶ Structure/Union member
-
sorted
¶ Structure/Union member
-
table_number_
¶ Structure/Union member
-
target_precision
¶ Structure/Union member
-
trees
¶ Structure/Union member
-
pyflann.index module¶
-
class
pyflann.index.
FLANN
(**kwargs)[source]¶ Bases:
object
This class defines a python interface to the FLANN lirary.
Example
>>> from pyflann import FLANN >>> import numpy as np >>> dvecs = np.random.rand(1000, 128) >>> qvecs = np.random.rand(10, 128) >>> flann = FLANN() >>> params = flann.build_index(dvecs)
-
add_points
(pts, rebuild_threshold=2)[source]¶ Adds points to pre-built index.
Parameters: - pts – 2D numpy array of points.
- rebuild_threshold – reallocs index when it grows by factor of rebuild_threshold. A smaller value results is more space efficient but less computationally efficient. Must be greater than 1.
-
build_index
(pts, **kwargs)[source]¶ This builds and internally stores an index to be used for future nearest neighbor matchings. It erases any previously stored indexes, so use multiple instances of this class to work with multiple stored indices. Use nn_index(…) to find the nearest neighbors in this index.
pts is a 2d numpy array or matrix. All the computation is done in np.float32 type, but pts may be any type that is convertable to np.float32.
-
delete_index
(**kwargs)[source]¶ Deletes the current index freeing all the momory it uses. The memory used by the dataset that was indexed is not freed unless there are no other references to those numpy arrays.
-
get_indexed_data
()[source]¶ returns all the data indexed by the FLANN object
(this returns points that have been removed but still exist in memory)
-
hierarchical_kmeans
(pts, branch_size, num_branches, max_iterations=None, dtype=None, **kwargs)[source]¶ Clusters the data by using multiple runs of kmeans to recursively partition the dataset. The number of resulting clusters is given by (branch_size-1)*num_branches+1.
This method can be significantly faster when the number of desired clusters is quite large (e.g. a hundred or more). Higher branch sizes are slower but may give better results.
If dtype is None (the default), the array returned is the same type as pts. Otherwise, the returned array is of type dtype.
-
kmeans
(pts, num_clusters, max_iterations=None, dtype=None, **kwargs)[source]¶ Runs kmeans on pts with num_clusters centroids. Returns a numpy array of size num_clusters x dim.
If max_iterations is not None, the algorithm terminates after the given number of iterations regardless of convergence. The default is to run until convergence.
If dtype is None (the default), the array returned is the same type as pts. Otherwise, the returned array is of type dtype.
-
nn
(pts, qpts, num_neighbors=1, **kwargs)[source]¶ Returns the num_neighbors nearest points in dataset for each point in testset.
-
nn_index
(qpts, num_neighbors=1, **kwargs)[source]¶ For each point in querypts, (which may be a single point), it returns the num_neighbors nearest points in the index built by calling build_index.
-
remove_points
(id_list)[source]¶ Removes multiple points from the index
- Params:
- id_list = point ids to be removed
Returns: void
-
shape
¶
-
Module contents¶
mkinit pyflann
-
class
pyflann.
CustomStructure
[source]¶ Bases:
_ctypes.Structure
This class extends the functionality of the ctype’s structure class by adding custom default values to the fields and a way of translating field types.
-
class
pyflann.
FLANN
(**kwargs)[source]¶ Bases:
object
This class defines a python interface to the FLANN lirary.
Example
>>> from pyflann import FLANN >>> import numpy as np >>> dvecs = np.random.rand(1000, 128) >>> qvecs = np.random.rand(10, 128) >>> flann = FLANN() >>> params = flann.build_index(dvecs)
-
add_points
(pts, rebuild_threshold=2)[source]¶ Adds points to pre-built index.
Parameters: - pts – 2D numpy array of points.
- rebuild_threshold – reallocs index when it grows by factor of rebuild_threshold. A smaller value results is more space efficient but less computationally efficient. Must be greater than 1.
-
build_index
(pts, **kwargs)[source]¶ This builds and internally stores an index to be used for future nearest neighbor matchings. It erases any previously stored indexes, so use multiple instances of this class to work with multiple stored indices. Use nn_index(…) to find the nearest neighbors in this index.
pts is a 2d numpy array or matrix. All the computation is done in np.float32 type, but pts may be any type that is convertable to np.float32.
-
delete_index
(**kwargs)[source]¶ Deletes the current index freeing all the momory it uses. The memory used by the dataset that was indexed is not freed unless there are no other references to those numpy arrays.
-
get_indexed_data
()[source]¶ returns all the data indexed by the FLANN object
(this returns points that have been removed but still exist in memory)
-
hierarchical_kmeans
(pts, branch_size, num_branches, max_iterations=None, dtype=None, **kwargs)[source]¶ Clusters the data by using multiple runs of kmeans to recursively partition the dataset. The number of resulting clusters is given by (branch_size-1)*num_branches+1.
This method can be significantly faster when the number of desired clusters is quite large (e.g. a hundred or more). Higher branch sizes are slower but may give better results.
If dtype is None (the default), the array returned is the same type as pts. Otherwise, the returned array is of type dtype.
-
kmeans
(pts, num_clusters, max_iterations=None, dtype=None, **kwargs)[source]¶ Runs kmeans on pts with num_clusters centroids. Returns a numpy array of size num_clusters x dim.
If max_iterations is not None, the algorithm terminates after the given number of iterations regardless of convergence. The default is to run until convergence.
If dtype is None (the default), the array returned is the same type as pts. Otherwise, the returned array is of type dtype.
-
nn
(pts, qpts, num_neighbors=1, **kwargs)[source]¶ Returns the num_neighbors nearest points in dataset for each point in testset.
-
nn_index
(qpts, num_neighbors=1, **kwargs)[source]¶ For each point in querypts, (which may be a single point), it returns the num_neighbors nearest points in the index built by calling build_index.
-
remove_points
(id_list)[source]¶ Removes multiple points from the index
- Params:
- id_list = point ids to be removed
Returns: void
-
shape
¶
-
-
class
pyflann.
FLANNParameters
[source]¶ Bases:
pyflann.flann_ctypes.CustomStructure
-
algorithm
¶ Structure/Union member
-
branching
¶ Structure/Union member
-
build_weight
¶ Structure/Union member
-
cb_index
¶ Structure/Union member
-
centers_init
¶ Structure/Union member
-
checks
¶ Structure/Union member
-
cores
¶ Structure/Union member
-
eps
¶ Structure/Union member
-
iterations
¶ Structure/Union member
-
key_size_
¶ Structure/Union member
-
leaf_max_size
¶ Structure/Union member
-
log_level
¶ Structure/Union member
-
max_neighbors
¶ Structure/Union member
-
memory_weight
¶ Structure/Union member
-
multi_probe_level_
¶ Structure/Union member
-
random_seed
¶ Structure/Union member
-
sample_fraction
¶ Structure/Union member
-
sorted
¶ Structure/Union member
-
table_number_
¶ Structure/Union member
-
target_precision
¶ Structure/Union member
-
trees
¶ Structure/Union member
-
-
pyflann.
FLANN_INDEX
¶ alias of
ctypes.c_void_p
-
pyflann.
STRING
¶ alias of
ctypes.c_char_p
-
pyflann.
index_type
¶ alias of
numpy.int32