I've used the nprtool to generate the script to train a neural network. I wanted to change the training algorithm from trainlm to conjugate gradient descent or something like that.
% Solve a Pattern Recognition Problem with a Neural Network
% Script generated by NPRTOOL
% Created Tue Nov 01 18:08:00 IST 2011
%
% This script assumes these variables are defined:
% % train - input data.
% train_labels - target data.
clc; inputs = train'; targets = train_labels';% Create a Pattern Recognition Network
hiddenLayerSize = 60;net = patternnet(hiddenLayerSize);% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 80/100;net.divideParam.valRatio = 15/100;net.divideParam.testRatio = 5/100;% For help on training function 'trainlm' type: help trainlm
% For a list of all training functions type: help nntrain
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean squared error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ... 'plotregression', 'plotfit'};% Train the Network
[net,tr] = train(net,inputs,targets);% Test the Network
outputs = net(inputs);errors = gsubtract(targets,outputs);performance = perform(net,targets,outputs)% Recalculate Training, Validation and Test Performance
trainTargets = targets .* tr.trainMask{1};valTargets = targets .* tr.valMask{1};testTargets = targets .* tr.testMask{1};trainPerformance = perform(net,trainTargets,outputs)valPerformance = perform(net,valTargets,outputs)testPerformance = perform(net,testTargets,outputs)% View the Network
view(net)% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, plotconfusion(targets,outputs)
%figure, ploterrhist(errors)
When I run this code, I get the error,
??? Indexing cannot yield multiple results.Error in ==> untitled2 at 46[net,tr] = train(net,inputs,targets);
Can you please help me out with this?
Thanks
Best Answer