forked from enriquedecote/repeatedgames
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze_runs.sh
executable file
·109 lines (79 loc) · 2.89 KB
/
analyze_runs.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# ################################################################# #
# Compute the mobile average of a numerical series obtained as the #
# average of a set of numerical series in the specified directory #
# ################################################################# #
# ################ #
# Input Parameters #
# ################ #
# Directory that contains all the numerical series files
dir=$1
# Number of the column to consider in averaging
col=$2
# First line in the file
first_row=$3
# Number of sample in the numerical series
length=$4
# Name of the output file
outfile=$5
# Size of the fixed window used to compute the mobile average
window=$6
# Name of the octave script file
script="oct_script.m"
# ########## #
# Script #
# ########## #
echo "Directory = "$dir
echo "Column = "$col
echo "First Row = "$first_row
echo "Length = "$length
echo "Outfile = "$outfile
echo "Window = "$window
let last_col=$col
# Create the script
echo "" > $script
# Move into the directory
echo "cd "$dir >> $script
# Read all the files in the directory
echo "files = readdir('.');" >> $script
# Store the number of files in the directory
echo "num_files = rows(files);" >> $script
# Since the first two files are "." and "..", start from the third
# Import the series corresponding to the specified column
echo "tmp = dlmread(files{3},\"\t\",["$first_row","$col","$length","$last_col"]);" >> $script
# The matrix containing all the series
echo "m = tmp;" >> $script
# Loop on the file in the directory
echo "if (num_files > 3)" >> $script
echo "for i = 4:num_files;" >> $script
echo "files{i};" >> $script
echo "tmp = dlmread(files{i},\"\t\",["$first_row","$col","$length","$last_col"]);" >> $script
echo "m = [m tmp];" >> $script
echo "endfor;" >> $script
# Compute the average and the standard deviation
echo "result = mean(m')';" >> $script
echo "result = [result std(m')'];" >> $script
echo "w = "$window";" >> $script
echo "n = size(result,1);" >> $script
echo "only_mean = result*[1 0]';" >> $script
echo "z_mean = [0 cumsum(only_mean')];" >> $script
echo "y_mean = ( z_mean(w+1:n+1) - z_mean(1:n-w+1) )/w;" >> $script
echo "only_std = result*[0 1]';" >> $script
echo "z_std = [0 cumsum(only_std')/(num_files-2)];" >> $script
echo "y_std = ( z_std(w+1:n+1) - z_std(1:n-w+1) )/w;" >> $script
echo "final_res = [y_mean' y_std'];" >> $script
echo "else">> $script
# Compute the average and the standard deviation
echo "result = m;" >> $script
echo "w = "$window";" >> $script
echo "n = size(result,1);" >> $script
echo "only_mean = result;" >> $script
echo "z_mean = [0 cumsum(only_mean')];" >> $script
echo "y_mean = ( z_mean(w+1:n+1) - z_mean(1:n-w+1) )/w;" >> $script
echo "final_res = [y_mean'];" >> $script
echo "endif" >> $script
# Write the result on the output file
echo "dlmwrite(\""$outfile"\",final_res,'\t');" >> $script
# Launch the octave script
octave -qf $script
#rm -f $script