-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUpdateBundleFull.m
118 lines (99 loc) · 2.94 KB
/
UpdateBundleFull.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
function [ Bundle, Alphas ] = UpdateBundleFull(Bundle, Alphas, outcome, parameterObj, fxdMinusfd, dt, sTildeK, alphaTildeK, skPlus, alphakPlus)
%Updates the current Bundle, considering the result of the attempted step
currentSize = size(Bundle);
currentSize = currentSize(2); % sadly no chaining :(
maxBundleSize = parameterObj.maxBundleSize;
update = parameterObj.bundleUpdate;
protected = 0;
for i = currentSize:-1:1
if Alphas(i) == 0
protected = i;
break;
end
end
%Update of Alphas
currentSize = size(Bundle,2);
%[ismem1, ind1] = isMemberTol(Bundle, sTildeK, 1e-6);
%[ismem2, ind2] = isMemberTol(Bundle, skPlus, 1e-6);
ismem1 = false;
ismem2 = false;
if outcome == -1
if (~ismem1)
Bundle(:,currentSize+1) = sTildeK;
Alphas(currentSize+1) = alphaTildeK;
else
Bundle(:,ind1) = sTildeK;
Alphas(ind1) = alphaTildeK;
end
if (~ismem2)
Bundle(:,currentSize+2) = skPlus;
Alphas(currentSize+2) = alphakPlus;
else
Bundle(:,ind2) = skPlus;
Alphas(ind2) = alphakPlus;
end
else
if (~ismem1)
Bundle(:,currentSize+1) = sTildeK;
Alphas(currentSize+1) = alphaTildeK;
else
Bundle(:,ind1) = sTildeK;
Alphas(ind1) = alphaTildeK;
end
Alpha1 = repmat(fxdMinusfd,1,size(Bundle,2));
Alpha2 = -dt' * Bundle;
Alphas = Alphas + Alpha1 + Alpha2;
if (~ismem2)
Bundle(:,currentSize+2) = skPlus;
Alphas(currentSize+2) = 0;
else
Bundle(:,ind2) = skPlus;
Alphas(ind2) = 0;
end
end
sizeAfterUpdate = size(Bundle,2);
tooMuch = sizeAfterUpdate - maxBundleSize;
if tooMuch >= 1
switch update
case 'largest error'
AValidToDelete = Alphas(1:currentSize);
% prevents the deletion of the newly added
[~,index] = max(AValidToDelete);
Bundle(:,index) = [];
Alphas(index) = [];
AValidToDelete(index) = [];
if tooMuch == 2
[~,index2] = max(AValidToDelete);
Bundle(:,index2) = [];
Alphas(index2) = [];
end
case 'fifo'
for i = 1:tooMuch
if 1 ~= protected
Bundle(:,1) = [];
Alphas(1) = [];
else
Bundle(:,2) = [];
Alphas(2) = [];
end
end
case 'random'
r = getNonProtectedInt(currentSize, protected);
Bundle(:,r) = [];
Alphas(r) = [];
if tooMuch == 2
r = getNonProtectedInt(currentSize-1, protected);
Bundle(:,r) = [];
Alphas(r) = [];
end
otherwise
error('Update nicht unterstützt.');
end
end
end
function r = getNonProtectedInt(max,protected)
r = randi(max,1);
while r == protected
r = randi(max,1);
end
end