I don't consider my question a duplicate of this one since I already have a bias in my implementation.
I try to implement a perceptron and its training of recognizing a linear slope in Erlang. The problem is that it is not properly trained. The values it guesses are still about 50% correct after 50 epochs.
The starting weights are supplied in a list [X_weight, Y_Weight, Bias_weight]
and the training set is supplied in a another list [X,Y,Desired_guess]
where X and Y are integers and Desired_guess is -1 if the coordinate is under the line or 1 if it is over the line.
First is the calculation of the new weights:
% Exported starting clause
% Inputs are - List of input values for one perceptron ([X,Y,Bias]), A list of weights corresponding to the inputs [X_weight, Y_weight, Bias_weight], the learning constant and the error (Desired-Guess)
train_perceptron([InputsH|InputsT], [WeightsH|WeightsT], Learning_constant, Error) ->
train_perceptron(InputsT, WeightsT, Learning_constant, Error,
[WeightsH + (Learning_constant * Error) * InputsH]).
% Not exported clause called by train_perceptron/4 This also has a list of the new adjusted weights.
% When the tail of input lists are empty lists it is the last value, and thereby the Bias
train_perceptron([InputsH|[]], [WeightsH|[]], Learning_constant, Error, Adjusted_weights) ->
train_perceptron([], [], Learning_constant, Error,
Adjusted_weights ++ [WeightsH + Learning_constant * Error]);
%Normal cases, calcualting the new weights and add them to the Adjusted_weights
train_perceptron([InputsH|InputsT], [WeightsH|WeightsT], Learning_constant, Error, Adjusted_weights) ->
train_perceptron(InputsT, WeightsT,Learning_constant, Error,
Adjusted_weights ++ [WeightsH + (Learning_constant * Error) * InputsH]);
%Base case the lists are empty, no more to do. Return the Adjusted_weights
train_perceptron([], [],_, _, Adjusted_weights) ->
Adjusted_weights.
This is the function that calls the train_perceptron function
line_trainer(Weights,[],_) ->
Weights;
line_trainer(Weights, [{X,Y,Desired}|TST], Learning_constant)->
Bias = 1,
Error = Desired - feedforward([X,Y,Bias],Weights),
Adjusted_weights = train_perceptron([X,Y,Bias], Weights, Learning_constant, Error),
line_trainer(Adjusted_weights, TST, Learning_constant).
One solution, could be if someone supplied me with a training set for that kind of function three starting weights and outputs for each epoch. That could help me debug this myself.