1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-15 15:03:08 +02:00
wernermisc/m1rc3/norruption/2/plot-cdf
Werner Almesberger 9b2f2d1c00 m1rc3/norruption/2/plot-cdf: start empirical distribution at (0, 0)
Looks better when a run is just getting started and has few samples.
2011-10-13 11:06:29 -03:00

62 lines
1.2 KiB
Perl
Executable File

#!/usr/bin/perl
sub usage
{
print STDERR "usage: $0 [-i] [log_file]\n";
exit(1);
}
$with = "steps";
if ($ARGV[0] eq "-i") {
shift @ARGV;
$with = "lines";
}
&usage if $ARGV[0] =~ /^-/;
$n = 1;
while (<>) {
next unless /^=== (\d+) ===/;
while ($1 != $n) {
push(@f, $n);
$n++;
}
$n++;
}
$n--;
$f = int($n/@f+0.5);
$last = 0;
for (@f) {
push(@d, $_-$last);
$last = $_;
}
$cmd = "|gnuplot -e '".
'set term postscript color eps enhanced solid lw 2 20;'.
'set output "out.eps";'.
'set title "Probability distribution of time between NOR corruptions";'.
'set xlabel "Power cycles";'.
'set ylabel "Cumulative probability";'.
'set key bottom;'.
'plot "-" with '.$with.' title "Empirical distribution (N='.@f.')", '.
'1-exp(-'.1/$f.'*x) with lines lt 3 '.
'title "Exponential distribution ({/Symbol l}=1/'.$f.')"'.
"'";
open(PIPE, $cmd) || die "open: $!";
print PIPE "0 0\n";
$i = 0;
for (sort { $a <=> $b } @d) {
$i++;
print PIPE $_, " ", $i/@f, "\n";
}
close(PIPE) || die "close: $!";
system("cat out.eps | ".
"gs -sDEVICE=ppmraw -r100 -sOutputFile=- ".
"-dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sPAPERSIZE=a4 -q - | ".
"convert -trim - out.png");
unlink("out.eps");