RePrec/EP.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 56 CC 5 SCAR 29.7
CC
5
Cov
0%
precision
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 19.5
1 ######################### -*- Mode: Perl -*- #########################
2 ##
3 ## File : EP.pm
4 ##
5 ## Author : Norbert Goevert
6 ## Created On : Wed Feb 5 11:19:51 1997
7 ## Last Modified : Time-stamp: <2002-04-25 17:19:11 goevert>
8 ##
9 ## Description : Expected Precision
10 ##
11 ## $Id: EP.pm,v 1.28 2003/06/13 12:29:30 goevert Exp $
12 ##
13 ######################################################################
14  
15  
16 use strict;
17  
18  
19 =pod #---------------------------------------------------------------#
20  
21 =head1 NAME
22  
23 RePrec::EP - compute precision values
24  
25 =head1 SYNOPSIS
26  
27 (see RePrec(3))
28  
29 =head1 DESCRIPTION
30  
31 Computation of precision values according to the I<Expected Precision>
32 measure (user standpoint: stop at a given number of relevant
33 documents).
34  
35 =head1 METHODS
36  
37 Mainly see RePrec(3). The precision function gives an unique
38 interpretation for each recall point. Precision can be computed for
39 each simple recall point only.
40  
41 =cut #---------------------------------------------------------------#
42  
43  
44 package RePrec::EP;
45  
46  
47 use base qw(RePrec);
48  
49 use RePrec::Tools qw(choose);
50  
51  
52 our $VERSION;
53 '$Name: release_0_32 $ 0_0' =~ /(\d+)[-_](\d+)/; $VERSION = sprintf '%d.%03d', $1, $2;
54  
55  
56 ## public ############################################################
57  
58 sub precision {
59  
60 my $self = shift;
61 my @recall = @_;
62  
63 my @result;
64  
65 foreach my $recall (sort @recall) {
66  
67 return undef unless $recall and $recall > 0 and $recall <= 1;
68  
69 # at which number of relevant documents do we stop?
70 my $NR = $recall * $self->{rels};
71  
72 # we can compute EP for simple recall points only
73 return undef unless $NR == int $NR;
74  
75 # how many ranks do we have to examine?
76 my $rank = $self->{rels_rank}->[$NR - 1];
77  
78 # number of relevant docs within the previous ranks
79 my $t_r = 0;
80 $t_r = $self->{rank_rels_nrels}->[$rank - 1]->[0] if $rank;
81  
82 # number of non relevant docs within the previous ranks
83 my $j = 0;
84 $j = $self->{rank_rels_nrels}->[$rank - 1]->[1] if $rank;
85  
86 # number of non relevant docs within the current rank
87 my $i = $self->{rank_rels_nrels}->[$rank]->[1] - $j;
88  
89 # number of relevant docs within the current rank
90 my $r = $self->{rank_rels_nrels}->[$rank]->[0] - $t_r;
91  
92 # number of relevant documents to be drawn
93 my $s = $NR - $t_r;
94  
95 my $EP = 0;
96 foreach my $k ($s .. $s+$i) {
97 $EP += choose($r, $s-1) * choose($i, $k - $s) / choose($r + $i, $k - 1) *
98 ($r - $s + 1) / ($r + $i - $k +1) *
99 ($s +$t_r) / ($k + $t_r + $j);
100 }
101 push @result, [$recall, $EP];
102 }
103  
104 @result;
105 }
106  
107  
108 ## private ###########################################################
109  
110  
111 =pod #---------------------------------------------------------------#
112  
113 =head1 BUGS
114  
115 Yes. Please let me know!
116  
117 =head1 SEE ALSO
118  
119 RePrec(3),
120 perl(1).
121  
122 =head1 AUTHOR
123  
124 Norbert GE<ouml>vert E<lt>F<goevert@ls6.cs.uni-dortmund.de>E<gt>
125  
126 =cut #---------------------------------------------------------------#
127  
128  
129 1;
130 __END__