1
1
function show_centroid_plots()
2
+ % This file is part of RSOpt package.
3
+ %
4
+ % Created by H.Kasai and B.Mishra on July 20, 2018
5
+ % Modified by H.Kasai on Sep. 13, 2018
2
6
3
7
clc ; close all ; clear
4
8
5
- %% Define parameters
9
+ %% define parameters
6
10
tolgradnorm = 1e-8 ;
7
11
inner_repeat = 1 ;
8
12
@@ -22,28 +26,31 @@ function show_centroid_plots()
22
26
cn = 5 ;
23
27
srg_varpi = 0.05 ;
24
28
end
25
-
26
29
30
+
31
+
32
+
33
+ %% generate dataset
27
34
input_filename = sprintf(' ./dataset/psd/psd_mean_%d _%d _%d .mat' , d , N , cn );
28
35
fprintf(' Reading file %s with (d:%d N:%d cn:%d ) .... ' , input_filename , d , N , cn );
29
36
input_data = load(input_filename );
30
-
31
37
A = zeros(d , d , N );
32
-
33
38
A = input_data.x_sample{1 };
34
39
fprintf(' done\n ' );
35
-
36
40
f_sol = input_data.f_sol{1 };
37
41
fprintf(' f_sol: %.16e\n ' , f_sol );
38
42
39
43
40
- %% Set manifold
44
+
45
+
46
+
47
+ %% set manifold
41
48
problem.M = sympositivedefinitefactory_mod(d );
42
49
problem.ncostterms = N ;
43
50
44
51
45
52
46
- % Cost function
53
+ %% define problem
47
54
problem.cost = @cost ;
48
55
function f = cost(X )
49
56
f= 0 ;
@@ -60,11 +67,9 @@ function show_centroid_plots()
60
67
f = f + norm(logm(arg ),' fro' )^2 ;
61
68
end
62
69
63
- f = f /(N );
70
+ f = f /(2 * N );
64
71
end
65
72
66
-
67
-
68
73
% Riemannian gradient of the cost function
69
74
problem.rgrad = @rgrad ;
70
75
function g = rgrad(X )
@@ -78,11 +83,10 @@ function show_centroid_plots()
78
83
79
84
g = 2 * X * logsum ;
80
85
g = (g + g ' )/2 ;
81
- g = g / N ;
86
+ g = g /( 2 * N ) ;
82
87
end
83
88
84
89
85
-
86
90
% Riemannian stochastic gradient of the cost function
87
91
problem.partialgrad = @partialgrad ;
88
92
function g = partialgrad(X , idx_batchsize )
@@ -106,27 +110,29 @@ function show_centroid_plots()
106
110
107
111
108
112
109
- %% Run algorithms
110
113
111
- % Initialize
114
+
115
+ %% run algorithms
116
+
117
+ % initialize
112
118
Uinit = problem .M .rand();
113
119
114
120
115
- % Run R-SD
121
+ % R-SD
116
122
clear options ;
117
123
options.maxiter = maxepoch ;
118
124
options.tolgradnorm = tolgradnorm ;
119
125
[~ , ~ , infos_sd , options_sd ] = steepestdescent(problem , Uinit , options );
120
126
121
127
122
- % Run R-CG
128
+ % R-CG
123
129
clear options ;
124
130
options.maxiter = maxepoch ;
125
131
options.tolgradnorm = tolgradnorm ;
126
132
[~ , ~ , infos_cg , options_cg ] = conjugategradient(problem , Uinit , options );
127
133
128
134
129
- % Run SGD with decay step-size
135
+ % R- SGD with decay step-size
130
136
clear options ;
131
137
options.verbosity = 1 ;
132
138
options.batchsize = 10 ;
@@ -141,7 +147,7 @@ function show_centroid_plots()
141
147
[~ , ~ , infos_sgd , options_sgd ] = Riemannian_svrg(problem , Uinit , options );
142
148
143
149
144
- % Run SVRG
150
+ % R- SVRG
145
151
clear options ;
146
152
options.verbosity = 1 ;
147
153
options.batchsize = 10 ;
@@ -158,7 +164,7 @@ function show_centroid_plots()
158
164
[~ , ~ , infos_svrg , options_svrg ] = Riemannian_svrg(problem , Uinit , options );
159
165
160
166
161
- % Run SRG
167
+ % R- SRG
162
168
clear options ;
163
169
options.verbosity = 1 ;
164
170
options.batchsize = 10 ;
@@ -187,7 +193,7 @@ function show_centroid_plots()
187
193
[~ , ~ , infos_srg_plus , options_srg_plus ] = Riemannian_srg(problem , Uinit , options );
188
194
189
195
190
- % Calculate # of gradient evaluations
196
+ % calculate # of gradient evaluations
191
197
num_grads_sd = (1 : length([infos_sd .cost ])) - 1 ; % N*options_sd.maxiter;
192
198
num_grads_cg = (1 : length([infos_cg .cost ])) - 1 ; % N*options_sd.maxiter;
193
199
num_grads_sgd = ceil(options_sgd .maxinneriter / N )*((1 : length([infos_sgd .cost ])) - 1 ); % options.maxepoch*(options_sgd.maxinneriter);
@@ -206,7 +212,7 @@ function show_centroid_plots()
206
212
207
213
208
214
209
- %% Plots
215
+ %% plots
210
216
fs = 20 ;
211
217
212
218
% Optimality gap (Train loss - optimum) versus #grads/N
0 commit comments