Hyperplane in perceptrons

499 views Asked by At

What is Hyperplane in the discussion of neural networks and Perceptrons?

The following perceptron is implemented using Hyperplane.

perceptron_minin.m(Octave)

function [errors, sepplane ] = perceptron_minin ( pclass , nclass)
    sepplane = rand ( 1 , columns ( pclass ) + 1 ) - 0.5;
    tset = [ones(rows(pclass), 1),  pclass ; -ones(rows(nclass), 1), -nclass];
    i = 1;
    do
        misind = tset * sepplane' < 0;

        correction = sum ( tset ( misind , :), 1 ) / sqrt ( i );

        sepplane = sepplane + correction;

        ++i;
    until ( norm(sepplane) * 0.0005 ) - norm(correction) > 0 || i > 1000);

    errors = mean( tset * sepplane' < 0);
    dzeros = tvec(tlab == 1 , :);
    dones = tvec(tlab == 2 , :);
    perceptron(dzeros, dones)
end

But, in the following program, the logic is designed without using hyperplanes.

perceptron_test.m (MATLAB)

bias = -1;
coeff = 0.7;
rand('state', sum(100 * clock));
weights = -1*2 .* rand(3,1);

train_iter = 10000;
train_data_count = 4;
test_data_count  =  100;

%%  training section

train_data = [   0  0; 
                 0  1; 
                 1  0; 
                 1  1];

class_labels = [0;
               1;
               1;
               1];

bias_vector(1:train_data_count, 1) = bias;

train_data_biased = [bias_vector, train_data];

for i=1:train_iter
    output = zeros(train_data_count,1);
    for j=1:train_data_count   
        y = product(train_data_biased(j,:), weights);

        output(j)  = activ_func(y);

        delta = class_labels(j) - output(j);

        inc = train_data_biased(j,:) * (coeff  * delta);

        weights = weights + inc';
    end
end

table(train_data(:,1), train_data(:,2), output, 'VariableNames', {'A' 'B' 'A_xor_B'})


%% test Section

test_data = randi([0 , 1], [test_data_count, 2]) + 
            (2 * rand(test_data_count,2) - 1) / 20;

for i=1:test_data_count
   y = bias*weights(1,1)+...
       test_data(i,1)*weights(2,1)+...
       test_data(i,2)*weights(3,1);
   output(i) = 1/(1+exp(-y));
end

table(test_data(:,1),test_data(:,2), output,
       'VariableNames',{'A' 'B' 'A_xor_B'})

Now, I have several questions,

(1) Is the 1st source code correct?

(2) If YES, Explain why they both work.

1

There are 1 answers

0
Scott Hunter On

Weight is not synonymous to Hyperplane, but they are related: the Hyperplane is defined by the values of the weights.