问题与MATLAB IRIS Perceptron

时间:2018-01-30 05:17:08

标签: matlab machine-learning neural-network perceptron iris-recognition

Link to the github page with all of the code

抱歉,这是在黑暗中拍摄的。我一直试图让这个MATLAB感知器对虹膜数据集进行数月分类。我已经尝试改变超参数,激活函数,不同形式的梯度下降,初始化,梯度检查和许多其他的东西,但我不能让它工作。如果有人能给我任何关于它为什么不起作用的线索,我将不胜感激。

%% Define Hyperparameters
% This will be a 4 layer neural network, with two hidden layers

inputLayerSize = 4; % representing the 4 features 
outputLayerSize = 3; % representing the 3 kinds of iris
hiddenLayer1Size = 6;
hiddenLayer2Size = 5;


%% Randomly Initialize Weights and Biases

W12 = rand(hiddenLayer1Size, inputLayerSize);
b12 = rand(hiddenLayer1Size, 1);
W23 = rand(hiddenLayer2Size, hiddenLayer1Size);
b23 = rand(hiddenLayer2Size, 1);
W34 = rand(outputLayerSize, hiddenLayer2Size);
b34 = rand(outputLayerSize, 1);

%% Number of iterations of training 
for i = 1 : 100

%% Randomly Select Training Example
% Because this neural network is trained using Stochastic gradient descent
% the network is trained using only one example

[~,s] = size(X_train);
n = randi(s);
Xone = X_train(:,n);
Yone = Y_train(:,n);

%% Forward Propagation

[Yout, a3, a2, z4, z3, z2] = ForwardProp( Xone, W12, b12, W23, b23, W34, b34 );

%% Back Propagation

[del4, del3, del2] = Backprop(Yout, Yone, z4, z3, z2, W34, W23);

%% Update Weights and bias

nu = 0.1; %learning rate

W34 = W34 - nu * (del4*a3');
b34 = b34 - nu * del4;

W23 = W23 - nu * (del3*a2');
b23 = b23 - nu * del3;

W12 = W12 - nu * (del2*Xone');
b12 = b12 - nu * del2;


%% Check Accuracy
if rem(i, 10) == 0
[ Ycheck, a3, a2, z4, z3, z2 ] = ForwardProp( X_test, W12, b12, W23, b23, W34, b34 );
AccuracyCheck(Ycheck, Y_test)

end 
end

0 个答案:

没有答案