[−][src]Function arrayfire::nearest_neighbour
pub fn nearest_neighbour<T>(
query: &Array<T>,
train: &Array<T>,
dist_dim: i64,
n_dist: u32,
dist_type: MatchType
) -> (Array<u32>, Array<T::AggregateOutType>) where
T: HasAfEnum + ImageFilterType,
T::AggregateOutType: HasAfEnum,
Nearest Neighbour.
Calculates nearest distances between two 2-dimensional arrays containing features based on the type of distance computation chosen. Currently, AF_SAD (sum of absolute differences), AF_SSD (sum of squared differences) and AF_SHD (hamming distance) are supported. One of the arrays containing the training data and the other the query data. One of the dimensions of the both arrays must be equal among them, identifying the length of each feature. The other dimension indicates the total number of features in each of the training and query arrays. Two 1-dimensional arrays are created as results, one containg the smallest N distances of the query array and another containing the indices of these distances in the training array. The resulting 1-dimensional arrays have length equal to the number of features contained in the query array.
Parameters
query
is the array containing the data to be queriedtrain
is the array containing the data used as training datadist_dim
indicates the dimension to analyze for distance (the dimension indicated here must be of equal length for both query and train arrays)n_dist
is the number of smallest distances to return (currently, only values <= 256 are supported)dist_type
is the distance computation type. CurrentlyMatchType::SAD
,MatchType::SSD
, andMatchType::SHD
are supported.
Return Values
A tuple of Arrays.
The first Array is is an array of MxN size, where M is equal to the number of query features
and N is equal to n_dist
. The value at position IxJ indicates the index of the Jth smallest
distance to the Ith query value in the train data array. the index of the Ith smallest distance
of the Mth query.
The second Array is is an array of MxN size, where M is equal to the number of query features
and N is equal to n_dist
. The value at position IxJ indicates the distance of the Jth smallest
distance to the Ith query value in the train data array based on the dist_type
chosen.