Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lose all;
- clear all;
- mnistImgs = loadMNISTImages('../../../Database/MNIST/train-images.idx3-ubyte');
- mnistLabels = loadMNISTLabels('../../../Database/MNIST/train-labels.idx1-ubyte');
- nDigits = 10;
- labelsLen = length(mnistLabels);
- % Transform the labels to correct target values.
- targetValues = zeros(nDigits, labelsLen);
- for n = 1 : labelsLen
- % +1 to avoid 0 index
- targetValues(mnistLabels(n) + 1, n) = 1;
- end;
- nNeurons = 20;
- batchSize = 100;
- epochs = 500;
- learningRate = 0.1;
- activFunction = @logisticSigmoid;
- dActivFunction = @dLogisticSigmoid;
- fprintf('Number of neurons: %d\n', nNeurons);
- fprintf('Number of Epochs: %d\n', epochs);
- fprintf('Batch number: %d\n', batchSize);
- fprintf('Learning rate: %d\n', learningRate);
- [hiddenWeights, ...
- outputWeights, ...
- error] = trainStochasticSquaredErrorTwoLayerPerceptron(activFunction,
- dActivFunction,
- nNeurons,
- mnistImgs,
- targetValues,
- epochs,
- batchSize,
- learningRate);
- toFile(hiddenWeights, "hiddenweights");
- toFile(outputWeights, "outputweights");
- # NOWE
- labels = [0,1,2,3,4,5,6,7,8,9];
- predicted_labels = zeros(1, length(digit_data_base));
- for idx_img in range(length(digit_data_base)):
- inputVector = digit_data_base(idx_img)
- hiddenActualInput = hiddenWeights * inputVector;
- hiddenOutputVector = activFunction(hiddenActualInput);
- outputActualInput = outputWeights * hiddenOutputVector;
- outputVector = activFunction(outputActualInput);
- predicted_labels(idx_img) = labels(idx_from_max(outputVector))
- cnf_matrix = confusion_matrix(predicted_labels , mnistLabels )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement