Гистограмма вхождений из разных файлов данных - PullRequest
0 голосов
/ 05 декабря 2018

Результатами моделирования моей программы являются несколько файлов данных, в первом столбце указано успешное выполнение (=0) или ошибка (=1), а во втором столбце указано время моделирования в секундах.

Примерэти два столбца:

1 185.48736852299064
1 199.44533672989186
1 207.35654106612733
1 213.5214031236177 
1 215.50576147950017
0 219.62444310777695
0 222.26750248416354
0 236.1402270910635 
1 238.5124609287994 
0 246.4538392581228 
.   .
.   .
.   .
1 307.482605596962
1 329.16494123373445
0 329.6454558227778 
1 330.52804695995303
0 332.0673690346546 
0 358.3001385706268 
0 359.82271742496414
1 400.8162129871805 
0 404.88783391725985
1 411.27012219170393

Я могу сделать частотный график (гистограмма) ошибок (1's), связывающих данные.

set encoding iso_8859_1
set key left top 
set ylabel "P_{error}" 
set xlabel "Time [s]" 
set size 1.4, 1.2
set terminal postscript eps enhanced color "Helvetica" 16 
set grid ytics
set key spacing 1.5
set style fill transparent solid 0.3

`grep '^ 1' lookup-ratio-50-0.0034-50-7-20-10-3-1.txt | awk '{print $2}' > t7.dat`

stats 't7.dat' u 1
set output "t7.eps"
binwidth=2000
bin(x,width)=width*floor(x/width)
plot 't7.dat' using (bin($1,binwidth)):(1.0/STATS_records) smooth freq with boxes lc rgb "midnight-blue" title "7x7_P_error"

Результат

enter image description here

Я хочу улучшить приведенный выше Gnuplot и включить остальные файлы данных lookup-.....-.txt и их выборки ошибок и объединить их в одном частотном графике.

Я также хотел бы избежать использования промежуточных файлов, таких как t7.dat.

Кроме того, я хотел бы построить горизонтальную линию среднего значения вероятности ошибки.

Как я могу построить все данные образца на одном графике?

С уважением

Ответы [ 2 ]

0 голосов
/ 06 декабря 2018

Если я вас правильно понимаю, вы хотите сделать гистограмму для нескольких файлов.Таким образом, вам нужно объединить несколько файлов данных.Конечно, вы можете сделать это с помощью некоторых внешних программ, таких как awk и т. Д., Или с помощью команд оболочки.Ниже приведено возможное решение для gnuplot и системной команды, и нет необходимости во временном файле.Системная команда для Windows, но вы, вероятно, можете легко перевести это на Linux.И, возможно, вам нужно проверить, не влияют ли значения «NaN» на результаты биннинга и гистограммы.

### start code
reset session
# create some dummy data files
do for [i=1:5] {
    set table sprintf("lookup-blahblah_%d.txt", i)
    set samples 50
    plot '+' u (int(rand(0)+0.5)):(rand(0)*0.9+0.1) w table
    unset table
}
# end creating dummy data files

FILELIST = system("dir /B lookup*.txt")   # this is for Windows
print FILELIST

undefine $AllDataWithError
set table $AllDataWithError append
do for [i=1:words(FILELIST)] {
    plot word(FILELIST,i) u ($1==1? $1 : NaN):($1==1? $2 : NaN) w table
}
unset table

print $AllDataWithError

# ... do your binning and plotting
### end of code

Редактировать:

Очевидно, NaN и / или пустые строки кажутсяиспортить smooth freq и / или биннинг ?!Итак, нам нужно извлечь только строки с ошибками (= 1).Из приведенного выше кода вы можете объединить несколько файлов в один блок данных.Код ниже уже начинается с одного блока данных, похожего на ваши данные.

### start of code
reset session

# create some dummy datablock with some distribution (with no negative values)
Height =3000
Pos = 6000
set table $Data
    set samples 1000
    plot '+' u (int(rand(0)+0.3)):(abs(invnorm(rand(0))*Height+Pos)) w table
unset table
# end creating dummy data

stats $Data nooutput
Datapoints = STATS_records

# get only the error lines
# plot $Data into the table $Dummy.
# If $1==1 (=Error) write the line number $0 into column 1 and value into column 2
# else write NaN into column 1 and column 2.
# Since $0 is the line number which is unique 
# 'smooth frequency' will keep these lines "as is"
# but change the NaN lines to empty lines.
Error = 1
Success = 0
set table $Dummy
    plot $Data u ($1==Error ? $0 : NaN):($1==Error ? $2 : NaN) smooth freq
unset table
# get rid of empty lines in $Dummy
# Since empty lines seem to also mess up binning you need to remove them
# by writing $Dummy into the dataset $Error via "plot ... with table".
set table $Error
   plot $Dummy u 1:2 with table
unset table

bin(x) = binwidth*floor(x/binwidth)
stats $Error nooutput
ErrorCount = STATS_records

set multiplot layout 3,1
set key outside
set label 1 sprintf("Datapoints: %g\nSuccess: %g\nError: %g",\
    Datapoints, Datapoints-ErrorCount,ErrorCount) at graph 1.02, first 0
plot $Data u 0:($1 == Success ? $2 : NaN) w impulses lc rgb "web-green" t "Success",\
    $Data u 0:($1 == Error ? -$2 : NaN) w impulses lc rgb "red" t "Error",\

unset label 1
set key inside
binwidth = 1000
plot $Error using (bin($2)):(1.0/STATS_records) smooth freq with boxes t sprintf("binwidth: %d",binwidth) lc rgb "blue"

binwidth=100
set xrange[GPVAL_X_MIN:GPVAL_X_MAX] # use same xrange as graph before
plot $Error using (bin($2)):(1.0/STATS_records) smooth freq with boxes t sprintf("binwidth: %d",binwidth) lc rgb "magenta"

unset multiplot
### end of code

, что приводит к чему-то вроде: enter image description here

0 голосов
/ 05 декабря 2018

вы можете передать данные и директивы заговора в gnuplot без временного файла,

, например,

$ awk 'BEGIN{print "plot \"-\" using ($1):($2)"; 
             while(i++<20) print i,rand()*20; print "e"}' | gnuplot -p

создаст случайный график.Вы можете напечатать директиву в блоке BEGIN, как я, и основной оператор awk может фильтровать данные.

Для вашего графика, что-то вроде этого

$ awk 'BEGIN{print "...." }
       $1==1{print $2}
       END  {print "e"}' lookup-*.txt | gnuplot -p
...