91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-19
  • 語言: Matlab
  • 標簽: psoSVM.rar??

資源簡介

用粒子群算法優化支持向量機的matlab程序,簡單易學,適合matlab初學者

資源截圖

代碼片段和文件信息

%%?清空環境
clc
clear

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)];

[trainpstrain]?=?mapminmax(train‘);
pstrain.ymin?=?0;
pstrain.ymax?=?1;
[trainpstrain]?=?mapminmax(trainpstrain);

[testpstest]?=?mapminmax(test‘);
pstest.ymin?=?0;
pstest.ymax?=?1;
[testpstest]?=?mapminmax(testpstest);

train?=?train‘;
test?=?test‘;

%%?參數初始化

%粒子群算法中的兩個參數
c1?=?1.6;?%?c1?belongs?to?[02]
c2?=?1.5;?%?c2?belongs?to?[02]

maxgen=300;???%?進化次數?
sizepop=30;???%?種群規模

popcmax=10^(2);
popcmin=10^(-1);
popgmax=10^(3);
popgmin=10^(-2);
k?=?0.6;?%?k?belongs?to?[0.11.0];
Vcmax?=?k*popcmax;
Vcmin?=?-Vcmax?;
Vgmax?=?k*popgmax;
Vgmin?=?-Vgmax?;

%?SVM參數初始化?
v?=?3;

%%?產生初始粒子和速度
for?i=1:sizepop
????%?隨機產生種群
????pop(i1)?=?(popcmax-popcmin)*rand+popcmin;????%?初始種群
????pop(i2)?=?(popgmax-popgmin)*rand+popgmin;
????V(i1)=Vcmax*rands(1);?%?初始化速度
????V(i2)=Vgmax*rands(1);
????%?計算初始適應度
????cmd?=?[‘-v?‘num2str(v)‘?-c?‘num2str(?pop(i1)?)‘?-g?‘num2str(?pop(i2)?)];
????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.81.2]
????????V(j:)?=?wV*V(j:)?+?c1*rand*(local_x(j:)?-?pop(j:))?+?c2*rand*(global_x?-?pop(j:));
????????if?V(j1)?>?Vcmax
????????????V(j1)?=?Vcmax;
????????end
????????if?V(j1)?????????????V(j1)?=?Vcmin;
????????end
????????if?V(j2)?>?Vgmax
????????????V(j2)?=?Vgmax;
????????end
????????if?V(j2)?????????????V(j2)?=?Vgmin;
????????end
???????
????????%種群更新
????????wP?=?0.6;
????????pop(j:)=pop(j:)+wP*V(j:);
????????if?pop(j1)?>?popcmax
????????????pop(j1)?=?popcmax;
????????end
????????if?pop(j1)?????????????pop(j1)?=?popcmin;
????????end
????????if?pop(j2)?>?popgmax
????????????pop(j2)?=?popgmax;
????????end
????????if?pop(j2)?????????????pop(j2)?=?popgmin;
????????end
???????
????????%?自適應粒子變異
????????if?rand>0.5
????????????k=ceil(2*rand);
????????????if?k?==?1
????????????????pop(jk)?=?(20-1)*rand+1;
????????????end
????????????if?k?==?2
????????????????pop(jk)?=?(popgmax-popgmin)*rand+popgmin;
????????????end???????????
????????end
???????
????????%適應度值
????????cmd?=?[‘-v?‘num2str(v)‘?-c?‘num2str(?pop(j1)?)‘?-g?‘num2str(?pop(j2)?)];
????????fitness(j)?=?svmtrain(train_label?train?cmd);
????????fitness(j)?=?-fitness(j);
????end
???
????%個體最優更新
????if?fitness(j)?????????local_x(j:)?=?pop(j:);
????????local_fitness(j

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????3862??2010-04-07?21:22??psoSVM.m

-----------?---------??----------?-----??----

?????????????????3862????????????????????1


評論

共有 條評論

相關資源