-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadObjFun2.m
32 lines (28 loc) · 1.03 KB
/
LoadObjFun2.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
function f = LoadObjFun(x, config)
% f = LoadObjFun(x, config)
%
global models model_vars CurrentLoadTarget
% Compute all model predictions
machine_names = string(fieldnames(config.machines))';
n_machines = numel(machine_names);
y_means = nan(n_machines, 1);
y_sigmas = nan(n_machines, 1);
for i = 1:n_machines
machine = machine_names{i};
model_name = config.machines.(machine).model;
model_config = config.models.(model_name);
[y_means(i), y_sigmas(i), ~] = builtin( ...
"feval", ...
model_config.predictFcn, ...
models.(machine), ...
x(i), ...
model_vars.(machine), ...
model_config.params ...
);
end
% Weights for cost function
w = config.optimizer.params.w; % load error vs target
z = config.optimizer.params.z; % model uncertainty
% Compute objective function
f = sum(y_means).^2 + w .* (sum(x) - CurrentLoadTarget).^2 ...
- z .* sum(y_sigmas.^2);