導航:首頁 > 網路安全 > matlab如何獲得神經網路次數

matlab如何獲得神經網路次數

發布時間:2022-09-27 11:17:28

A. 找高手教我matlab的神經網路訓練

% 運用比例共軛梯度動量演算法來訓練 BP網路
clear all;
pause(1);
P=[0.1452 0.1466 0.1314 0.2243 0.3523 0.4642 0.5015 0.6981 0.7821 0.8345 0.9649 1.156 0.2415 0.3027 0;
0.1217 0.1581 0.1408 0.2304 0.3143 0.4312 0.5819 0.7125 0.8065 0.8647 0.9726 1.132 0.2385 0.3125 0;
0.1525 0.1627 0.1507 0.2406 0.3502 0.4636 0.5051 0.7352 0.8459 0.8915 0.9654 1.156 0.2216 0.2701 1;
0.1016 0.1105 0.1234 0.1978 0.3021 0.4232 0.5819 0.6952 0.8015 0.8725 0.9825 1.095 0.2352 0.2506 0.5;
0.1115 0.1201 0.1312 0.2019 0.3532 0.4736 0.5029 0.7032 0.8189 0.8619 0.9365 1.125 0.2542 0.3125 0;
0.1335 0.1322 0.1534 0.2214 0.3623 0.4827 0.5198 0.7276 0.8359 0.8906 0.9592 1.143 0.2601 0.3198 0;
0.1368 0.1432 0. 0.2205 0.3823 0.4971 0.5136 0.7129 0.8263 0.8953 0.9891 1.137 0.2579 0.3099 0;
0.1342 0.1368 0.1602 0.2131 0.3726 0.4822 0.5101 0.7098 0.8127 0.8921 0.9995 1.126 0.2301 0.2867 0.5;
0.1113 0.1212 0.1305 0.1819 0.3952 0.4312 0.5886 0.6898 0.7999 0.8423 0.9721 1.095 0.2234 0.2799 1;
0.1005 0.1121 0.1207 0.1605 0.3556 0.4022 0.5553 0.6673 0.7798 0.8623 0.9521 1.087 0.2314 0.2977 0]';
T=[0.1217 0.1581 0.1408 0.2304 0.3143 0.4312 0.5819 0.7125 0.8265 0.8847 0.9826 1.132;
0.1525 0.1627 0.1507 0.2406 0.3502 0.4636 0.5051 0.7352 0.8459 0.8915 0.9464 1.156;
0.1016 0.1105 0.1234 0.1978 0.3021 0.4232 0.5819 0.6952 0.8015 0.8825 0.9825 1.102;
0.1115 0.1201 0.1312 0.2019 0.3532 0.4736 0.5029 0.7032 0.8189 0.8919 0.9965 1.125;
0.1335 0.1322 0.1534 0.2214 0.3623 0.4827 0.5198 0.7276 0.8359 0.8506 0.9892 1.123;
0.1368 0.1432 0. 0.2205 0.3823 0.4971 0.5136 0.7129 0.8263 0.8953 0.9691 1.117;
0.1342 0.1368 0.1602 0.2131 0.3726 0.4822 0.5101 0.7098 0.8127 0.8921 0.9995 1.126;
0.1113 0.1212 0.1305 0.1819 0.3952 0.4312 0.5886 0.6898 0.7999 0.8323 0.9721 1.156;
0.1005 0.1121 0.1207 0.1605 0.3556 0.4022 0.5553 0.6673 0.7798 0.8623 0.9521 1.156;
0.1123 0.1257 0.1343 0.2079 0.3579 0.4716 0.5459 0.7145 0.8205 0.8901 0.9419 1.136]';
threshold=[0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1];
net=newff(threshold,[32,12],{'tansig','logsig'},'trainscg','learngdm');%新建BP神經網路
net.trainParam.epochs=1000;%bp網路訓練次數
net.trainParam.goal=0.002;%網路訓練目標
net.trainParam.lr=0.01;%網路學習速率
[net,tr]=train(net,P,T);%訓練網路
P_test=[0.1123 0.1257 0.1343 0.2079 0.3579 0.4716 0.5459 0.7145 0.8205 0.8901 0.9419 1.136 0.2317 0.2936 0]';%網路輸入數據
Out=sim(net,P_test);%網路模擬
X=[0.1119 0.1215 0.1621 0.2161 0.3471 0.4639 0.5555 0.7061 0.8243 0.8923 0.9522 1.129];%實際測得數據
t=1:1:12;
box off;
grid off;
plot(t,Out,'b',t,X,'r');%畫出二維圖形
set(gca,'Xtick',0:1:24,'Ytick',0:.1:1.4);%設置坐標
title('基於BP網路的設備故障時間序列預測');
xlabel('時間/2小時');
ylabel('加速度/g');
text(1.5,1.2,'預測振動曲線(藍)');
text(1.5,1.1,'實際測試曲線(紅)');

B. matlab 神經網路

net=newff(pr,[3,2],{'logsig','logsig'}); %創建 一個bp 神經網路
net.trainParam.show = 10; %顯示訓練迭代過程
net.trainParam.lr = 0.05; %學習速率0,05
net.trainParam.goal = 1e-10; %訓練精度
net.trainParam.epochs = 50000; %最大訓練次數
net = train(net,p,goal); %訓練
結果要麼接近於1 ,要麼就是0,就這倆類啊,這就是分類結果;
每次都有些差異 很正常,只要不大

C. matlab中如何獲取神經網路訓練之後的迭代次數

多種方法途徑可以獲取,如訓練後,運行以下語句:

nntraintool

--------------出現窗口中的Progress-epoch顯示迭代次數

D. matlab中如何對newrb神經網路進行多次訓練就是好幾組輸入輸出數組對同一網路進行多次訓練。求代碼

[slot].name);printf("Enterstreet:");gets(addr_list[slot].street);printf("Entercity:");gets(addr_list[slot].city);printf("Enterstate:");gets(addr_list[slot].state);printf("Enterzip:");gets(s);addr_list[slot].zip=strtoul(s,'\0',10);}/*Findanunusedstructure.*/intfind_free(void){registerintt;for(t=0;addr_list[t].name[0]&&t=0&&slot

E. MATLAB線性神經網路的程序,跪求。。

美國Michigan 大學的 Holland 教授提出的遺傳演算法(GeneticAlgorithm, GA)是求解復雜的組合優化問題的有效方法 ,其思想來自於達爾文進化論和門德爾松遺傳學說 ,它模擬生物進化過程來從龐大的搜索空間中篩選出較優秀的解,是一種高效而且具有強魯棒性方法。所以,遺傳演算法在求解TSP和 MTSP問題中得到了廣泛的應用。

matlab程序如下:

function[opt_rte,opt_brk,min_dist] =mtspf_ga(xy,dmat,salesmen,min_tour,pop_size,num_iter)

%%

%實例

% n = 20;%城市個數

% xy = 10*rand(n,2);%城市坐標 隨機產生,也可以自己設定

% salesmen = 5;%旅行商個數

% min_tour = 3;%每個旅行商最少訪問的城市數

% pop_size = 80;%種群個數

% num_iter = 200;%迭代次數

% a = meshgrid(1:n);

% dmat =reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),n,n);

% [opt_rte,opt_brk,min_dist] = mtspf_ga(xy,dmat,salesmen,min_tour,...

% pop_size,num_iter);%函數

%%

[N,dims]= size(xy); %城市矩陣大小

[nr,nc]= size(dmat); %城市距離矩陣大小

n = N -1;% 除去起始的城市後剩餘的城市的數

% 初始化路線、斷點的選擇

num_brks= salesmen-1;

dof = n- min_tour*salesmen; %初始化路線、斷點的選擇

addto =ones(1,dof+1);

for k =2:num_brks

addto = cumsum(addto);

end

cum_prob= cumsum(addto)/sum(addto);

%% 初始化種群

pop_rte= zeros(pop_size,n); % 種群路徑

pop_brk= zeros(pop_size,num_brks); % 斷點集合的種群

for k =1:pop_size

pop_rte(k,:) = randperm(n)+1;

pop_brk(k,:) = randbreaks();

end

% 畫圖路徑曲線顏色

clr =[1 0 0; 0 0 1; 0.67 0 1; 0 1 0; 1 0.5 0];

ifsalesmen > 5

clr = hsv(salesmen);

end

%%

% 基於遺傳演算法的MTSP

global_min= Inf; %初始化最短路徑

total_dist= zeros(1,pop_size);

dist_history= zeros(1,num_iter);

tmp_pop_rte= zeros(8,n);%當前的路徑設置

tmp_pop_brk= zeros(8,num_brks); %當前的斷點設置

new_pop_rte= zeros(pop_size,n);%更新的路徑設置

new_pop_brk= zeros(pop_size,num_brks);%更新的斷點設置

foriter = 1:num_iter

% 計算適應值

for p = 1:pop_size

d = 0;

p_rte = pop_rte(p,:);

p_brk = pop_brk(p,:);

rng = [[1 p_brk+1];[p_brk n]]';

for s = 1:salesmen

d = d + dmat(1,p_rte(rng(s,1)));% 添加開始的路徑

for k = rng(s,1):rng(s,2)-1

d = d + dmat(p_rte(k),p_rte(k+1));

end

d = d + dmat(p_rte(rng(s,2)),1); % 添加結束的的路徑

end

total_dist(p) = d;

end

% 找到種群中最優路徑

[min_dist,index] = min(total_dist);

dist_history(iter) = min_dist;

if min_dist < global_min

global_min = min_dist;

opt_rte = pop_rte(index,:); %最優的最短路徑

opt_brk = pop_brk(index,:);%最優的斷點設置

rng = [[1 opt_brk+1];[opt_brk n]]';%設置記錄斷點的方法

figure(1);

for s = 1:salesmen

rte = [1 opt_rte(rng(s,1):rng(s,2))1];

plot(xy(rte,1),xy(rte,2),'.-','Color',clr(s,:));

title(sprintf('城市數目為 = %d,旅行商數目為 = %d,總路程 = %1.4f, 迭代次數 =%d',n+1,salesmen,min_dist,iter));

hold on

grid on

end

plot(xy(1,1),xy(1,2),'ko');

hold off

end

% 遺傳操作

rand_grouping = randperm(pop_size);

for p = 8:8:pop_size

rtes = pop_rte(rand_grouping(p-7:p),:);

brks = pop_brk(rand_grouping(p-7:p),:);

dists =total_dist(rand_grouping(p-7:p));

[ignore,idx] = min(dists);

best_of_8_rte = rtes(idx,:);

best_of_8_brk = brks(idx,:);

rte_ins_pts = sort(ceil(n*rand(1,2)));

I = rte_ins_pts(1);

J = rte_ins_pts(2);

for k = 1:8 %產生新種群

tmp_pop_rte(k,:) = best_of_8_rte;

tmp_pop_brk(k,:) = best_of_8_brk;

switch k

case 2% 倒置操作

tmp_pop_rte(k,I:J) =fliplr(tmp_pop_rte(k,I:J));

case 3 % 互換操作

tmp_pop_rte(k,[I J]) =tmp_pop_rte(k,[J I]);

case 4 % 滑動平移操作

tmp_pop_rte(k,I:J) =tmp_pop_rte(k,[I+1:J I]);

case 5% 更新斷點

tmp_pop_brk(k,:) = randbreaks();

case 6 % 倒置並更新斷點

tmp_pop_rte(k,I:J) =fliplr(tmp_pop_rte(k,I:J));

tmp_pop_brk(k,:) =randbreaks();

case 7 % 互換並更新斷點

tmp_pop_rte(k,[I J]) =tmp_pop_rte(k,[J I]);

tmp_pop_brk(k,:) =randbreaks();

case 8 % 評議並更新斷點

tmp_pop_rte(k,I:J) =tmp_pop_rte(k,[I+1:J I]);

tmp_pop_brk(k,:) =randbreaks();

otherwise

end

end

new_pop_rte(p-7:p,:) = tmp_pop_rte;

new_pop_brk(p-7:p,:) = tmp_pop_brk;

end

pop_rte = new_pop_rte;

pop_brk = new_pop_brk;

end

figure(2)

plot(dist_history,'b','LineWidth',2);

title('歷史最優解');

xlabel('迭代次數')

ylabel('最優路程')

% 隨機產生一套斷點 的集合

function breaks = randbreaks()

if min_tour == 1 % 一個旅行商時,沒有斷點的設置

tmp_brks = randperm(n-1);

breaks =sort(tmp_brks(1:num_brks));

else % 強制斷點至少找到最短的履行長度

num_adjust = find(rand <cum_prob,1)-1;

spaces =ceil(num_brks*rand(1,num_adjust));

adjust = zeros(1,num_brks);

for kk = 1:num_brks

adjust(kk) = sum(spaces == kk);

end

breaks = min_tour*(1:num_brks) +cumsum(adjust);

end

end

disp('最優路徑為:/n')

disp(opt_rte);

disp('其中斷點為為:/n')

disp(opt_brk);

end


F. 如何用matlab訓練BP神經網路

net = newff(PR,[S1 S2...SNl],{TF1 TF2...TFNl},BTF,BLF,PF)

newff(PR,[S1 S2...SNl],{TF1 TF2...TFNl},BTF,BLF,PF) takes,
PR - Rx2 matrix of min and max values for R input elements.
Si - Size of ith layer, for Nl layers.
TFi - Transfer function of ith layer, default = 'tansig'.
BTF - Backprop network training function, default = 'trainlm'.
BLF - Backprop weight/bias learning function, default = 'learngdm'.
PF - Performance function, default = 'mse'.
然後train一下就可以了,具體其他參數查閱相關文檔,一般有前四個參數就夠了。
看一個簡單的例子:
有兩個向量或者矩陣,pn和tn:
net=newff(minmax(pn),[3,1],{'tansig','purelin'},'trainlm');
net.trainParam.epochs=1000;
net.trainParam.goal =1e-5;
net=train(net,pn,tn);
照葫蘆畫瓢就行,具體參數意義就不說了,自己查閱matlab幫助。

G. 如何利用matlab進行神經網路預測

matlab 帶有神經網路工具箱,可直接調用,建議找本書看看,或者MATLAB論壇找例子。
核心調用語句如下:
%數據輸入

%選連樣本輸入輸出數據歸一化
[inputn,inputps]=mapminmax(input_train);
[outputn,outputps]=mapminmax(output_train);
%% BP網路訓練
% %初始化網路結構
net=newff(inputn,outputn,[8 8]);
net.trainParam.epochs=100;
net.trainParam.lr=0.01;
net.trainParam.goal=0.01;
%網路訓練
net=train(net,inputn,outputn);
%% BP網路預測
%預測數據歸一化
inputn_test=mapminmax('apply',input_test,inputps);
%網路預測輸出
an=sim(net,inputn_test);
%網路輸出反歸一化
BPoutput=mapminmax('reverse',an,outputps);
%% 結果分析

H. 您好,請問關於matlab中神經網路問題

不知道你問的是什麼意思。我試著解答一下,
P1代表第一個輸入 ,P2代表第二個輸入,
當訓練好後,將兩個輸入輸入到網路,網路就輸出目標goal。
實際就是有一個函數goal = f(p1,p2),當你輸入這個P1,P2的時候,就會根據函數得到goal。

I. matlab中神經網路怎麼使用

可以直接用神經網路工具箱,GUI內設置訓練的輸入、目標、訓練方法、迭代次數等。

J. MATLAB中如何獲取BP神經網路訓練後的參數

sim命令將運行指定的模型。模型執行時使用傳遞給sim命令的數據,這些數據包括在options結構中設定的參數值。a=sim(net,[ ])中,net是你的訓練網路,後面的中括弧是你要訓練的結構參數!

閱讀全文

與matlab如何獲得神經網路次數相關的資料

熱點內容
電腦網路連接不見了怎麼回事 瀏覽:576
教室移動網路被屏蔽 瀏覽:969
對網路安全法重要意義的理解 瀏覽:77
網路通信軟體哪個好 瀏覽:302
網路異常請排查網路和配置監控 瀏覽:888
sfs201nv網路設置 瀏覽:437
九音車機裡面網路設置 瀏覽:625
深圳線尚網路營銷 瀏覽:194
現在網路教育的大學有哪些 瀏覽:173
蘋果4s用4g網路嗎 瀏覽:622
網路在手機上怎麼不讓別人使用 瀏覽:202
美能達246i設置網路掃描 瀏覽:699
iphone12有信號沒網路 瀏覽:272
為什麼家裡某個房間網路很差 瀏覽:745
網路工程出差能帶有攝像頭手機嗎 瀏覽:141
行業找工作app網路連接失敗 瀏覽:556
南部廣電網路公司電話號碼多少 瀏覽:667
共享網路地址 瀏覽:933
漳州被什麼網路覆蓋 瀏覽:137
動手製作網路信號增強器 瀏覽:511

友情鏈接