日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 人工智能 > 循环神经网络 >内容正文

循环神经网络

svm回归matlab工具箱很慢,PSO优化SVM参数进行回归预测,结果很不理想

發(fā)布時(shí)間:2024/9/27 循环神经网络 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 svm回归matlab工具箱很慢,PSO优化SVM参数进行回归预测,结果很不理想 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

具體程序代碼如下,主要問(wèn)題就是不管我怎么調(diào)整參數(shù),最終的預(yù)測(cè)結(jié)果都沒(méi)有太大的變化,還請(qǐng)了解這兩大算法的幫忙看看問(wèn)題出在哪里了,十分感謝!

tic;

close all;

clear;

clc;

format compact;

load M2.mat? ? %載入數(shù)據(jù)

% 提取數(shù)據(jù)

N=length(M2)-36;

train_tsx=zeros(N,36);

for i=1:N

train_tsx(i,:)=M2(i:i+35);

Y(i)=M2(i+36);? ?? ?? ?? ?? ?%36個(gè)月代表貨幣周期,從歷史數(shù)據(jù)來(lái)看,大致與短經(jīng)濟(jì)周期一樣(3-4年)

end

train_ts=Y';

%數(shù)據(jù)預(yù)處理,將原始數(shù)據(jù)進(jìn)行歸一化

ts = train_ts';

tsx = train_tsx';

% mapminmax為matlab自帶的映射函數(shù)

% 對(duì)ts進(jìn)行歸一化

[TS,TSps] = mapminmax(ts,0,1);

% 對(duì)TS進(jìn)行轉(zhuǎn)置,以符合libsvm工具箱的數(shù)據(jù)格式要求

TS = TS';

% mapminmax為matlab自帶的映射函數(shù)

% 對(duì)tsx進(jìn)行歸一化

[TSX,TSXps] = mapminmax(tsx,0,1);

% 對(duì)TSX進(jìn)行轉(zhuǎn)置,以符合libsvm工具箱的數(shù)據(jù)格式要求

TSX = TSX';

% PSO尋找最佳的SVM參數(shù)c&g

% 參數(shù)初始化

%粒子群算法中的兩個(gè)參數(shù)

c1 = 0.5; % c1 belongs to [0,2]

c2 = 0.5; % c2 belongs to [0,2]

maxgen=200;? ?% 進(jìn)化次數(shù)

sizepop=50;? ?% 種群規(guī)模

popcmax=10^(2);

popcmin=10^(-1);

popgmax=10^(3);

popgmin=10^(-2);

k = 0.5;? ?? ? % k belongs to [0.1,1.0];

Vcmax = 500;

Vcmin = 1 ;

Vgmax = 10;

Vgmin = 0.1 ;

% SVM參數(shù)初始化

v = 5;

% 產(chǎn)生初始粒子和速度

for i=1:sizepop? ???% 隨機(jī)產(chǎn)生種群

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

% 計(jì)算初始適應(yīng)度

cmd = ['-v ',num2str(v),' -c ',num2str( pop(i,1) ),' -g ',num2str( pop(i,2) ),' -s 3 -t 2 -p 0.01 '];

fitness(i) = svmtrain(TS, TSX, cmd);

fitness(i) = -fitness(i);

end

% 找極值和極值點(diǎn)

[global_fitness, bestindex]=min(fitness); % 全局極值

local_fitness=fitness;? ?% 個(gè)體極值初始化

global_x=pop(bestindex,:);? ?% 全局極值點(diǎn)

local_x=pop;? ? % 個(gè)體極值點(diǎn)初始化

% 迭代尋優(yōu)

for i=1:maxgen

for j=1:sizepop? ?? ? %速度更新

wV = 1;? ?? ?% 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;

end

if V(j,1) < Vcmin

V(j,1) = Vcmin;

end

if V(j,2) > Vgmax

V(j,2) = Vgmax;

end

if V(j,2) < Vgmin

V(j,2) = Vgmin;

end

%種群更新

wP = 0.5;

pop(j,:)=pop(j,:)+wP*V(j,:);

if pop(j,1) > popcmax

pop(j,1) = popcmax;

end

if pop(j,1) < popcmin

pop(j,1) = popcmin;

end

if pop(j,2) > popgmax

pop(j,2) = popgmax;

end

if pop(j,2) < popgmin

pop(j,2) = popgmin;

end

% 自適應(yīng)粒子變異

if rand>0.5

k=ceil(2*rand);

if k == 1

pop(j,k) = (20-1)*rand+1;

end

if k == 2

pop(j,k) = (popgmax-popgmin)*rand+popgmin;

end

end

%適應(yīng)度值

cmd = ['-v ',num2str(v),' -c ',num2str( pop(j,1) ),' -g ',num2str( pop(j,2) ),' -s 3 -t 2 -p 0.01 '];

fitness(j) = svmtrain(TS, TSX, cmd);

fitness(j) = -fitness(j);

end

%個(gè)體最優(yōu)更新

if fitness(j) < local_fitness(j)

local_x(j,:) = pop(j,:);

local_fitness(j) = fitness(j);

end

%群體最優(yōu)更新

if fitness(j) < global_fitness

global_x = pop(j,:);

global_fitness = fitness(j);

end

fit_gen(i)=global_fitness;

end

toc

bestc = global_x(1);

bestg = global_x(2);

bestmse = -fit_gen(maxgen);

% 利用回歸預(yù)測(cè)分析最佳的參數(shù)進(jìn)行SVM訓(xùn)練

cmd = ['-c ',num2str( bestc ),' -g ',num2str( bestg ),' -s 3 -t 2 -p 0.01 '];

model = svmtrain(TS,TSX,cmd);

% 進(jìn)行SVM預(yù)測(cè)

test_tsx1 = TS(163:198);

test_tsx1=test_tsx1';

[predict1,mse,detesvalue] = svmpredict(8.29,test_tsx1,model);

test_ts1 = mapminmax('reverse',predict1',TSps);

總結(jié)

以上是生活随笔為你收集整理的svm回归matlab工具箱很慢,PSO优化SVM参数进行回归预测,结果很不理想的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。