Documentation
Classes
KDTree

KDTree

KDTree for fast generalized N-point problems

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new KDTree(opts?: object): KDTree;

Parameters

NameTypeDescription
opts?object-
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.
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. Default Value 40
opts.metric?stringMetric to use for distance computation. Default is “minkowski”, which results in the standard Euclidean distance when p = 2. kd_tree.valid_metrics gives a list of the metrics which are valid for KDTree. See the documentation of scipy.spatial.distance (opens in a new tab) and the metrics listed in distance\_metrics for more information. Default Value 'minkowski'

Returns

KDTree

Defined in: generated/neighbors/KDTree.ts:23 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/neighbors/KDTree.ts:21 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/neighbors/KDTree.ts:20 (opens in a new tab)

_py

PythonBridge

Defined in: generated/neighbors/KDTree.ts:19 (opens in a new tab)

id

string

Defined in: generated/neighbors/KDTree.ts:16 (opens in a new tab)

opts

any

Defined in: generated/neighbors/KDTree.ts:17 (opens in a new tab)

Accessors

data

The training data

Signature

data(): Promise<any>;

Returns

Promise<any>

Defined in: generated/neighbors/KDTree.ts:487 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/neighbors/KDTree.ts:47 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/neighbors/KDTree.ts:51 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

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

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/neighbors/KDTree.ts:101 (opens in a new tab)

get_arrays()

Get data and node arrays.

Signature

get_arrays(opts: object): Promise<any>;

Parameters

NameType
optsobject

Returns

Promise<any>

Defined in: generated/neighbors/KDTree.ts:118 (opens in a new tab)

get_n_calls()

Get number of calls.

Signature

get_n_calls(opts: object): Promise<any>;

Parameters

NameType
optsobject

Returns

Promise<any>

Defined in: generated/neighbors/KDTree.ts:144 (opens in a new tab)

get_tree_stats()

Get tree status.

Signature

get_tree_stats(opts: object): Promise<any>;

Parameters

NameType
optsobject

Returns

Promise<any>

Defined in: generated/neighbors/KDTree.ts:170 (opens in a new tab)

init()

Initializes the underlying Python resources.

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

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/neighbors/KDTree.ts:60 (opens in a new tab)

kernel_density()

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

Signature

kernel_density(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]An array of points to query. Last dimension should match dimension of training data.
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). Default Value 0
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. Default Value false
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’ Default Value 'gaussian'
opts.return_log?booleanReturn the logarithm of the result. This can be more accurate than returning the result itself for narrow kernels. Default Value false
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). Default Value 1e-8

Returns

Promise<any>

Defined in: generated/neighbors/KDTree.ts:196 (opens in a new tab)

query()

query the tree for the k nearest neighbors

Signature

query(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]An array of points to query
opts.breadth_first?booleanif true, then query the nodes in a breadth-first manner. Otherwise, query the nodes in a depth-first manner. Default Value false
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. Default Value false
opts.k?numberThe number of nearest neighbors to return Default Value 1
opts.return_distance?booleanif true, return a tuple (d, i) of distances and indices if false, return array i Default Value true
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. Default Value true

Returns

Promise<any>

Defined in: generated/neighbors/KDTree.ts:275 (opens in a new tab)

query_radius()

query the tree for neighbors within a radius r

Signature

query_radius(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]An array of points to query
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. Default Value false
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. Default Value false
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. Default Value false

Returns

Promise<any>

Defined in: generated/neighbors/KDTree.ts:349 (opens in a new tab)

reset_n_calls()

Reset number of calls to 0.

Signature

reset_n_calls(opts: object): Promise<any>;

Parameters

NameType
optsobject

Returns

Promise<any>

Defined in: generated/neighbors/KDTree.ts:414 (opens in a new tab)

two_point_correlation()

Compute the two-point correlation function

Signature

two_point_correlation(opts: object): Promise<ArrayLike>;

Parameters

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

Returns

Promise<ArrayLike>

Defined in: generated/neighbors/KDTree.ts:440 (opens in a new tab)