File Coverage

blib/lib/Text/NSP/Measures/3D/MI/ps.pm
Criterion Covered Total %
statement 21 22 95.4
branch 2 2 100.0
condition n/a
subroutine 6 7 85.7
pod n/a
total 29 31 93.5


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Text::NSP::Measures::3D::MI::ps - Perl module that implements
4             Poisson Stirling Measure for trigrams.
5              
6             =head1 SYNOPSIS
7              
8             =head3 Basic Usage
9              
10             use Text::NSP::Measures::3D::MI::ps;
11              
12             $ps_value = calculateStatistic( n111=>10,
13             n1pp=>40,
14             np1p=>45,
15             npp1=>42,
16             n11p=>20,
17             n1p1=>23,
18             np11=>21,
19             nppp=>100);
20              
21             if( ($errorCode = getErrorCode()))
22             {
23             print STDERR $erroCode." - ".getErrorMessage()."\n";
24             }
25             else
26             {
27             print getStatisticName."value for bigram is ".$ps_value."\n";
28             }
29              
30              
31             =head1 DESCRIPTION
32              
33             The log-likelihood ratio measures the devitation between the observed data
34             and what would be expected if , and were independent.
35             The higher the score, the less evidence there is in favor of concluding that
36             the words are independent.
37              
38             The expected values for the internal cells are calculated by taking the
39             product of their associated marginals and dividing by the sample size,
40             for example:
41              
42             n1pp * np1p * npp1
43             m111= --------------------
44             nppp
45              
46             The poisson stirling measure is a negative lograthimic approximation
47             of the poisson-likelihood measure. It uses the stirlings firmula to
48             approximate the factorial in poisson-likelihood measure. It is
49             computed as follows:
50              
51             Posson-Stirling = n111 * ( log(n111) - log(m111) - 1)
52              
53             =head2 Methods
54              
55             =over
56              
57             =cut
58              
59             package Text::NSP::Measures::3D::MI::ps;
60              
61              
62 1     1   1638 use Text::NSP::Measures::3D::MI;
  1         3  
  1         263  
63 1     1   4 use strict;
  1         2  
  1         17  
64 1     1   4 use Carp;
  1         1  
  1         47  
65 1     1   4 use warnings;
  1         2  
  1         21  
66 1     1   4 no warnings 'redefine';
  1         2  
  1         215  
67             require Exporter;
68              
69             our ($VERSION, @EXPORT, @ISA);
70              
71             @ISA = qw(Exporter);
72              
73             @EXPORT = qw(initializeStatistic calculateStatistic
74             getErrorCode getErrorMessage getStatisticName);
75              
76             $VERSION = '0.97';
77              
78             =item calculateStatistic() - This method calculates the ps value
79              
80             INPUT PARAMS : $count_values .. Reference of an hash containing
81             the count values computed by the
82             count.pl program.
83              
84             RETURN VALUES : $poissonStirling .. Poisson-Stirling value for this trigram.
85              
86             =cut
87              
88             sub calculateStatistic
89             {
90 16     16   2727 my %values = @_;
91              
92             # computes and returns the observed and expected values from
93             # the frequency combination values. returns 0 if there is an
94             # error in the computation or the values are inconsistent.
95 16 100       52 if( !(Text::NSP::Measures::3D::MI::getValues(\%values)) ) {
96 15         35 return;
97             }
98              
99             # Now for the actual calculation of Loglikelihood!
100 1         2 my $poissonStirling = 0;
101              
102             # dont want ($nxy / $mxy) to be 0 or less! flag error if so!
103 1         5 $poissonStirling = $n111 * (Text::NSP::Measures::3D::MI::computePMI($n111, $m111) - 1);
104              
105 1         4 return $poissonStirling;
106             }
107              
108              
109             =item getStatisticName() - Returns the name of this statistic
110              
111             INPUT PARAMS : none
112              
113             RETURN VALUES : $name .. Name of the measure.
114              
115             =cut
116              
117             sub getStatisticName
118             {
119 0     0     return "Poisson-Stirling Measure";
120             }
121              
122              
123              
124             1;
125             __END__