Class: KDTree

KDTree for fast generalized N-point problems

Read more in the User Guide.

Python Reference

Constructors

new KDTree()

new KDTree(opts?): KDTree

Parameters

ParameterTypeDescription
opts?object-
opts.leaf_size?anyNumber of points at which to switch to brute-force. Changing leaf_size will not affect the results of a query, but can significantly impact the speed of a query and the memory required to store the constructed tree. The amount of memory needed to store the tree scales as approximately n_samples / leaf_size. For a specified leaf_size, a leaf node is guaranteed to satisfy leaf_size <= n_points <= 2 \* leaf_size, except in the case that n_samples < leaf_size.
opts.metric?stringMetric to use for distance computation. Default is “minkowski”, which results in the standard Euclidean distance when p = 2. A list of valid metrics for KDTree is given by the attribute valid_metrics. See the documentation of scipy.spatial.distance and the metrics listed in distance_metrics for more information on any distance metric.
opts.X?ArrayLike[]n_samples is the number of points in the data set, and n_features is the dimension of the parameter space. Note: if X is a C-contiguous array of doubles then data will not be copied. Otherwise, an internal copy will be made.

Returns KDTree

Defined in generated/neighbors/KDTree.ts:23

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/neighbors/KDTree.ts:21
_isInitializedbooleanfalsegenerated/neighbors/KDTree.ts:20
_pyPythonBridgeundefinedgenerated/neighbors/KDTree.ts:19
idstringundefinedgenerated/neighbors/KDTree.ts:16
optsanyundefinedgenerated/neighbors/KDTree.ts:17

Accessors

data

Get Signature

get data(): Promise<any>

The training data

Returns Promise<any>

Defined in generated/neighbors/KDTree.ts:460


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/neighbors/KDTree.ts:47

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/neighbors/KDTree.ts:98


get_arrays()

get_arrays(opts): Promise<any>

Get data and node arrays.

Parameters

ParameterType
optsobject

Returns Promise<any>

Defined in generated/neighbors/KDTree.ts:115


get_n_calls()

get_n_calls(opts): Promise<any>

Get number of calls.

Parameters

ParameterType
optsobject

Returns Promise<any>

Defined in generated/neighbors/KDTree.ts:141


get_tree_stats()

get_tree_stats(opts): Promise<any>

Get tree status.

Parameters

ParameterType
optsobject

Returns Promise<any>

Defined in generated/neighbors/KDTree.ts:167


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/neighbors/KDTree.ts:60


kernel_density()

kernel_density(opts): Promise<any>

Compute the kernel density estimate at points X with the given kernel, using the distance metric specified at tree creation.

Parameters

ParameterTypeDescription
optsobject-
opts.atol?numberSpecify the desired absolute tolerance of the result. If the true result is K_true, then the returned result K_ret satisfies abs(K_true \- K_ret) < atol + rtol \* K_ret The default is zero (i.e. machine precision).
opts.breadth_first?booleanIf true, use a breadth-first search. If false (default) use a depth-first search. Breadth-first is generally faster for compact kernels and/or high tolerances.
opts.h?numberthe bandwidth of the kernel
opts.kernel?stringspecify the kernel to use. Options are - ‘gaussian’ - ‘tophat’ - ‘epanechnikov’ - ‘exponential’ - ‘linear’ - ‘cosine’ Default is kernel = ‘gaussian’
opts.return_log?booleanReturn the logarithm of the result. This can be more accurate than returning the result itself for narrow kernels.
opts.rtol?numberSpecify the desired relative tolerance of the result. If the true result is K_true, then the returned result K_ret satisfies abs(K_true \- K_ret) < atol + rtol \* K_ret The default is 1e-8 (i.e. machine precision).
opts.X?ArrayLike[]An array of points to query. Last dimension should match dimension of training data.

Returns Promise<any>

Defined in generated/neighbors/KDTree.ts:193


query()

query(opts): Promise<any>

query the tree for the k nearest neighbors

Parameters

ParameterTypeDescription
optsobject-
opts.breadth_first?booleanif true, then query the nodes in a breadth-first manner. Otherwise, query the nodes in a depth-first manner.
opts.dualtree?booleanif true, use the dual tree formalism for the query: a tree is built for the query points, and the pair of trees is used to efficiently search this space. This can lead to better performance as the number of points grows large.
opts.k?numberThe number of nearest neighbors to return
opts.return_distance?booleanif true, return a tuple (d, i) of distances and indices if false, return array i
opts.sort_results?booleanif true, then distances and indices of each point are sorted on return, so that the first column contains the closest points. Otherwise, neighbors are returned in an arbitrary order.
opts.X?ArrayLike[]An array of points to query

Returns Promise<any>

Defined in generated/neighbors/KDTree.ts:265


query_radius()

query_radius(opts): Promise<any>

query the tree for neighbors within a radius r

Parameters

ParameterTypeDescription
optsobject-
opts.count_only?booleanif true, return only the count of points within distance r if false, return the indices of all points within distance r If return_distance==true, setting count_only=true will result in an error.
opts.r?anyr can be a single value, or an array of values of shape x.shape[:-1] if different radii are desired for each point.
opts.return_distance?booleanif true, return distances to neighbors of each point if false, return only neighbors Note that unlike the query() method, setting return_distance=true here adds to the computation time. Not all distances need to be calculated explicitly for return_distance=false. Results are not sorted by default: see sort_results keyword.
opts.sort_results?booleanif true, the distances and indices will be sorted before being returned. If false, the results will not be sorted. If return_distance == false, setting sort_results = true will result in an error.
opts.X?ArrayLike[]An array of points to query

Returns Promise<any>

Defined in generated/neighbors/KDTree.ts:332


reset_n_calls()

reset_n_calls(opts): Promise<any>

Reset number of calls to 0.

Parameters

ParameterType
optsobject

Returns Promise<any>

Defined in generated/neighbors/KDTree.ts:390


two_point_correlation()

two_point_correlation(opts): Promise<ArrayLike>

Compute the two-point correlation function

Parameters

ParameterTypeDescription
optsobject-
opts.dualtree?booleanIf true, use a dualtree algorithm. Otherwise, use a single-tree algorithm. Dual tree algorithms can have better scaling for large N.
opts.r?ArrayLikeA one-dimensional array of distances
opts.X?ArrayLike[]An array of points to query. Last dimension should match dimension of training data.

Returns Promise<ArrayLike>

Defined in generated/neighbors/KDTree.ts:416