For the implementation of single layer neural network, I have two data files.
In:
0.832 64.643
0.818 78.843
Out:
0 0 1
0 0 1
The above is the format of 2 data files.
The target output is "1 for a particular class that the corresponding input belongs to and "0 for the remaining 2 outputs.
The problem is as follows:
Your single layer neural network will find A(3 by 2 matrix) and b (3 by 1 vector) in Y = A*X + b where Y is [C1, C2, C3]' and X is [x1, x2]'.
To solve the problem above with a neural network, we can re-write the equation as follow: Y = A' * X' where A' = [A b] (3 by 3 matrix) and X' is [x1, x2, 1]'
Now you can use a neural network with three input nodes (one for x1, x2, and 1 respectively) and three outputs (C1, C2, C3).
The resulting 9 (since we have 9 connections between 3 inputs and 3 outputs) weights will be equivalent to elements of A' matrix.
Basicaly, i am trying to do something like this, but it is not working:
function neuralNetwork
load X_Q2.data
load T_Q2.data
x = X_Q2(:,1);
y = X_Q2(:,2);
learningrate = 0.2;
max_iteration = 50;
% initialize parameters
count = length(x);
weights = rand(1,3); % creates a 1-by-3 array with random weights
globalerror = 0;
iter = 0;
while globalerror ~= 0 && iter <= max_iteration
iter = iter + 1;
globalerror = 0;
for p = 1:count
output = calculateOutput(weights,x(p),y(p));
localerror = T_Q2(p) - output
weights(1)= weights(1) + learningrate *localerror*x(p);
weights(2)= weights(1) + learningrate *localerror*y(p);
weights(3)= weights(1) + learningrate *localerror;
globalerror = globalerror + (localerror*localerror);
end
end
I write this function in some other file and calling it in my previous code.
function result = calculateOutput (weights, x, y)
s = x * weights(1) + y * weights(2) + weights(3);
if s >= 0
result = 1;
else
result = -1;
end
Now plz help in getting the right solution. I am not going to put any more question on this topic. Plz help me with the right code.