?? batch_digits.m
字號(hào):
function batch_Digitsclose all;dbstop if error;load Digits_Data[num_ex,num_labels] = size(True_Y);for i = 1:num_labels ind_data(i).labels = find(True_Y(:,i) == 1);endlrn_par = Set_Default_Learning_Paramters;% Optimization for both ALPHA and SIGMA togetherlrn_par.OPT_S_A = 1; % set to 1 to optimize for both alpha and sigma%Clustering ExampleY = []; %Set to null for clusteringmodel = LG_Cluster(Data_X,lrn_par)lrn_par.OPT_S_A = 0;model2 = LG_Cluster(Data_X,lrn_par);fprintf(1,'sigma %f alpha %f clusters %i\n',model.my_sigma,model.my_alpha,model.num_classes);save digits_model;True_Y=True_Y(:,[1 3 4 2]);errors = abs(model.Y - True_Y);err_ind = find(sum(abs(model.Y - True_Y)')'>0);num_errors = length(err_ind);err_rate = num_errors / num_exerrors = abs(model2.Y - True_Y);err_ind = find(sum(abs(model2.Y - True_Y)')'>0);num_errors = length(err_ind);err_rate = num_errors / num_ext10000 = 5;pix=16;line=[];nifty_plot=[];for i=1:model.num_classes pic = 256 * ((reshape(Data_X(model.ind_clust(i),:),16,16))' + 1)/2; % representant for the class line=[line,zeros(pix,1),pic]; if mod(i,4)==0 nifty_plot=[nifty_plot; zeros(1,length(line)); line]; line=[]; end;end;if mod(i,4)~=0 while size(line,2) < size(nifty_plot,2) line=[line,zeros(pix,1),zeros(pix,pix)]; end; nifty_plot=[nifty_plot; zeros(1,length(line)); line];end;figure;colormap(gray);image(nifty_plot);axis off;title('Class Representants');nifty_plot=[];% plot class outliers outliersfor i = [1 3 4 2] line= 256 * ((reshape(Data_X(model.ind_clust(i),:),16,16))' + 1)/2; % representant for the class line=[line,zeros(pix,1),256*ones(pix,2),zeros(pix,1)]; for j = 1:8 ex_dig = 256 * ((reshape(Data_X(model.Class_Outlier(i).ind_sort(j),:),16,16))' + 1)/2; line=[line,zeros(pix,1),ex_dig]; %figure;image(ex_dig); t77 = 77; end line = [line,zeros(pix,1)]; nifty_plot=[nifty_plot; zeros(1,length(line)); line ]; t77 = 0;endfigure;colormap(gray);image(nifty_plot);axis off;title('Class Outliers');% plot overall outliersnifty_plot=[];ii=1;for i = 1:5 line=[]; for j=1:5 ex_dig = 256 * ((reshape(Data_X(model.ind_sort_mean_dist(ii),:),16,16))' + 1)/2; line=[line,zeros(pix,1),ex_dig]; ii=ii+1; end; %figure;image(ex_dig); line = [line,zeros(pix,1)]; nifty_plot=[nifty_plot; zeros(1,length(line)); line ]; t77 = 77;endfigure;colormap(gray);image(nifty_plot);axis off;title('Worst overall outliers');if 1==2 fprintf(1,'Handling unseen data...\n'); load Digits_Data_us [un_class] = Classify_New_Data(Data_X_us,model); True_Y_us=True_Y_us(:,[1 3 4 2]); err_ind = find(sum(abs(un_class.Y - True_Y_us)')'>0); num_errors = length(err_ind); err_rate = num_errors / size(Data_X_us,1)end;if 1==2 fprintf(1,'Handling unseen data 2...\n'); load Digits_Data_us [un_class] = Classify_New_Data(Data_X_us,model2); True_Y_us=True_Y_us(:,[1 3 4 2]); err_ind = find(sum(abs(un_class.Y - True_Y_us)')'>0); num_errors = length(err_ind); err_rate = num_errors / size(Data_X_us,1)end;t10000 = 5;[i,labels]=max(model.F_orig,[],2);figure;hold on;for i=1:model.num_classes ind_x=find(labels==i); plot_values = model.Class_Outlier(i).plot_values; plot_value2 = model2.Class_Outlier(i).plot_values; plot(plot_values(ind_x,:),'r*'); %plot the points in each cluster plot(plot_value2(ind_x,:),'b+'); %plot the points in each clusterend;legend('Optimizing Alpha+Sigma','Optimizing Sigma only')title('Class outliers');legendpos=[0,2,2,0];for i=1:model.num_classes plot_values = model.Class_Outlier(i).plot_values; plot_value2 = model2.Class_Outlier(i).plot_values; figure; hold on; plot(plot_values,'r*'); %plot the points in each cluster plot(plot_value2,'b+'); %plot the points in each cluster legend('Optimizing Alpha+Sigma','Optimizing Sigma only',legendpos(i)) mytitle=sprintf('Class outliers for class %i',i); title(mytitle);end;% err_rate =% % 0.0362% % % err_rate =% % 0.0388
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -