Algorithm::LSH - perl implementation of Locality Sensitive Hashing
use Algorithm::LSH; my $lsh = Algorithm::LSH->new( L => 5, # number of hash functions k => 10, # number of reductions d => 3, # number of dimentions, ); while(my($label, $vector) = each %database){ $lsh->insert($label, $vector); } $lsh->save("data.bin"); my $query_vector = [ 123, 456, 789 ]; $lsh->load("data.bin"); my $neighbours = $lsh->neighbours($query_vector); my $nearest = $lsh->nearest($neighbours); # or my $nearest = $lsh->nearest_neighbours($query_vector); # or my $nearest = $lsh->nn($query_vector);
Algorithm::LSH is a perl implementation of Locality Sensitive Hashing algorithm.
THIS MODULE IS IN ITS VERY ALPHA QUALITY.
constructor. it needs three parameters.
L : a number of hash function. k : a number of reduction. it must be smaller than parameter 'd'. d : a number of dimention.
insert a vector data to buckets.
it extracts some datas as neighbours with query vector.
pickup 1 nearest data from neighbours.
it does neighbours() and nearset() at onece.
an alias of nearest_neighbours()
save the data to storage.
load th data from storage
accessor method
Takeshi Miki <miki@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Algorithm::LSH, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Algorithm::LSH
CPAN shell
perl -MCPAN -e shell install Algorithm::LSH
For more information on module installation, please visit the detailed CPAN module installation guide.