diff --git a/log_norm.pl b/log_norm.pl new file mode 100755 index 0000000..1dc8099 --- /dev/null +++ b/log_norm.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl +use strict; + +open(FL, "log_scores.txt"); + +my @logScores = ; + +chomp @logScores; + +close FL; + +my $total = 0.0; + +$total = lnXpluslnY($logScores[0], $logScores[1]); + +for(my $i=2;$i<@logScores;$i++) { + $total = lnXpluslnY($total, $logScores[$i]); +} + +for(my $i=0;$i<@logScores;$i++) { + + my $percent = exp($logScores[$i] - $total)*100.0; + print "Total score $total\n"; + print "Log score $logScores[$i] is $percent % of total score\n"; +} + +sub lnXpluslnY { + + my ($first, $second) = @_; + my $MAXEXP = -310; + + my $x = $first; + my $y = $second; + my $temp; + my $ln_yMINUSln_x; + my $plus; + + + if ($y > $x) { + $temp = $x; + $x = $y; + $y = $temp; + } + + $ln_yMINUSln_x = $y - $x; + if ($ln_yMINUSln_x < $MAXEXP) { + $plus = $x; + } + else { + $plus = log(1 + exp($ln_yMINUSln_x)) + $x; + } + + return $plus; +} + diff --git a/log_scores.txt b/log_scores.txt new file mode 100644 index 0000000..185f437 --- /dev/null +++ b/log_scores.txt @@ -0,0 +1,8 @@ +2.972013412 +1.557986984 +4.648754528 +3.506570268 +-0.434294482 +-2.694955206 +-3.643825586 +-0.508617802