sample1: 1 2 3 4 label: A
sample2: 1 5 7 7 label: B
Every sample must be put in a column
=============================
featureIn
1 1
2 5
3 7
4 7
featureOut
A
B
function [yPredict] = doBP(trainFeature,trainValue)
trainFeature = trainFeature'; % to fit matlab format
trainValue = trainValue';% to fit matlab format
% % version 2010a
net=newff(trainFeature,trainValue,[13 1],{'tansig' 'purelin'}); % tansig purelin
% version 2009a
% net=newff(trainFeature,trainValue,[13 1]);
% net.layers{1}.transferFcn = 'tansig';
% net.layers{2}.transferFcn = 'purelin';
net=init(net);
net.trainParam.epochs = 99999999;
net.trainParam.goal = 0.0000001; %(stop training if the error goal hit)
net.trainParam.lr= 0.000001; % (learning rate, not default trainlm) [0.01]
net.trainParam.epochs = 99999999;
net.trainParam.goal = 0.0000001; %(stop training if the error goal hit)
net.trainParam.lr= 0.000001; % (learning rate, not default trainlm) [0.01]
% net.trainParam.lr_dec = 0.000001;
% net.trainParam.mc = 0.9;
% net.trainParam.min_grad = 1e-10;
net.trainParam.show=1 ; %(no. epochs between showing error) [25]
net.trainParam.time =100000; % (Max time to train in sec) [inf]
net.trainFcn = 'trainlm'; % trainrp trainbfg trainlm
net.divideParam.trainRatio = 80/100; % Adjust as desired
net.divideParam.valRatio = 20/100; % Adjust as desired
net.divideParam.testRatio = 0/100; % Adjust as desired
% TRAIN
[net,tr,Ytrain,E,Pf,Af] = train(net,trainFeature,trainValue); %train(net,subset_active_input',subset_active_output');plotperf(tr);
end
function doTesting(testFeatureIn)
testFeatureIn = testFeatureIn'; % to fit matlab format
testFeatureOut = testFeatureOut'; % to fit matlab format
load net ;% will retrive the network and put it in your workspace
[predictedY,Pf,Af,E,perf] = sim(net,testFeatureIn);
end
Comments
Post a Comment