1 簡(jiǎn)介
BP神經(jīng)網(wǎng)絡(luò)模型是目前應(yīng)用最為廣泛神經(jīng)網(wǎng)絡(luò)之一。它的本質(zhì)是通過對(duì)歷史數(shù)據(jù)的學(xué)習(xí)找出數(shù)據(jù)變化趨勢(shì)之間的非線性關(guān)系,并通過輸出量與預(yù)期值之間的誤差不斷調(diào)整網(wǎng)絡(luò)中各個(gè)單元的權(quán)重用matlab編bp神經(jīng)網(wǎng)絡(luò)預(yù)測(cè)程序,使整個(gè)網(wǎng)絡(luò)的誤差最小。因此,為達(dá)到較好的預(yù)測(cè)精度,需要對(duì)網(wǎng)絡(luò)預(yù)測(cè)模型自身的結(jié)構(gòu)進(jìn)行確定。
1)網(wǎng)絡(luò)層數(shù)的設(shè)計(jì)。本文需要構(gòu)建的預(yù)測(cè)模型,主要是用于研究在短時(shí)間交通流走勢(shì)。在這種情況下,不需選擇增加網(wǎng)絡(luò)層數(shù)的辦法而是選擇增加隱含層神經(jīng)元節(jié)點(diǎn)的數(shù)目來提高輸出結(jié)果的精度。因此,本文選用單一隱層的 BP神經(jīng)網(wǎng)絡(luò)模型。
2)輸入層神經(jīng)節(jié)點(diǎn)的設(shè)計(jì)。在單因素預(yù)測(cè)中僅使用交通流作為原始數(shù)據(jù).
3)傳遞函數(shù)和學(xué)習(xí)函數(shù)的設(shè)計(jì)。本文所設(shè)計(jì)的模型均采用了相同的隱含層傳遞函數(shù)tansig、輸出層傳遞函數(shù)logsig和學(xué)習(xí)函數(shù)learngdm。
4)性能函數(shù)的確定。網(wǎng)絡(luò)誤差能直觀的反映預(yù)測(cè)效果的好壞程度,是預(yù)測(cè)精度的具體反映。本文在構(gòu)建 BP神經(jīng)網(wǎng)絡(luò)模型時(shí)選擇均方誤差來確定網(wǎng)絡(luò)的誤差情況。
5)隱含層神經(jīng)節(jié)點(diǎn)的設(shè)計(jì)。在模型中其它參數(shù)值保持不變的情況下,本文通過調(diào)整隱含層神經(jīng)節(jié)點(diǎn)的數(shù)目進(jìn)行重復(fù)實(shí)驗(yàn)用matlab編bp神經(jīng)網(wǎng)絡(luò)預(yù)測(cè)程序,通過對(duì)比輸出誤差,確定最佳隱含層神經(jīng)元節(jié)點(diǎn)的數(shù)目。對(duì)于單因素 BP神經(jīng)網(wǎng)絡(luò),當(dāng)隱含層神經(jīng)元節(jié)點(diǎn)的數(shù)目為24時(shí),BP神經(jīng)網(wǎng)絡(luò)的均方誤差最小,即對(duì)函數(shù)的逼近效果最好,此時(shí)的均方誤差為1.1609;對(duì)于多因素 BP神經(jīng)網(wǎng)絡(luò),隱含層神經(jīng)元節(jié)點(diǎn)數(shù)目為5時(shí),BP神經(jīng)網(wǎng)絡(luò)的均方誤差達(dá)到最小,最小值為0.0126。根據(jù)以上分析,單因素 BP神經(jīng)網(wǎng)絡(luò)預(yù)測(cè)模型的結(jié)構(gòu)為:?jiǎn)我浑[含層和單一輸出層;輸入層神經(jīng)節(jié)點(diǎn)數(shù)目為5 ;隱含層神經(jīng)節(jié)點(diǎn)數(shù)目為24;輸出層神經(jīng)節(jié)點(diǎn)數(shù)目為1;隱含層傳遞函數(shù)、輸出層傳遞函數(shù)、學(xué)習(xí)函數(shù)分別為tansig、logsig和learngdm;性能函數(shù)為 mse。
2 部分代碼
function varargout = bp_demo(varargin)
% BP_DEMO M-file for bp_demo.fig
% BP_DEMO, by itself, creates a new BP_DEMO or raises the existing
% singleton*.
%
% H = BP_DEMO returns the handle to a new BP_DEMO or the handle to
% the existing singleton*.
%
% BP_DEMO('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BP_DEMO.M with the given input arguments.
%
% BP_DEMO('Property','Value',...) creates a new BP_DEMO or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before bp_demo_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to bp_demo_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help bp_demo
% Last Modified by GUIDE v2.5 19-May-2021 09:29:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @bp_demo_OpeningFcn, ...
'gui_OutputFcn', @bp_demo_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before bp_demo is made visible.
function bp_demo_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to bp_demo (see VARARGIN)
% Choose default command line output for bp_demo
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes bp_demo wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = bp_demo_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function t_sim_Callback(hObject, eventdata, handles)
% hObject handle to t_sim (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of t_sim as text
% str2double(get(hObject,'String')) returns contents of t_sim as a double
% --- Executes during object creation, after setting all properties.
function t_sim_CreateFcn(hObject, eventdata, handles)
% hObject handle to t_sim (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in train_button.
function train_button_Callback(hObject, eventdata, handles)
% hObject handle to train_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
warning off
global net P_train T_train N Epochs Show Goal Lr fcn_hidden fcn_output fcn_learn
% default value
N=10;
Epochs=1000;
Show=10;
Goal=1e-3;
Lr=0.01;
fcn_hidden='tansig';
fcn_output='purelin';
fcn_learn='trainlm';
% create neural network
net=newff(minmax(P_train),[N size(T_train,1)],{fcn_hidden,fcn_output},fcn_learn);
net.trainParam.epochs=Epochs;
net.trainParam.show=Show;
net.trainParam.goal=Goal;
net.trainParam.lr=Lr;
net.trainParam.showwindow=0;
[net,tr]=train(net,P_train,T_train);
% show waitbar
perf=tr.perf;
perf_t=abs(perf(2:end)-perf(1))/(perf(1)-perf(end));
h=waitbar(0,'please wait.......');
for i=1:length(perf_t)
waitbar(perf_t(i));
end
close(h);
3 運(yùn)行結(jié)果
4 參考文獻(xiàn)
[1]高寧. 基于BP神經(jīng)網(wǎng)絡(luò)的農(nóng)作物蟲情預(yù)測(cè)預(yù)報(bào)及其實(shí)現(xiàn). Diss. 安徽農(nóng)業(yè)大學(xué).
博主簡(jiǎn)介:擅長(zhǎng)智能優(yōu)化算法、神經(jīng)網(wǎng)絡(luò)預(yù)測(cè)、信號(hào)處理、元胞自動(dòng)機(jī)、圖像處理、路徑規(guī)劃、無人機(jī)等多種領(lǐng)域的仿真,相關(guān)代碼問題可私信交流。部分理論引用網(wǎng)絡(luò)文獻(xiàn),若有侵權(quán)聯(lián)系博主刪除。