Commit fcc0e9058bcdda14f824000d3e485d3b811fc174
0 parents
Exists in
master
first commit
Showing
2 changed files
with
63 additions
and
0 deletions
Show diff stats
log_norm.pl
| ... | ... | @@ -0,0 +1,55 @@ |
| 1 | +#!/usr/bin/perl | |
| 2 | +use strict; | |
| 3 | + | |
| 4 | +open(FL, "log_scores.txt"); | |
| 5 | + | |
| 6 | +my @logScores = <FL>; | |
| 7 | + | |
| 8 | +chomp @logScores; | |
| 9 | + | |
| 10 | +close FL; | |
| 11 | + | |
| 12 | +my $total = 0.0; | |
| 13 | + | |
| 14 | +$total = lnXpluslnY($logScores[0], $logScores[1]); | |
| 15 | + | |
| 16 | +for(my $i=2;$i<@logScores;$i++) { | |
| 17 | + $total = lnXpluslnY($total, $logScores[$i]); | |
| 18 | +} | |
| 19 | + | |
| 20 | +for(my $i=0;$i<@logScores;$i++) { | |
| 21 | + | |
| 22 | + my $percent = exp($logScores[$i] - $total)*100.0; | |
| 23 | + print "Total score $total\n"; | |
| 24 | + print "Log score $logScores[$i] is $percent % of total score\n"; | |
| 25 | +} | |
| 26 | + | |
| 27 | +sub lnXpluslnY { | |
| 28 | + | |
| 29 | + my ($first, $second) = @_; | |
| 30 | + my $MAXEXP = -310; | |
| 31 | + | |
| 32 | + my $x = $first; | |
| 33 | + my $y = $second; | |
| 34 | + my $temp; | |
| 35 | + my $ln_yMINUSln_x; | |
| 36 | + my $plus; | |
| 37 | + | |
| 38 | + | |
| 39 | + if ($y > $x) { | |
| 40 | + $temp = $x; | |
| 41 | + $x = $y; | |
| 42 | + $y = $temp; | |
| 43 | + } | |
| 44 | + | |
| 45 | + $ln_yMINUSln_x = $y - $x; | |
| 46 | + if ($ln_yMINUSln_x < $MAXEXP) { | |
| 47 | + $plus = $x; | |
| 48 | + } | |
| 49 | + else { | |
| 50 | + $plus = log(1 + exp($ln_yMINUSln_x)) + $x; | |
| 51 | + } | |
| 52 | + | |
| 53 | + return $plus; | |
| 54 | +} | |
| 55 | + |
log_scores.txt