ALBD
view release on metacpan or search on metacpan
#read in gold time slicing output
(my $goldAPScoresRef, my $goldMAP, my $goldPAtKScoresRef, my $goldFAtKScoresRef)
= &readTimeSlicingData('./t/goldSampleTimeSliceOutput');
#read in new time slicing output
(my $newAPScoresRef, my $newMAP, my $newPAtKScoresRef, my $newFAtKScoresRef)
= &readTimeSlicingData('./samples/sampleTimeSliceOutput');
#check that the correct number of values are read for all the
# time slicing metrics
ok (scalar @{$newAPScoresRef} == 11, "Correct Count of Average Precisions");
ok (scalar @{$newPAtKScoresRef} == 19, "Correct Count of Precision at K's");
ok (scalar @{$newFAtKScoresRef} == 19, "Correct Count of Freq at K's");
#check that each of the AP scores match the gold (within error tolerance)
my $apSame = 1;
for (my $i = 0; $i < scalar @{$goldAPScoresRef}; $i++) {
#check both comma seperated values (precision and recall)
my @goldScores = split(',',${$goldAPScoresRef}[$i]);
my @newScores = split(',',${$newAPScoresRef}[$i]);
if ((abs($goldScores[0]-$newScores[0]) > $precRecallErrorTol)
&& (abs($goldScores[1]-$newScores[1]) > $precRecallErrorTol)) {
$apSame = 0;
last;
}
}
ok($apSame == 1, "Average Precisions Match");
#check MAP is the same (within error tolerance)
ok (abs($goldMAP - $newMAP) > $precRecallErrorTol, "Mean Average Precision Matches");
#check that each of Precision at K scores match the gold
# (within error tolerance)
my $pAtKSame = 1;
for (my $i = 0; $i < scalar @{$goldPAtKScoresRef}; $i++) {
if (abs(${$goldPAtKScoresRef}[$i] - ${$newPAtKScoresRef}[$i]) > $atKErrorTol) {
$pAtKSame = 0;
last;
}
}
ok($pAtKSame == 1, "Precision at K Matches");
#check that each of the Freq at K scores match the gold
# (within error tolerance)
my $fAtKSame = 1;
for (my $i = 0; $i < scalar @{$goldFAtKScoresRef}; $i++) {
if (abs(${$goldFAtKScoresRef}[$i] - ${$newFAtKScoresRef}[$i]) > $atKErrorTol) {
$fAtKSame = 0;
last;
}
}
ok($fAtKSame == 1, "Frequency at K Matches");
print "Done with Time Slicing Tests\n";
############################################################
#function to read in time slicing data values
sub readTimeSlicingData {
my $fileName = shift;
#read in the gold time slicing values
my @APScores = ();
my $MAP;
my @PAtKScores = ();
my @FAtKScores = ();
open IN, "$fileName"
#open IN, './t/goldSampleTimeSliceOutput'
or die ("Error: Cannot open timeSliceOutput: $fileName\n");
while (my $line = <IN>) {
#read in the 11 values of average precision
if ($line =~ /average precision at 10% recall intervals/ ) {
while (my $line2 = <IN>) {
if ($line2 =~ /\d\s(\d\.?\d*)\s(\d\.\d*)/) {
push @APScores, "$1,$2";
}
else {
last;
}
}
}
#read in the MAP value
if ($line =~ /MAP = (\d+\.\d+)/ ) {
$MAP = $1;
}
#read in the 19 values of precision at k
if ($line =~ /mean precision at k interval/ ) {
while (my $line2 = <IN>) {
if ($line2 =~ /\d\s(\d\.\d*)/) {
push @PAtKScores, "$1";
}
else {
last;
}
}
}
#read in the 19 values of frequency at k
if ($line =~ /mean cooccurrences at k intervals/ ) {
while (my $line2 = <IN>) {
if ($line2 =~ /\d+\s(\d\.?\d*)/) {
push @FAtKScores, "$1";
}
else {
last;
}
}
}
}
close IN;
return (\@APScores, $MAP, \@PAtKScores, \@FAtKScores)
}
( run in 0.776 second using v1.01-cache-2.11-cpan-39bf76dae61 )