Pastebin
Paste #1826: nn.m
< previous paste - next paste>
Pasted by karass
%% noisy-xor
% Load data from files
data = load('noisy-xor.txt');
T=data(:,1);
P=data(:,2:end);
% Set training data to first half of data
data_t = data(1:500,:);
% Set performance data to second half of data
data_p = data(501:end,:);
% Create new neural network
net = network;
% Define the input layer
net.numInputs = 1; % number of input layers
net.inputs{1}.size = 2; % number of neurons in the input layer
% Network properties
net.numLayers = 1; % total number of layers in the network
net.layers{1}.size = 1; % number of neurons in the layer
% Layer connections
net.inputConnect(1) = 1; % which layer the inputs are connected
net.outputConnect(1) = 1; % which layer is the output layer
%net.targetConnect(1) = 1;
% Transfer functions
net.layers{1}.transferFcn = 'logsig'; % set the layer to use sigmoid transfer functions
%net.layers{1}.transferFcn = 'purelin'; % set the layer to use linear transfer functions
% Weights and biases
% define which layers have biases
net.biasConnect = [1];
% Initialisation procedure for weights and biases
net = init(net);
net.initFcn = 'initlay';
net.layers{1}.initFcn = 'initnw'; % Nguyen-Widrow initialisation
%net.layers{1}.initFcn = 'initwb';
%net.inputWeights{1,1}.initFcn = 'rands';
%net.biases{1}.initFcn = 'rands';
%net.layerWeights{1,1}.initFcn = 'rands';
% Set performance function to Mean Absolute Error
%net.performFcn = 'mae';
% Set performance function to Mean Squared Error
net.performFcn = 'mse';
% Train network using a Gradient Descent with Momentum algorithm
net.trainFcn = 'traingdm';
net.trainParam.lr = 0.1; % learning rate
net.trainParam.mc = 0.9; % momentum term
% Maximum number of times the complete data set may be used for training
net.trainParam.epochs = 1000;
% time between status reports of the training function
net.trainParam.show = 100;
[n, tr] = train(net, P', T')
%%%%%%%%%%%%%%%%%%%%%%%%%%%
Output from running nn.m
Training with TRAINGDM.
??? Attempt to reference field of non-structure array.
Error in ==> nntraintool at 75
result = trainTool.isStopped;
Error in ==> traingdm at 229
[userStop,userCancel] = nntraintool('check');
Error in ==> network.train at 219
[net,tr] = feval(net.trainFcn,net,tr,trainV,valV,testV);
Error in ==> nn at 64
[n, tr] = train(net, P', T')
>>
New Paste
Go to most recent paste.