Repository navigation
Expand file tree
/
Copy pathdrive
More file actions
executable file
·127 lines (109 loc) · 3.43 KB
/
Copy pathdrive
File metadata and controls
executable file
·127 lines (109 loc) · 3.43 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
OUTPUT_DIR="./outputs"
PLOT_FLAG=""
RATE_FLAG=""
STABILITY_FLAG=""
SOLVERS=("rk4" "adaptive_rk" "ab" "am" "mlp")
show_help() {
echo "Usage: $0 x0 y0 y0_prime [OPTIONS]"
echo "Options:"
echo " --plot : plot the result"
echo " --rate : rate the result"
echo " --stability : stability check"
echo " --help : this message"
echo ""
echo "Examples:"
echo " $0 2.0 0.5 0.2"
echo " $0 2.0 0.5 0.2 --plot --rate"
echo " $0 2.0 0.5 0.2 --stability"
exit 0
}
add_perturbation() {
local value=$1
local range=$2
awk -v val="$value" -v r="$range" 'BEGIN {
srand();
perturbation = val * r * (2 * rand() - 1);
printf "%.6f", val + perturbation
}'
}
validate_arguments() {
if [ "$#" -lt 3 ]; then
echo "Error: Missing required arguments"
show_help
exit 1
fi
for num in "$1" "$2" "$3"; do
if ! [[ $num =~ ^-?[0-9]+(\.[0-9]+)?$ ]]; then
echo "Error: Invalid number format: $num"
exit 1
fi
done
}
run_stability_test() {
echo "Running stability test for $solver."
echo "perturbation: x0=$2, y0=$3, y0'=$4"
python3 "./experiments/${solver}/${solver}.py" \
"$2" "$3" "$4" \
$PLOT_FLAG $STABILITY_FLAG
}
main() {
validate_arguments "$@"
x0=$1
y0=$2
y0_prime=$3
range=0.01
perturbed_x0=$(add_perturbation $x0 $range)
perturbed_y0=$(add_perturbation $y0 $range)
perturbed_y0_prime=$(add_perturbation $y0_prime $range)
shift 3
while [ "$#" -gt 0 ]; do
case "$1" in
--plot)
PLOT_FLAG="--plot"
;;
--rate)
RATE_FLAG="--rate"
;;
--stability)
STABILITY_FLAG="--stability"
;;
--help)
show_help
;;
*)
echo "Error: Unknown option $1"
show_help
;;
esac
shift
done
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
OUTPUT_FILE="${OUTPUT_DIR}/results_${x0}_${y0}_${y0_prime}_${TIMESTAMP}.txt"
mkdir -p "$OUTPUT_DIR" "${OUTPUT_DIR}/points" "./img"
for solver in "${SOLVERS[@]}"; do
SOLVER_PATH="./experiments/${solver}/${solver}.py"
if [ ! -f "$SOLVER_PATH" ]; then
echo "Warning: Solver ${solver} not found at ${SOLVER_PATH}" | tee -a "$OUTPUT_FILE"
continue
fi
echo "Running ${solver} with x0=${x0}, y0=${y0}, y0'=${y0_prime}" | tee -a "$OUTPUT_FILE"
START_TIME=$(date +%s.%N)
python3 "$SOLVER_PATH" "$x0" "$y0" "$y0_prime" $PLOT_FLAG | tee -a "$OUTPUT_FILE"
END_TIME=$(date +%s.%N)
ELAPSED=$(echo "$END_TIME - $START_TIME" | bc)
echo "Execution time: ${ELAPSED} seconds" | tee -a "$OUTPUT_FILE"
if [ "$STABILITY_FLAG" == "--stability" ]; then
run_stability_test "$solver" "$perturbed_x0" "$perturbed_y0" "$perturbed_y0_prime" | tee -a "$OUTPUT_FILE"
fi
echo "-------------------------------------" | tee -a "$OUTPUT_FILE"
done
if [ "$STABILITY_FLAG" == "--stability" ]; then
python3 "./experiments/stability.py"
fi
if [ "$RATE_FLAG" == "--rate" ]; then
python3 "./experiments/rate.py" "$OUTPUT_FILE"
fi
echo "All operations completed. Results saved to ${OUTPUT_DIR} and ./img"
}
main "$@"