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.
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 Constraints
|
Property for numNeighbours
. See new
Property for radius
. See new
Build the tree by scanning the points of a FluidDataSet
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 |
Returns the identifiers of the k
points nearest to the one passed.
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 |
Get the distances of the K nearest neighbours to a point.
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 |
The number of columns (dimensions) in this model or dataset / labeset
action |
A function to execute when the server has completed running cols |
Resets the internal state of the model
(action) |
A function to execute when the server has completed running clear |
The number of data points (entries / observations) in this model or dataset / labeset
action |
A function to execute when the server has completed running size |
Replace the internal state of the object from a Dictionary.
dict | |
action |
A function to execute when the server has completed running load |
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.
action |
A function to execute when the server has completed running dump |
Save the internal state of the object to a JSON file on disk. This object must first be fit
before write
can be called.
filename |
Path of the file to load from |
action |
A function to execute when the server has completed running write |
Replace the internal state of the object from a JSON file on disk.
filename |
Path of the file to load from |
action |
A function to execute when the server has completed running read |
Big Example
radius and num neighbours
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.