Blame view

log_norm.pl 963 Bytes
fcc0e9058   Changwon Yoo   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  #!/usr/bin/perl
  use strict;
  
  open(FL, "log_scores.txt");
  
  my @logScores = <FL>;
  
  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
  ";
  	print "Log score $logScores[$i] is $percent % of total score
  ";
  }
  
  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;
  }