1樓:在晴天的雨傘
elapsed time is 64.799304 seconds.
bestc =
45.3915
bestg =
0.0100
bestcvaccuarcy =
97.7528
accuracy = 97.7528% (87/89) (classification)
trainacc =
97.7528
0.0225
0.9633
accuracy = 93.2584% (83/89) (classification)
testacc =
93.2584
0.0674
0.9007
**:%% 清空環境
clcclear
load wine;
train = [wine(1:30,:);wine(60:95,:);wine(131:153,:)];
train_label = [wine_labels(1:30);wine_labels(60:95);wine_labels(131:153)];
test = [wine(31:59,:);wine(96:130,:);wine(154:178,:)];
test_label = [wine_labels(31:59);wine_labels(96:130);wine_labels(154:178)];
[train,pstrain] = mapminmax(train');
pstrain.ymin = 0;
pstrain.ymax = 1;
[train,pstrain] = mapminmax(train,pstrain);
[test,pstest] = mapminmax(test');
pstest.ymin = 0;
pstest.ymax = 1;
[test,pstest] = mapminmax(test,pstest);
train = train';
test = test';
%% 引數初始化
%粒子群演算法中的兩個引數
c1 = 1.6; % c1 belongs to [0,2]
c2 = 1.5; % c2 belongs to [0,2]
maxgen=300; % 進化次數
sizepop=30; % 種群規模
popcmax=10^(2);
popcmin=10^(-1);
popgmax=10^(3);
popgmin=10^(-2);
k = 0.6; % k belongs to [0.1,1.0];
vcmax = k*popcmax;
vcmin = -vcmax ;
vgmax = k*popgmax;
vgmin = -vgmax ;
% svm引數初始化
v = 3;
%% 產生初始粒子和速度
for i=1:sizepop
% 隨機產生種群
pop(i,1) = (popcmax-popcmin)*rand+popcmin; % 初始種群
pop(i,2) = (popgmax-popgmin)*rand+popgmin;
v(i,1)=vcmax*rands(1); % 初始化速度
v(i,2)=vgmax*rands(1);
% 計算初始適應度
cmd = ['-v ',num2str(v),' -c ',num2str( pop(i,1) ),' -g ',num2str( pop(i,2) )];
fitness(i) = svmtrain(train_label, train, cmd);
fitness(i) = -fitness(i);
end% 找極值和極值點
[global_fitness bestindex]=min(fitness); % 全域性極值
local_fitness=fitness; % 個體極值初始化
global_x=pop(bestindex,:); % 全域性極值點
local_x=pop; % 個體極值點初始化
tic%% 迭代尋優
for i=1:maxgen
for j=1:sizepop
%速度更新
wv = 0.9; % wv best belongs to [0.8,1.2]
v(j,:) = wv*v(j,:) + c1*rand*(local_x(j,:
) - pop(j,:)) + c2*rand*(global_x - pop(j,:));
if v(j,1) > vcmax
v(j,1) = vcmax;
endif v(j,1) < vcmin
v(j,1) = vcmin;
endif v(j,2) > vgmax
v(j,2) = vgmax;
endif v(j,2) < vgmin
v(j,2) = vgmin;
end%種群更新
wp = 0.6;
pop(j,:)=pop(j,:)+wp*v(j,:);
if pop(j,1) > popcmax
pop(j,1) = popcmax;
endif pop(j,1) < popcmin
pop(j,1) = popcmin;
endif pop(j,2) > popgmax
pop(j,2) = popgmax;
endif pop(j,2) < popgmin
pop(j,2) = popgmin;
end% 自適應粒子變異
if rand>0.5
k=ceil(2*rand);
if k == 1
pop(j,k) = (20-1)*rand+1;
endif k == 2
pop(j,k) = (popgmax-popgmin)*rand+popgmin;
endend%適應度值
cmd = ['-v ',num2str(v),' -c ',num2str( pop(j,1) ),' -g ',num2str( pop(j,2) )];
fitness(j) = svmtrain(train_label, train, cmd);
fitness(j) = -fitness(j);
end%個體最優更新
if fitness(j) < local_fitness(j)
local_x(j,:) = pop(j,:);
local_fitness(j) = fitness(j);
end%群體最優更新
if fitness(j) < global_fitness
global_x = pop(j,:);
global_fitness = fitness(j);
endfit_gen(i)=global_fitness;
endtoc
%% 結果分析
plot(-fit_gen,'linewidth',5);
title(['適應度曲線','(引數c1=',num2str(c1),',c2=',num2str(c2),',終止代數=',num2str(maxgen),')'],'fontsize',13);
xlabel('進化代數');ylabel('適應度');
bestc = global_x(1)
bestg = global_x(2)
bestcvaccuarcy = -fit_gen(maxgen)
cmd = ['-c ',num2str( bestc ),' -g ',num2str( bestg )];
model = svmtrain(train_label,train,cmd);
[trainpre,trainacc] = svmpredict(train_label,train,model);
trainacc
[testpre,testacc] = svmpredict(test_label,test,model);
testacc
2樓:匿名使用者
你搞懂了嗎,這個適應度值40或50左右,確實不知道是表示的是什麼
有哪些方法可以優化支援向量機svm的引數?
3樓:匿名使用者
遺傳演算法 ,差分進化,粒子群,蟻群,模擬退火,人工魚群,蜂群,果蠅優化等都可以優化svm引數
4樓:珊瑚海
其實,真正在實際用的時候,還是徑向基核函式用的比較多,所以裡面的問題就歸結於核函式引數delta的優化,具體的方法很多,就如樓上哥們所說的,之前我也做過有關核函式引數優化的一點研究。。。。
求助ga優化svm引數的matlab **
如何用遺傳演算法優化svm的引數
5樓:玉皇廟加工麵條
將下屬兩個目標函式分別儲存在兩個m檔案中 function f1=func1(x) %第一目標函式 f1=x(:,1).*x(:
,1)./4+x(:,2).
*x(:,2)./4; function f2=func2(x) %第二目標函式 f2=x(:
,1).*(1-x(:,2))+10; function ga() clear;clc;close all nind=100; %個體數...
粒子群優化演算法(pso 的matlab執行程式謝謝大家啦
不知道你具體的問題是什麼,下面是一個最基本的pso演算法解決函式極值問題,如果是一些大型的問題,需要對速度 慣性常數 和自適應變異做進一步優化,希望對你有幫助 function y fun x y 20 exp 0.2 sqrt x 1 2 x 2 2 2 exp cos 2 pi x 1 cos ...
關於程序優化的問題
看錯你要優化程序?你設定優先就可以達到了 你裝的東西多程序不多?優化也沒有用和你說實話。用瑞星卡卡安全助手可以做到。1 查殺惡意流氓軟體,全部刪除。2 外掛管理及解除安裝,不常用的全部卸掉。3 系統啟動項管理,除了系統項及防毒軟體專案都可以刪除。4 重起一下機器,程序能減少不少,機器提速不少。1不用...
優化大師的問題
windows優化大師 設 計 魯錦 聯絡郵件 mailoflujin 163.net 版 本 v3.5 檔案大小 1177kb 授權方式 共享軟體 國產 註冊費用 20.00 應用平臺 windows 95 98 me nt 2000 windows優化大師 是一個不錯的windows系統加速和硬...