0001 classdef (ConstructOnLoad = true) PCA < handle
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 properties (Access = private)
0137
0138
0139
0140 DATA;
0141 estandar;
0142 model;
0143
0144 Z;
0145 P;
0146 Num;
0147 Num_save;
0148 T;
0149 Landa;
0150 Landai;
0151 sta;
0152 mea;
0153 E;
0154 T2;
0155 LimT2;
0156 LimQ;
0157 metode;
0158 metodee;
0159 treuFM;
0160 conv;
0161 analitic;
0162 structura;
0163
0164 CLimQstd;
0165 CLimQmea;
0166 CLimT2std;
0167 CLimT2mea;
0168
0169 ContMetode;
0170 end
0171
0172
0173
0174
0175
0176 methods
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190 function obj = PCA(data)
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206 z=whos('data');
0207 if(strcmp( z.class , 'DATA'))
0208 obj.DATA = data.copy();
0209 obj.estandar=0;
0210 obj.model=1;
0211 obj.metode=1;
0212 obj.metodee=1;
0213 obj.treuFM=1;
0214 obj.conv=0;
0215 obj.analitic=0;
0216 obj.ContMetode=0;
0217
0218 obj.structura=[];
0219
0220
0221 obj.Z=[];
0222 obj.P=[];
0223 obj.T=[];
0224 obj.Landa=[];
0225 obj.Landai=[];
0226 obj.sta=[];
0227 obj.mea=[];
0228 obj.E=[];
0229 obj.T2=[];
0230 obj.LimT2=[];
0231 obj.LimQ=[];
0232 obj.Num=[];
0233 obj.Num_save=[];
0234 obj.CLimQstd=[];
0235 obj.CLimQmea=[];
0236 obj.CLimT2std=[];
0237 obj.CLimT2mea=[];
0238
0239 else
0240 disp('data must be a DATA object')
0241 end
0242 end
0243
0244 function copy = copy(obj)
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260 copy=PCA(obj.DATA.copy);
0261
0262
0263 copy.estandar=obj.estandar;
0264 copy.model=obj.model;
0265 copy.metode=obj.metode;
0266 copy.metodee=obj.metodee;
0267 copy.treuFM=obj.treuFM;
0268 copy.conv=obj.conv;
0269 copy.analitic=obj.analitic;
0270 copy.ContMetode=obj.ContMetode;
0271
0272
0273 copy.structura=obj.structura;
0274
0275
0276
0277 copy.Z=obj.Z;
0278 copy.P=obj.P;
0279 copy.T=obj.T;
0280 copy.Landa=obj.Landa;
0281 copy.Landai=obj.Landai;
0282 copy.sta=obj.sta;
0283 copy.mea=obj.mea;
0284 copy.E=obj.E;
0285 copy.T2=obj.T2;
0286 copy.LimT2=obj.LimT2;
0287 copy.LimQ=obj.LimQ;
0288 copy.Num=obj.Num;
0289 copy.CLimQstd=obj.CLimQstd;
0290 copy.CLimQmea= obj.CLimQmea;
0291 copy.CLimT2std=obj.CLimT2std;
0292 copy.CLimT2mea=obj.CLimT2mea;
0293 copy.Num_save=obj.Num_save;
0294
0295 end
0296
0297
0298
0299
0300
0301
0302
0303
0304 function obj = getRawData(obj)
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322 obj = obj.DATA.getRawData(obj.conv);
0323 end
0324 function dades =getDATA(obj)
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335 dades=obj.DATA.copy();
0336 end
0337
0338 function clas=getClass(obj, i)
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348 if nargin > 1
0349 clas=obj.DATA.getClass(i);
0350 else
0351 clas=obj.DATA.getClass();
0352 end
0353 end
0354 function setClass(obj,class)
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364 obj.DATA.setClass(class);
0365 end
0366
0367 function deleteBatch(obj,i)
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400 if(obj.isModel)
0401
0402 obj.estandar=0;
0403
0404 obj.structura=[];
0405 obj.Z=[];
0406 obj.P=[];
0407 obj.T=[];
0408 obj.Landa=[];
0409 obj.Landai=[];
0410 obj.sta=[];
0411 obj.mea=[];
0412 obj.E=[];
0413 obj.T2=[];
0414 obj.LimT2=[];
0415 obj.LimQ=[];
0416 obj.Num=[];
0417 obj.CLimQstd=[];
0418 obj.CLimQmea=[];
0419 obj.CLimT2std=[];
0420 obj.CLimT2mea=[];
0421 else
0422
0423
0424
0425
0426 lots=obj.DATA.getBatchCount();
0427
0428
0429
0430 temps = obj.DATA.getSampleCount();
0431
0432 if(obj.conv==0)
0433
0434 x=logical(1:lots);
0435 x(i)=0;
0436
0437 if(not(isempty(obj.Z)))
0438 obj.Z=obj.Z(x,:);
0439 end
0440 if(not(isempty(obj.T)))
0441 obj.T=obj.T(x,:);
0442 end
0443 if(not(isempty(obj.E)))
0444 obj.E=obj.E(x,:);
0445 end
0446 if(not(isempty(obj.T2)))
0447 obj.T2=obj.T2(x);
0448 end
0449
0450 else
0451
0452 x=logical(1:lots*temps);
0453 x(temps*(i-1)+(1:temps))=0;
0454
0455 if(not(isempty(obj.Z)))
0456 obj.Z=obj.Z(x,:);
0457 end
0458 if(not(isempty(obj.T)))
0459 obj.T=obj.T(x,:);
0460 end
0461 if(not(isempty(obj.E)))
0462 obj.E=obj.E(x,:);
0463 end
0464 if(not(isempty(obj.T2)))
0465 obj.T2=obj.T2(x);
0466 end
0467 end
0468 end
0469 obj.DATA.deleteBatch(i);
0470 end
0471 function addBatch(obj,dad, clase, nom)
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507 if(obj.isModel)
0508
0509 obj.estandar=0;
0510
0511 obj.structura=[];
0512 obj.Z=[];
0513 obj.P=[];
0514 obj.T=[];
0515 obj.Landa=[];
0516 obj.Landai=[];
0517 obj.sta=[];
0518 obj.mea=[];
0519 obj.E=[];
0520 obj.T2=[];
0521 obj.LimT2=[];
0522 obj.LimQ=[];
0523 obj.Num=[];
0524 obj.CLimQstd=[];
0525 obj.CLimQmea=[];
0526 obj.CLimT2std=[];
0527 obj.CLimT2mea=[];
0528 else
0529
0530 aux=obj.DATA.copy();
0531 aux.setRawData(dad);
0532 aux.setClass(clase);
0533 aux2=obj.project(aux);
0534
0535 if(not(isempty(aux2.Z)))
0536 obj.Z=[obj.Z; aux2.getZ()];
0537 else
0538 error('no dades?');
0539 end
0540 if(not(isempty(aux2.T)))
0541 obj.T=[obj.T; aux2.getT()];
0542 else
0543 obj.T=[];
0544 end
0545 if(not(isempty(aux2.E)))
0546 obj.E=[obj.E; aux2.getE()];
0547 else
0548 obj.E=[];
0549 end
0550 if(not(isempty(aux2.T2)))
0551 obj.T2=[obj.T2; aux2.getT2()];
0552 else
0553 obj.T2=[];
0554 end
0555 end
0556 if nargin == 4
0557 obj.DATA.addBatch(dad,clase,nom);
0558 else
0559 obj.DATA.addBatch(dad,clase);
0560 end
0561 end
0562 function [data clas nom]=getBatch(obj, i)
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595 [data clas nom]=obj.DATA.getBatch(i);
0596 end
0597
0598 function obji = getBatchCount(obj)
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611 obji = obj.DATA.getBatchCount();
0612 end
0613 function num = getVariableCount(obj)
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625 num = obj.DATA.getVariableCount();
0626 end
0627 function num = getSampleCount(obj)
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639 num = obj.DATA.getSampleCount();
0640 end
0641
0642 function setBatchLabel(obj, in)
0643
0644
0645
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655
0656 obj.DATA.setBatchLabel(in);
0657 end
0658 function out=getBatchLabel(obj,i)
0659
0660
0661
0662
0663
0664
0665
0666
0667
0668
0669
0670
0671
0672
0673 if nargin > 1
0674 out=obj.DATA.getBatchLabel(i);
0675 else
0676 out=obj.DATA.getBatchLabel();
0677 end
0678 end
0679
0680 function obj = getZ(obj)
0681
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692
0693
0694 if(isempty(obj.Z) && obj.getBatchCount>0)
0695 estandaritza(obj);
0696 end
0697 obj = obj.Z;
0698 end
0699
0700 function obj = getP(obj)
0701
0702
0703
0704
0705
0706
0707
0708
0709
0710
0711
0712
0713
0714 if(isempty(obj.P) && obj.getBatchCount>0)
0715 obj.pca();
0716 end
0717 obj = obj.P;
0718 end
0719
0720 function obj = getT(obj)
0721
0722
0723
0724
0725
0726
0727
0728
0729
0730
0731
0732 if(isempty(obj.T) && obj.getBatchCount>0)
0733 obj.pca();
0734 end
0735 obj = obj.T;
0736 end
0737
0738 function obj = getLambda(obj)
0739
0740
0741
0742
0743
0744
0745
0746
0747
0748
0749
0750
0751
0752 if(isempty(obj.Landa) && obj.getBatchCount>0)
0753 obj.pca();
0754 end
0755 obj = obj.Landa;
0756 end
0757 function obj = getLambdaAll(obj)
0758
0759
0760
0761
0762
0763
0764
0765
0766
0767
0768
0769
0770
0771 if(isempty(obj.Landai) && obj.getBatchCount>0)
0772 obj.pca();
0773 end
0774 obj = obj.Landai;
0775 end
0776
0777 function obj = getStd(obj)
0778
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790 if(isempty(obj.sta) && obj.getBatchCount>0)
0791 estandaritza(obj);
0792 end
0793 obj = obj.sta;
0794 end
0795
0796 function obj = getMean(obj)
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809 if(isempty(obj.mea) && obj.getBatchCount>0)
0810 estandaritza(obj);
0811 end
0812 obj = obj.mea;
0813 end
0814
0815 function obj = getE(obj)
0816
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826 if(isempty(obj.E) && obj.getBatchCount>0)
0827 calculaE(obj);
0828 end
0829 obj = obj.E;
0830 end
0831
0832 function obj = getT2(obj)
0833
0834
0835
0836
0837
0838
0839
0840
0841
0842
0843
0844 if(isempty(obj.T2) && obj.getBatchCount>0)
0845
0846 if(isempty(obj.T) && obj.getBatchCount>0)
0847 obj.pca();
0848 end
0849 obj.T2=((obj.T).^2);
0850 obj.T2=((obj.T2)./repmat(obj.Landa',size(obj.T2,1),1))*ones(size(obj.T2,2),1);
0851 end
0852 obj = obj.T2;
0853 end
0854
0855 function obj = getT2Limit(obj)
0856
0857
0858
0859
0860
0861
0862
0863
0864
0865
0866
0867
0868 if(isempty(obj.LimT2)&& obj.getBatchCount>0)
0869 calculaLimT2(obj);
0870 end
0871 obj = obj.LimT2();
0872 end
0873
0874 function obj = getQLimit(obj)
0875
0876
0877
0878
0879
0880
0881
0882
0883
0884
0885
0886
0887 if(isempty(obj.LimQ)&& obj.getBatchCount>0)
0888 calculaLimQ(obj);
0889 end
0890 obj = obj.LimQ;
0891 end
0892
0893 function obj = getNum(obj)
0894
0895
0896
0897
0898
0899
0900
0901
0902
0903
0904
0905 if(isempty(obj.Num))
0906
0907
0908
0909 N = str2double(inputdlg('Number of Principal componens to use:'));
0910 z=whos('N');
0911 while(~strcmp(z.class,'double'))
0912
0913 N = str2double(inputdlg('Number of Principal componens to use:'));
0914 z=whos('N');
0915 end
0916
0917 obj.Num=N;
0918 obj.Num_save=N;
0919 end
0920 obj = obj.Num;
0921 end
0922
0923 function setNum(obj, n)
0924
0925
0926
0927
0928
0929
0930
0931
0932
0933
0934
0935
0936
0937
0938 z=whos('n');
0939 if(not(strcmp(z.class,'double')))
0940 error('PCA/setNum: Waiting for double, no changes have been made.');
0941 end
0942 if(obj.model~=1)
0943 error('PCA/setNum: Object must be model, no changes have been made.');
0944 end
0945
0946
0947 obj.metode = 0;
0948 obj.Num_save=n;
0949 if(n ~= obj.Num)
0950 if(n < obj.Num)
0951 obj.Num = n;
0952
0953 obj.P = obj.P(:, 1:(obj.Num));
0954 obj.T = obj.T(:, 1:(obj.Num));
0955 obj.Landa = obj.Landa(1:(obj.Num));
0956
0957 obj.E=[];
0958 obj.T2=[];
0959 obj.LimT2=[];
0960 obj.LimQ=[];
0961 obj.CLimQstd=[];
0962 obj.CLimQmea=[];
0963 obj.CLimT2std=[];
0964 obj.CLimT2mea=[];
0965
0966 obj.structura=[];
0967
0968 else
0969 obj.Num = n;
0970
0971
0972 obj.P=[];
0973 obj.T=[];
0974 obj.Landa=[];
0975 obj.Landai=[];
0976 obj.E=[];
0977 obj.T2=[];
0978 obj.LimT2=[];
0979 obj.LimQ=[];
0980 obj.CLimQstd=[];
0981 obj.CLimQmea=[];
0982 obj.CLimT2std=[];
0983 obj.CLimT2mea=[];
0984
0985 obj.structura=[];
0986
0987 obj.pca();
0988 end
0989 end
0990 end
0991
0992 function bool =isModel(obj)
0993
0994
0995
0996
0997
0998
0999
1000
1001
1002
1003
1004
1005 bool=obj.model;
1006 end
1007
1008 function metode =getPCSelectionMethod(obj)
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028 metode=obj.metode;
1029
1030 end
1031 function setPCSelectionMethod(obj,x)
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053 z=whos('x');
1054 if(not(strcmp(z.class,'double')))
1055 error('PCA/setPCSelectionMethod: waiting for double, no changes have been made.');
1056 end
1057 if(not(0<=x && x<6))
1058 error('PCA/setPCSelectionMethod: No valid selection method.');
1059 end
1060 if(not(obj.isModel()))
1061 error('PCA/setPCSelectionMethod: No changes can be made in non model objects!');
1062 end
1063
1064
1065 if(obj.metode~=x)
1066 obj.structura=[];
1067
1068
1069 obj.Z=[];
1070 obj.P=[];
1071 obj.T=[];
1072 obj.Landa=[];
1073 obj.Landai=[];
1074 obj.sta=[];
1075 obj.mea=[];
1076 obj.E=[];
1077 obj.T2=[];
1078 obj.LimT2=[];
1079 obj.LimQ=[];
1080 obj.Num=[];
1081 obj.CLimQstd=[];
1082 obj.CLimQmea=[];
1083 obj.CLimT2std=[];
1084 obj.CLimT2mea=[];
1085 obj.estandar=0;
1086 end
1087
1088 obj.metode=x;
1089
1090
1091 if(x==5 && obj.conv==0 )
1092 warndlg('PCA/setPCSelectionMethod: VRE works only with Variable Wise.','ATTENTION!');
1093 end
1094 end
1095
1096 function metode =getNormalizationMethod(obj)
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113 metode=obj.metodee;
1114
1115 end
1116 function setNormalizationMethod(obj,x)
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138 z=whos('x');
1139 if(not(strcmp(z.class,'double')))
1140 error('PCA/setNormalizationMethod: Waiting for double, no changes have been made.');
1141 end
1142 if(not(1<=x && x<=4))
1143 error('PCA/setNormalizationMethod: No valid estandaritzation method.');
1144 end
1145 if(not(obj.isModel()))
1146 error('PCA/setNormalizationMethod: No changes can be made in non model objects!');
1147 end
1148 if(obj.metodee~=x)
1149 obj.structura=[];
1150
1151
1152 obj.Z=[];
1153 obj.P=[];
1154 obj.T=[];
1155 obj.Landa=[];
1156 obj.Landai=[];
1157 obj.sta=[];
1158 obj.mea=[];
1159 obj.E=[];
1160 obj.T2=[];
1161 obj.LimT2=[];
1162 obj.LimQ=[];
1163 obj.Num=[];
1164 obj.CLimQstd=[];
1165 obj.CLimQmea=[];
1166 obj.CLimT2std=[];
1167 obj.CLimT2mea=[];
1168 obj.estandar=0;
1169 end
1170
1171 obj.metodee=x;
1172
1173 end
1174
1175 function setTrajectoryRemoval(obj,x)
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188 z=whos('x');
1189 if(not(strcmp(z.class,'double')))
1190 error('PCA/setTrajectoryRemoval: Waiting for double, no changes have been made.');
1191 end
1192 if(not(0<=x && x<=1))
1193 error('PCA/setTrajectoryRemoval: Only is allowed 1 or 0');
1194 end
1195 if(not(obj.isModel()))
1196 error('PCA/setTrajectoryRemoval: No changes can be made in non model objects!');
1197 end
1198 if(obj.treuFM~=x)
1199 obj.structura=[];
1200
1201
1202 obj.Z=[];
1203 obj.P=[];
1204 obj.T=[];
1205 obj.Landa=[];
1206 obj.Landai=[];
1207 obj.sta=[];
1208 obj.mea=[];
1209 obj.E=[];
1210 obj.T2=[];
1211 obj.LimT2=[];
1212 obj.LimQ=[];
1213 obj.Num=[];
1214 obj.CLimQstd=[];
1215 obj.CLimQmea=[];
1216 obj.CLimT2std=[];
1217 obj.CLimT2mea=[];
1218 obj.estandar=0;
1219 end
1220
1221 obj.treuFM=x;
1222
1223 end
1224 function val =getTrajectoryRemoval(obj)
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238 val = obj.treuFM;
1239 end
1240
1241 function setUnfoldingMethod(obj,x)
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254 z=whos('x');
1255 if(not(strcmp(z.class,'double')))
1256 error('PCA/setUnfoldingMethod: Waiting for double, no changes have been made.');
1257 end
1258 if(not(0<=x && x<=1))
1259 error('PCA/setUnfoldingMethod: Only is allowed 1 or 0');
1260 end
1261 if(not(obj.isModel()))
1262 error('PCA/setUnfoldingMethod: No changes can be made in non model objects!');
1263 end
1264 if(obj.conv~=x)
1265 obj.structura=[];
1266
1267
1268 obj.Z=[];
1269 obj.P=[];
1270 obj.T=[];
1271 obj.Landa=[];
1272 obj.Landai=[];
1273 obj.sta=[];
1274 obj.mea=[];
1275 obj.E=[];
1276 obj.T2=[];
1277 obj.LimT2=[];
1278 obj.LimQ=[];
1279 obj.Num=[];
1280 obj.CLimQstd=[];
1281 obj.CLimQmea=[];
1282 obj.CLimT2std=[];
1283 obj.CLimT2mea=[];
1284 obj.estandar=0;
1285 end
1286
1287 obj.conv= x;
1288 end
1289 function obj = getUnfoldingMethod(obj)
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300 obj = obj.conv;
1301 end
1302
1303 function setLimitMethod(obj,x)
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317 z=whos('x');
1318 if(not(strcmp(z.class,'double')))
1319 error('PCA/setLimitMethod: Waiting for double, no changes have been made.');
1320 end
1321 if(not(0<=x && x<=1))
1322 error('PCA/setLimitMethod: Only is allowed 1 or 0');
1323 end
1324 if(not(obj.isModel()))
1325 error('PCA/setUnfoldingMethod: No changes can be made in non model objects!');
1326 end
1327 if(obj.analitic~=x)
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340 obj.LimT2=[];
1341 obj.LimQ=[];
1342
1343 obj.CLimQstd=[];
1344 obj.CLimQmea=[];
1345 obj.CLimT2std=[];
1346 obj.CLimT2mea=[];
1347 end
1348 obj.analitic= x;
1349 end
1350 function x = getLimitMethod(obj)
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362 x = obj.analitic;
1363 end
1364
1365 function setContributionMethod(obj,x)
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379 if x ~= 1 && x ~= 0
1380 error('PCA/setContributionMethod: Waiting for double, no changes have been made.');
1381 end
1382 if obj.model ~= 1
1383 error('PCA/setContributionMethod: No changes can be made in non model objects!');
1384 end
1385
1386 obj.ContMetode=x;
1387
1388
1389
1390 obj.CLimQstd=[];
1391 obj.CLimQmea=[];
1392 obj.CLimT2std=[];
1393 obj.CLimT2mea=[];
1394 end
1395 function x = getContMetode(obj)
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409 x = obj.ContMetode;
1410 end
1411
1412 function obj = getQ(obj)
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426 if(isempty(obj.E) && obj.getBatchCount>0)
1427 calculaE(obj);
1428 end
1429
1430 obj = ((obj.E).^2)*ones(size(obj.E,2),1);
1431 end
1432
1433 function sort = getQContribution(obj)
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447 sort = calculaContQ(obj);
1448 end
1449
1450 function sort = getT2Contribution(obj)
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462 sort = calculaContT2(obj);
1463 end
1464
1465 function obj = getQContributionLimitMean(obj)
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479 if(isempty(obj.CLimQmea))
1480 calculaContQ(obj);
1481 end
1482
1483 obj=obj.CLimQmea;
1484 end
1485
1486 function obj = getQContributionLimitStd(obj)
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500 if(isempty(obj.CLimQstd))
1501 calculaContQ(obj);
1502 end
1503
1504 obj=obj.CLimQstd;
1505 end
1506
1507 function obj = getT2ContributionLimitMean(obj)
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520 if(isempty(obj.CLimT2mea))
1521 calculaContT2(obj);
1522 end
1523
1524 obj=obj.CLimT2mea;
1525 end
1526
1527 function obj = getT2ContributionLimitStd(obj)
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541 if(isempty(obj.CLimT2std))
1542 calculaContT2(obj);
1543 end
1544
1545 obj=obj.CLimT2std;
1546 end
1547
1548 function weka(obj,nomfitx)
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563 aux=obj.foraCQ;
1564 celles=obj.DATA.getClass();
1565 aux = [aux'; celles];
1566 if isempty(strfind(nomfitx,'.arff'))
1567 nomfitx = strcat(nomfitx,'.arff');
1568 end
1569 new_file = fopen(nomfitx,'w');
1570
1571 fprintf(new_file,'@RELATION %s \r\n',obj.DATA.getName());
1572
1573 for x = 1:length(obj.DATA.getVariableLabel)
1574 for y = 1:length(obj.DATA.getStages)
1575 fprintf(new_file,'@ATTRIBUTE %s_%s NUMERIC\r\n',obj.DATA.getVariableLabel{x},obj.DATA.getStages{y});
1576 end
1577 end
1578
1579 fprintf(new_file,'@ATTRIBUTE class NUMERIC\r\n');
1580
1581 fprintf(new_file,'@DATA\r\n');
1582 fclose(new_file);
1583
1584 dlmwrite(nomfitx,aux,'-append','newline','pc');
1585 end
1586
1587 function [x_rec, f_i, direccio, valid] = reconstruct(obj)
1588
1589
1590 if obj.metode==5 && obj.conv==1
1591
1592 if(isempty(obj.P))
1593 obj.pca();
1594 end
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613 X=obj.Z;
1614 MPCA_struc= struct('mx',obj.getMean,'std',obj.getStd,'P',obj.getP,'SPE_lim',obj.getQLimit,'lambda',obj.getLambda,'T2_lim',obj.getT2Limit,'R',(X'*X)/(size(X,1)-1));
1615 [f_i, direccio, x_rec] = VRE_fault_rec(X, MPCA_struc);
1616 valid=f_i==0;
1617
1618 else
1619
1620 disp('RECONSTRUCTION FAILED');
1621 end
1622 end
1623
1624 function canvis = deleteOutLiers(obj,alt)
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644 if(obj.isModel)
1645
1646 if(obj.conv == 1)
1647 error('PCA/deleteOutLiers: can not be used in Variable Wise.');
1648 end
1649
1650 if nargin == 1
1651 ind = getOutLiers(obj);
1652 else
1653 ind = getOutLiers(obj,alt);
1654 end
1655 obj.deleteBatch(ind);
1656
1657
1658 canvis = sum(ind);
1659
1660 else
1661
1662
1663
1664 error('PCA/deleteOutLiers: The object must be a Model.');
1665
1666 end
1667 end
1668
1669 function outs = getOutLiers(obj,alt)
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688 if nargin ==2
1689 switch alt
1690 case {'all' 'ALL' 'All'}
1691
1692 otherwise
1693
1694
1695 alt = [];
1696 end
1697 end
1698
1699 if nargin ==1
1700 alt = [];
1701 end
1702
1703 if(obj.isModel)
1704
1705 if(obj.conv == 1)
1706 error('PCA/getOutLiers: can not be used in Variable Wise.');
1707 end
1708 cl = obj.getClass;
1709 for i = unique(cl)
1710 index = (cl == i);
1711
1712
1713 Qs=obj.getQ;
1714 Ts=obj.getT2();
1715
1716
1717
1718 qrts = prctile(Qs(index),[25 75]);
1719
1720
1721 IRQ = qrts(2) - qrts(1);
1722
1723 if isempty(alt)
1724
1725 qrts(1) = qrts(1) - 2.75*IRQ;
1726 qrts(2) = qrts(2) + 2.75*IRQ;
1727 else
1728
1729 qrts(1) = qrts(1) - 1.5*IRQ;
1730 qrts(2) = qrts(2) + 1.5*IRQ;
1731 end
1732
1733
1734 ind1 = or(Qs < qrts(1) , Qs > qrts(2));
1735
1736
1737
1738 ind1(~index) = 0;
1739
1740
1741
1742
1743
1744
1745 qrts = prctile(Ts(index),[25 75]);
1746
1747
1748 IRQ = qrts(2) - qrts(1);
1749
1750 if isempty(alt)
1751
1752 qrts(1) = qrts(1) - 2.75*IRQ;
1753 qrts(2) = qrts(2) + 2.75*IRQ;
1754 else
1755
1756 qrts(1) = qrts(1) - 1.5*IRQ;
1757 qrts(2) = qrts(2) + 1.5*IRQ;
1758 end
1759
1760
1761 ind = or(Ts < qrts(1) , Ts > qrts(2));
1762 ind(~index) = 0;
1763
1764 ant{i}= or(ind,ind1);
1765
1766 end
1767
1768 outs = [ant{:}];
1769 outs= sum(outs,2);
1770 outs = outs >= 1;
1771
1772 else
1773
1774
1775
1776 error('PCA/getOutLiers: The object must be a Model.');
1777
1778 end
1779 end
1780
1781
1782
1783
1784
1785
1786 function [a b c] = pca(obj)
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799 if(~obj.isModel())
1800 errordlg('PCA\pca: You can''t use this method ober a non model object!','error');
1801 end
1802
1803 if(isempty(obj.P)|| (isempty(obj.T) && obj.getBatchCount>0) || isempty(obj.Landa))
1804
1805 if(obj.estandar~=1)
1806
1807 estandaritza(obj);
1808 end
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818 switch obj.metode
1819 case 0
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832 if license('test','statistics_toolbox')
1833 [obj.P obj.T obj.Landa]=princomp(obj.Z);
1834 else
1835 r=obj.Z'*obj.Z/(size(obj.Z,1)-1);
1836 [~,D,obj.P]=svd(r,'econ');
1837 obj.Landa=diag(D);
1838 obj.T=obj.Z*obj.P;
1839 end
1840 if(isempty(obj.Num))
1841 if isempty(obj.Num_save)
1842 getNum(obj);
1843 else
1844 obj.Num = obj.Num_save;
1845 end
1846 end
1847 case 1
1848
1849
1850
1851
1852 if license('test','statistics_toolbox')
1853 [obj.P obj.T obj.Landa]=princomp(obj.Z);
1854 else
1855 r=obj.Z'*obj.Z/(size(obj.Z,1)-1);
1856 [~,D,obj.P]=svd(r,'econ');
1857 obj.Landa=diag(D);
1858 obj.T=obj.Z*obj.P;
1859 end
1860 cDKaiser(obj);
1861 case 2
1862
1863
1864 if license('test','statistics_toolbox')
1865 [obj.P obj.T obj.Landa]=princomp(obj.Z);
1866 else
1867 r=obj.Z'*obj.Z/(size(obj.Z,1)-1);
1868 [~,D,obj.P]=svd(r,'econ');
1869 obj.Landa=diag(D);
1870 obj.T=obj.Z*obj.P;
1871 end
1872 cGrafscree(obj);
1873 case 3
1874
1875
1876 if license('test','statistics_toolbox')
1877 [obj.P obj.T obj.Landa]=princomp(obj.Z);
1878 else
1879 r=obj.Z'*obj.Z/(size(obj.Z,1)-1);
1880 [~,D,obj.P]=svd(r,'econ');
1881 obj.Landa=diag(D);
1882 obj.T=obj.Z*obj.P;
1883 end
1884 colzeanalitic(obj);
1885 case 4
1886
1887
1888 if license('test','statistics_toolbox')
1889 [obj.P obj.T obj.Landa]=princomp(obj.Z);
1890 else
1891 r=obj.Z'*obj.Z/(size(obj.Z,1)-1);
1892 [~,D,obj.P]=svd(r,'econ');
1893 obj.Landa=diag(D);
1894 obj.T=obj.Z*obj.P;
1895 end
1896 cVarExp(obj);
1897 case 5
1898
1899 obj.structura=variance_reconstruction_error(obj.Z,eye(size(obj.Z,2)));
1900 obj.Num=obj.structura.l_rec{obj.structura.n_loops};
1901 obj.Z=obj.structura.X_rec{obj.structura.n_loops};
1902 r=obj.Z'*obj.Z/(size(obj.Z,1)-1);
1903 [V, D] = eig(r);
1904 obj.Landa=flipud(diag(D));
1905 obj.P=fliplr(V);
1906 obj.T=obj.Z*obj.P;
1907 otherwise
1908 error('PCA\pca: Invalid component selection method')
1909 end
1910
1911
1912
1913
1914 obj.P = obj.P(:, 1:(obj.Num));
1915 obj.T = obj.T(:, 1:(obj.Num));
1916 obj.Landai=obj.Landa;
1917 obj.Landa = obj.Landa(1:(obj.Num));
1918
1919 end
1920 if nargout ~= 0
1921
1922 a=obj.P;
1923 b=obj.T;
1924 c=obj.Landa;
1925 end
1926 end
1927
1928 function nou = project(obj,x)
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945 z=whos('x');
1946 if(not(strcmp( z.class , 'DATA')))
1947
1948 error('PCA\project:waiting for DATA');
1949 end
1950
1951 if(isempty(obj.P)||isempty(obj.Landa)||isempty(obj.mea)||(isempty(obj.T) && obj.getBatchCount>0))
1952
1953
1954 obj.pca();
1955 end
1956
1957 nou=PCA(x);
1958
1959
1960
1961 nou.mea=obj.mea;
1962 nou.sta=obj.sta;
1963 nou.conv=obj.conv;
1964 nou.metode=obj.metode;
1965 nou.metodee=obj.metodee;
1966 nou.treuFM=obj.treuFM;
1967 nou.ContMetode=obj.ContMetode;
1968
1969
1970
1971
1972
1973
1974 nou.LimT2=obj.getT2Limit;
1975 nou.LimQ=obj.getQLimit;
1976 nou.CLimQstd=obj.getQContributionLimitStd;
1977 nou.CLimQmea=obj.getQContributionLimitMean;
1978 nou.CLimT2std=obj.getT2ContributionLimitStd;
1979 nou.CLimT2mea=obj.getT2ContributionLimitMean;
1980
1981
1982 nou.estandaritz2();
1983
1984
1985 nou.model=0;
1986
1987 nou.structura=obj.structura;
1988 if(obj.metode==5)
1989 nou.Z=nou.Z(:,nou.structura.sensors{nou.structura.n_loops});
1990 nou.T=nou.Z*obj.P;
1991 nou.P=obj.P;
1992 nou.Landa=obj.Landa;
1993 nou.Landai=obj.Landai;
1994 nou.Num=obj.Num;
1995 else
1996 nou.T=nou.Z*obj.P;
1997 nou.P=obj.P;
1998 nou.Landa=obj.Landa;
1999 nou.Landai=obj.Landai;
2000 nou.Num=obj.Num;
2001 end
2002 end
2003
2004
2005
2006
2007
2008
2009 function plotT2Contribution(obj,mostrar)
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023 if nargin == 1
2024 error('PCA\plotT2Contribution: we need another parameter!')
2025 end
2026 aux=obj.getT2Contribution();
2027 aux=aux(mostrar,:)';
2028
2029 bar(aux,'HitTest','off');
2030
2031
2032 obj.plotLimCT2('k');
2033
2034 if(obj.conv == 0)
2035
2036 hold on;
2037
2038 z=obj.DATA.getStagesDurations();
2039 a=0;
2040 i=1;
2041
2042
2043 maxim = max(max(max(aux)),max(obj.getT2ContributionLimitMean+obj.getT2ContributionLimitStd*3));
2044 minim = min(min(min(aux)),min(-(obj.getT2ContributionLimitMean+obj.getT2ContributionLimitStd*3))) * obj. ContMetode;
2045
2046 vars=obj.DATA.getVariableLabel();
2047 fases=obj.DATA.getStages();
2048 for x = 1:length(z)*length(obj.DATA.getVariableLabel)
2049 a=a+z(i);
2050 line([a,a],[maxim+0.2,minim-0.2],'linestyle',':','color',[0.40,0.40,0.40],'HitTest','off');
2051 text(a-z(i)/2,minim-0.2,fases(i),'FontSize',8,'LineWidth',0.5);
2052 if(i==length(z))
2053 i=0;
2054 line([a,a],[maxim+0.2,minim-0.2],'linestyle','--','color','k','HitTest','off');
2055 text(a-sum(z)/2,maxim+0.2,vars(x/length(z)),'FontSize',15,'LineWidth',0.7);
2056 end
2057 i=i+1;
2058 end
2059 hold off;
2060 end
2061 end
2062
2063 function plotQContribution(obj,mostrar)
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077 if nargin == 1
2078 error('PCA\plotQContribution: We need another parameter!')
2079 end
2080
2081 aux=obj.getQContribution();
2082 aux=aux(mostrar,:)';
2083 bar(aux,'HitTest','off');
2084
2085
2086
2087 obj.plotLimCQ('k');
2088 if(obj.conv == 0)
2089 hold on;
2090
2091
2092 z=obj.DATA.getStagesDurations();
2093 a=0;
2094 i=1;
2095
2096
2097 maxim = max(max(max(aux)),max(obj.getQContributionLimitMean+obj.getQContributionLimitStd*3));
2098 minim = min(min(min(aux)),min(-(obj.getQContributionLimitMean+obj.getQContributionLimitStd*3))) * obj. ContMetode;
2099
2100 vars=obj.DATA.getVariableLabel();
2101 fases=obj.DATA.getStages();
2102 for x = 1:length(z)*length(obj.DATA.getVariableLabel)
2103 a=a+z(i);
2104 line([a,a],[maxim+0.2,minim-0.2],'linestyle',':','color',[0.40,0.40,0.40],'HitTest','off');
2105 text(a-z(i)/2,minim-0.2,fases(i),'FontSize',8,'LineWidth',0.5);
2106 if(i==length(z))
2107 i=0;
2108 line([a,a],[maxim+0.2,minim-0.2],'linestyle','--','color','k','HitTest','off');
2109 text(a-sum(z)/2,maxim+0.2,vars(x/length(z)),'FontSize',15,'LineWidth',0.7);
2110 end
2111 i=i+1;
2112 end
2113 hold off;
2114 end
2115 end
2116
2117 function plotT2MeanContribution(obj)
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129 cla = obj.getClass();
2130 num=unique(cla);
2131 col=hsv(length(num));
2132 in = 1;
2133
2134 conts=obj.getT2Contribution();
2135
2136 for j = num
2137 subplot(length(num),1,j)
2138 hold on;
2139 title(['Class ' num2str(j)])
2140 aux =(conts(cla == j,:))';
2141 mitja = mean( aux , 2);
2142 estan = std( aux ,0, 2);
2143
2144 aux2 = mitja - estan;
2145 if(obj.getContMetode == 0)
2146 aux2(aux2 < 0) = 0;
2147 end
2148 area(mitja + estan,'FaceColor',col(in,:), 'BaseValue',min(aux2), 'LineStyle','none')
2149 area(aux2,'FaceColor','W','BaseValue',min(aux2),'LineStyle','none')
2150 in=in+1;
2151
2152
2153
2154
2155 z=obj.DATA.getStagesDurations();
2156 a=0;
2157 i=1;
2158 maxim=max(max(mitja + estan)) +0.2;
2159 minim = min(min(aux2)) -0.2;
2160 vars=obj.DATA.getVariableLabel();
2161 fases=obj.DATA.getStages();
2162 for x = 1:length(z)*length(obj.DATA.getVariableLabel)
2163 a=a+z(i);
2164 line([a,a],[maxim,minim],'linestyle',':','color',[0.40,0.40,0.40]);
2165 aux =a-z(i)/2;
2166 text(aux,minim,fases(i),'FontSize',8,'LineWidth',0.5);
2167 if(i==length(z))
2168 i=0;
2169 line([a,a],[maxim,minim],'linestyle','--','color','k');
2170 text(aux - sum(z)*2/3,maxim,vars(x/length(z)),'FontSize',15,'LineWidth',0.7);
2171 end
2172 i=i+1;
2173 end
2174 end
2175 end
2176
2177 function plotQMeanContribution(obj)
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190 cla = obj.getClass();
2191 num=unique(cla);
2192 col=hsv(length(num));
2193 in = 1;
2194
2195 conts=obj.getQContribution();
2196
2197 for j = num
2198 subplot(length(num),1,j)
2199 hold on;
2200 title(['Class ' num2str(j)])
2201 aux =(conts(cla == j,:))';
2202 mitja = mean( aux , 2);
2203 estan = std( aux ,0, 2);
2204 aux2 = mitja - estan;
2205 if(obj.getContMetode == 0)
2206 aux2(aux2 < 0) = 0;
2207 end
2208 area(mitja + estan,'FaceColor',col(in,:), 'BaseValue',min(aux2), 'LineStyle','none')
2209 area(aux2,'FaceColor','W','BaseValue',min(aux2),'LineStyle','none')
2210 in=in+1;
2211
2212
2213
2214 z=obj.DATA.getStagesDurations();
2215 a=0;
2216 i=1;
2217 maxim=max(max(mitja + estan)) +0.2;
2218 minim = min(min(aux2)) -0.2;
2219 vars=obj.DATA.getVariableLabel();
2220 fases=obj.DATA.getStages();
2221 for x = 1:length(z)*length(obj.DATA.getVariableLabel)
2222 a=a+z(i);
2223 line([a,a],[maxim,minim],'linestyle',':','color',[0.40,0.40,0.40]);
2224 aux =a-z(i)/2;
2225 text(aux,minim,fases(i),'FontSize',8,'LineWidth',0.5);
2226 if(i==length(z))
2227 i=0;
2228 line([a,a],[maxim,minim],'linestyle','--','color','k');
2229 text(aux - sum(z)*2/3,maxim,vars(x/length(z)),'FontSize',15,'LineWidth',0.7);
2230 end
2231 i=i+1;
2232 end
2233 end
2234 end
2235
2236 function handle = plotT2Q(obj,forma,color,aux)
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254 T22=obj.getT2;
2255 Q=obj.getQ;
2256 classe=obj.getClass;
2257 dcm_obj = datacursormode(gcf);
2258
2259 hold on
2260
2261 tr= 1==1;
2262 if isempty(whos('color')) || isempty(color)
2263 col=hsv(length(unique(classe)));
2264 tr= 1==0;
2265 end
2266
2267 if isempty(whos('forma'))
2268 forma = '.';
2269 end
2270 in =1;
2271 num=unique(classe);
2272 handle=zeros(1,max(num));
2273 for i = num
2274 if tr
2275 handle(i)=semilogy(T22(classe==i),Q(classe==i),forma,'color',color);
2276 else
2277 handle(i)=semilogy(T22(classe==i),Q(classe==i),forma,'color',col(in,:));
2278 in=in+1;
2279 end
2280 end
2281
2282 if exist('aux','var') && strcmp(aux,'no')
2283 userdata =get(gca,'Userdata');
2284 noms=obj.getBatchLabel();
2285
2286 userdata.noms = {userdata.noms{:}, noms{:}};
2287 userdata.punts{1} = [userdata.punts{1}; T22];
2288 userdata.punts{2} = [userdata.punts{2}; Q];
2289 else
2290 userdata.punts={T22,Q};
2291 userdata.noms=obj.getBatchLabel();
2292 end
2293 if nargin ~= 4
2294 line([obj.getT2Limit obj.getT2Limit],[1 max(Q)],'color','k','HitTest','off')
2295 line([1 max(T22)],[obj.getQLimit obj.getQLimit],'color','k','HitTest','off')
2296 end
2297
2298
2299 if nargin >= 4 && strcmp(aux,'log')
2300 ax = axis;
2301 set (gca, 'yscale', 'log')
2302 set (gca, 'xscale', 'log')
2303 axis (ax)
2304 end
2305
2306
2307 xlabel('T2')
2308 ylabel('Q')
2309
2310 hold off
2311
2312 set(gca,'userdata',userdata);
2313 set(dcm_obj,'UpdateFcn',@tipmelot)
2314 end
2315
2316 function plotScores(varargin)
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327 obj = varargin{1};
2328 switch length(varargin)
2329 case 1
2330 errordlg('We need parameters!','Error');
2331
2332 case 2
2333 a=varargin{2};
2334 ts=obj.getT();
2335 dcm_obj = datacursormode(gcf);
2336
2337 hold on
2338
2339 clas=obj.DATA.getClass;
2340 col=hsv(max(clas));
2341 for i=unique(clas)
2342 index=clas ==i;
2343 plot(ts(index,a),'.','color',col(i,:));
2344 end
2345 userdata.punts={ts(:,a)};
2346 userdata.noms=obj.getBatchLabel();
2347 line([0,length(ts)],[sqrt(obj.Landa(a))*3, sqrt(obj.Landa(a))*3],'color','K','HitTest','off')
2348 line([0,length(ts)],[-sqrt(obj.Landa(a))*3, -sqrt(obj.Landa(a))*3],'color','K','HitTest','off')
2349 axis equal
2350 xlabel('Time')
2351 ylabel(['T(' num2str(a) ') (' num2str(sum(obj.Landa(a))*100/sum(obj.Landa)) '%)'])
2352 hold off
2353
2354 set(gca,'userdata',userdata);
2355 set(dcm_obj,'UpdateFcn',@tipme)
2356
2357 case 3
2358 a=varargin{2};
2359 b=varargin{3};
2360 ts=obj.getT();
2361 dcm_obj = datacursormode(gcf);
2362 hold on
2363
2364
2365 lamb = obj.Landai;
2366 sumlamb = sum(lamb);
2367
2368 [X,Y,Zeta]=ellipsoid(0,0,0,sqrt(lamb(a))*3,sqrt(lamb(b))*3,0);
2369 surf(X,Y,Zeta,'EdgeColor','none','facecolor',[0.9 0.9 0.9],'HitTest','off');
2370
2371 clas=obj.DATA.getClass;
2372 col=hsv(max(clas));
2373 for i=unique(clas)
2374 index=clas ==i;
2375 plot(ts(index,a),ts(index,b),'.','color',col(i,:));
2376 end
2377
2378 userdata.punts={ts(:,a),ts(:,b)};
2379 userdata.noms=obj.getBatchLabel();
2380
2381
2382 axis equal
2383 xlabel(['T(' num2str(a) ') (' num2str((lamb(a))*100/sumlamb) '%)'])
2384 ylabel(['T(' num2str(b) ') (' num2str(sum(lamb(b))*100/sumlamb) '%)'])
2385 hold off
2386
2387 set(gca,'userdata',userdata);
2388 set(dcm_obj,'UpdateFcn',@tipme)
2389
2390 case 4
2391 a=varargin{2};
2392 b=varargin{3};
2393 c=varargin{4};
2394 ts=obj.getT();
2395 dcm_obj = datacursormode(gcf);
2396 set(dcm_obj,'SnapToDataVertex','off');
2397
2398
2399 clas=obj.DATA.getClass;
2400 col=hsv(max(clas));
2401 for i=unique(clas)
2402 index=clas ==i;
2403 plot3(ts(index,a),ts(index,b),ts(index,c),'.','color',col(i,:));
2404 hold on
2405 end
2406
2407
2408 lamb = obj.Landai;
2409 sumlamb = sum(lamb);
2410
2411 [X,Y,Zeta]=ellipsoid(0,0,0,sqrt(lamb(a))*3,sqrt(lamb(b))*3,sqrt(lamb(c))*3);
2412 surf(X,Y,Zeta,'EdgeColor','none','facecolor',[0.9 0.9 0.9],'HitTest','off');
2413
2414
2415 userdata.punts={ts(:,a),ts(:,b),ts(:,c)};
2416 userdata.noms=obj.getBatchLabel();
2417
2418 alpha(0.3);
2419 axis equal
2420 xlabel(['T(' num2str(a) ') (' num2str((lamb(a))*100/sumlamb) '%)'])
2421 ylabel(['T(' num2str(b) ') (' num2str(sum(lamb(b))*100/sumlamb) '%)'])
2422 zlabel(['T(' num2str(c) ') (' num2str(sum(lamb(c))*100/sumlamb) '%)'])
2423
2424 hold off
2425 set(gca,'userdata',userdata);
2426 set(dcm_obj,'UpdateFcn',@tipme)
2427
2428 otherwise
2429 errordlg('4D is not allowed!','Error');
2430
2431 end
2432
2433
2434
2435 end
2436
2437 function plotVarianceCaptured(obj)
2438
2439
2440
2441
2442 mP=obj.getP();
2443
2444 if(obj.conv == 0)
2445
2446 mP= mP.^2;
2447 aux= reshape(mP,obj.DATA.getSampleCount,obj.Num * obj.DATA.getVariableCount);
2448 v1=reshape((sum(aux,1)'./ obj.DATA.getSampleCount) * 100,obj.DATA.getVariableCount,obj.Num)';
2449 bar(v1','stacked');
2450 if ~isempty(obj.DATA.getVariableLabel)
2451 set(gca,'XTickLabel',obj.DATA.getVariableLabel);
2452 set(gca,'XTick',1:length(obj.DATA.getVariableLabel));
2453 end
2454 inst=cell(1,obj.Num);
2455 for i=1:obj.Num
2456 inst{i} = ['% ' num2str(i)] ;
2457 end
2458 legend(inst)
2459 else
2460
2461
2462 bar(mP.^2 * 100,'stacked');
2463 inst=cell(1,obj.Num);
2464 for i=1:obj.Num
2465 inst{i} = ['% ' num2str(i)] ;
2466 end
2467 legend(inst)
2468 end
2469 xlabel('Variable names')
2470 ylabel('%')
2471 end
2472
2473 function plotQSignatures(obj)
2474
2475
2476
2477
2478
2479
2480 CBgcQ=obj.getQContribution();
2481 CBgcQ= CBgcQ> repmat((obj.getQContributionLimitMean + obj.getQContributionLimitStd *3),[size(CBgcQ,1) 1] );
2482 class = obj.getClass;
2483 mcl = max(class);
2484
2485 hold on
2486
2487 colormap('lines');
2488 color= colormap('lines');
2489
2490
2491
2492 leg = cell(mcl,1);
2493 for i = 1 : mcl
2494 plot(0,0,'.','color',color(i,:),'HitTest','off');
2495 leg{i} = ['Classe' num2str(i)];
2496 end
2497
2498
2499 title('Signatures de Q');
2500 xlabel('Time * Variables');
2501 ylabel('Batch Number');
2502 legend(leg);
2503
2504
2505 sbq1 = size(CBgcQ,1);
2506 sbq2 = size(CBgcQ,2);
2507 set (gca, 'yscale', 'linear')
2508 set (gca, 'xscale', 'linear')
2509 set (gca,'xLim',[-2 sbq2+10])
2510 set (gca,'yLim',[-2 sbq1+10])
2511 set(gca,'Ytick',1 :floor(sbq1/20)+1: sbq1)
2512 set(gca,'Xtick',1 :floor(sbq2/20)+1: sbq2)
2513 set(gca,'Yticklabel',1 :floor(sbq1/20)+1: sbq1)
2514 set(gca,'Xticklabel',1 :floor(sbq2/20)+1: sbq2)
2515 aux2 = repmat((1:sbq1)',[1 sbq2]);
2516 aux1 = CBgcQ .* repmat((1 : sbq2), [sbq1 1] );
2517 for i = 1 : mcl
2518 index = i ==class;
2519 plot( aux1 .* repmat(index', [1 sbq2]) , aux2 , '.', 'color', color(i,:),'HitTest','off');
2520 end
2521
2522 plot(zeros(obj.getBatchCount+1,1),0:obj.getBatchCount,'.W','HitTest','off');
2523
2524
2525 z=obj.DATA.getStagesDurations();
2526 a=0;
2527 i=1;
2528 maxim=max(get(gca,'Ytick')) + 5;
2529 vars=obj.DATA.getVariableLabel();
2530 fases=obj.DATA.getStages();
2531 for x = 1:length(z)*length(obj.DATA.getVariableLabel)
2532 a=a+z(i);
2533 line([a,a],[maxim,-0.2],'linestyle',':','color',[0.40,0.40,0.40],'HitTest','off');
2534 aux =a-z(i)/2;
2535 text(aux,-0.2,fases(i),'FontSize',8,'LineWidth',0.5);
2536 if(i==length(z))
2537 i=0;
2538 line([a,a],[maxim,-0.2],'linestyle','--','color','k','HitTest','off');
2539 text(aux - sum(z)*2/3,maxim,vars(x/length(z)),'FontSize',15,'LineWidth',0.7);
2540 end
2541 i=i+1;
2542 end
2543
2544
2545 hold off;
2546 end
2547
2548 function plotT2Signatures(obj)
2549
2550
2551
2552
2553
2554
2555 CBgcQ=obj.getT2Contribution();
2556
2557
2558 CBgcQ= CBgcQ> repmat((obj.getT2ContributionLimitMean + obj.getT2ContributionLimitStd * 3 ),[size(CBgcQ,1) 1] );
2559
2560
2561 class = obj.getClass;
2562 mcl = max(class);
2563
2564 hold on
2565
2566 colormap('lines');
2567 color= colormap('lines');
2568
2569
2570 leg = cell(mcl,1);
2571
2572
2573 for i = 1 : mcl
2574 plot(0,0,'.','color',color(i,:),'HitTest','off');
2575 leg{i} = ['Classe' num2str(i)];
2576 end
2577
2578
2579 title('Signatures de T2');
2580 xlabel('Time * Variables');
2581 ylabel('Batch number');
2582 legend(leg);
2583
2584
2585 sbq1 = size(CBgcQ,1);
2586 sbq2 = size(CBgcQ,2);
2587 set (gca, 'yscale', 'linear')
2588 set (gca, 'xscale', 'linear')
2589 set (gca,'xLim',[-2 sbq2+10])
2590 set (gca,'yLim',[-2 sbq1+10])
2591 set(gca,'Ytick',1 :floor(sbq1/20)+1: sbq1)
2592 set(gca,'Xtick',1 :floor(sbq2/20)+1: sbq2)
2593 set(gca,'Yticklabel',1 :floor(sbq1/20)+1: sbq1)
2594 set(gca,'Xticklabel',1 :floor(sbq2/20)+1: sbq2)
2595
2596 aux2 = repmat((1:sbq1)',[1 sbq2]);
2597 aux1 = CBgcQ .* repmat((1 : sbq2), [sbq1 1] );
2598 for i = 1 : mcl
2599 index = i ==class;
2600 plot( aux1 .* repmat(index', [1 sbq2]) , aux2 , '.', 'color', color(i,:),'HitTest','off');
2601 end
2602
2603 plot(zeros(obj.getBatchCount+1,1),0:obj.getBatchCount,'.W','HitTest','off');
2604
2605
2606 z=obj.DATA.getStagesDurations();
2607 a=0;
2608 i=1;
2609 maxim=max(get(gca,'Ytick')) + 5;
2610 vars=obj.DATA.getVariableLabel();
2611 fases=obj.DATA.getStages();
2612 for x = 1:length(z)*length(obj.DATA.getVariableLabel)
2613 a=a+z(i);
2614 line([a,a],[maxim,-0.2],'linestyle',':','color',[0.40,0.40,0.40],'HitTest','off');
2615 aux =a-z(i)/2;
2616 text(aux,-0.2,fases(i),'FontSize',8,'LineWidth',0.5);
2617 if(i==length(z))
2618 i=0;
2619 line([a,a],[maxim,-0.2],'linestyle','--','color','k','HitTest','off');
2620 text(aux - sum(z)*2/3,maxim,vars(x/length(z)),'FontSize',15,'LineWidth',0.7);
2621 end
2622 i=i+1;
2623 end
2624 hold off;
2625 end
2626
2627 function plotScreePlot(obj)
2628
2629
2630 hold on;
2631 plot(obj.Landai(obj.Landai~=0));
2632 plot(obj.Num,obj.Landa(obj.Num),'*r');
2633 legend({'Lambda';'Priincipal components number'});
2634 hold off;
2635 end
2636
2637 function plotMean(obj)
2638
2639
2640 hold on
2641 plot(obj.mea,'b')
2642 legend({'Mean'});
2643
2644
2645
2646 z=obj.DATA.getStagesDurations();
2647 a=0;
2648 i=1;
2649 maxim=max(max(obj.mea)) +0.2;
2650 minim = min(min(obj.mea)) -0.2;
2651 vars=obj.DATA.getVariableLabel();
2652 fases=obj.DATA.getStages();
2653 for x = 1:length(z)*length(obj.DATA.getVariableLabel)
2654 a=a+z(i);
2655 line([a,a],[maxim,minim],'linestyle',':','color',[0.40,0.40,0.40]);
2656 aux =a-z(i)/2;
2657 text(aux,minim,fases(i),'FontSize',8,'LineWidth',0.5);
2658 if(i==length(z))
2659 i=0;
2660 line([a,a],[maxim,minim],'linestyle','--','color','k');
2661 text(aux - sum(z)*2/3,maxim,vars(x/length(z)),'FontSize',15,'LineWidth',0.7);
2662 end
2663 i=i+1;
2664 end
2665 hold off;
2666 end
2667
2668 function plotStd(obj)
2669
2670
2671
2672 hold on
2673 plot(obj.sta,'b')
2674 legend({'Standard Desviation'});
2675
2676
2677
2678 z=obj.DATA.getStagesDurations();
2679 a=0;
2680 i=1;
2681 maxim = max(max(obj.sta)) +0.2 ;
2682 minim = min(min(obj.sta)) -0.2;
2683 vars=obj.DATA.getVariableLabel();
2684 fases=obj.DATA.getStages();
2685 for x = 1:length(z)*length(obj.DATA.getVariableLabel)
2686 a=a+z(i);
2687 line([a,a],[maxim,minim],'linestyle',':','color',[0.40,0.40,0.40]);
2688 aux =a-z(i)/2;
2689 text(aux,minim,fases(i),'FontSize',8,'LineWidth',0.5);
2690 if(i==length(z))
2691 i=0;
2692 line([a,a],[maxim,minim],'linestyle','--','color','k');
2693 text(aux - sum(z)*2/3,maxim,vars(x/length(z)),'FontSize',15,'LineWidth',0.7);
2694 end
2695 i=i+1;
2696 end
2697 hold off;
2698 end
2699
2700 function plotP(obj,index)
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711 hold on
2712
2713 plot(obj.P(:,index))
2714 mis=cell(1,length(index));
2715 for i = 1:length(index)
2716 mis{i} = ['Principal Component ' num2str(index(i))] ;
2717 end
2718 legend(mis)
2719
2720
2721 z=obj.DATA.getStagesDurations();
2722 a=0;
2723 i=1;
2724 maxim=max(max(obj.P(:,index))) ;
2725 minim = min(min(obj.P(:,index))) ;
2726 vars=obj.DATA.getVariableLabel();
2727 fases=obj.DATA.getStages();
2728 for x = 1:length(z)*length(obj.DATA.getVariableLabel)
2729 a=a+z(i);
2730 line([a,a],[maxim,minim],'linestyle',':','color',[0.40,0.40,0.40]);
2731 aux =a-z(i)/2;
2732 text(aux,minim,fases(i),'FontSize',8,'LineWidth',0.5);
2733 if(i==length(z))
2734 i=0;
2735 line([a,a],[maxim,minim],'linestyle','--','color','k');
2736 text(aux - sum(z)*2/3,maxim,vars(x/length(z)),'FontSize',15,'LineWidth',0.7);
2737 end
2738 i=i+1;
2739 end
2740 hold off;
2741 end
2742
2743 function plotLoadings(varargin)
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754 obj = varargin{1};
2755 switch length(varargin)
2756 case 1
2757 errordlg('we need parameters!','Error');
2758 case 2
2759 Ps=obj.getP();
2760 a = varargin{2};
2761
2762 vars = obj.getVariableCount;
2763 temps = obj.getSampleCount;
2764 col=hsv(vars);
2765 hold on
2766 for i=1:vars
2767 index = ((i-1) * temps) +1 : i*temps;
2768 plot(Ps(index,a),'-','color',col(i,:));
2769 end
2770 hold off
2771
2772 xlabel('Time')
2773 ylabel(['PC ' num2str(a) ' (' num2str(sum(obj.Landa(a))*100/size(Ps,1)) '%)'])
2774
2775 noms = obj.DATA.getVariableLabel;
2776 if ~isempty(noms)
2777 legend(noms)
2778 end
2779 case 3
2780 Ps=obj.getP();
2781 a = varargin{2};
2782 b = varargin{3};
2783
2784 vars = obj.getVariableCount;
2785 temps = obj.getSampleCount;
2786 col=degradatcolors(vars, temps);
2787 hold on
2788 for j=temps:-1:1
2789 for i=1:vars
2790 ind =(j + (i-1)*temps);
2791 plot(Ps(ind,a),Ps(ind,b),'*','color',col(ind,: ));
2792 end
2793 end
2794
2795 minimx = min(min(Ps(:,a)));
2796 minimy = min(min(Ps(:,b)));
2797 maximx = max(max(Ps(:,a)));
2798 maximy = max(max(Ps(:,b)));
2799 line([0,0],[(minimy - abs(minimy/10)), (maximy + maximy/10)],'color','K','linestyle','--');
2800 line([(minimx - abs(minimx/10)), (maximx + maximx/10)],[0,0],'color','K','linestyle','--');
2801
2802 hold off
2803 xlabel(['PC ' num2str(a) ' (' num2str(sum(obj.Landa(a))*100/size(Ps,1)) '%)'])
2804 ylabel(['PC ' num2str(b) ' (' num2str(sum(obj.Landa(b))*100/size(Ps,1)) '%)'])
2805
2806 noms = obj.DATA.getVariableLabel;
2807 if ~isempty(noms)
2808 legend(noms)
2809 end
2810
2811 case 4
2812 Ps=obj.getP();
2813 a = varargin{2};
2814 b = varargin{3};
2815 c = varargin{4};
2816
2817 vars = obj.getVariableCount;
2818 temps = obj.getSampleCount;
2819 col=degradatcolors(vars, temps);
2820 for j=temps:-1:1
2821 for i=1:vars
2822 ind =(j + (i-1)*temps);
2823 plot3(Ps(ind,a),Ps(ind,b),Ps(ind,c),'*','color',col(ind,:));
2824 hold on
2825 end
2826 end
2827
2828 minimx = min(min(Ps(:,a)));
2829 minimy = min(min(Ps(:,b)));
2830 minimz = min(min(Ps(:,c)));
2831
2832 maximx = max(max(Ps(:,a)));
2833 maximy = max(max(Ps(:,b)));
2834 maximz = max(max(Ps(:,c)));
2835
2836
2837 line([0,0],[(minimy - abs(minimy/10)), (maximy + maximy/10)],[0,0],'color','K','linestyle','--');
2838 line([(minimx - abs(minimx/10)), (maximx + maximx/10)],[0,0],[0,0],'color','K','linestyle','--');
2839 line([0,0],[0,0],[(minimz - abs(minimz/10)),(maximz + maximz/10 )],'color','K','linestyle','--');
2840
2841 hold off
2842
2843 xlabel(['PC ' num2str(a) ' (' num2str(obj.Landa(a)*100/size(Ps,1)) '%)'])
2844 ylabel(['PC ' num2str(b) ' (' num2str(obj.Landa(b)*100/size(Ps,1)) '%)'])
2845 zlabel(['PC ' num2str(c) ' (' num2str(obj.Landa(c)*100/size(Ps,1)) '%)'])
2846
2847 noms = obj.DATA.getVariableLabel;
2848 if ~isempty(noms)
2849 legend(noms)
2850 end
2851 otherwise
2852 errordlg('4D is not allowed!','Error');
2853 end
2854 end
2855
2856 function plotOutLiers(obj)
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870 if(obj.conv == 1)
2871 error('PCA/plotOutLiers: can not be used in Variable Wise.');
2872 end
2873
2874
2875 Qs=obj.getQ;
2876 Ts=obj.getT2();
2877
2878
2879 cl=obj.getClass;
2880 noms = obj.getBatchLabel();
2881
2882
2883 for i = unique(cl)
2884
2885
2886 fig=figure;
2887 dcm_obj = datacursormode(fig);
2888
2889
2890
2891 axe=axes;
2892 boxplot(axe,[Ts(cl==i) Qs(cl==i)]);
2893
2894 hold on;
2895
2896 set(gca,'userdata',{Ts, Qs, noms});
2897
2898
2899 title(['Class ' num2str(i) ]);
2900 hold off;
2901 set(gca,'XTickLabel',{'T^2' 'Q'});
2902
2903
2904 set(dcm_obj,'UpdateFcn',@datatiper);
2905
2906 end
2907
2908 end
2909
2910
2911
2912
2913
2914 function openvar(nom,~)
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924 x=whos('nom');
2925 if strcmp(x.class,'PCA')
2926
2927 else
2928 if(evalin('base',['size(' nom ');']) == [1 1])
2929 Menu_Configura_PCA(nom)
2930 end
2931 end
2932 end
2933
2934
2935
2936 function disp(obj)
2937
2938
2939
2940
2941
2942
2943
2944 obj.DATA.disp(1)
2945 disp(['unique(classes) = ' num2str(unique(obj.getClass))])
2946 end
2947
2948 function s = saveobj(varargin)
2949
2950
2951
2952
2953
2954
2955 obj = varargin{1};
2956
2957 s.DATA = obj.DATA;
2958 s.estandar = obj.estandar;
2959 s.model = obj.model;
2960 s.Z = obj.Z;
2961 s.P = obj.P;
2962 s.Num = obj.Num;
2963 s.Num_save = obj.Num_save;
2964 s.T = obj.T;
2965 s.Landa = obj.Landa;
2966 s.Landai = obj.Landai;
2967 s.sta = obj.sta;
2968 s.mea = obj.mea;
2969 s.E = obj.E;
2970 s.T2 = obj.T2;
2971 s.LimT2 = obj.LimT2;
2972 s.LimQ = obj.LimQ;
2973 s.metode = obj.metode;
2974 s.metodee = obj.metodee;
2975 s.treuFM = obj.treuFM;
2976 s.conv = obj.conv;
2977 s.analitic = obj.analitic;
2978 s.structura = obj.structura;
2979 s.CLimQstd = obj.CLimQstd;
2980 s.CLimQmea = obj.CLimQmea;
2981 s.CLimT2std = obj.CLimT2std;
2982 s.CLimT2mea = obj.CLimT2mea;
2983 s.ContMetode = obj.ContMetode;
2984 end
2985 end
2986
2987 methods (Static)
2988 function obj = loadobj(obj)
2989
2990
2991
2992
2993 if isstruct(obj)
2994
2995 newObj = PCA(DATA());
2996
2997 newObj.DATA = obj.DATA;
2998 newObj.estandar = obj.estandar;
2999 newObj.model = obj.model;
3000 newObj.Z = obj.Z;
3001 newObj.P = obj.P;
3002 newObj.Num = obj.Num;
3003 newObj.Num_save = obj.Num_save;
3004 newObj.T = obj.T;
3005 newObj.Landa = obj.Landa;
3006 newObj.Landai = obj.Landai;
3007 newObj.sta = obj.sta;
3008 newObj.mea = obj.mea;
3009 newObj.E = obj.E;
3010 newObj.T2 = obj.T2;
3011 newObj.LimT2 = obj.LimT2;
3012 newObj.LimQ = obj.LimQ;
3013 newObj.metode = obj.metode;
3014 newObj.metodee = obj.metodee;
3015 newObj.treuFM = obj.treuFM;
3016 newObj.conv = obj.conv;
3017 newObj.analitic = obj.analitic;
3018 newObj.structura = obj.structura;
3019 newObj.CLimQstd = obj.CLimQstd;
3020 newObj.CLimQmea = obj.CLimQmea;
3021 newObj.CLimT2std = obj.CLimT2std;
3022 newObj.CLimT2mea = obj.CLimT2mea;
3023 newObj.ContMetode = obj.ContMetode;
3024 obj = newObj;
3025 end
3026 end
3027 end
3028
3029
3030
3031
3032
3033 methods(Access = private)
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045 function cDKaiser(obj)
3046
3047
3048 obj.Num = find(obj.Landa >= 1,1,'last');
3049
3050 if isempty(obj.Num)
3051 obj.Num= 1;
3052 end
3053 end
3054
3055 function cGrafscree(obj)
3056
3057
3058 figure
3059 plot(obj.Landa);
3060 N = str2double(inputdlg('Entra el punt on hi ha el colze:'));
3061
3062 z=whos('N');
3063 while(~strcmp(z.class,'double'))
3064 plot(obj.Landa);
3065 N = str2double(inputdlg('Entra el punt on hi ha el colze:'));
3066
3067 z=whos('N');
3068 end
3069 obj.Num=N;
3070
3071 end
3072
3073 function cVarExp(obj)
3074
3075
3076
3077 N = str2double(inputdlg('Choose % of variance:'));
3078
3079 z=whos('N');
3080 while(~strcmp(z.class,'double') || (N>100 || N<0))
3081
3082 N = str2double(inputdlg('Choose % of variance:'));
3083 z=whos('N');
3084 end
3085
3086 i = find(cumsum(obj.Landa)*100 / sum(obj.Landa)>N,1);
3087
3088 obj.Num=i;
3089
3090 end
3091
3092 function colzeanalitic(obj)
3093
3094
3095
3096
3097 i=2;
3098 zmax=0;
3099
3100 lan = obj.Landa~=0;
3101 lan=obj.Landa(lan);
3102 Land=lan/max(lan);
3103
3104
3105 while(i<size(Land,1)-1)
3106
3107
3108 z=dpr(0,0,(i-1)/(size(Land,1)),Land(i-1),(i+1)/(size(Land,1)),Land(i+1));
3109 if(zmax<z)
3110 zmax=z;
3111 x=i;
3112 end
3113 i=i+1;
3114 end
3115 obj.Num=x;
3116 end
3117
3118
3119
3120
3121
3122
3123 function estandaritza(obj)
3124
3125 if(obj.estandar~=1)
3126
3127 switch (obj.metodee)
3128
3129 case 1
3130
3131
3132
3133 data=getRawData(obj);
3134
3135 obj.mea=mean(data,1);
3136 obj.sta=std(data,0,1);
3137
3138
3139 case 2
3140
3141 vars=obj.DATA.getVariableCount();
3142 if(obj.conv==0)
3143
3144 data=getRawData(obj);
3145 duration=size(data,2)/vars;
3146 for i=1:1:vars
3147
3148 aux = data(:,duration * (i - 1) + 1:duration * i);
3149
3150 deviation_i = std(aux(:));
3151
3152
3153
3154
3155 obj.sta(duration * (i - 1) + 1:duration * i) = deviation_i;
3156 end
3157 else
3158 if(obj.treuFM>=1)
3159
3160 obj.conv=0;
3161 data=getRawData(obj);
3162 obj.conv=1;
3163
3164 duration=size(data,2)/vars;
3165 for i=1:1:vars
3166
3167 aux = data(:,duration * (i - 1) + 1:duration * i);
3168
3169 deviation_i = std(aux(:));
3170
3171
3172
3173 obj.sta(duration * (i - 1) + 1:duration * i) = deviation_i;
3174 end
3175 else
3176
3177 data=getRawData(obj);
3178
3179
3180 obj.sta=std(data,0,1);
3181 end
3182 end
3183
3184 obj.mea=mean(data,1);
3185
3186
3187 case 3
3188
3189 vars=obj.DATA.getVariableCount();
3190 if(obj.conv==0)
3191
3192 data=getRawData(obj);
3193 duration=size(data,2)/vars;
3194 for i=1:1:vars
3195
3196 aux = data(:,duration * (i - 1) + 1:duration * i);
3197
3198 mean_i = mean(aux(:));
3199 deviation_i = std(aux(:));
3200
3201
3202 obj.mea(duration * (i - 1) + 1: duration * i) = mean_i;
3203
3204
3205
3206 obj.sta(duration * (i - 1) + 1:duration * i) = deviation_i;
3207 end
3208 else
3209
3210 if(obj.treuFM>=1)
3211 obj.conv=0;
3212 data=getRawData(obj);
3213 obj.conv=1;
3214
3215 duration=size(data,2)/vars;
3216 for i=1:1:vars
3217
3218 aux = data(:,duration * (i - 1) + 1:duration * i);
3219
3220 mean_i = mean(aux(:));
3221 deviation_i = std(aux(:));
3222
3223
3224
3225
3226
3227
3228 obj.mea(duration * (i - 1) + 1: duration * i) = mean_i;
3229 obj.sta(duration * (i - 1) + 1:duration * i) = deviation_i;
3230 end
3231 else
3232
3233 data=getRawData(obj);
3234
3235 obj.mea=mean(data,1);
3236 obj.sta=std(data,0,1);
3237 end
3238 end
3239
3240
3241 case 4
3242
3243 vars=obj.DATA.getVariableCount();
3244 if(obj.conv==0)
3245
3246 duration = obj.DATA.getSampleCount();
3247
3248 aux = inputdlg('Enter the block: format [1 1 1 2 2 3 3 3] (for each variavle his wheight)');
3249 block = evalin('base',aux{1});
3250
3251 data=getRawData(obj);
3252
3253 obj.mea=mean(data,1);
3254 obj.sta=std(data,0,1);
3255 for i=1:1:length(block)
3256 obj.sta(duration * (i - 1) + 1:duration * i) = obj.sta(duration * (i - 1) + 1:duration * i) .* repmat(sqrt(block(i)), 1, duration);
3257 end
3258 else
3259
3260 if(obj.treuFM>=1)
3261 obj.conv=0;
3262 data=getRawData(obj);
3263 obj.conv=1;
3264
3265 duration=size(data,2)/vars;
3266
3267 aux = inputdlg('Enter the block: format [1 1 1 2 2 3 3 3] (for each variavle his wheight)');
3268 block = evalin('base',aux{1});
3269
3270 obj.mea=mean(data,1);
3271 obj.sta=std(data,0,1);
3272 for i=1:1:length(block)
3273 obj.sta(duration * (i - 1) + 1:duration * i) = obj.sta(duration * (i - 1) + 1:duration * i) .* repmat(sqrt(block(i)), 1, duration);
3274 end
3275 else
3276
3277 data=getRawData(obj);
3278
3279 obj.mea=mean(data,1);
3280 obj.sta=std(data,0,1);
3281
3282 aux = inputdlg('Enter the block: format [1 1 1 2 2 3 3 3] (for each variavle his wheight)');
3283 block = evalin('base',aux{1});
3284 for j=1:length(block)
3285 obj.sta(j)=obj.sta(j)*sqrt(block(j));
3286 end
3287 end
3288 end
3289 otherwise
3290 error('PCA\estandaritza:estandaritzation method not valid')
3291 end
3292
3293
3294 obj.Z = (data - repmat(obj.mea, size(data, 1), 1)) ./ repmat(obj.sta, size(data, 1), 1);
3295
3296 obj.estandar=1;
3297
3298 if( obj.conv==1 && obj.metodee~=1)
3299
3300 duration=size(data,2)/vars;
3301
3302 x=reshape(obj.Z',[duration vars size(data,1)]);
3303 x=permute(x,[1 3 2]);
3304 obj.Z=reshape(x,size(x,2)*size(x,1),size(x,3));
3305 end
3306 end
3307 end
3308
3309 function estandaritz2(obj)
3310
3311
3312 if (obj.conv==1 && obj.metodee~=1 && obj.treuFM>=1)
3313 obj.conv=0;
3314 data=obj.getRawData();
3315 obj.conv=1;
3316
3317 else
3318 data=obj.getRawData();
3319 end
3320
3321
3322 obj.Z = (data - repmat(obj.mea, size(data, 1), 1)) ./ repmat(obj.sta, size(data, 1), 1);
3323
3324 obj.estandar=1;
3325
3326 if( obj.conv==1 && obj.metodee~=1 && obj.treuFM>=1)
3327
3328 vars=obj.DATA.getVariableCount();
3329 duration=size(data,2)/vars;
3330 x=reshape(obj.Z',[duration vars size(data,1)]);
3331 x=permute(x,[1 3 2]);
3332 obj.Z=reshape(x,size(x,2)*size(x,1),size(x,3));
3333
3334 end
3335
3336 end
3337
3338
3339
3340
3341
3342
3343 function calculaE(obj)
3344
3345 if(isempty(obj.P)||isempty(obj.Z))&& obj.getBatchCount>0
3346
3347 obj.pca();
3348 end
3349
3350 obj.E= (obj.Z-obj.Z*obj.P*obj.P');
3351 end
3352
3353 function calculaLimQ(obj)
3354
3355 if(obj.analitic)
3356
3357 calculaLimQv2(obj)
3358 else
3359
3360 calculaLimQv1(obj)
3361 end
3362 end
3363
3364 function calculaLimT2(obj)
3365
3366 if(isempty(obj.T) && obj.getBatchCount>0)
3367
3368 obj.pca();
3369 end
3370
3371 if(obj.analitic)
3372
3373 calculaLimT2v2(obj)
3374 else
3375
3376 calculaLimT2v1(obj)
3377 end
3378 end
3379
3380 function calculaLimQv1(obj)
3381
3382 if(isempty(obj.E) && obj.getBatchCount>0)
3383
3384
3385 getE(obj);
3386 end
3387
3388 Q=((obj.E).^2)*ones(size(obj.E,2),1);
3389 obj.LimQ=mean(Q)+std(Q)*3;
3390 end
3391
3392 function calculaLimQv2(obj)
3393
3394 if(isempty(obj.Landai) && obj.getBatchCount>0)
3395
3396
3397 obj.pca();
3398 end
3399
3400
3401 alpha=0.95;
3402 ca=norminv(alpha, 0, 1);
3403 ncp=obj.Num;
3404 D=obj.Landai;
3405 theta=zeros(3);
3406 aux = D(ncp+1:length(D));
3407 for i=1:3
3408 theta(i)=sum(aux.^i);
3409 end
3410 h0=1-2*theta(1)*theta(3)/3/theta(2)^2;
3411 obj.LimQ=theta(1)*(ca*h0*sqrt(2*theta(2))/theta(1)+1+theta(2)*h0*(h0-1)/theta(1)^2)^(1/h0);
3412
3413 end
3414
3415 function calculaLimT2v1(obj)
3416
3417
3418 obj.T2=((obj.T).^2);
3419 obj.T2=((obj.T2)./repmat(obj.Landa',size(obj.T2,1),1))*ones(size(obj.T2,2),1);
3420
3421 obj.LimT2=mean(obj.T2)+ std(obj.T2)*3;
3422 end
3423
3424 function calculaLimT2v2(obj)
3425
3426
3427 if(isempty(obj.Num))
3428
3429 obj.pca();
3430 end
3431
3432 alpha=0.95;
3433 n=size(obj.Z,1);
3434 a=obj.Num;
3435 obj.LimT2=a*(n-1)/(n-a)*finv(alpha,a,n-a);
3436
3437 end
3438
3439 function x = calculaContT2(obj)
3440
3441 if(isempty(obj.T) && obj.getBatchCount>0)
3442 obj.pca();
3443 end
3444
3445
3446
3447 aux = (obj.T * diag(1./sqrt(obj.Landa)) * obj.P') .* obj.Z;
3448
3449 if(obj.ContMetode == 0)
3450
3451 x = aux .* (aux > 0) ;
3452 else
3453
3454 x = aux;
3455 end
3456
3457 if(isempty(obj.CLimT2mea)||isempty(obj.CLimT2std))
3458
3459
3460 obj.CLimT2mea=mean(x);
3461
3462 obj.CLimT2std=std(x);
3463
3464 end
3465
3466
3467 end
3468
3469 function x = calculaContQ(obj)
3470
3471
3472 if(isempty(obj.E)&& obj.getBatchCount>0)
3473 calculaE(obj);
3474 end
3475
3476
3477 if(obj.ContMetode == 0)
3478
3479 x = (obj.E).^2;
3480 else
3481
3482 x = obj.E;
3483 end
3484
3485 if(isempty(obj.CLimQmea)||isempty(obj.CLimQstd))
3486
3487 obj.CLimQmea=mean(x);
3488
3489 obj.CLimQstd=std(x);
3490
3491 end
3492
3493 end
3494
3495
3496
3497
3498
3499 function vect = foraCQ(obj)
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512 x= (repmat(obj.getQContributionLimitMean-obj.getQContributionLimitStd *3,size(obj.getQContribution,1),1) > obj.getQContribution) + (obj.getQContribution > repmat(obj.getQContributionLimitMean+obj.getQContributionLimitStd *3,size(obj.getQContribution,1),1));
3513 z=obj.DATA.getStagesDurations();
3514 resp=zeros(size(x,1),length(z)*length(obj.DATA.getVariableLabel()));
3515 k=1;
3516 for i=1:length(obj.DATA.getVariableLabel())
3517 for j=1:length(z)
3518 resp(:,(i-1)*length(z)+j)= sum(x(:,k:k+z(j)-1),2);
3519 k=k+z(j);
3520 end
3521 end
3522 vect=resp;
3523
3524
3525
3526 end
3527
3528 function plotLimCT2(obj,char)
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539 if(isempty(obj.CLimT2mea)||isempty(obj.CLimT2std))
3540 calculaContT2(obj);
3541 end
3542 hold on;
3543 plot(obj.CLimT2mea+obj.CLimT2std*3,char,'HitTest','off');
3544
3545 if(obj.ContMetode == 1)
3546
3547 plot(obj.CLimT2mea-obj.CLimT2std*3,char,'HitTest','off');
3548 end
3549
3550 hold off;
3551 end
3552
3553 function plotLimCQ(obj,char)
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564 if(isempty(obj.CLimQmea)||isempty(obj.CLimQstd))
3565 calculaContQ(obj);
3566 end
3567 hold on;
3568 plot(obj.CLimQmea+obj.CLimQstd*3,char,'HitTest','off');
3569
3570 if(obj.ContMetode == 1)
3571
3572 plot(obj.CLimQmea-obj.CLimQstd*3,char,'HitTest','off');
3573 end
3574
3575 hold off;
3576 end
3577
3578 end
3579 end
3580
3581
3582 function out = datatiper(varargin)
3583
3584
3585
3586
3587
3588 try
3589 dades=get(gca,'Userdata');
3590 pos=varargin{2}.Position;
3591 a=get(gco,'yData');
3592 pos(2)=a(pos(2) - 7);
3593 nomlots = dades{3};
3594 if pos(1)==1 || pos(1)==2
3595 numlot=find(dades{pos(1)} == pos(2), 1,'first');
3596 if ~isempty(numlot)
3597 out ={['Batch number:' num2str(numlot)];['Batch name: ' nomlots{numlot}] };
3598 else
3599 out='Not a batch!';
3600 end
3601 else
3602 out='Not a batch!';
3603 end
3604 catch
3605 out='Not a batch!';
3606 end
3607 end
3608
3609
3610 function out = tipme(varargin)
3611
3612
3613
3614
3615
3616 dades=get(gca,'Userdata');
3617 pos=varargin{2}.Position;
3618 switch length(dades.punts)
3619 case 1
3620 numlot=find(dades.punts{1} == pos(2),1,'first');
3621 case 2
3622 numlot=find(and(dades.punts{1} == pos(1), dades.punts{2} == pos(2)),1,'first');
3623 case 3
3624 numlot=find(and(and(dades.punts{1} == pos(1), dades.punts{2} == pos(2)), dades.punts{3} == pos(3)),1,'first');
3625 end
3626
3627 if ~isempty(numlot)
3628 out ={['Batch number:' num2str(numlot)];['Batch name: ' dades.noms{numlot}] };
3629 else
3630 out='Not a batch!';
3631 end
3632
3633 end
3634
3635
3636 function out = tipmelot(varargin)
3637
3638
3639
3640
3641
3642 try
3643 dades=get(gca,'Userdata');
3644 pos=varargin{2}.Position;
3645 switch length(dades.punts)
3646 case 1
3647 numlot=find(dades.punts{1} == pos(2),1,'first');
3648 case 2
3649 numlot=find(and(dades.punts{1} == pos(1), dades.punts{2} == pos(2)),1,'first');
3650 case 3
3651 numlot=find(and(and(dades.punts{1} == pos(1), dades.punts{2} == pos(2)), dades.punts{3} == pos(3)),1,'first');
3652 end
3653
3654 if ~isempty(numlot)
3655 out ={['Batch name: ' dades.noms{numlot}] };
3656 else
3657 out='Not a batch!';
3658 end
3659 catch err
3660 out='Not a batch!';
3661 end
3662 end