-
Notifications
You must be signed in to change notification settings - Fork 3
/
bank_10.m
116 lines (100 loc) · 2.9 KB
/
bank_10.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
clear;
for time=1:10
%data preprocessing
%------------------
load('bank.mat');
shuffle_idx=randperm(size(data,1));
data=data(shuffle_idx,:);
y = data(:,63);
data=data(:,2:62);
centered_data = data-mean(data);
%------------------
iter = 1000;
m = size(data,1) %whole datasize
K = 10 %numebr of workers
worker_size_ls=num_dist_data(K, m) ;%decide distributed workers K:number of workers; m:dataset size
[coeff,score,latent,tsquared,explained,mu]=pca(data);
%center the data matrix and allocate the data to workers
D = distr_data(worker_size_ls, centered_data);
num_pcs = 2
rho = repelem([1], num_pcs)
iter = 1000;
[pc_list,pc_cosin_history, z_list, primal_history, dual_history] = admm_pcs(num_pcs, data, D, rho, coeff, iter);
[yang_pc_list, yang_cosin_history, yang_z_list] = yang_pcs(num_pcs, data, coeff, 20);
pc_cosin_history_10{time} = pc_cosin_history
yang_cosin_history_10{time} = yang_cosin_history
primal_history_10{time}=primal_history
dual_history_10{time}=dual_history
end
exp_name='bank'
pc = 2
iter_ls = 0
for time = 1:10
for iter = 1:size(pc_cosin_history_10{time}{pc},2)
if (pc_cosin_history_10{time}{pc}(iter) >= 0.9999)
iter_ls(time) = iter
break
end
end
end
max(iter_ls)
hold on
for time = 1:10
plot(pc_cosin_history_10{time}{pc}(1:end))
end
hold off
title(['PC', num2str(pc), ' Cosine Similarity Convergence plot'])
xlabel('iterations')
ylabel('Cosine Similarity')
xline(max(iter_ls),'--')
xlim([1 30])
ylim([0.5 1.0001])
saveas(gcf,['/Users/weng/Documents/pca_plot2/',exp_name,'_10_pc', num2str(pc),'.png'])
%yang
pc = 2
iter_ls = 0
for time = 1:10
for iter = 1:size(yang_cosin_history_10{time}{pc},2)
if (yang_cosin_history_10{time}{pc}(iter) >= 0.9999)
iter_ls(time) = iter
break
end
end
end
max(iter_ls)
hold on
for time = 1:10
plot(yang_cosin_history_10{time}{pc}(1:20))
end
hold off
xline(max(iter_ls),'--')
title(['PC', num2str(pc),' Cosine Similarity Convergence plot'])
xlabel('iterations')
ylabel('Cosine Similarity')
xlim([1 20])
saveas(gcf,['/Users/weng/Documents/pca_plot2/',exp_name,'_10_yangpc', num2str(pc), '.png'])
%primal residaul
hold on
for time = 1:10
plot(primal_history_10{time}{pc}(1:end))
end
hold off
xlim([1 15])
title(['PC', num2str(pc), ' Primal Residual Convergence Plot'])
xlabel('iterations')
ylabel('Primal Residual')
% ylim([0 10])
saveas(gcf,['/Users/weng/Documents/pca_plot2/',exp_name,'_10_pc', num2str(pc),'_prires.png'])
%dual
hold on
for time = 1:10
plot(dual_history_10{time}{pc}(1:end))
end
hold off
xlim([1 250])
title(['PC', num2str(pc), ' Dual Residual Convergence Plot'])
xlabel('iterations')
ylabel('Dual Residual')
saveas(gcf,['/Users/weng/Documents/pca_plot2/',exp_name,'_10_pc', num2str(pc),'_dualres.png'])
save('exp_bank_10_0525')
load('exp_bank_10_0525')