📄 createnetwork.m
字号:
% annie - Neural Network Library for C++
% http://annie.sourceforge.net/
% asimshankar@users.sourceforge.net
%
% Last Modified On :
% January 12, 2003
%
% Author(s):
% Asim Shankar
%
% This file contains Matlab commands to create a two-layer
% feed-forward network in Matlab using the Neural Network
% toolbox.
%
% You can use this toolbox to make modifications to the
% network (such as training it) and then export it to
% a format that will be recognized by annie, and thus
% use the network created in your C++ applications.
%
% In this sample code, we create a two-layer network
% to learn the XOR function:
% 2 inputs - the value of both inputs ranges between 0 and 1
% 3 hidden neurons
% 1 output neuron
%
% The activation function (called transfer
% function in Matlab) used is - tansig.
% If you export this network to annie then do
% remember to change the activation function
% after loading from a file to 'tansig' using
% MultiLayerNetwork::setActivationFunction()
%
% The training algorithm used is backpropagation
% (gradient descent) - traingd. Matlab's default is
% traingdx which uses momentum and an adaptive learning
% rate. You can use anything.
%
% We then set training parameters:
% Number of epochs = 500
% Show the training error after every 100 epochs
% Learning Rate = 0.5
% Desired error = 0.01
% Modify the code below to change these parameters to your
% liking.
%
% To train the network, see the last few lines
% where the input and desired output vectors are
% created in P and T and then the network is trained.
% These lines have been commented out.
%
% See also: sim (in the Neural Network Toolbox documentation)
%
% To convert this network to an annie network see
% * toAnnie.m
% and the command line utility provided with this pack:
% * matlab2annie
net = newff([0,1;0,1],[3,1],{'tansig','tansig'},'traingd');
net.trainParam.epochs = 500;
net.trainParam.show = 100;
net.trainParam.lr = 0.5;
net.trainParam.goal = 0.001;
% Line below trains the network with the required input
% vectors in matrix P and corresponding output vectors
% in T. ( P contains (0,0), (0,1), (1,0) & (1,1)
% while T contains the corresponding XORed values
% ie, 0,1,1,0).
% P(i,j) = ith component of jth input vector
% T(i,j) = ith component of jth output vector
% P = [ 0,0,1,1 ; 0,1,0,1];
% T = [ 0, 1, 1, 0];
% [net,tr]=train(net,P,T);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -