Algorithm-KNN-XS
view release on metacpan or search on metacpan
lib/Algorithm/KNN/XS.pm view on Meta::CPAN
Please refer the libANN manual for the meaning of these values but for the
most people ANN_BD_SUGGEST should work well.
This parameter only affects bd trees.
The default value is ANN_BD_SUGGEST.
=back
=back
=cut
sub new {
my ($class, %args) = @_;
$args{split_rule} = 'ANN_KD_SUGGEST'
if !$args{split_rule} || !$ANN_SPLIT_RULE{$args{split_rule}};
$args{shrink_rule} = 'ANN_BD_SUGGEST'
if !$args{shrink_rule} || !$ANN_SHRINK_RULE{$args{shrink_rule}};
my $self = {
_tree => Algorithm::KNN::XS::LibANNInterface->new(
$args{points} || [],
$args{dump} || '',
$args{bd_tree} ? 1 : 0,
$args{bucket_size} || 1,
$ANN_SPLIT_RULE{$args{split_rule}},
$ANN_SHRINK_RULE{$args{shrink_rule}},
),
};
bless $self, $class;
return $self;
}
=over 4
=item * $knn->tree()
This class method returns the current tree object and can be used to access
the XS methods directly.
my $tree = $knn->tree();
=back
=cut
sub tree {
return shift->{_tree};
}
=over 4
=item * $knn->set_annMaxPtsVisit( ... )
This class method sets the maximum number of points that the search methods
are going to process before they abort. They can return more points than the
set value because the abort condition is only checked before processing a
leaf node.
$knn->set_annMaxPtsVisit(
max_points => 5,
);
=over 8
=item * max_points
Must be 0 or greater. The value 0 means no limit.
The default value is 0.
=back
=back
=cut
sub set_annMaxPtsVisit {
my ($self, %args) = @_;
return $self->tree->set_annMaxPtsVisit($args{max_points} || 0);
}
=over 4
=item * $knn->annkSearch( ... )
This class method performs a k nearest neighbor search.
my %result = $knn->annkSearch(
query_point => [],
limit_neighbors => 0,
epsilon => 0,
);
=over 8
=item * query_point
A list of points which must be the same dimension as the tree.
=item * limit_neighbors
Determines how many neighbors should be returned. The value 0 means no limit.
The default value is 0.
=item * epsilon
The relative error bound for approximate nearest neighbor searching. Please
refer the libANN manual for more information.
The default value is 0.
=item * Return value
Following structure is returned:
( run in 2.974 seconds using v1.01-cache-2.11-cpan-e93a5daba3e )