-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap_variant.m
46 lines (38 loc) · 1.33 KB
/
bootstrap_variant.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
function [x, it] = bootstrap(alpha, v, R, tol, maxit)
% Successive Newtons incrasing the value of alpha
target_alpha = alpha;
n = length(v);
if not(exist('tol','var')) || isempty(eps)
tol = sqrt(eps);
end
if not(exist('maxit','var')) || isempty(maxit)
maxit = 10000;
end
assert(target_alpha >= 0.7); %TODO: for now we focus on this case
alpha = 0.7;
[x, it] = fixed_point(alpha, v, R);
total_iterations = it;
while alpha < target_alpha
% selects epsilon as large as possible such that
% the fixed point eqn is a contraction, i.e., 4*norm(RR)*norm(vv) < 1
epsilon = 0.0000001;
M = eye(n) - (alpha+epsilon)*(R*kron(eye(n),x)+R*kron(x,eye(n)));
vv = epsilon*(M\(R*kron(x,x) - v));
RR = (alpha + epsilon) * (M\R);
assert(4*norm(RR)*norm(vv)<1);
while 4*norm(RR)*norm(vv)<1
last_good_epsilon = epsilon;
epsilon = epsilon * 1.1;
M = eye(n) - (alpha+epsilon)*(R*kron(eye(n),x)+R*kron(x,eye(n)));
vv = epsilon*(M\(R*kron(x,x) - v));
RR = (alpha + epsilon) * (M\R);
end
% 4*norm(RR)*norm(vv)
epsilon = last_good_epsilon;
if alpha + epsilon >= target_alpha
epsilon = target_alpha - alpha;
end
alpha = alpha + epsilon;
[x, it] = newton(alpha, v, R, tol, maxit-total_iterations, x);
total_iterations = total_iterations + it;
end