FluidKDTree:
Filter:
Classes (extension) | Libraries > FluidCorpusManipulation

FluidKDTree : FluidModelObject : FluidDataObject : FluidServerObject : Object
ExtensionExtension

Efficient lookup of data using a k-d tree.

Description

A k-dimensional tree for efficient neighbourhood searches of multi-dimensional data.

FluidKDTree facilitates efficient nearest neighbour searches of multi-dimensional data stored in a FluidDataSet.

k-d trees are most useful for repeated querying of a dataset, because there is a cost associated with building them. If you just need to do a single lookup then using the kNearest message of FluidDataSet will probably be quicker

Whilst k-d trees can offer very good performance relative to naïve search algorithms, they suffer from something called “the curse of dimensionality” (like many algorithms for multi-dimensional data). In practice, this means that as the number of dimensions of your data goes up, the relative performance gains of a k-d tree go down.

Read more about FluidKDTree on the learn platform.

Class Methods

FluidKDTree.new(server, numNeighbours: 1, radius: 0)

Arguments:

server

The Server on which to construct this object

numNeighbours

The number of neighbours to return.

radius

The maximum distance (in high dimensional space) that a returned point can be. Any points beyond radius will not be returned (even if they're within the nearest numNeighbours points). When radius is 0, it is no longer a constraint and the distance of a nearest neighbour is not taken into account.

Constraints

  • Minimum: 0

Inherited class methods

Instance Methods

.numNeighbours

.numNeighbours = k

Property for numNeighbours. See new

.radius

.radius = r

Property for radius. See new

.fit(dataSet, action)

Build the tree by scanning the points of a FluidDataSet

Arguments:

dataSet

The FluidDataSet of interest. This can either be a data set object itself, or the name of one.

action

A function to execute when the server has completed running fit

.kNearest(buffer, k, action)

Returns the identifiers of the k points nearest to the one passed.

Arguments:

buffer

A Buffer containing a data point to match against. The number of frames in the buffer must match the dimensionality of the FluidDataSet the tree was fitted to.

k

(optional) The number of nearest neighbours to return. The identifiers will be sorted, beginning with the nearest.

action

A function to execute when the server has completed running kNearest

.kNearestDist(buffer, k, action)

Get the distances of the K nearest neighbours to a point.

Arguments:

buffer

A Buffer containing a data point to match against. The number of frames in the buffer must match the dimensionality of the FluidDataSet the tree was fitted to.

k

(optional) The number of nearest neighbours to return. The identifiers will be sorted, beginning with the nearest.

action

A function to execute when the server has completed running kNearestDist

.cols(action)

From superclass: FluidDataObject

The number of columns (dimensions) in this model or dataset / labeset

Arguments:

action

A function to execute when the server has completed running cols

.clear

From superclass: Object

Resets the internal state of the model

Arguments:

(action)

A function to execute when the server has completed running clear

.size(action)

From superclass: FluidDataObject

The number of data points (entries / observations) in this model or dataset / labeset

Arguments:

action

A function to execute when the server has completed running size

.load(dict, action)

From superclass: FluidDataObject

Replace the internal state of the object from a Dictionary.

Arguments:

dict
action

A function to execute when the server has completed running load

.dump(action)

From superclass: FluidDataObject

Dump the state of this object as a Dictionary, which will be passed to the action function provided. This object must first be fit``ted before ``dump can be called.

Arguments:

action

A function to execute when the server has completed running dump

.write(filename, action)

From superclass: FluidDataObject

Save the internal state of the object to a JSON file on disk. This object must first be fit before write can be called.

Arguments:

filename

Path of the file to load from

action

A function to execute when the server has completed running write

.read(filename, action)

From superclass: FluidDataObject

Replace the internal state of the object from a JSON file on disk.

Arguments:

filename

Path of the file to load from

action

A function to execute when the server has completed running read

Inherited instance methods

Undocumented instance methods

.fitMsg(dataSet)

.kNearestDistMsg(buffer, k)

.kNearestMsg(buffer, k)

.kr(trig, inputBuffer, outputBuffer, numNeighbours, radius, lookupDataSet)

.prGetParams

Examples

Big Example

radius and num neighbours

Queries in a Synth

Input and output is done via buffers, which will need to be preallocated to the correct sizes:

We can't simply return labels (i.e. strings) from a UGen, so the query returns the actual data points from a DataSet instead. By default, this is the FluidDataSet against which the tree was fitted. However, by passing a different dataset to kr's lookupDataSet argument instead, you can return different points, so long as the labels in the two datasets match. In this way, the FluidKDTree can be used to perform nearest neighbour mappings in a synth.

For instance, whilst fitting the tree against some n-dimensional descriptor data, our lookup dataset could use the same labels to map descriptor entries back to buffers, or locations in buffers, so that queries can be used to trigger audio.