-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyMatA.m
372 lines (367 loc) · 13 KB
/
MyMatA.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
function A = MyMatA(eidx, d)
lambda=1E-6;
switch eidx
case 1
error('matrix A is defined!');
case 2
error('matrix A is defined!');
case 3
% A has block size2 on the diagonal
% with noise off the diagonal
e0 = [1;0];
e1 = e0(:,ones(ceil(d/2),1));
e1 = reshape(e1 ,numel(e1),1);
A = sprandsym(d,3/d,0.5,1);
A_off = -A./(A+eps);
A = spdiags([-e1,e1*0,-[0;e1(1:end-1)]],[-1,0,1],A_off);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 4
% A has block size2 on the diagonal with shift
% with noise off the diagonal
e0 = [0;1]; % change from [0,1] to [1,0] as shift
e1 = e0(:,ones(ceil(d/2),1));
e1 = reshape(e1 ,numel(e1),1);
A = sprandsym(d,3/d,0.5,1);
A_off = -A./(A+eps);
A = spdiags([-e1,e1*0,-[0;e1(1:end-1)]],[-1,0,1],A_off);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 5
error('matrix A is defined!');
case 6
error('matrix A is defined!');
case 7
% A has block size3 on the diagonal
% with noise off the diagonal
e0 = [1;1;0];
e1 = e0(:,ones(ceil(d/3),1));
e1 = reshape(e1 ,numel(e1),1);
e0 = [1;0;0];
e2 = e0(:,ones(ceil(d/3),1));
e2 = reshape(e2 ,numel(e2),1);
A = sprandsym(d,3/d,0.5,1);
A_off = -A./(A+eps);
A = spdiags([-e2,-e1,e1*0,-[0;e1(1:end-1)],-[0;0;e2(1:end-2)]],...
[-2,-1,0,1,2],A_off);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 8
% A has block size3 on the diagonal with shift
% with noise off the diagonal
e0 = [0;1;1];
e1 = e0(:,ones(ceil(d/3),1));
e1 = reshape(e1 ,numel(e1),1);
e0 = [0;1;0];
e2 = e0(:,ones(ceil(d/3),1));
e2 = reshape(e2 ,numel(e2),1);
A = sprandsym(d,3/d,0.5,1);
A_off = -A./(A+eps);
A = spdiags([-e2,-e1,e1*0,-[0;e1(1:end-1)],-[0;0;e2(1:end-2)]],...
[-2,-1,0,1,2],A_off);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 9
error('matrix A is defined!');
case 10
error('matrix A is defined!');
case 11
% A has block size4 on the diagonal WITH noise
e0 = [1;1;1;0];
e1 = e0(:,ones(ceil(d/4),1));
e1 = reshape(e1 ,numel(e1),1);
e0 = [1;1;0;0];
e2 = e0(:,ones(ceil(d/4),1));
e2 = reshape(e2 ,numel(e2),1);
e0 = [1;0;0;0];
e3 = e0(:,ones(ceil(d/4),1));
e3 = reshape(e3 ,numel(e3),1);
A = sprandsym(d,3/d,0.5,1);
A_off = -A./(A+eps);
A = spdiags([-e3,-e2,-e1,-[0;e1(1:end-1)],-[0;0;e2(1:end-2)],...
-[0;0;0;e3(1:end-3)]],[-3,-2,-1,1,2,3],A_off);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 100
error('matrix A is defined!');
case 101
error('matrix A is defined!');
case 102
error('matrix A is defined!');
case 103
% A is a tri-diagonal matrix WITH noise
e1 = ones(d,1);
A = sprandsym(d,3/d,0.5,1);
A_off = -A./(A+eps);
A = spdiags([-e1,e1*0,-e1],[-1,0,1],A_off);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 104
% A is a 5-band matrix WITH noise
e1 = ones(d,1);
A = sprandsym(d,3/d,0.5,1);
A_off = -A./(A+eps);
A = spdiags([-e1,-e1,-e1,-e1],[-2,-1,1,2],A_off);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 105
% A is a 7-band matrix WITH noise
e1 = ones(d,1);
A = sprandsym(d,3/d,0.5,1);
A_off = -A./(A+eps);
A = spdiags([-e1,-e1,-e1,-e1,-e1,-e1],[-3,-2,-1,1,2,3],A_off);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 200
% A is a random symmetric matrix
% sparsity 3/d
A = sprandsym(d,3/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 201
% A is a random symmetric matrix
% sparsity 5/d
A = sprandsym(d,5/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 202
% A is a random symmetric matrix
% sparsity 7/d
A = sprandsym(d,7/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 203
% A is a random symmetric matrix
% sparsity 9/d
A = sprandsym(d,9/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 204
% A is a random symmetric matrix
% sparsity 11/d
A = sprandsym(d,11/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 205
% A is a random symmetric matrix
% sparsity 13/d
A = sprandsym(d,13/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 206
% A is a random symmetric matrix
% sparsity 15/d
A = sprandsym(d,15/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 207
% A is a random symmetric matrix
% sparsity 17/d
A = sprandsym(d,17/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 208
% A is a random symmetric matrix
% sparsity 30/d
A = sprandsym(d,30/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 209
% A is a random symmetric matrix
% sparsity 40/d
A = sprandsym(d,40/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A);
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal'+lambda,0,A);
case 300
% A is a random symmetric matrix
% sparsity 3/d
% same with 20X but init is 0.5
A = sprandsym(d,3/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 301
% A is a random symmetric matrix
% sparsity 5/d
% same with 20X but init is 0.5
A = sprandsym(d,5/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 302
% A is a random symmetric matrix
% sparsity 7/d
% same with 20X but init is 0.5
A = sprandsym(d,7/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 303
% A is a random symmetric matrix
% sparsity 9/d
% same with 20X but init is 0.5
A = sprandsym(d,9/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 304
% A is a random symmetric matrix
% sparsity 11/d
% same with 20X but init is 0.5
A = sprandsym(d,11/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 305
% A is a random symmetric matrix
% sparsity 13/d
% same with 20X but init is 0.5
A = sprandsym(d,13/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 306
% A is a random symmetric matrix
% sparsity 15/d
% same with 20X but init is 0.5
A = sprandsym(d,15/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 400
% A is a random symmetric matrix
% sparsity 3/d
% same with 20X but init is 1
A = sprandsym(d,3/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 401
% A is a random symmetric matrix
% sparsity 5/d
% same with 20X but init is 1
A = sprandsym(d,5/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 402
% A is a random symmetric matrix
% sparsity 7/d
% same with 20X but init is 1
A = sprandsym(d,7/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 403
% A is a random symmetric matrix
% sparsity 9/d
% same with 20X but init is 1
A = sprandsym(d,9/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 404
% A is a random symmetric matrix
% sparsity 11/d
% same with 20X but init is 1
A = sprandsym(d,11/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 405
% A is a random symmetric matrix
% sparsity 13/d
% same with 20X but init is 1
A = sprandsym(d,13/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 406
% A is a random symmetric matrix
% sparsity 15/d
% same with 20X but init is 1
A = sprandsym(d,15/d,0.5,1);
A = spdiags(zeros(d,1),0,A);
A = -A./(A+eps);
diagonal = -sum(A)+lambda;
diagonal(diagonal==0)=1;% if sum of row/colomn is 0, set diagonal as 1
A = spdiags(diagonal',0,A);
case 900
error('matrix A is defined!');
case 901
error('matrix A is defined!');
case 902
error('matrix A is defined!');
case 903
c = 0.8;
A = ones(d,d)*c;
A = A + diag(ones(d,1)*(1-c));
[U,~,~] = svd(1-2*rand(d,d));
A = U'*A*U;
A = sparse(A);
end
end