% Testing the proposed RAEOCSVMs on Wdbc
close all
clear all
warning off
% Domains of prameters for OCSVM
sigma_all=[0.3,0.4,0.5,0.8,2,4,8,16,64];
nu_all=[0.01,0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1];
% Parameter settings for RAEOCSVMs
n_base=20; % Number of base classifiers
% Load data set
load wdbc
n_T=length(find(labels==1)); % Number of target samples
n_O=length(find(labels==-1)); % Number of non-target samples
T=data(find(labels==1),:); % Target samples
O=data(find(labels==-1),:); % Non-target samples
% Normalization
x_min=-1;
x_max=1;
T_scale=x_min+(T-ones(n_T,1)*min(T))./(ones(n_T,1)*(max(T)-min(T)))*(x_max-x_min);
O_scale=x_min+(O-ones(n_O,1)*min(T))./(ones(n_O,1)*(max(T)-min(T)))*(x_max-x_min);
% Choosing the optimal pamaters for OCSVM
par1=sigma_all; % sigma1
par2=nu_all; % nu
for k=1:length(par1)
for l=1:length(par2)
u=par1(k); % sigma1
v=par2(l); % nu
n_T_tr=round(n_T*0.7);
n_O_tr=round(n_O*0.05);
if n_O_tr<=5
n_O_tr=5;
end
rind_T=[];rind_O=[];
x_tr_all=[];x_ts_all=[];
rind_T=randperm(n_T);
rind_O=randperm(n_O);
x_tr_all=[T_scale(rind_T(1:n_T_tr),:);O_scale(rind_O(1:n_O_tr),:)];
x_ts_all=[T_scale(rind_T(n_T_tr+1:end),:);O_scale(rind_O(n_O_tr+1:end),:)];
labels=[];ocsvm=[];y_ocsvm=[];labels_ocsvm=[];
labels=[ones(n_T-n_T_tr,1);-ones(n_O-n_O_tr,1)];
ocsvm=ocsvm_tr(x_tr_all,u,v);
y_ocsvm=ocsvm_ts(x_ts_all,ocsvm,u);
labels_ocsvm=y_ocsvm.labels;
g_ocsvm_ts_avg(k,l)=g_mean(labels,labels_ocsvm);
end
end
% The optimal parameters for OCSVM
[val,ind]=max(g_ocsvm_ts_avg(:));
row=mod(ind-1,length(par1))+1;
col=floor((ind-1)/length(par1))+1;
sigma=par1(row);
nu=par2(col);
max_iter=20; % 20 trials for repetitions
for iter=1:max_iter
% For OCSVM
n_T_tr=round(n_T*0.7);
n_O_tr=round(n_O*0.05);
if n_O_tr<=5
n_O_tr=5;
end
rind_T=randperm(n_T);
rind_O=randperm(n_O);
x_tr=[];x_ts=[];x_tr_all=[];x_ts_all=[];
x_tr=[T(rind_T(1:n_T_tr),:);O(rind_O(1:n_O_tr),:)];
n_tr=size(x_tr,1);
x_ts=[T(rind_T(n_T_tr+1:end),:);O(rind_O(n_O_tr+1:end),:)];
n_ts=size(x_ts,1);
x_tr_all=x_min+(x_tr-ones(n_tr,1)*min(x_tr))./(ones(n_tr,1)*(max(x_tr)-min(x_tr)))*(x_max-x_min);
x_ts_all=x_min+(x_ts-ones(n_ts,1)*min(x_tr))./(ones(n_ts,1)*(max(x_tr)-min(x_tr)))*(x_max-x_min);
labels=[];ocsvm=[];y_ocsvm=[];labels_ocsvm=[];
labels_tr=[];y_ocsvm_tr=[];labels_ocsvm_tr=[];
labels=[ones(n_T-n_T_tr,1);-ones(n_O-n_O_tr,1)];
labels_tr=[ones(n_T_tr,1);-ones(n_O_tr,1)];
ocsvm=ocsvm_tr(x_tr_all,sigma,nu);
y_ocsvm=ocsvm_ts(x_ts_all,ocsvm,sigma);
y_ocsvm_tr=ocsvm_ts(x_tr_all,ocsvm,sigma);
labels_ocsvm=y_ocsvm.labels;
labels_ocsvm_tr=y_ocsvm_tr.labels;
g_ocsvm(iter)=g_mean(labels,labels_ocsvm);
g_ocsvm_tr(iter)=g_mean(labels_tr,labels_ocsvm_tr);
% For RAEOCSVMs
ocsvm_rada=[];y_ocsvm_rada=[];labels_ocsvm_rada=[];
y_ocsvm_rada_tr=[];labels_ocsvm_rada_tr=[];
ocsvm_rada=raeocsvms_tr(x_tr_all,sigma,nu,n_base);
y_ocsvm_rada=raeocsvms_ts(x_ts_all,ocsvm_rada,sigma);
y_ocsvm_rada_tr=raeocsvms_ts(x_tr_all,ocsvm_rada,sigma);
labels_ocsvm_rada=sign(y_ocsvm_rada.values);
labels_ocsvm_rada_tr=sign(y_ocsvm_rada_tr.values);
g_ocsvm_rada(iter)=g_mean(labels,labels_ocsvm_rada);
g_ocsvm_rada_tr(iter)=g_mean(labels_tr,labels_ocsvm_rada_tr);
end
% Show the results
clc
fprintf('*****************************************************\n')
fprintf('sigma nu \n');
fprintf('%s %s \n',num2str(sigma),num2str(nu));
fprintf('******************** Training accuracy *************\n');
fprintf('acc_ocsvm_tr std_ocsvm_tr \n');
fprintf('----------------------------------------------------------------------\n');
fprintf('%s %s \n',num2str(mean(g_ocsvm_tr)),num2str(std(g_ocsvm_tr)));
fprintf('\n');
fprintf('acc_raeocsvms_tr std_raeocsvms_tr \n');
fprintf('----------------------------------------------------------------------\n');
fprintf('%s %s\n',num2str(mean(g_ocsvm_rada_tr)),num2str(std(g_ocsvm_rada_tr)));
fprintf('\n');
fprintf('******************** Testing accuracy *************\n');
fprintf('acc_ocsvm_ts std_ocsvm_ts \n');
fprintf('----------------------------------------------------------------------\n');
fprintf('%s %s \n',num2str(mean(g_ocsvm)),num2str(std(g_ocsvm)));
fprintf('\n');
fprintf('acc_raeocsvms_ts std_raeocsvms_ts \n');
fprintf('----------------------------------------------------------------------\n');
fprintf('%s %s\n',num2str(mean(g_ocsvm_rada)),num2str(std(g_ocsvm_rada)));
天天Matlab科研工作室
- 粉丝: 4w+
- 资源: 1万+
最新资源
- pyheif-0.8.0-cp37-cp37m-win-amd64.whl.zip
- pyheif-0.8.0-cp38-cp38-win-amd64.whl.zip
- pyheif-0.8.0-cp39-cp39-win-amd64.whl.zip
- pyheif-0.8.0-cp313-cp313-win-amd64.whl.zip
- MyBatis SQL mapper framework for Java.zip
- pyheif-0.8.0-cp312-cp312-win-amd64.whl.zip
- pyheif-0.8.0-cp311-cp311-win-amd64.whl.zip
- pyheif-0.8.0-cp310-cp310-win-amd64.whl.zip
- 基于51单片机万年历(程序源码、原理图、实验报告)-基于单片机的万年历设计
- 51单片机万年历(源码+实验报告).zip (高分大作业项目)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈