#!/usr/local/bin/perl # reads data files and works out confidence interval for MNC performance and makes graph # of p versus EbNo # March 22 96 # Also find quartiles of the number of iterations # # What if the true value of M is different from the reported M? # R is computed from K/N in find_eb # where # N = a4+a5 # and K = a4 # Until Thu 11/4/02 this was not overrideable. # See extract_ebno2.p for a version that fixes this. # usage: # extract_ebno.p read_directory=/home/mackay/code/rGH write_directory=/home/mackay/_doc/code/rGH codename=961.S 1.40 1.45 1.50 1.55 1.60 # mean loop calcuation modified because in a few cases two algms wrote to the # same file at the same time so the counts reported are incorrect. $period="."; $sortmax = 4000 ; # maximum number of lines to read to get stats on loops # $directory = "/home/mackay/_doc/code/rmncN" ; $fudge="0"; # set fudge=0.90 to get it to look for fudge files $read_directory = "/home/mackay/data/code/rmncNall" ; $write_directory = "/home/mackay/_doc/code/rmncNall" ; $codename = "15000.10000.3.0.1523" ; $indivsymbol = "# " ; $finalsymbol = "" ; $latex_print_C = 1 ; $latex_printt = 0 ; $latex_printlower = 0 ; $latex_print_fn = 0 ; $lowerbound = 1e-06; $findmean = 1 ; $z_score = 2.0 ; $sigma = 1.0; $small_number_loops = 100 ; $verbose = 0 ; $clobber = 1 ; eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; # exit(0); sub bynumber { $a <=> $b; } $loop25 = 0 ; $loop50 = 0 ; $loop75 = 0 ; $loop05 = 0 ; $loop95 = 0 ; if ( $fudge == 0 ) { $thiscodefile = $write_directory."/".$codename ; } else { $thiscodefile = $write_directory."/".$codename.".".$fudge ; } print STDERR "# writing $thiscodefile\n" ; if ( $clobber ) { open ( OUT , "> $thiscodefile" ) || print STDERR "failed\n" ; } else { open ( OUT , ">> $thiscodefile" ) || print STDERR "failed\n" ; } close ( OUT ) ; $very_first_time = 1 ; foreach $x (@ARGV) { $mncfile = $thiscodefile.".".$x ; print STDERR "# writing $mncfile\n" ; open ( OUT , "> $mncfile " ) || print STDERR "failed\n" ; $first_time = 1 ; # # search for files with relevant reports # if ( $fudge == 0 ) { open ( IN , "ls $read_directory/$codename.*$period$x | " ) ; } else { open ( IN , "ls $read_directory/$codename.*.$fudge$period$x | " ) ; } # pipes us the names of files ; $numpoints = 0 ; $totbitswrong = 0 ; $toterrors = 0 ; $tot_undetected_errors = 0 ; $tot_undetected_bits = 0 ; $tottrials = 0 ; $totsumloops = 0 ; # for combining results (on assumption that it's appropriate) # - i.e. same N and t and maxloops $successful_trialnum = 0 ; # used to label nnumber of loops each trial $loop25 = 0 ; $loop50 = 0 ; $loop75 = 0 ; $loop05 = 0 ; $loop95 = 0 ; while ( $r = ) { $rawtrials = 0 ; $rawerrors = 0 ; $numpoints ++ ; print STDERR "# reading $r" ; open ( R , "< $r" ) ; $dont_know_maxloops = 1 ; $maxloops = 0 ; $sumloops = 0 ; $bitswrong = 0 ; $undetected_bits = 0 ; $undetected_errors = 0 ; $line = 0 ; while ( ) { $last = $_ ; $line ++ ; if ( $dont_know_maxloops || $findmean ) { s/^\s*// ; if ( !/^#/ ) { $rawtrials ++ ; @a = split ; if ( $dont_know_maxloops ) { if ( $maxloops < $a[23] - 1 ) { $maxloops = $a[23] - 1 ; # } # } if ( $a[0] != "0" ) { # it is a failure $rawerrors ++ ; $bitswrong += $a[0] ; # used for finding mean bit error rate if ( $a[3] != "0" ) { # then this was a flagged error (viols detected) $dont_know_maxloops = 0 ; # and we do know maxloops now. if ( $a[23] < $small_number_loops ) { print STDERR "warning, $a[23] loops only! line $line\n" ; } } else { # an undetected error - bad! $undetected_errors ++ ; $undetected_bits += $a[0] ; print STDERR "!! codeword of weight $a[0] .. "; } } else { $sumloops += $a[23] - 1 ; # for mean number of loops if ( $successful_trialnum < $sortmax ) { $loops[$successful_trialnum] = $a[23] - 1 ; $successful_trialnum ++ ; } } } } } $_ = $last ; s/^\s*// ; @a = split ; $errors = $a[25] ; $trials = $a[24] ; if ( $errors != $rawerrors || $trials != $rawtrials ) { print STDERR "mismatch between $errors <-> $rawerrors ; or $trials <=> $rawtrials \n" ; $errors = $rawerrors ; $trials = $rawtrials ; } $toterrors += $errors ; $tottrials += $trials ; $totbitswrong += $bitswrong ; $totsumloops += $sumloops ; $tot_undetected_bits += $undetected_bits ; $tot_undetected_errors += $undetected_errors ; $t = $a[6] ; $Nnmn = $a[5] ; $Knmn = $a[4] ; $N = $Nnmn + $Knmn ; # "L" $K = $N - $Nnmn ; # $f = $a[7] ; $R = sprintf ( "%6.4g" , $K / $N ) ; &find_ebs_and_print ( 0 ) ; $first_time = 0 ; } if ($numpoints>0 ) { # last time round, aggregate all info together: # sort al the loops and find quartiles. print STDERR "sorting loop counts..." ; @sorted = sort bynumber ( @loops ) ; print STDERR "reading out element ", int($successful_trialnum*0.25), " in list of size $successful_trialnum\n" ; $loop05 = $sorted[int($successful_trialnum*0.05)] ; $loop25 = $sorted[int($successful_trialnum*0.25)] ; $loop50 = $sorted[int($successful_trialnum*0.50)] ; $loop75 = $sorted[int($successful_trialnum*0.75)] ; $loop95 = $sorted[int($successful_trialnum*0.95)] ; print STDERR "done.\n"; if ( $tot_undetected_errors > 0 ) { print STDERR "WARNING!! $codename !! " ; print STDERR "undetected errors : " , $tot_undetected_errors ; print STDERR " WARNING!! $codename !!\n" ; } # $undetected_errors = $tot_undetected_errors ; $undetected_bits = $tot_undetected_bits ; $bitswrong = $totbitswrong ; $trials = $tottrials ; $errors = $toterrors ; $sumloops = $totsumloops ; &find_ebs_and_print ( 1 ) ; close ( OUT ) ; open ( OUT , ">> $thiscodefile" ) || print STDERR "failed\n" ; &find_ebs_and_print ( 2 ) ; $very_first_time = 0 ; } } # sub find_ebs_and_print { # this routine looks at the global variables $errors and $trials # and computes a confidence interval and maximum likelihood value. # these are called $blep_lower and $blep_upper, and $blep_point (ML value) # the size of the interval is dictated by $zscore, e.g. 2.0 # # [a value called $blockep is also computed, which is the point to plot # if one wants a plot which just shows point estimates. # this is not currently used in the paper, Sep 30 95] # # a bit error probability is also computed, $bitep, by looking at the # global variables $bitswrong and $N # local ( $arg ) = @_ ; # typesetting $symbol = $arg ? $finalsymbol : $indivsymbol ; # $Neff = ( $errors == 0 ) ? 1 : $errors ; # make the point $blockep = $Neff / $trials ; # estimate $blockep # # Confidence interval # if ( $errors == 0 ) { $blep_point = $lowerbound ; $blep_lower = $lowerbound ; $blep_upper = 1.0 - exp( - 2.0 / $trials ) ; $factor = $blep_upper / $blep_point ; } else { $blep_point = $errors / $trials ; # factor corresponding z sd's in log p $factor = exp ( $z_score * sqrt( ($trials - $errors ) / ( $errors * $trials ) ) ) ; # this is a lot like sqrt( $errors ) $blep_upper = $blep_point * $factor ; $blep_lower = $blep_point / $factor ; } # # end of confidence interval bit # $bitep = $bitswrong / ( $trials * $N ) ; $biep_lower = $bitep / $factor ; $biep_upper = $bitep * $factor ; $R = $K / $N ; $ebno = $x * $x / ( 2.0 * $R * $sigma * $sigma ) ; $logEb = 10.0 * log ( $ebno ) / log (10.0) ; $C = 0.5 * log ( 1.0 + $x * $x / ( $sigma * $sigma ) ) / log ( 2.0 ) ; # limitting value of x^2/sigma^2 $x2s_lim = exp ( 2 * $R * log (2.0)) - 1 ; $ebno_lim = $x2s_lim / ( 2.0 * $R ) ; $logEbno_lim = 10.0 * log ( $ebno_lim ) / log (10.0) ; $d = $logEb - $logEbno_lim ; if ( $verbose ) { printf "# x2s_lim = %9.4g\n" , $x2s_lim ; printf "# ebno_lim = %9.4g\n" , $ebno_lim ; printf "# logEbno_lim = %9.4g\n" , $logEbno_lim ; } # the above is from bernebno.p if ( ( $arg == 2 && $very_first_time == 1 ) || $first_time == 1 || $arg == 1 ) { print OUT "# ebno (dB) distance C R x errors trials undet blep point upper lower bitsw undet bitep:point upper lower maxloops mean_lps K N loop05:25:50:75:95\n" ; } printf OUT "%s%-7.4g %7.4g %7.4g %7.4g %7.4g %5.4g " , $symbol, $ebno, $logEb , $d , $C , $R , $x ; # printf OUT "%-4s %6s %4s " , $errors, $trials , $undetected_errors ; printf OUT "%9.4g %9.4g %9.4g %9.4g ", $blockep, $blep_point , $blep_upper , $blep_lower ; printf OUT " %6d %5d %9.4g %9.4g %9.4g %4d " , $bitswrong, $undetected_bits , $bitep , $biep_upper , $biep_lower , $maxloops ; if ( $findmean && ( $trials - $errors > 1 ) ) { $factory = 1 / ($trials - $errors) ; } else { $factory = 1 ; } printf OUT "%8.4g " , $sumloops * $factory ; printf OUT "%6d " , $K ; printf OUT "%6d " , $N ; printf OUT "%8.4g " , $loop05 ; printf OUT "%8.4g " , $loop25 ; printf OUT "%8.4g " , $loop50 ; printf OUT "%8.4g " , $loop75 ; printf OUT "%8.4g " , $loop95 ; print OUT "\n" ; if ( $arg == 1 ) { # print some latex stuff too printf STDERR # "%s%5s/%5s & %7.4g " , # " ", $K,$N, $R ; if ( $latex_printt ) { # printf STDERR "& %s " , $t ; # } if ( $latex_print_fn ) { # printf STDERR "& %s " , $x ; # } if ( $latex_print_C ) { printf STDERR "& %8.3g " , $C ; } printf STDERR "& %4s & %4s " , $errors, $trials ; if ( $findmean ) { printf STDERR "& %8.3g " , $sumloops * $factory ; } printf STDERR "& %8.3g & %8.3g " , $blep_point , $blep_upper ; if ( $latex_printlower ) { printf STDERR "& %8.3g ", $blep_lower ; } printf STDERR "& %8.3g & %8.3g " , $bitep , $biep_upper ; if ( $latex_printlower ) { printf STDERR "& %8.3g ", $biep_lower ; } print STDERR "\\\\ \n" ; } } #