-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_multi.m
104 lines (75 loc) · 2.88 KB
/
main_multi.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
function [out, params] = main_multi(Dataset,out,input_params)
% This is the main script to run multiple iterations, try main_one.m first.
% The inputs and outputs are optional.
close all;
reset_path;
% To create a Dataset use: Dataset = importParquet('XXX.csv');
% Dataset = parquetread('Code/Common/Import/ExampleDataset.parquet');
if ~exist('Dataset','var'), Dataset = []; end
% To append the output from a previous estimation, use the input out.
if ~exist('out','var'), out = []; end
% To pass the parameters from a previous estimation, use the input params.
% To generate a parameters structure, use: params = load_output(out);
if ~exist('input_params','var'), input_params = []; end
%% Iterations
% Load index of measurement data to access multiple files
index_name = 'Data/Examples/Test_Index.parquet';
index = parquetread(index_name);
% Set the cell number(s)
cell_num = [3];
for n = cell_num
% Reset the parameters for each cell
params = input_params;
% Select files from the index
file_index = find(index.Cell_Number==n & index.Performance_Test);
filenames = index.File_Name(file_index(:));
subfolder = index.Folder_Name(file_index(:));
for k = 1:length(filenames)
% Set the section number(s) or number of repetitions
rep_num = 1:3;
for j = rep_num
%% Setup
% The following settings must be defined.
% ModelName: choose from the available Models (OCV, RORC, EHMT, etc.)
% Target: choose from Simulate, Plot, Compare or Parameter
% Estimator: choose from the available Methods (Fmincon, PEM)
if j==1
% Settings
ModelName = 'OCV';
Target = 'Parameter';
Estimator = 'PEM';
Dataset = import_parquet([subfolder{k} '/' filenames{k}]);
elseif j==2
ModelName = 'RORC';
end
%% Start
fprintf('\nComputation started at %s\n', datetime("now"));
% Add relevant paths
reset_path;
addpath(genpath(strcat('./Code/Models/',ModelName)));
addpath(genpath(strcat('./Code/Methods/',Estimator)));
% Define dimensionless model
params.fit_derivative = false; % true or false
[Model, params] = step0(ModelName,j,params);
Model.Noise = false; % true or false
% Load or generate data
[params.cycle_step, params.DataType] = data_selection(j);
[true_sol, params] = step1(Target,Model,params,j,Dataset);
% Perform estimation and update parameter values
[est_sol, params] = step2(Target,Model,params,j);
% Run simulation using updated parameters
[pred_sol, params] = step3(Target,Model,params,j,est_sol);
% Compare prediction and data
params = step4(Target,params,true_sol,pred_sol);
%% Save
% Only need to save the updated parameters structure as plots
% can be re-generated using Simulate or Compare.
% Convert and save the parameters in a table
out = tabulate_output(params,out);
% Save output and current figure (true = overwrite by default)
save_output(out,['Data/out_' ModelName '_' num2str(n) '_' num2str(k)],true);
% save_plot(gcf,['Data/plot_' ModelName '_' num2str(n) '_' num2str(k)],true);
end
end
end
end