Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function classifier(trainMatrixEnhanced)
- %UNTITLED Summary of this function goes here
- % Detailed explanation goes here
- % trainfunc,activfunc,learnfunc
- trainfunc = "traingd";
- activfunc = "hardlim"; % %logsig hardlim purelin
- %learnfunc = "learnp";
- W = rand(10,256); %Weights
- b = rand(10,1); %bias
- % targets = zeros(10, 500);
- % for i=1:10
- % for j=1:50
- % targets(i,i) = 1;
- % end
- % end
- target_arrays= [[1 0 0 0 0 0 0 0 0 0];[0 1 0 0 0 0 0 0 0 0];[0 0 1 0 0 0 0 0 0 0];[0 0 0 1 0 0 0 0 0 0];[0 0 0 0 1 0 0 0 0 0];[0 0 0 0 0 1 0 0 0 0];[0 0 0 0 0 0 1 0 0 0];[0 0 0 0 0 0 0 1 0 0];[0 0 0 0 0 0 0 0 1 0];[0 0 0 0 0 0 0 0 0 1]];
- %Função fornecida por um colega
- targets = [];
- A = targets;
- for i=1:10
- for j=1:50
- targets= [A target_arrays(1:10,i)];
- A= targets;
- end
- end
- if(activfunc == "hardlim")
- net = perceptron; %Hard limit transfer function (default = 'hardlim') / Perceptron learning rule (default = 'learnp')
- else
- net = network();
- net.numInputs = 1;
- net.inputs{1}.size = 256;
- net.numLayers = 1;
- net.layers{1}.size = 10;
- net.inputConnect(1) = 1;
- net.biasConnect(1) = 1;
- net.outputConnect(1) = 1;
- net.layers{1}.transferFcn = "purelin";
- net.trainFcn = "traingd"; %gradient / to see all training funcs - help nntrain
- end
- view(net)
- net = configure(net, trainMatrixEnhanced, targets);
- %Initialization
- net.IW{1,1} = W;
- net.b{1,1}= b;
- %Training parameters
- net.performParam.lr = 0.5; % learning rate
- net.trainParam.epochs = 1000; % maximum epochs
- net.trainParam.show = 35; % show
- net.trainParam.goal = 1e-6; % goal=objective
- net.performFcn = 'sse'; % criterion
- %Training -> Trains a network net according to net.trainFcn and net.trainParam.
- net = train(net, trainMatrixEnhanced, targets);
- %Access weighs and bias
- W = net.IW{1,1};
- b = net.b{1,1};
- load("validateData.mat")
- % %Validation
- a = sim(net, P, targets)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement