Download this file

76 lines (54 with data), 2.5 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
% Runs various limited-memory solvers on 2D rosenbrock function for 25
% function evaluations
maxFunEvals = 25;
fprintf('Result after %d evaluations of limited-memory solvers on 2D rosenbrock:\n',maxFunEvals);
fprintf('---------------------------------------\n');
fprintf('x1 = %.4f, x2 = %.4f (starting point)\n',0,0);
fprintf('x1 = %.4f, x2 = %.4f (optimal solution)\n',1,1);
fprintf('---------------------------------------\n');
if exist('minimize') == 2
% Minimize.m - conjugate gradient method
x = minimize([0 0]', 'rosenbrock', -maxFunEvals);
fprintf('x1 = %.4f, x2 = %.4f (minimize.m by C. Rasmussen)\n',x(1),x(2));
end
options = [];
options.display = 'none';
options.maxFunEvals = maxFunEvals;
% Steepest Descent
options.Method = 'sd';
x = minFunc(@rosenbrock,[0 0]',options);
fprintf('x1 = %.4f, x2 = %.4f (minFunc with steepest descent)\n',x(1),x(2));
% Cyclic Steepest Descent
options.Method = 'csd';
x = minFunc(@rosenbrock,[0 0]',options);
fprintf('x1 = %.4f, x2 = %.4f (minFunc with cyclic steepest descent)\n',x(1),x(2));
% Barzilai & Borwein
options.Method = 'bb';
options.bbType = 1;
x = minFunc(@rosenbrock,[0 0]',options);
fprintf('x1 = %.4f, x2 = %.4f (minFunc with spectral gradient descent)\n',x(1),x(2));
% Hessian-Free Newton
options.Method = 'newton0';
x = minFunc(@rosenbrock,[0 0]',options);
fprintf('x1 = %.4f, x2 = %.4f (minFunc with Hessian-free Newton)\n',x(1),x(2));
% Hessian-Free Newton w/ L-BFGS preconditioner
options.Method = 'pnewton0';
x = minFunc(@rosenbrock,[0 0]',options);
fprintf('x1 = %.4f, x2 = %.4f (minFunc with preconditioned Hessian-free Newton)\n',x(1),x(2));
% Conjugate Gradient
options.Method = 'cg';
x = minFunc(@rosenbrock,[0 0]',options);
fprintf('x1 = %.4f, x2 = %.4f (minFunc with conjugate gradient)\n',x(1),x(2));
% Scaled conjugate Gradient
options.Method = 'scg';
x = minFunc(@rosenbrock,[0 0]',options);
fprintf('x1 = %.4f, x2 = %.4f (minFunc with scaled conjugate gradient)\n',x(1),x(2));
% Preconditioned Conjugate Gradient
options.Method = 'pcg';
x = minFunc(@rosenbrock,[0 0]',options);
fprintf('x1 = %.4f, x2 = %.4f (minFunc with preconditioned conjugate gradient)\n',x(1),x(2));
% Default: L-BFGS (default)
options.Method = 'lbfgs';
x = minFunc(@rosenbrock,[0 0]',options);
fprintf('x1 = %.4f, x2 = %.4f (minFunc with limited-memory BFGS - default)\n',x(1),x(2));
fprintf('---------------------------------------\n');