-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathupdate_model.m
More file actions
49 lines (49 loc) · 1.98 KB
/
update_model.m
File metadata and controls
49 lines (49 loc) · 1.98 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
function [Theta, Gamma] = update_model(Theta, Gamma, y, x, c, lambdad, lambdar)
%
% This file includes code for the paper Probabilistic Load Forecasting based on Adaptive Online Learning.
% @author: Verónica Álvarez
%
% This function updates model parameters and state variables
%
% Inputs
% Theta is the list of model parameters
% Gamma is the list of state variables
% y is the vector of new loads
% x = [s0, w] is the instance vector (wt is included in Theta is updated in this step)
% c is the calendar information
% lambdad, lambdar forgetting factors
%
% Outputs
% Theta is the updated list of model parameters
% Gamma is the updated list of state variables
%
% Prediction horizon
s0 = x(1);
w = x(2:end);
L = length(y);
y = [s0, y'];
for i = 1:L
% Update the mean of temperatures with the forgetting factor lambda = 1 and the
% feature vector u = 1
[Theta.wt(c(i)), Theta.sigmat(c(i)), Gamma.Pt(c(i)), Gamma.gammat(c(i))] = update_parameters(Theta.wt(c(i)), Theta.sigmat(c(i)), Gamma.Pt(c(i)), Gamma.gammat(c(i)), 1, w(i), 1);
% Dummy varibles
if Theta.wt(c(i)) - w(i) > 20 && (w(i) > 80 || w(i) < 20)
alpha1 = 1;
alpha2 = 0;
elseif Theta.wt(c(i)) - w(i) < - 20 && (w(i) > 80 || w(i) < 20)
alpha1 = 0;
alpha2 = 1;
else
alpha1 = 0;
alpha2 = 0;
end
% Feature vector that represents load
ud = [1, y(i)]';
% Update parameters denoted by d
[Theta.etad(:, c(i)), Theta.sigmad(c(i)), Gamma.Pd(:, :, c(i)), Gamma.gammad(c(i))] = update_parameters(Theta.etad(:, c(i)), Theta.sigmad(c(i)), Gamma.Pd(:, :, c(i)), Gamma.gammad(c(i)), lambdad, y(i+1), ud);
% Feature vector that represents observations
ur = [1, alpha1, alpha2]';
% Update parameters denoted by r
[Theta.etar(:, c(i)), Theta.sigmar(c(i)), Gamma.Pr(:, :, c(i)), Gamma.gammar(c(i))] = update_parameters(Theta.etar(:, c(i)), Theta.sigmar(c(i)), Gamma.Pr(:, :, c(i)), Gamma.gammar(c(i)), lambdar, y(i+1), ur);
end
end