in reply to Re: Shannon Index
in thread Shannon Index

Hi,
Thanks for your suggestion.
I want to find the similarity between $data1 with $data2 using this shannon implementation.
I got an another view of finding similarites or information and that could be,
#!c:\perl\bin\perl use strict; use warnings; use Statistics::Shannon; use Data::Dumper; my @data1=(1,3,2,4,6); my @data2=(2,3,2,3,6); my $data=[(@data1,@data2)]; my $base_index=2; my $shannon=Statistics::Shannon->new($data,$base_index); my $output=$shannon->index; print Dumper ($data); print "$output";

suggest me if i'm wrong
Thanks,
-kulls

Replies are listed 'Best First'.
Re^3: Shannon Index
by GrandFather (Saint) on Sep 06, 2006 at 05:04 UTC

    You still haven't said anything about your application domain. From a Perl perspective there seem to be not hard choices to make - the issue is more to do with how you use the result than how you calculate it.


    DWIM is Perl's answer to Gödel
      Hi,
      I have check the similarity values between two sequences (values). Absoultely in bioinformatics.. still I couldn't able to find out the exact behaviour of this
      When you run the example,
      #!c:\perl\bin\perl use strict; use warnings; use Statistics::Shannon; use Data::Dumper; my @data1=(1,3,2,4,6); my @data2=(2,3,2,3,6); my $data=[(@data1,@data2)]; my $base_index=2; my $shannon=Statistics::Shannon->new($data,$base_index); my $output=$shannon->index; print Dumper($shannon); __OUTPUT___ $VAR1 = bless( { 'shannon' => { '2.71828182845905' => '1.4681399390162 +1' }, 'min' => 1, 'max' => 4, 'data' => { '6' => 2, '4' => 1, '1' => 1, '3' => 3, '2' => 4 }, 'update' => sub { "DUMMY" }, 'sum' => 11 }, 'Statistics::Shannon' );
      I got this result.
      if you look into the perldoc of Statistics::Shannon ,
      It says that  $base_index denoted for the logerthemic specification. But the dumer output denotes that  $base_index also added up with the data and hence it shows  '2' => 4 { 4 denotes the count of value '2' in the list } .
      Anyone can please help me out ??.
      -kulls

        You are passing $base_index as an additional data set. If you wish to retreive the index you use the index member and pass an optional base. Changling your last few lines to:

        my $shannon=Statistics::Shannon->new($data,); my $output=$shannon->index ($base_index); print "Index: $output\n"; print Dumper($shannon);

        Prints:

        Index: 2.17095059445467 $VAR1 = bless( { 'shannon' => { '2' => '1.50478828368119' }, 'min' => 1, 'max' => 3, 'data' => { '6' => 2, '4' => 1, '1' => 1, '3' => 3, '2' => 3 }, 'update' => sub { "DUMMY" }, 'sum' => 10 }, 'Statistics::Shannon' );

        DWIM is Perl's answer to Gödel