ALBD
view release on metacpan or search on metacpan
lib/LiteratureBasedDiscovery/TimeSlicing.pm view on Meta::CPAN
# ALBD::TimeSlicing
#
# Library module of time slicing methods for LBD
#
# Copyright (c) 2017
#
# Sam Henry
# henryst at vcu.edu
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to
#
# The Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
package TimeSlicing;
use strict;
use warnings;
use LiteratureBasedDiscovery::Discovery;
#
# Calculates and outputs to STDOUT Time Slicing evaluation stats of
# precision and recall at $numIntervals intervals, Mean Average Precision
# (MAP), precision at k, and frequency at k
# input: $trueMatrixRef <- a ref to a hash of true discoveries
# $rowRanksRef <- a ref to a hash of arrays of ranked predictions.
# Each hash key is a cui, each hash element is an
# array of ranked predictions for that cui. The ranked
# predictions are cuis are ordered in descending order
# based on association. (from Rank::RankDescending)
# $numIntervals <- the number of recall intervals to generate
sub outputTimeSlicingResults {
#grab the input
my $goldMatrixRef = shift;
my $rowRanksRef = shift;
my $numIntervals = shift;
#calculate and output stats
#------------------------------------------
#calculate precision and recall
print "calculating precision and recall\n";
my ($precisionRef, $recallRef) = &calculatePrecisionAndRecall_implicit(
$goldMatrixRef, $rowRanksRef, $numIntervals);
#output precision and recall
print "----- average precision at 10% recall intervals (i recall precision) ----> \n";
foreach my $i (sort {$a <=> $b} keys %{$precisionRef}) {
print " $i ${$recallRef}{$i} ${$precisionRef}{$i}\n";
}
print "\n";
#-------------------------------------------
#calculate mean average precision
my $map = &calculateMeanAveragePrecision(
$goldMatrixRef, $rowRanksRef);
#output mean average precision
print "---------- mean average precision ---------------> \n";
print " MAP = $map\n";
print "\n";
#-------------------------------------------
#calculate precision at k
print "calculating precision at k\n";
my $precisionAtKRef = &calculatePrecisionAtK($goldMatrixRef, $rowRanksRef);
#output precision at k
print "---------- mean precision at k intervals ---------------> \n";
foreach my $k (sort {$a <=> $b} keys %{$precisionAtKRef}) {
print " $k ${$precisionAtKRef}{$k}\n";
}
print "\n";
#-------------------------------------------
#calculate cooccurrences at k
print "calculating mean cooccurrences at k\n";
my $cooccurrencesAtKRef = &calculateMeanCooccurrencesAtK($goldMatrixRef, $rowRanksRef);
#output cooccurrences at k
print "---------- mean cooccurrences at k intervals ---------------> \n";
( run in 0.687 second using v1.01-cache-2.11-cpan-98e64b0badf )