Computes the Cosine Similarity
Perl
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/Data
t
.gitignore
Build.PL
MANIFEST
META.json
META.yml
Makefile.PL
README

README

NAME
    Data::CosineSimilarity - Compute the Cosine Similarity

SYNOPSIS
     $cs = Data::CosineSimilarity->new;
     $cs->add( label1 => { feature1 => 3, feature2 => 1, feature3 => 10 } );
     $cs->add( label2 => ... );
     $cs->add( label3 => ... );

     # computes the cosine similarity
     my $r = $cs->similarity( 'label1', 'label2' );

     # the result object
     my $cosine = $r->cosine;
     my $radian = $r->radian;
     my $degree = $r->degree;
     my ($label1, $label2) = $r->labels;

     # computes all the cosine similarity between 'label1' and the others.
     my @all = $cs->all_for_label('label1');

     # computes all, and returns the best
     my ($best_label, $r) = $cs->best_for_label('label2');

     # computes all, and returns the worst
     my ($worst_label, $r) = $cs->worst_for_label('label2');

DESCRIPTION
    Compute the cosine similarities between a set of vectors.

  $class->new( %opts )
    If all the feature vectors are normed then the computation of the cosine
    becomes just the dot product of the vectors. In this case, specify the
    option normed => 1, the performance will be greatly improved.

  $self->add( label => $features )
  $self->similarity( $label1, $label2 )
  $self->all_for_label( $label )
  $self->best_for_label( $label )
  $self->worst_for_label( $label )
AUTHOR
    Antoine Imbert, "<antoine.imbert at gmail.com>"

LICENSE AND COPYRIGHT
    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.