NearestNeighbourAlgorithm

class NearestNeighbourAlgorithm(*args)

Nearest neighbour lookup.

Base class to define an algorithm to search for nearest neighbours of a list of points.

Available constructors:

NearestNeighbourAlgorithm(sample)

Parameters
sampleSample

Input points.

Notes

Two algorithms can be selected in any dimension:

Two algorithms are specific to 1D input dimension, and much more efficient:

It is recommended to use derived classes in order to select the best algorithm according to your data. If you create a generic NearestNeighbourAlgorithm, here is how the derived class is selected:

Examples

>>> import openturns as ot
>>> sample = ot.Normal(2).getSample(10)
>>> finder = ot.NearestNeighbourAlgorithm(sample)
>>> neighbour = sample[finder.query([0.1, 0.2])]

Methods

getClassName(self)

Accessor to the object’s name.

getId(self)

Accessor to the object’s id.

getImplementation(self)

Accessor to the underlying implementation.

getName(self)

Accessor to the object’s name.

getSample(self)

Get the points which have been used to build this nearest neighbour algorithm.

query(self, \*args)

Get the index of the nearest neighbour of the given point.

queryK(self, x, k[, sorted])

Get the indices of nearest neighbours of the given point.

setName(self, name)

Accessor to the object’s name.

setSample(self, sample)

Build a NearestNeighbourAlgorithm from these points.

__init__(self, \*args)

Initialize self. See help(type(self)) for accurate signature.

getClassName(self)

Accessor to the object’s name.

Returns
class_namestr

The object class name (object.__class__.__name__).

getId(self)

Accessor to the object’s id.

Returns
idint

Internal unique identifier.

getImplementation(self)

Accessor to the underlying implementation.

Returns
implImplementation

The implementation class.

getName(self)

Accessor to the object’s name.

Returns
namestr

The name of the object.

getSample(self)

Get the points which have been used to build this nearest neighbour algorithm.

Returns
sampleSample

Input points.

query(self, \*args)

Get the index of the nearest neighbour of the given point.

Available usages:

query(point)

query(sample)

Parameters
pointsequence of float

Given point.

sample2-d sequence of float

Given points.

Returns
indexint

Index of the nearest neighbour of the given point.

indicesopenturns.Indices

Index of the nearest neighbour of the given points.

queryK(self, x, k, sorted=False)

Get the indices of nearest neighbours of the given point.

Parameters
xsequence of float

Given point.

kint

Number of indices to return.

sortedbool, optional

Boolean to tell whether returned indices are sorted according to the distance to the given point.

Returns
indicessequence of int

Indices of the k nearest neighbours of the given point.

setName(self, name)

Accessor to the object’s name.

Parameters
namestr

The name of the object.

setSample(self, sample)

Build a NearestNeighbourAlgorithm from these points.

Parameters
sampleSample

Input points.