Algorithm-KNN-XS

 view release on metacpan or  search on metacpan

lib/Algorithm/KNN/XS.pm  view on Meta::CPAN

=item * bd_tree

If set to 1 a bd tree will be created, otherwise a kd tree is used.

=item * bucket_size

Must be greater 1 and influences the split and shrinking rule behaviour.

Please refer the libANN manual for further information.

The default value is 1.

=item * split_rule

A String which sets the splitting rule. Possible values are: ANN_KD_SUGGEST,
ANN_KD_STD, ANN_KD_MIDPT, ANN_KD_FAIR, ANN_KD_SL_MIDPT and ANN_KD_SL_FAIR.

Please refer the libANN manual for the meaning of these values but for the
most people ANN_KD_SUGGEST should work well.

The default value is ANN_KD_SUGGEST.

=item * shrink_rule

A String which sets the shrinking rule. Possible values are: ANN_BD_SUGGEST,
ANN_BD_NONE, ANN_BD_SIMPLE, ANN_BD_CENTROID.

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(



( run in 1.800 second using v1.01-cache-2.11-cpan-39bf76dae61 )