-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActiveDiverseMultitask.m
1812 lines (1733 loc) · 65.4 KB
/
ActiveDiverseMultitask.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [ALresult,model_set,Y_set]= ActiveDiverseMultitask(warmStart, Model, learningparams)
global cnstData
% This function and ActiveCRSemiSVM03 have exactly the same code. But
% there is two copies of them. I must delete unrelevant code from each of
% them.
ALresult.active = true;
sw = 2;%%Doing Diverse subTask SDP Active Learning
initL = cnstData.initL;
unlabeled = cnstData.unlabeled;
n_l = cnstData.n_l;
n_u = cnstData.n_u;
batchSize = cnstData.batchSize;
n_o = cnstData.n_o;
lambda = learningparams.lambda;
Yl = cnstData.Yl;
labeled = initL;
n_l = size(labeled,1);
aln_u = n - n_l; % all unlabeled data
% select only n_u points from unlabled data
n_u = aln_u; % manually set unlabeled data
unlabeleda= setdiff(1:n,labeled)';
YfChecka = yTrain(unlabeleda)';
yuforsel = unlabeleda.* YfChecka;
ulindexp = yuforsel(yuforsel>=0)';
np = floor(n_u/2);
if size(ulindexp,2)> np,
ulindexp = ulindexp(1:np);
end
ulindexn = yuforsel(yuforsel<=0);
ulindexn = abs(ulindexn(1:(n_u-np)))';
unlabeled = sort([ulindexp,ulindexn]');
YfCheck = yTrain(unlabeled);
queryDup = unlabeled;
if n_u==0
return
end
n_q = n_u;
%% initialize variable q for querying randomly
q = rand(n_q,1);
%% Make Kernel matrices of labeled,unlabeled and query data
% (data that will be queried from)
Kll = ModelInfo.Kernel([initL'],[initL']);
Kuu = ModelInfo.Kernel([unlabeled'],[unlabeled']);
Klu = ModelInfo.Kernel([initL'],[unlabeled']);
Kqq = Kuu;
Klq = Klu;
Kuq = Kuu;
switch sw
case 1 % Convex Relax Semi-supervised SVM
[q,A]= ActiveConvexRelaxSemiSVM(Kll,Klu,Kuu,Yl,n_l,n_u,lambda);
case 2 % Diverse subTask
T = 1;% number of sub tasks
trainOptions.lambda=lambda;
trainOptions.muPar =0.1;
%% select subtasks data
subTaskdata = selectsubtaskData(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,T);
%% train subtasks
[q,model_set,Y_set]= diverseSubTaskAL(subTaskdata,trainOptions);
end
ALresult.q = q;
end
function [q,A]= ActiveConvexRelaxSemiSVM(Kll,Klu,Kuu,Yl,n_l,n_u,lambda)
% This function minimzes the SDP Objective function of Convex Relaxation of
% Semisupervised SVM using Alternating minimization
% It is changed at 93/11/25 in order to use method of paper: "A hybrid
% algorithm for convex semidefinite optimization"
%% comment:Finding optimal with search to compare result
% [qi,OPTMAT,ZA]=findOptimalWithSearch(Kll,Klu,Kuu,Yl,n_l,n_u,lambda)
%% Initializing Q: the subset of unlabeled data to query from
% Assuming Q = U, i.e, Using all unlabeled data for querying, instead
% of using only a part of unlabeled data searching for query points
n_q = n_u; % consider all of unlabeled data for selecting query
bSize = 2;
g = 0; % For now!
%% Initialize some constants
ONEA = ones(n_l+n_u+n_q,1);
ONEL = ones(n_l,1);
ONED = [ones(n_l+n_u,1);zeros(n_q,1)];
ONEU = ones(n_u,1);
ONEQ = ones(n_q,1);
ONEQMATRIX = ONEQ*ONEQ';
%% Prepare Kernel Matrix
Klq = Klu;
Kqq = Kuu;
Kuq = Kuu;
%% Initalize starting point of (query,Lables)for Alternating Minimization
q = bSize*ones(n_u,1)/n_u;
% initialize label for unlabled data randomly
% use it for making label matrix A
Yu =sign(-1+2*rand(n_u,1));
Ya = [Yl;Yu;ONEQ];
AMatrix = Ya*Ya';
%% Starting Alternating minimization Loop for query and (Learning,Lables)
for i=1:4
%% comment: Some previous code to Optimizing Directly beta,eta and A()
% qc = q;
% goto function: OptimizeR_beta_eta
%% Fix q and ADMM Optimizing Semi-supervised SVM(Learning,Lables)
qc = q;
acceptableError = 2;% for controling error if necessary
[AMatrix,beta_Var,eta_Var]=ADMMOpt_SemiSVM03(acceptableError,Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,AMatrix);
%% Fix (Learning,Lables) and Optimizing to find q: query point(s)
% the following function will do the same work
%[q,A]=UpdateQuery(n_l,n_u,Kll,Klu,Kuu,eta_Varc,beta_Varc);
eta_Varc=eta_Var;
beta_Varc=beta_Var;
cvx_begin sdp
variable A_uu(n_u,n_u)% lable matrix for unlabeled data
variable A_uq(n_u,n_q)% lable matrix for unlabeled and query data
variable A_lu(n_l,n_u)% lable matrix for labeled and query data
variable q(n_q,1) % query variable, the largest elements are for querying
variable tVar % objective function
expression K % Kernel Matrix as a whole
expression A % Lable Matrix as a whole
expression ASmall1
expression ASmall2
expression r_q
expression p_q
r_q=[ONEL;1-q;q];
p_q=[zeros(n_l+n_u,1);q];
K = [Kll,Klu,Klq;Klu',Kuu,Kuq;Klq',Kuq',Kqq];
% This is the lable matrix which we want to estimate it's
% unlabeled part
A = [Yl*Yl',A_lu,Yl*ONEQ';A_lu',A_uu,A_uq;ONEQ*Yl',A_uq',ONEQMATRIX];
ASmall1 = [Yl*Yl',A_lu;A_lu',A_uu];
ASmall2 = [A_uu,A_uq';A_uq,ONEQMATRIX];
% Declare Optimization problem for CVX
minimize (tVar)
subject to
0 <= q <=1;
%A>=0;
ASmall1>=0;
ASmall2>=0;
q'*ONEQ==bSize;
diag(A_uu)==ONEU;
[K .* A,ONED-beta_Varc+eta_Varc;(ONED-beta_Varc+eta_Varc)',2*(tVar-beta_Varc'*r_q-eta_Varc'*p_q)/lambda ]>=0;
cvx_end
end
end
function [AMatrix,beta_Var,eta_Var]=ADMMOpt_SemiSVM02(acceptableError,Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,AMatrix)
% This function attempts to optimizes Semi-supervised SVM using AM(
% Alteranting Minimzation). But unfortunately, the dual derived
% doesn't work with this problem. There is a one-dimensional variable rho which we
% attempt to find it's optimum by changing it's value in a range.
% The Dual and Primal problem doesn't have the same objective function.
% I post this problem in stackexchange.com and cvx forum.
% ADMM_Label032 works correctly but it is very slow. The aim was to
% improve it's speed.
Error = acceptableError +10 ;
[eta_Var,beta_Var] = ADMM_Classifier(Kll,Klu,Kuu,n_l,n_u,lambda,q,AMatrix);
Apre = AMatrix;
[AMatrix1,optval1,dualVars] = ADMM_Label032(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var);
dualVars.rho = dualVars.drho;
stepsize = 0.0001;
i = 1;
while (dualVars.rho > 0 )
[AMatrix2,optval2] = ADMM_Label041(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var,dualVars);
nne = norm(AMatrix2-AMatrix1,'fro')/norm(AMatrix1,'fro')
RHODATA(i,1)=dualVars.rho;
RHODATA(i,2)=nne;
RHODATA(i,3)=optval2;
RHODATA(i,4)=optval1;
dualVars.rho = dualVars.rho - stepsize;
i= i +1;
if ( mod(i,50)==0 )
save('rhodatafile','RHODATA');
end
if ( mod(i,120)==0 )
save('rhodatafile','RHODATA');
end
end
save('rhodatafile','RHODATA');
%% [AMatrix2] = ADMM_Label04(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var,AMatrix1);
% Error12 = norm(AMatrix1-AMatrix2,'fro')/norm(AMatrix1,'fro')
% h = 800;
% while Error > acceptableError
%
% [AMatrix3] = ADMM_Label06(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var,AMatrix1);
% %[AMatrix4] = ADMM_Label07(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var);
% Error12 = norm(AMatrix3-AMatrix2,'fro')/norm(AMatrix1,'fro')
% Error12 = norm(AMatrix3-AMatrix1,'fro')/norm(AMatrix1,'fro')
% h=h+10;
% % Error23 = norm(AMatrix3-AMatrix2,'fro');
% % Error34 = norm(AMatrix3-AMatrix4,'fro');
% end
end
function [AMatrix,beta_Var,eta_Var]=ADMMOpt_SemiSVM03(acceptableError,Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,AMatrix)
%% Optimizing to compute Learning and Lables using Alternating Minimzation
Error = acceptableError +10 ;
for i=1:4
%% Fix A ( Label Matrix ) and Optimizes beta,eta
[eta_Var,beta_Var] = ADMM_Classifier(Kll,Klu,Kuu,n_l,n_u,lambda,q,AMatrix);
Apre = AMatrix;
%% Fix beta,eta and Optimize A( Label Matrix )
% ADMM_Label032 works correctly, but it is very slow, to improve
% speed, I wrote ADMM_LabelSDPConstrReduction.
% Unfortunately, I don't know how to compute primal variable from dual.
% It is needed to check it more, but I think it is correct.
% I must find a way to compute the primal variables.
[AMatrix1,optval1,dualVars] = ADMM_Label032(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var);
dualVars.rho = dualVars.drho;
[AMatrix2,optval2] = ADMM_LabelSDPConstrReduction(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var,AMatrix1);
nne = norm(AMatrix2-AMatrix1,'fro')/norm(AMatrix1,'fro')
AMatrix=AMatrix1;
end
end
%% This function fixes A ( Lable Matrix ) and Optimizes beta and eta
function [eta_Varc,beta_Varc] = ADMM_Classifier(Kll,Klu,Kuu,n_l,n_u,lambda,q,AMatrix)
bSize = 2;
g = 0; % For now!
% Assuming Q = U, i.e, Using all unlabeled data for querying, instead
% of using only a part of unlabeled data searching for query points
%% PREPARE KERNEL MATRIX
Klq = Klu;
Kqq = Kuu;
Kuq = Kuu;
K = [Kll,Klu,Klq;Klu',Kuu,Kuq;Klq',Kuq',Kqq];
n_q = n_u;
%% CONSTANTS
ONEA = ones(n_l+n_u+n_q,1);
ONEL = ones(n_l,1);
ONED = [ones(n_l+n_u,1);zeros(n_q,1)];
ONEU = ones(n_u,1);
ONEQ = ones(n_q,1);
%% PARAMTERS THAT ARE FIXED IN THIS OPTIMIZATION: q,AMatrix
qc = q; % a copy of Q
r_q=[ONEL;1-qc;qc];
p_q=[zeros(n_l+n_u,1);qc];
KA= K.*AMatrix;
KApinv = pinv(KA);
cvx_begin
variable beta_Var(n_l+n_u+n_q,1)
variable theta_Var(n_l+n_u+n_q,1)
variable dtVar
%% DECLARE OPTIMIZATION TO CVX AS A SOCP
minimize (1/2*lambda*dtVar+beta_Var'*(r_q+p_q)+theta_Var'*p_q)
subject to
theta_Var+beta_Var-ONED>=0;
beta_Var>=0;
theta_Var'*KApinv*theta_Var<=dtVar;
cvx_end
%% RETURNING RESULTS: beta_var,eta_var
beta_Varc=beta_Var;
eta_Varc =theta_Var+beta_Var-ONED;
end
%% This function calculates A the lable matrix using SDP formulation
% it has two SDP constraint as the original
function [AMatrix] = ADMM_Label01(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var)
bSize = 2;
g = 0; % For now!
% Assuming Q = U, i.e, Using all unlabeled data for querying, instead
% of using only a part of unlabeled data searching for query points
Klq = Klu;
Kqq = Kuu;
Kuq = Kuu;
n_q = n_u;
ONEA = ones(n_l+n_u+n_q,1);
ONEL = ones(n_l,1);
ONED = [ones(n_l+n_u,1);zeros(n_q,1)];
ONEU = ones(n_u,1);
ONEQ = ones(n_q,1);
qc = q; % a copy of Q
cvx_begin sdp
variable A_uu(n_u,n_u)
variable A_uq(n_u,n_q)
variable A_lu(n_l,n_u)
variable tVar
expression K
expression A
expression r_q
expression p_q
r_q=[ONEL;1-qc;qc];
p_q=[zeros(n_l+n_u,1);qc];
K = [Kll,Klu,Klq;Klu',Kuu,Kuq;Klq',Kuq',Kqq];
% This is the lable matrix which we want to estimate it's
% unlabeled part
A = [Yl*Yl',A_lu,Yl*ONEQ';A_lu',A_uu,A_uq;ONEQ*Yl',A_uq',ONEQ*ONEQ'];
minimize (tVar)
subject to
A>=0
diag(A_uu)==ONEU
eta_Var>=0
beta_Var>=0
[K .* A,ONED-beta_Var+eta_Var;(ONED-beta_Var+eta_Var)',2*(tVar-beta_Var'*r_q-eta_Var'*p_q)/lambda ]>=0;
cvx_end
AMatrix = A;
end
%% This code computes Lable Matrix regulating it's norm in order to minimize the rank of it
%% function [AMatrix,optval,dualVars] = ADMM_Label03(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var)
% This function is deleted from this file it is in ActiveCRSemiSVM02.m
% function [AMatrix,optval] = ADMM_Label031(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var,rho)
% This function is deleted from this file it is in ActiveCRSemiSVM02.m
%% Fix beta,eta and Optimize A (Label Matrix)
function [AMatrix,optval,dualVars] = ADMM_Label032(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var)
bSize = 2;
r = 25;
g = 0; % For now!
% Assuming Q = U, i.e, Using all unlabeled data for querying, instead
% of using only a part of unlabeled data searching for query points
%% Prepare KERNEL MATRIX
Klq = Klu;
Kqq = Kuu;
Kuq = Kuu;
K = [Kll,Klu,Klq;Klu',Kuu,Kuq;Klq',Kuq',Kqq];
n_q = n_u;
n_luq = n_l+n_u+n_q;
%% CONSTANTS
ONEA = ones(n_luq,1);
ONEL = ones(n_l,1);
ONED = [ones(n_l+n_u,1);zeros(n_q,1)];
ONEU = ones(n_u,1);
ONEQ = ones(n_q,1);
e_lq =[ones(n_l,1);zeros(n_u,1);ones(n_q,1)];
I_u =zeros(n_luq,n_luq);
I_u(n_l+1:n_l+n_u,n_l+1:n_l+n_u)=eye(n_u);
Y_lq = [Yl;zeros(n_u,1);ONEQ];
YY_lq = Y_lq*Y_lq';
ALLA = ONEA*ONEA';
CM =e_lq*e_lq'+I_u;
C_lq = YY_lq+I_u;
ONE_lq = [ONEL;zeros(n_u,1);ONEQ];
%% FIXED VARIABLES IN THIS OPTIMIZATION: eta,beta,q
tau = ONED-beta_Var+eta_Var;
qc = q;
r_q=[ONEL;1-qc;qc];
p_q=[zeros(n_l+n_u,1);qc];
tau = ONED-beta_Var+eta_Var;
m=2/lambda*(beta_Var'*r_q+eta_Var'*p_q);
%% CVX
cvx_precision low
cvx_begin sdp
variable A_uu(n_u,n_u) symmetric
variable A_uq(n_u,n_q)
variable A_lu(n_l,n_u)
variable A_lq(n_l,n_q)
variable A_qq(n_q,n_q) symmetric
variable A_ll(n_l,n_l) symmetric
variable tVar
dual variable drho;
dual variable U_uu;
dual variable Z;
dual variable T;
dual variable U;
expression B
expression A
% This is the lable matrix which we want to estimate it's
% unlabeled part
% A = [Yl*Yl',A_lu,Yl*ONEQ';A_lu',A_uu,A_uq;ONEQ*Yl',A_uq',ONEQ*ONEQ'];
A = [A_ll,A_lu,A_lq;A_lu',A_uu,A_uq;A_lq',A_uq',A_qq]; % LABEL MATRIX AS A WHOLE
B = [Yl*Yl',Yl*ONEQ';ONEQ*Yl',ONEQ*ONEQ'];
%% DECLARE OPTIMIZATION PROBLEM TO CVX
minimize (tVar)
subject to
T:A>=0;
U:[A_ll,A_lq;A_lq',A_qq]==B;
Z:[K .* A,ONED-beta_Var+eta_Var;(ONED-beta_Var+eta_Var)',2*tVar/lambda-m ]>=0;
U_uu:diag(A_uu)==ONEU;
drho: norm(A,'fro')<=r;
cvx_end
%% RETURN RESULTS
optval = cvx_optval;
AMatrix = A;
lind = 1:n_l; qind=n_l+1:n_l+n_q;
U2=[U(lind,lind),zeros(n_l,n_u),U(lind,qind);zeros(n_u,n_l),diag(U_uu),zeros(n_u,n_q);U(qind,lind),zeros(n_u,n_u),U(qind,qind)];
U2 = -U2;% !!! CVX returns equality constraint parameters negatively
dualVars.drho=drho;
dualVars.U_uu = U_uu;
dualVars.U = U2; % !!! CVX returns equality constraint parameters negatively
dualVars.Z=Z;
dualVars.T=T;
sn=size(dualVars.Z,1)-1;
X=dualVars.Z(1:sn,1:sn);
x=dualVars.Z(1:sn,sn+1);
end
%% This function doesnot worked correctly and I don't know why?!!!
function [AMatrix,optval] = ADMM_Label041(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var,dualVars)
rho = dualVars.rho;
bSize = 2;
r = 25;
g = 0; % For now!
% Assuming Q = U, i.e, Using all unlabeled data for querying, instead
% of using only a part of unlabeled data searching for query points
Klq = Klu;
Kqq = Kuu;
Kuq = Kuu;
n_q = n_u;
n_luq=n_l+n_u+n_q;
ONEA = ones(n_l+n_u+n_q,1);
ONEL = ones(n_l,1);
ONED = [ones(n_l+n_u,1);zeros(n_q,1)];
ONEU = ones(n_u,1);
ONEQ = ones(n_q,1);
K = [Kll,Klu,Klq;Klu',Kuu,Kuq;Klq',Kuq',Kqq];
tau = ONED-beta_Var+eta_Var;
e_lq =[ones(n_l,1);zeros(n_u,1);ones(n_q,1)];
I_u =zeros(n_luq,n_luq);
I_u(n_l+1:n_l+n_u,n_l+1:n_l+n_u)=eye(n_u);
Y_lq = [Yl;zeros(n_u,1);ONEQ];
YY_lq = Y_lq*Y_lq';
ALLA = ONEA*ONEA';
CM =e_lq*e_lq'+I_u;
C_lqu = YY_lq+I_u;
normClqu = norm(C_lqu,'fro')
stepsize = 0.1;
epsgrad = 0.1;
rhogradz= 1;
qc = q; % a copy of Q
r_q=[ONEL;1-qc;qc];
p_q=[zeros(n_l+n_u,1);qc];
m=2/lambda*(beta_Var'*r_q+eta_Var'*p_q);
cvx_begin sdp
variable U(n_luq,n_luq) symmetric
variable x(n_luq,1)
variable tb
X = semidefinite(n_luq);
T = semidefinite(n_luq);
minimize (1/(4*rho)*square(tb)+trace(U'*C_lqu)+2*x'*tau+rho*r-1/2*lambda*m)
subject to
[X,x;x',lambda/2]>=0;
norm(T+X.*K-U.*CM,'fro')<= tb;
T+X.*K-U.*CM >=0;
cvx_end
optval = cvx_optval;
AMatrix =1/(2*rho)*(T+X.*K-U.*CM);
rhogradz = -norm(T+X.*K-U.*CM,'fro')^2/(4*rho^2)+r;
rhonext = 1/2*norm(T+X.*K-U.*CM,'fro')*sqrt(1/r);
%rho = rhonext;
% if rhogradz < 0
% rho = rho+stepsize;
% else
% rho = rho-stepsize;
% end
end
%% Optimization based on converting two sdp constraints to one. The problem is I don't know how to find the primal variables
function [AMatrix,optval] = ADMM_LabelSDPConstrReduction(Kll,Klu,Kuu,Yl,n_l,n_u,lambdal,q,beta_Var,eta_Var,AMatrix)
%% Optimize :max_(?,X)f(X,?)= m+(2?)^(1/2) (<X,D_?k>-?)^(1/2)-<X,D_lq>-<X,D_u>
% This objective function is the dual of the original ADMM_Label Objective
% by removing one sdp constraint of the original problem.
% This method is converts two sdp constriants in original problem to one problem and the uses a method
% based on the paper "A Hybrid algorithm for convex semidefinite Optimiztation".
%% DEFINE CONSTANTS
[bSize,r,g,K,tau,set_Dl,set_Du,set_Dq]=defineConsts(Kll,Klu,Kuu,Yl,n_l,n_u,lambdal,q,beta_Var,eta_Var);
% ??^T?K= U D_{?k}^(+-) U^T
% D_?k=max {0,D_?k^(+,-)}
% D_lq :D_lq=2?_(i,j?D_l?D_Q,i<j)E_ij/(U^T E_ij U) y_i* y_j %
% Is this coefficient(2) is correct?
% D_u :D_u=2?_(i?D_u)E_ii/(U^T E_ii U)
% D_u is equal to I_u;
%% DEFINE GLOBAL VARIABLES
global lambda
global C_D
global D_luq
global D_u
global theta
global V_i
global v_i
%%
lambda=lambdal;
n_q = size(set_Dq,2);
TA=tau*tau';
% TAK=TA./K;
% [U,D_TKMN]=eig(TAK);
% C_D2=U*D_TKMN*U';
% norm(TAK-C_D2,'fro')
% Zd=zeros(size(K,1));
% D_TK = bsxfun(@max,D_TKMN,Zd); % D_TK=max(D_TKMN,0)
% C_D=U*D_TK*U';
% norm(C_D-C_D','fro')
% C_D=(C_D+C_D')/2;
% p=minsgreater(AMatrix,C_D);
% it's better to make near zero elements of U equal to zero
%% Constructing Constant Matrix D_lq
C_D=TA;
Yset=[Yl;zeros(n_u,1);ones(n_q,1)];
E_ij=zeros(size(K,1));
D_luq=Yset*Yset';
D_luq(n_l+1:n_l+n_u,n_l+1:n_l+n_u)=eye(n_u); % make diagonal elements of u equal to 1
D_luq=D_luq .* K;
c=sqrt(2*lambda);
%% OPTIMIZE THIS SIMPLER PROBLEM USING CVX IN ORDER TO COMPARE RESULTS
n = size(D_luq,1);
cvx_begin
variable X(n,n) semidefinite
minimize( trace(X'*D_luq)-c*sqrt(trace(X'*C_D)) )
cvx_end
%% OPTIMIZE THE SAME PROBLEM USING METHOD OF PAPER "A Hybrid ....."
theta =0 ; % we will prove that optimal theta is 0
%% These parameters are for minFunc
maxFunEvals = 25;
options = [];
options.display = 'none';
options.maxFunEvals = maxFunEvals;
options.Method = 'lbfgs';
% now we must find a vector v_0 for initialization such that v_0=argmin<v_0*v_0',D_lq+D_u>
% this is equal to eigenvector corresponding to min eigen value.
%% Initial point using smallest eigenvector
[v_0,d_0]=eigs(D_luq,1); % the smalleset eigenvector
f_i= 10000000;% Inf
V_i=v_0;
theta = 0 ;
%% Starting optimization loop
converged = false;
while ~converged
%% compute v_i= approxEV(-grad(f(V_i*V_i',eps))
% I must write function grad_f.
[v_i,e_v] = eigs(grad_f(V_i,eps,lambda,C_D,D_luq,theta),1);
%% solve min_c1,c2 f(c1*V_i*V_i'+c2*v_i*v_i') s.t.
% c1,c2 >=0
X_i=V_i*V_i';
X_1=v_i*v_i';
c1= trace(X_i*D_luq');
c2=trace(X_1*D_luq');
c3=trace(X_i*C_D');
c4=trace(X_1*C_D');
g_luq=[c1,c2]';
g_CD=[c3,c4]';
c=minObjective(lambda,g_luq,g_CD);
%[c,f_ip,exitflag,str]=minFunc(@f_minComb2d,[0.1 0.1]',options);
%[c,f_ip,exitflag,str]=minFunc(@f_combDirection,[0.1 0.1]',options);
%% UPDATE V_ip
V_ip = [sqrt(c(1))*V_i,sqrt(c(2))*v_i];
%set V_(i+1)=[sqrt(\alpha).V_i,sqrt(\beta).v_i]
% run nonlinear update,improve V_(i+1) by finding a local minimum of
% f(V*V') wrt V starting with V_(i+1)
% V_(i+1) = minFunc()
if abs(f_ip-f_i)<eps , converged = true; end
f_i = f_ip;
V_i = V_ip;
% until approximate guarantee has been reached
end
X = V_i*V_i';
%% HOW TO COMPUTE PRIMAL VARIABLES?...
end
function [c]=minObjective(lambda,gu,gc)
gamma=min(gu(1)/gc(1),gu(2)/gc(2));
cst=sqrt(2*lambda);
t=cst/(2*gamma);
end
function [ObVal,df,ddf]=f_minComb2d(d)
global V_i
global v_i
global C_D
global D_luq
%global theta
global lambda
X_i=V_i*V_i';
X_1=v_i*v_i';
c1= trace(X_i*D_luq');
c2=trace(X_1*D_luq');
c3=trace(X_i*C_D');
c4=trace(X_1*C_D');
g_luq=[c1,c2]';
g_CD=[c3,c4]';
ObVal = g_luq'*d-sqrt(2*lambda)*sqrt(g_CD'*d);
df = g_luq-0.5*sqrt(2*lambda)*g_CD/sqrt(g_CD'*d);
ddf =0.25*sqrt( 2*lambda)*g_CD*g_CD'/(sqrt(g_CD'*d)*(g_CD'*d));
end
%% This function computes objective function, also gradient and hessian of it
function [ObVal,df,ddf]=f_combDirection(d)
global V_i
global v_i
global C_D
global D_luq
global theta
global lambda
X=d(1)*V_i*V_i'+d(2)*v_i*v_i';
ObVal = sqrt(2*lambda)*sqrt(trace(X'*C_D)-theta)-trace(X'*D_luq);
df = 1/2 *sqrt( 2*lambda)* C_D/sqrt(trace(X'*C_D)-theta)-D_luq;
ddf =-0.25*sqrt( 2*lambda)*C_D*C_D/(sqrt(trace(X'*C_D)-theta)*(trace(X'*C_D)-theta));
% Make it negative because we want to maximize the objective function
ObVal = -ObVal;
df = -df;
ddf = -ddf;
end
%% gradient of Objective function is ?_X f(X,?)= 1/2 (2?)^(1/2) D_?k/(<X,D_?k>-?)^(1/(2 ))-D_lq-D_u
function [G]=grad_f(V_i,eps,lambda,C_D,D_luq,theta)
X=V_i*V_i';
G = D_luq-1/2 *sqrt( 2*lambda)* C_D/sqrt(trace(X'*C_D)-theta);
end
%% DEFINING CONSTANTS
function [bSize,r,g,K,tau,set_Dl,set_Du,set_Dq]=defineConsts(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var)
% this function stores and computes the constants within the calling
% function.
bSize = 2;
r = 25;
g = 0; % For now!
% Assuming Q = U, i.e, Using all unlabeled data for querying, instead
% of using only a part of unlabeled data searching for query points
Klq = Klu;
Kqq = Kuu;
Kuq = Kuu;
n_q = n_u;
n_luq=n_l+n_u+n_q;
ONEA = ones(n_l+n_u+n_q,1);
ONEL = ones(n_l,1);
ONED = [ones(n_l+n_u,1);zeros(n_q,1)];
ONEU = ones(n_u,1);
ONEQ = ones(n_q,1);
K = [Kll,Klu,Klq;Klu',Kuu,Kuq;Klq',Kuq',Kqq];
tau = ONED-beta_Var+eta_Var;
set_Dl = 1:n_l;
set_Dq = n_l+n_u+1:n_luq;
set_Du = n_l+1:n_u;
end
%% THIS FUNCTION DOES NOT WORKED MAY BE THE DUAL PROBLEM DERIVED INCORRECTLY
function [AMatrix] = ADMM_Label07(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,q,beta_Var,eta_Var)
bSize = 2;
r = 25;
g = 0; % For now!
% Assuming Q = U, i.e, Using all unlabeled data for querying, instead
% of using only a part of unlabeled data searching for query points
Klq = Klu;
Kqq = Kuu;
Kuq = Kuu;
n_q = n_u;
n_luq=n_l+n_u+n_q;
ONEA = ones(n_l+n_u+n_q,1);
ONEL = ones(n_l,1);
ONED = [ones(n_l+n_u,1);zeros(n_q,1)];
ONEU = ones(n_u,1);
ONEQ = ones(n_q,1);
K = [Kll,Klu,Klq;Klu',Kuu,Kuq;Klq',Kuq',Kqq];
tau = ONED-beta_Var+eta_Var;
TTAu=tau*tau';
e_lq =[ones(n_l,1);zeros(n_u,1);ones(n_q,1)];
I_u =zeros(n_luq,n_luq);
I_u(n_l+1:n_l+n_u,n_l+1:n_l+n_u)=eye(n_u);
Y_lq = [Yl;zeros(n_u,1);ONEQ];
YY_lq = Y_lq*Y_lq';
ALLA = ONEA*ONEA';
CM =e_lq*e_lq'+I_u;
C_lq = YY_lq+I_u;
%normYYI = norm(C_lq,'fro')
rho =0.0028;
h =42.0;
qc = q; % a copy of Q
r_q=[ONEL;1-qc;qc];
p_q=[zeros(n_l+n_u,1);qc];
epstol = 0.000001;
m=2/lambda*(beta_Var'*r_q+eta_Var'*p_q);
%this piece of code implements the alternating direction of multipliers for SDP problem PQ6 page 74 of my notes
X=rand(n_luq,n_luq);
U=rand(n_luq,n_luq);
X=(X+X')/2;
err = epstol +1000;
while err > epstol
XP=Prox_Snp(X);
norm(X-XP,'fro')
U_CM=2*XP.*K.*CM-2*rho*C_lq;
norm(U_CM-U_CM','fro')
XPre=X;
X=0.5*U_CM./K+rho/(2*h)*TTAu./K./K;
rhogradz = -norm(2*X.*K-U_CM,'fro')^2/(4*rho^2)+r;
rho = rhogradz;
norm(X-X','fro')
err = norm(X-XPre,'fro')
end
AMatrix =1/(2*rho)*(2*X.*K-U.*CM);
end
%% Projection of a matrix on Semidefinite Cone
function XP=Prox_Snp(X)
[V,D]=eig(X);
D_p = D;
for i=1:size(X,1)
if D_p(i,i)<0
D_p(i,i)=0;
end
end
XP = V*D_p*V';
end
%% Global search Only for test
% finds the global optimial to see which instance is the best query.
% it's a good idea to compare classification accuracy when this instance
% queried instead of the algorithm query.
function [qi,OPTMAT,ZA]=findOptimalWithSearch(Kll,Klu,Kuu,Yl,n_l,n_u,lambda)
bSize = 1;
g = 0; % For now!
% Assuming Q = U, i.e, Using all unlabeled data for querying, instead
% of using only a part of unlabeled data searching for query points
Klq = Klu;
Kqq = Kuu;
Kuq = Kuu;
n_q = n_u;
q = bSize*ones(n_u,1)/n_u;
ONEA = ones(n_l+n_u+n_q,1);
ONEL = ones(n_l,1);
ONED = [ones(n_l+n_u,1);zeros(n_q,1)];
ONEU = ones(n_u,1);
ONEQ = ones(n_q,1);
OptVal = 100000000000000;
qi =0 ;
for i=1:n_q
qc = zeros(n_q,1);qc(i)=1;
cvx_begin
variable A_uu(n_u,n_u)
variable A_uq(n_u,n_q)
variable A_lu(n_l,n_u)
variable beta_Var(n_l+n_u+n_q,1)
variable eta_Var(n_l+n_u+n_q,1)
variable tVar
expression K
expression A
expression r_q
expression p_q
r_q=[ONEL;1-qc;qc];
p_q=[zeros(n_l+n_u,1);qc];
K = [Kll,Klu,Klq;Klu',Kuu,Kuq;Klq',Kuq',Kqq];
% This is the lable matrix which we want to estimate it's
% unlabeled part
A = [Yl*Yl',A_lu,Yl*ONEQ';A_lu',A_uu,A_uq;ONEQ*Yl',A_uq',ONEQ*ONEQ'];
minimize (tVar)
subject to
A>=0;
diag(A_uu)==ONEU;
eta_Var>=0;
beta_Var>=0;
[K .* A,ONED-beta_Var+eta_Var;(ONED-beta_Var+eta_Var)',2*(tVar-beta_Var'*r_q-eta_Var'*p_q)/lambda ] >=0;
cvx_end
OPTMAT (i) = cvx_optval;
ZA = A;
if cvx_optval < OptVal
OptVal = cvx_optval;
qi = i;
end
end
end
function [p]=minsgreater(AMatrix,C_D)
p=100;
plow=0;
z=zeros(size(C_D,1),1);
phigh=100;
while plow<phigh
pMid=(plow+phigh)/2;
CompMatrix=AMatrix-p*C_D;
e=eig(CompMatrix);
c=bsxfun(@lt,e,z);
if c
plow = pMid;
else
phigh=pMid;
end
end
end
%% Select subTasks data for Diverse Subtask AL
% This function splits data to T subsets. It splits labeled data
% redundantly,but divides unlabeled data to T disjoint sets.
function subTaskdata = selectsubtaskData(Kll,Klu,Kuu,Yl,n_l,n_u,lambda,T)
%% select Labeled; A labeled may be selected more than once is redundant data in tasks
% number of Tasks:T
muPar = -1; % set to <0 to auto determine the amount of diversity
sample_pLabeled = 0.8; % random sample percentage (value 1 was used in the experiments for the paper)
% prepare index of training instances for each SVM
% such that every set has atleast one instance with any label
index_set_Labeled = cell(T,1);
for t = 1:T
rp = randperm(n_l);
rpp = find(Yl==1);
rpn = find(Yl==-1);
slp=round(sample_pLabeled*n_l/2);
sln=floor(sample_pLabeled*n_l)-slp;
if slp < 1 ,slp=1;end
if sln < 1 ,sln=1;end
idxlablepositive= rpp(1:slp);
idxlablenegative=rpn(1:sln);
index_set_Labeled{t,1}=[idxlablepositive,idxlablenegative];
taskn_l(t)=size(index_set_Labeled{t,1},2);
end
disp (['train .... with T=', num2str(T), ' mu=', num2str(muPar), ' p=', num2str(sample_pLabeled)])
%% Select Unlabeled data; each unlabeled data is selected only once
sample_pUnLabeled = 1/T; % random sample percentage (value 1 was used in the experiments for the paper)
tUnlbsize=floor(n_u/T);
index_set_UnLabeled = cell(T,1);
rp = randperm(n_u);
st=1;
for t = 1:T
en=st+tUnlbsize-1;
if en > n_u, en=n_u; end
if t==T, en=n_u;end % we must select all unlabeled data
index_set_UnLabeled{t,1} = rp(st:en);
taskn_u(t)=size(index_set_UnLabeled{t,1},2);
st=en+1;
end
%% prepare Kernels for each tasks
task_Kll = cell(T,1);
task_Klu = cell(T,1);
task_Kuu = cell(T,1);
for t=1:T
lbindex=index_set_Labeled{t,1};
ulbindex=index_set_UnLabeled{t,1}
task_Yl{t,1}=Yl(lbindex);
task_Kll{t,1}=Kll(lbindex,lbindex);
task_Klu{t,1}=Klu(lbindex,ulbindex);
task_Kuu{t,1}=Kuu(ulbindex,ulbindex);
end
subTaskdata.index_set_UnLabeled=index_set_UnLabeled;
subTaskdata.index_set_Labeled=index_set_Labeled;
subTaskdata.task_Kll=task_Kll;
subTaskdata.task_Klu=task_Klu;
subTaskdata.task_Kuu=task_Kuu;
subTaskdata.T = T;
subTaskdata.Kll=Kll;
subTaskdata.Klu=Klu;
subTaskdata.Kuu=Kuu;
subTaskdata.n_l=n_l;
subTaskdata.n_u=n_u;
subTaskdata.Yl=Yl;
subTaskdata.taskn_l=taskn_l;
subTaskdata.taskn_u=taskn_u;
subTaskdata.task_Yl=task_Yl;
end
%% learning and active learning for all subTasks
function [q,model_set,Y_set]=diverseSubTaskAL(subTaskdata,trainOptions)
%% Initializing Q: the subset of unlabeled data to query from
n_u = subTaskdata.n_u; % consider all of unlabeled data for selecting query
n_q=n_u;
n_l=subTaskdata.n_l;
Yl=subTaskdata.Yl;
bSize = 1;
g = 0; % For now!
%% Initialize some constants
ONEQ = ones(n_q,1);
%% Initalize starting point of (query,Lables)for Alternating Minimization
q = bSize*ones(n_u,1)/n_u;
% initialize label for unlabled data randomly
% use it for making label matrix A
Yu =sign(-1+2*rand(n_u,1));
Ya = [Yl;Yu;ONEQ];
AMatrix = Ya*Ya';
%% Starting Alternating minimization Loop for query and (Learning,Lables)
for i=1:4
%% Fix q and Optimize Semi-supervised SVM(Learning,Lables)
qc = q;
[model_set,Y_set]= trainDiverseSubTask(subTaskdata,trainOptions,qc,AMatrix);
%% Fix (Learning,Lables) and Optimizing to find q: query point(s)
% the following function will do the same work
[q]=OptQuerySubTask(subTaskdata,trainOptions,model_set,Y_set,q,bSize);
end
end
%% train Diverse subTask Semi-supervised Learning
function [model_set,Y_set]= trainDiverseSubTask(subTaskdata,trainOptions,qc,AMatrix)
T=subTaskdata.T;
n_l=subTaskdata.n_l;
n_u=subTaskdata.n_u;
n_q=n_u;
n=n_l+n_u+n_q;
%% initialize
model_set=cell(T,1);
indep=true;
linearterm=0;w0_norm=0;
linearterm = zeros(n,T);
alpha_set = zeros(n,T);
Y_set =zeros(n,T);
Kll=subTaskdata.Kll;Klu=subTaskdata.Klu;Kuu=subTaskdata.Kuu;Klq=Klu;Kuq=Kuu;Kqq=Kuu;
K=[Kll,Klu,Klq;Klu',Kuu,Kuq;Klq',Kuq',Kqq];
%% train each task independently
lambda_t=1;
muParInd=0;
for t=1:T
[model_set{t},~]=train_divtask(t,subTaskdata,Y_set(:,t),trainOptions,qc,indep,model_set,linearterm,w0_norm);
lambda_t = 1;
ind = indexSet(t,subTaskdata);
alpha_set(ind,t) = model_set{t}.alpha_t;
ind_l = indexSet(t,subTaskdata,1);
Y_set(ind,t) = estimateY(t,subTaskdata,model_set{t});
% set estimate y for labeled data equal to given Yl
Yl = subTaskdata.task_Yl{t,1};
Y_set(ind_l,t) = Yl;
end
lambda_t=1;
%% train all tasks simultaneously
muPar=trainOptions.muPar;
converged=false;
iter=1;
indep=false;
while ~converged && iter < 20
for t=1:T
ind=indexSet(t,subTaskdata);
% computing linearterm
[linearterm]=complinearterm(t,alpha_set,Y_set,subTaskdata,model_set);
[model_set{t},diff(t)]=train_divtask(t,subTaskdata,Y_set(ind,t),trainOptions,qc,indep,model_set{t},linearterm,muPar);
alpha_set(ind,t) = model_set{t}.alpha_t;
end
sdiff(iter)=sum(diff);
if sdiff(iter) < 0.01
converged = true;
end
iter = iter + 1;
end
%% send information to above em optimization.
% model_set
% Y_set
end
%% train a single subtask either independently or simulataneously
function [model_set,diff]=train_divtask(t,subTaskdata,Ypre,trainOptions,qc,indep,model_set,linearterm,muPar)
rhoPar=1;
%% extract subtask data:n_l,n_u,Kll,Klu,Kuu,Yl
n_l=subTaskdata.taskn_l(t);
n_u=subTaskdata.taskn_u(t);
n_q=n_u;
n=n_l+n_u+n_q;
Kll=subTaskdata.task_Kll{t,1};
Klu=subTaskdata.task_Klu{t,1};
Kuu=subTaskdata.task_Kuu{t,1};
Yl =subTaskdata.task_Yl{t,1};
q_t=qc(subTaskdata.index_set_UnLabeled{t,1});
Klq=Klu;Kuq=Kuu;Kqq=Kuu;
K_tt=[Kll,Klu,Klq;Klu',Kuu,Kuq;Klq',Kuq',Kqq];
T=subTaskdata.T;
tTask=t;
%% is it independently training or simultaneously?
if indep
%% directly optimize with respect to R_t,beta_t,eta_t
% qc ?
muPar=0;
lambda_t=1;
d_t=0%lambda_t;
flag=false;
iter=1;
c_t=1/(lambda_t);
[R_t,beta_t,eta_t,alpha_t]=OptimizeR_beta_eta(n_l,n_u,q_t,K_tt,Yl,c_t,d_t,false);
model_set.eta_t=eta_t;
model_set.beta_t=beta_t;
model_set.R_t=R_t;
model_set.lambda_t=lambda_t;
model_set.alpha_t = alpha_t;
% [alpha_t]=compalpha(t,subTaskdata,model_set,muPar,lambda_t,qc);
%% assume that lambda_t is given. In fact the result is converges towards zero otherwise
% while ~flag && iter < 2
% alpha_pre=alpha_t;
% lambda_t = 1;%max(0,sqrt(alpha_t'*(K_tt.*R_t)*alpha_t)/2-(T-1)*muPar);
% c_t=1/((subTaskdata.T-1)*muPar+lambda_t);
% [R_t,beta_t,eta_t]=OptimizeR_beta_eta(n_l,n_u,q_t,K_tt,Yl,c_t,d_t,true,R_t);
% model_set.eta_t=eta_t;
% model_set.beta_t=beta_t;
% model_set.R_t=R_t;
% [alpha_t]=compalpha(t,subTaskdata,model_set,muPar,lambda_t,qc);
% %%%%%%%%%%%%%%%%
% update the lambda, what is alpha?
% lambda = max(0,sqrt(alpha_t'*(K_tt.*R_t)*alpha_t-4*muPar*alpha'*linearterm+4*muPar^2*w0_norm)/2-(T-1)*muPar);
%
% iter=iter+1;
% if norm(alpha_t-alpha_pre)<10^(-5)
% flag=true;
% end
% end
else
lambda_t=model_set.lambda_t;
c_t=1/((T-1)*trainOptions.muPar+lambda_t);
d_t=0;% assume it is zero, i.e. we don't want to learn lambda_t
%% initialize Yprime equal to Y_t from independent training of subtask
Yprime = Ypre;%
R_t = model_set.R_t;
beta_t = model_set.beta_t;
eta_t = model_set.eta_t;
n_t=size(Yprime,1);
%% Start ADMM process