#!/usr/local/bin/perl # camitro3.p # Output mapping program # read target file and # put through log(x/(100-x)) # OR # Read output file and # put through 100/(1+exp(-x)) # ALSO # mark suspect lines # Default settings $verbose= 0 ; $sep=0; $hundred=100; # replace occurences of this number by $ninetynine=99.7; # this number $strip="36 79 81 113 116 127 192 220" ; $d=0; # DIRECTION 0= forward, 1=backward eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; if ( 1 eq $d ) { $_ = $strip ; @s = split ; $ss = ":".join(":",@s).":" ; print STDERR "read row suspects (number $#s)- $ss\n" ; } else { $ss = "" ; } # Read and write $line = 0 ; while ( <> ) { $line ++ ; s/^\s*//; # get rid of initial gap on line s/\n//; # get rid of newline if ( /^\#/ || /^\%/ || ($line<=$skip) ) { $comments ++ ; } else { if("0" eq $sep) { @w=split ; # use default space separator }else{ @w=split($sep, $_) ; } if ( $#w == -1 ) { $blank ++ ; } else { if ( $#w != $lastnum ) { # new block if ( $num_blocks > 0 ) { # report previous block &report () ; # } # $num_blocks ++ ; # $num_lines_same = 0 ; $lastnum = $#w ; # } # $num_lines_same ++ ; # for ($ii = 0 ;$ii<=$#w; $ii++){ print &f($d,$ii,$w[$ii])." " ; } if( ($d eq 1 )&& $ss =~ /:$line:/ ) { # MARK this row as dodgy print " UNCERTAIN" ; } print "\n" ; } } # } # &report () ; if ( $blank + $comments > 0 ) { print STDERR "-----------\n$blank blank lines, $comments comments\n" ; } sub f { local( $d,$i,$w ) = @_ ; if(0 eq $d) { if ( $i>0 ) { print STDERR "warning, only expected one item per row , should have d=1 ?\n" ; } # replace values at the edge if ($hundred eq $w) { $w = $ninetynine ; } $x = sprintf("%8.5g",log( $w / ( $hundred - $w ) ) ) ; } else { # output, error, lower, upper, noise level if ((0 eq $i)||(2 eq $i)||(3 eq $i)) { $x = sprintf("%8.5g", ($hundred / ( 1.0 + exp( - $w ) )) ) ; } else { $x = $w ; } } print " w = $w , x = $x\n" if ($verbose) ; return $x ; } sub report { $lastnum ++ ; print STDERR "Block $num_blocks: $num_lines_same lines, $lastnum entries\n" ; }