0001 function varargout = Menu_Exemples(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010 gui_Singleton = 1;
0011 gui_State = struct('gui_Name', mfilename, ...
0012 'gui_Singleton', gui_Singleton, ...
0013 'gui_OpeningFcn', @Menu_Exemples_OpeningFcn, ...
0014 'gui_OutputFcn', @Menu_Exemples_OutputFcn, ...
0015 'gui_LayoutFcn', [] , ...
0016 'gui_Callback', []);
0017 if nargin && ischar(varargin{1})
0018 gui_State.gui_Callback = str2func(varargin{1});
0019 end
0020
0021 if nargout
0022 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0023 else
0024 gui_mainfcn(gui_State, varargin{:});
0025 end
0026
0027
0028
0029
0030 function Menu_Exemples_OpeningFcn(hObject, ~, handles, varargin)
0031
0032
0033
0034 handles.output = hObject;
0035 guidata(hObject, handles);
0036
0037 set(handles.popupmenu1,'String',{'Basic Example 1' 'Basic Example 2' '------------------------' 'DATA Example 1' 'DATA Example 2' '------------------------' 'PCA Example 1' 'PCA Example 2' '------------------------' 'CBR Example'});
0038
0039
0040 function varargout = Menu_Exemples_OutputFcn(~, ~, handles)
0041 varargout{1} = handles.output;
0042
0043
0044 function listbox1_Callback(~, ~, ~)
0045
0046
0047 function listbox1_CreateFcn(hObject, ~, ~)
0048 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0049 set(hObject,'BackgroundColor','white');
0050 end
0051
0052
0053
0054 function pushbutton1_Callback(~, ~, handles)
0055 aux=get(handles.listbox1,'string');
0056 aux2=aux(get(handles.listbox1,'value'));
0057 if not(isempty(aux2{1})) && not(strcmp(aux2{1}(1),'%'))
0058 Envia_Comanda(aux{get(handles.listbox1,'value')});
0059 end
0060 if(get(handles.listbox1,'value')< length(aux))
0061 set(handles.listbox1,'value',get(handles.listbox1,'value')+1);
0062 end
0063
0064 function popupmenu1_Callback(~, ~, handles)
0065 Envia_Comanda('clc');
0066 switch get(handles.popupmenu1,'value')
0067 case 1
0068 set(handles.listbox1,'value',1)
0069 set(handles.listbox1,'string',{'%%Basic Example 1 <- This is the way to comment' '% <- This is also a coment line' '%In order to create a new variable we just need to give them a value:' 'a=0' '%from now on we can use a in our code' 'a=a+1' '%the last instruction has printed the results if we don''t want to see the results we just have to add ; to the end of the instruction' 'a=a+1;' '%to see a variable value we can type his name:' 'a' '%For more information you should use the manual'})
0070 case 2
0071 set(handles.listbox1,'value',1)
0072 set(handles.listbox1,'string',{'%%Basic Example 2' '' '%As we are executing code from a GUI if we want to do a plot we have to open a figure first.' 'figure;plot(sin(1:100))' '%we are limitated to use inline programation of Matlab for example a for instruction looks like:' 'for i=1:100; a=a+1; end' '%to clean the window we also have as in matlab the command clc' 'clc' '%and for deleting variables clear as in Matlab:' 'clear a' '%For more information you should use the manual'})
0073 case 3
0074 set(handles.listbox1,'value',1)
0075 set(handles.listbox1,'string', {'%% Select one Example ---->'} );
0076
0077 case 4
0078 set(handles.listbox1,'value',1)
0079 set(handles.listbox1,'string',{
0080 '%% DATA Exemple 1'
0081 ''
0082 '%we load some data to our workspace'
0083 'load ''.\\Exemples\\Matriu_Good_Cross_Learning_1_Sort.mat'';'
0084 'load ''.\\Exemples\\DatosProceso.mat'';'
0085 '%we create an empty DATA object'
0086 'dat=DATA();'
0087 '%we put some Data to the object'
0088 'dat.setRawDataBW(MatriuGCL1sort,4,461,59);%our data is currently in Batch-Wise'
0089 '%we set the names of the variables of our procces'
0090 'dat.setVariableLabel(model_process_data.var_name);'
0091 '%we set the phase durations'
0092 'dat.setStagesDurations(str2double(model_process_data.phase_time));'
0093 '%we set the phase Lables'
0094 'dat.setStages(model_process_data.phase_name);'
0095 '%we set the classes'
0096 'dat.setClass(ones(1,59));'
0097 '%we get the Raw data in a 3D matrix format '
0098 'dadesen3D=dat.getRawData3D();'
0099 ''
0100 '%we get the Raw data in a Batch-Wise matrix format '
0101 'dadesBW=dat.getRawData(0);'
0102 ''
0103 '%we get the Raw data in a Variable-Wise matrix format '
0104 'dadesVW=dat.getRawData(1);'
0105 ''
0106 '%we get the informationwe have from batch in the 5th position'
0107 '[lot classe]=dat.getBatch(5);'
0108 ''
0109 '%we delete the batch in the 5th position'
0110 'dat.deleteBatch(5);'
0111 ''
0112 '%we add the 5th batch to the object (allways we add to the end)'
0113 'dat.addBatch(lot, classe);'
0114 '%For more information you should use the manual'});
0115
0116 case 5
0117 set(handles.listbox1,'value',1)
0118 set(handles.listbox1,'string',{
0119 '%DATA Example 2'
0120 ''
0121 '%we load the data we will use to the workspace'
0122 'load(''.\\Exemples\\dades3D.mat'');'
0123 '%we create a new object DATA'
0124 'meu=DATA();'
0125 '%se set to the object a 3D raw data matrix'
0126 'meu.setRawData(dadesen3D);'
0127 '%we set the variable Label names'
0128 'meu.setVariableLabel({''pH'' ''O2'' ''RedOx'' ''Temp''})'
0129 '%we set the Phase durations'
0130 'meu.setStagesDurations([15 138 187 6 75 40])'
0131 '%we set the Phase Lable names'
0132 'meu.setStages({''F1'' ''ANA'' ''AE1'' ''F2'' ''ANO'' ''AE2''})'
0133 '%we set the classes'
0134 'meu.setClass(ones(1,59));'
0135 ''
0136 '%is a good practice to initialize the variables'
0137 'eliminar=logical(meu.getBatchCount());'
0138 '%the first one will not be removed'
0139 'eliminar(1)=0;'
0140 '%for every batch do:'
0141 'for i=2: meu.getBatchCount(); figure(1); plot(meu.getBatch(1)); figure(2); plot(meu.getBatch(i)); resposta=inputdlg(''You want to add this batch? ( 1=yes 0=no)''); eliminar(i)=(str2num(resposta{1})==1);end'
0142 ''
0143 '%delete the selected ones'
0144 'meu.deleteBatch(eliminar);'
0145
0146 '%we save ''meu'' object to the file ''meu.txt'''
0147 'meu.save(''meu.txt'',''csv'');'
0148 ''
0149 '%we create and empty DATA object named ''d'''
0150 'd=DATA();'
0151 ''
0152 '%we initialize ''d'' with the information from file ''meu.txt'''
0153 'd.load(''meu.txt'',''csv'');'
0154 '%we save again ''d'' to a new file'
0155 'd.save(''meu2.txt'',''csv'');'
0156 '%%For more information and examples you should use the manual'});
0157 case 6
0158 set(handles.listbox1,'value',1)
0159 set(handles.listbox1,'string', {'%% Select one Example ---->'} );
0160 case 7
0161 set(handles.listbox1,'value',1)
0162 set(handles.listbox1,'string',{
0163 '%%PCA Example 1'
0164 ''
0165 '%creation of a DATA object for our PCA'
0166 '%we load the data we will use to the workspace'
0167 'load(''.\\Exemples\\dades3D.mat'');'
0168 '%we create a new object DATA'
0169 'meu=DATA();'
0170 '%se set to the object a 3D raw data matrix'
0171 'meu.setRawData(dadesen3D);'
0172 '%we set the variable Label names'
0173 'meu.setVariableLabel({''pH'' ''O2'' ''RedOx'' ''Temp''})'
0174 '%we set the Phase durations'
0175 'meu.setStagesDurations([15 138 187 6 75 40])'
0176 '%we set the Phase Lable names'
0177 'meu.setStages({''F1'' ''ANA'' ''AE1'' ''F2'' ''ANO'' ''AE2''})'
0178 '%we set the classes'
0179 'meu.setClass(ones(1,59));'
0180 ''
0181 '%we create a new PCA object'
0182 'MY_PCA=PCA(meu);'
0183 'MY_PCA.setUnfoldingMethod(1);%1=Variable-Wise,0=Batch-Wise'
0184 'MY_PCA.setNormalizationMethod(1);%1=Auto Scaling,2=Group Scaling,3=Continuous Scaling,4=Block Scaling'
0185 'MY_PCA.setPCSelectionMethod(1);%0=Manual,1=Kaiser,2=screeplot,3=Auto-screeplot,4=% variance explication,5=VRE'
0186 'MY_PCA.setLimitMethod(1);%1=analytically,0=3sigma'
0187 'MY_PCA.setTrajectoryRemoval(0);%1=yes,0=no'
0188 ''
0189 '%we get all we need from the object'
0190 'p=MY_PCA.getP();'
0191 'z=MY_PCA.getZ();'
0192 'std=MY_PCA.getStd();'
0193 'mea=MY_PCA.getMean();'
0194 't=MY_PCA.getT();'
0195 't2=MY_PCA.getT2Limit();'
0196 'landa=MY_PCA.getLambda();'
0197 'e=MY_PCA.getE();'
0198 '%%For more information and examples you should use the manual'});
0199 case 8
0200 set(handles.listbox1,'value',1)
0201 set(handles.listbox1,'string',{
0202 '%%PCA Example 2'
0203 ''
0204 '%creation of a DATA object for our PCA'
0205 '%we load the data we will use to the workspace'
0206 'load(''.\\Exemples\\dades3D.mat'');'
0207 '%we create a new object DATA'
0208 'm=DATA();'
0209 '%se set to the object a 3D raw data matrix'
0210 'm.setRawData(dadesen3D);'
0211 '%we set the variable Label names'
0212 'm.setVariableLabel({''pH'' ''O2'' ''RedOx'' ''Temp''});'
0213 '%we set the Phase durations'
0214 'm.setStagesDurations([15 138 187 6 75 40]);'
0215 '%we set the Phase Lable names'
0216 'm.setStages({''F1'' ''ANA'' ''AE1'' ''F2'' ''ANO'' ''AE2''});'
0217 '%we set the classes'
0218 'm.setClass(ones(1,59));'
0219 ''
0220 '%%we load the data to be tested'
0221 'load(''.\\Exemples\\dades3Dclasificar.mat'');'
0222 'p=DATA();'
0223 '%se set to the object a 3D raw data matrix'
0224 'p.setRawDataBW(dadesen3Dclasificar,4,461,263);'
0225 '%we set the variable Label names'
0226 'p.setVariableLabel({''pH'' ''O2'' ''RedOx'' ''Temp''});'
0227 '%we set the Phase durations'
0228 'p.setStagesDurations([15 138 187 6 75 40]);'
0229 '%we set the Phase Lable names'
0230 'p.setStages({''F1'' ''ANA'' ''AE1'' ''F2'' ''ANO'' ''AE2''});'
0231 '%we set the classes'
0232 'p.setClass(ones(1,263));'
0233 ''
0234 '%%Creem El PCA model'
0235 'model=PCA(m);'
0236 'model.setUnfoldingMethod(0);%1=Variable-Wise,0=Batch-Wise'
0237 'model.setNormalizationMethod(3);;%1=Auto Scaling,2=Group Scaling,3=Continuous Scaling,4=Block Scaling'
0238 'model.setPCSelectionMethod(1);%0=Manual,1=Kaiser,2=screeplot,3=Auto-screeplot,4=% variance explication,5=VRE'
0239 'model.setLimitMethod(1);%1=analytically,0=3sigma'
0240 'model.setTrajectoryRemoval(0);%1=yes,0=no'
0241 ''
0242 '%we create a new PCA-projection'
0243 'projectat=model.project(p);'
0244 ''
0245 '%we initialize the vector for storing the answers'
0246 'e=false(p.getBatchCount(),1);'
0247 ''
0248 ''
0249 'for i=250:p.getBatchCount(); figure(1);projectat.plotQContribution(i); resposta=inputdlg(''S''''ha d''''afegir?( 1=si 0=no)''); e(i)=(str2num(resposta{1} )==1);end'
0250
0251 'if sum(e)>0 ; [data ,class] =projectat.getBatch(e); model.addBatch(data,class); end'
0252 '%%For more information and examples you should use the manual'});
0253 case 9
0254 set(handles.listbox1,'value',1)
0255 set(handles.listbox1,'string', {'%% Select one Example ---->'} );
0256
0257 case 10
0258 set(handles.listbox1,'value',1)
0259 set(handles.listbox1,'string', {
0260
0261 '%CBR Example'
0262 ''
0263 ''
0264 '%First we create a model for our CBR'
0265 ''
0266 '%we load the data we will need'
0267 'load ''.\\Exemples\\Matriu_LEQUIA_Bons_2A_Final.mat'';'
0268 'load ''.\\Exemples\\Matriu2A_Bons_3e.mat'';'
0269 ''
0270 '%We need a DATA object for create a new PCA model'
0271 'dat=DATA();'
0272 'dat.setRawDataBW(Matriu2ABons,4,424,70);'
0273 'dat.setVariableLabel(Matriu.Vars);'
0274 'cla1=ones(1,70);%we create the classes (class 1 = good)'
0275 'dat.setClass(cla1);'
0276 ''
0277 '%We creae the PCA model'
0278 'M=PCA(dat);'
0279 ''
0280 '%We need a DATA object as case base for our CBR'
0281 ''
0282 '%we load the data'
0283 'load ''.\\Exemples\\Matriu2A_Dolents.mat'';'
0284 ''
0285 'cla2=ones(1,91)*2;%we create the classes (class 2 = bad)'
0286 ''
0287 'aux=DATA();'
0288 'aux.setRawDataBW(Matriu2ADolents,4,424,91);'
0289 ''
0290 '%in the case base we need good and bad cases so we merge both'
0291 'dade=cat(3,aux.getRawData3D(), dat.getRawData3D());'
0292 'claa=cat(2,cla2,cla1);'
0293 ''
0294 '%we load regulr ones'
0295 'load ''.\\Exemples\\Matriu_LEQUIA_Regulars_2A.mat'';'
0296 ''
0297 'cla3=ones(1,62)*3;%we will use 3 as class rot regular ones'
0298 ''
0299 '%we also merge the regulars'
0300 'dade=cat(3,dade, Matriu.Variables);'
0301 'claa=cat(2,claa,cla3);'
0302 ''
0303 '%now we can create the Case Base'
0304 'dat1=DATA();'
0305 'dat1.setRawData(dade);'
0306 'dat1.setVariableLabel(Matriu.Vars);'
0307 'dat1.setClass(claa);'
0308 ''
0309 'dat1.shuffle();%we shuffle the case base to remove their order'
0310 ''
0311 '%We create our CBR object'
0312 'MY_CBR=CBR(M,dat1);'
0313 ''
0314 'prov=dat1.copy();'
0315 '% now we cane use the CBR example with full parameters'
0316 'vk = [5 3];'
0317 'dc = 10;'
0318 'methode = 3;'
0319 ''
0320 'MY_CBR.retrieve(prov,vk,dc);'
0321 'MY_CBR.reuse(methode);'
0322 'MY_CBR.IB2(vk,dc,methode);'
0323 'MY_CBR.IB3(vk,dc,methode);'
0324 'MY_CBR.IBUdG(3,0,vk,dc,methode);'
0325 'MY_CBR.DROP4(vk,dc,methode);'
0326 ''
0327 '% CBR example short form'
0328 ''
0329 'MY_CBR.retrieve(prov);'
0330 'MY_CBR.reuse();'
0331 'MY_CBR.IB2();'
0332 'MY_CBR.IB3();'
0333 'MY_CBR.IBUdG(3,0);'
0334 'MY_CBR.DROP4();'
0335 '%%For more information and examples you should use the manual'});
0336
0337
0338
0339
0340 end
0341
0342
0343 function popupmenu1_CreateFcn(hObject, ~, ~)
0344 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0345 set(hObject,'BackgroundColor','white');
0346 end
0347
0348
0349
0350 function figure1_ResizeFcn(hObject, ~, handles)
0351 pos=get(hObject,'Position');
0352 set(handles.listbox1,'Position',[1 1 pos(3)*0.75-1 pos(4)-2]);
0353 set(handles.popupmenu1,'Position',[pos(3)*0.75+1 4 pos(3)*0.25-2 pos(4)-5]);
0354 set(handles.pushbutton1,'Position',[pos(3)*0.75+1 pos(4)-10 pos(3)*0.25-2 2]);
0355
0356 function Update(~, ~, ~)
0357
0358
0359
0360 function figure1_CreateFcn(~, ~, ~)
0361
0362
0363