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
| File was created | 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 | |||
| 56 |
log_scores.txt
| File was created | 1 | 2.972013412 | |
| 2 | 1.557986984 | ||
| 3 | 4.648754528 | ||
| 4 | 3.506570268 | ||
| 5 | -0.434294482 | ||
| 6 | -2.694955206 | ||
| 7 | -3.643825586 | ||
| 8 | -0.508617802 | ||
| 9 |