-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_sim_specs_sim2_MKF_SF98_popt.m
124 lines (96 loc) · 3.4 KB
/
gen_sim_specs_sim2_MKF_SF98_popt.m
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
% Generate simulation specifications for tuning MKF_SF98
% observer parameters on 2x2 linear system
clear all
addpath("../yaml")
addpath("../process-observers")
% Main folder where all simulation results will be saved
sims_dir = 'simulations';
% Simulation group name
sim_name = "rod_obs_sim2_MKF_SF_popt";
% Create main directory for these simulations
base_dir = fullfile(sims_dir, sim_name);
if ~isfolder(base_dir)
mkdir(base_dir);
end
% Subdirectory for spec files
sim_specs_dir = 'sim_specs';
filepath = fullfile(base_dir, sim_specs_dir, "queue");
if ~isfolder(base_dir)
mkdir(base_dir);
end
% Parameter values to search
n_di_values = {3, 5, 10, 15, 20}; % number of detection intervals
m_values = {1, 2, 3};
d_values = {1, 2, 3, 5, 10};
fprintf("Generating simulation specification files...\n")
% Define struct to store info
% Basic info
data.info.label = "<placeholder>"; % this will be changed below
data.info.description = ...
"Simulations of MKF observer with sequence fusion algorithm " + ...
"(1998) on linear 2x2 system with varying covariance parameter to " + ...
"determine best tuning.";
fprintf("%16s: %s\n", "Simulation", sim_name)
% System
data.system.setup_script = "sys_rodin_step_2x2sym2.m";
data.system.label = "rodin_step_2x2sym2";
% Input generation
data.inputs.setup_script = "rod_obs_sim_inputs.m";
% Observers
data.observers.setup_script = "obs_rodin_step_2x2.m";
data.observers.adj_script = "obs_rodin_step_MKF_SF_RODD_fmd.m";
% Simulation setup
data.setup.plot_dir = fullfile(sims_dir, sim_name, "plots");
data.setup.results_dir = fullfile(sims_dir, sim_name, "results");
data.setup.seed = 0;
data.setup.observers = ["MKF_SF1"];
data.setup.t_stop = 5000;
data.setup.verbose = false;
% Output handling
data.outputs.setup_script = "rod_obs_sim_outputs.m";
%data.outputs.results_file = "<placeholder>"; % don't save outputs
data.outputs.summary_file = "rod_obs_sim_outputs_summary.csv";
[n_di_idx, m_idx, d_idx] = ndgrid(n_di_values, m_values, d_values);
n_combs = numel(n_di_idx);
nh_max = 200;
beta_min = 0.85;
% Load system
sys_rodin_step_2x2sym2
n_specs = 0;
for i_comb = 1:n_combs
% Get parameter values
nf = n_di_idx{i_comb}; % number of detection intervals
m = m_idx{i_comb}; % maximum number of shocks
d = d_idx{i_comb}; % spacing parameter
% Construct multiple model filter - to check beta and nh_max
q1 = 0.01; q2 = 0.01;
label = 'MKF_SF1';
P0 = 1000*eye(n);
Q0 = diag([q1 q2 0 0]);
R = diag(sigma_M.^2);
io.u_known = u_known;
io.y_meas = y_meas;
MKF_SF1 = MKFObserverSF_RODD(model,io,P0,epsilon,sigma_wp, ...
Q0,R,nf,m,d,label);
if MKF_SF1.nh > nh_max
fprintf("Skipping simulation due to nh > %d\n", nh_max)
continue
elseif MKF_SF1.beta < beta_min
fprintf("Skipping simulation due to beta < %.2f\n", beta_min)
continue
end
n_specs = n_specs + 1;
% Label
data.info.label = sprintf("%s_%03d", sim_name, n_specs);
%data.outputs.results_file = sprintf("rod_obs_sim_outputs_%02d_%02d.csv", i, j);
% Change simulation variables
%data.setup.seed = seed_values(i);
data.observers.params.nf = nf;
data.observers.params.m = m;
data.observers.params.d = d;
% Save to Yaml file
filename = sprintf("sim_spec_%03d.yml", n_specs);
yaml.dumpFile(fullfile(filepath, filename), data, "block")
fprintf("%16s: %s\n", "File created", filename)
end
%end