| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Text::NSP::Measures::3D::MI::pmi - Perl module that implements Pointwise |
|
4
|
|
|
|
|
|
|
Mutual Information for trigrams. |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head3 Basic Usage |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Text::NSP::Measures::3D::MI::pmi; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$pmi_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 ".$pmi_value."\n"; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
The expected values for the internal cells are calculated by taking the |
|
34
|
|
|
|
|
|
|
product of their associated marginals and dividing by the sample size, |
|
35
|
|
|
|
|
|
|
for example: |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
n1pp * np1p * npp1 |
|
38
|
|
|
|
|
|
|
m111= -------------------- |
|
39
|
|
|
|
|
|
|
nppp * nppp |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Pointwise Mutual Information (pmi) is defined as the log of the devitation |
|
42
|
|
|
|
|
|
|
between the observed frequency of a trigram (n111) and the probability of |
|
43
|
|
|
|
|
|
|
that trigram if it were independent (m111). |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
PMI = log (n111/m111) |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 Methods |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=over |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
package Text::NSP::Measures::3D::MI::pmi; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
1
|
|
|
1
|
|
1196
|
use Text::NSP::Measures::3D::MI; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
267
|
|
|
58
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
17
|
|
|
59
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
48
|
|
|
60
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
20
|
|
|
61
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
243
|
|
|
62
|
|
|
|
|
|
|
require Exporter; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
our ($VERSION, @EXPORT, @ISA, $exp); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$exp=1; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
@EXPORT = qw(initializeStatistic calculateStatistic |
|
71
|
|
|
|
|
|
|
getErrorCode getErrorMessage getStatisticName); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$VERSION = '0.97'; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item initializeStatistic() -Initialization of the pmi_exp parameter if required |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
INPUT PARAMS : none |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
RETURN VALUES : none |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub initializeStatistic |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
0
|
|
|
0
|
|
0
|
$exp = shift; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item calculateStatistic() - This method calculates the pmi value |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
INPUT PARAMS : $count_values .. Reference of a hash containing |
|
94
|
|
|
|
|
|
|
the count values computed by the |
|
95
|
|
|
|
|
|
|
count.pl program. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
RETURN VALUES : $pmi .. PMI value for this trigram. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub calculateStatistic |
|
102
|
|
|
|
|
|
|
{ |
|
103
|
16
|
|
|
16
|
|
2398
|
my %values = @_; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# computes and sets the observed and expected values from |
|
106
|
|
|
|
|
|
|
# the frequency combination values. returns 0 if there is an |
|
107
|
|
|
|
|
|
|
# error in the computation or the values are inconsistent. |
|
108
|
16
|
100
|
|
|
|
43
|
if( !(Text::NSP::Measures::3D::MI::getValues(\%values)) ) { |
|
109
|
15
|
|
|
|
|
39
|
return(0); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Now the calculations! |
|
113
|
1
|
|
|
|
|
6
|
my $pmi = Text::NSP::Measures::3D::MI::computePMI($n111**$exp, $m111); |
|
114
|
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
5
|
return($pmi/log(2)); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item getStatisticName() - Returns the name of this statistic |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
INPUT PARAMS : none |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
RETURN VALUES : $name .. Name of the measure. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub getStatisticName |
|
129
|
|
|
|
|
|
|
{ |
|
130
|
0
|
|
|
0
|
|
|
return "Pointwise Mutual Information"; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
|
136
|
|
|
|
|
|
|
__END__ |