Machine learning Erlang中的感知器训练后不学习 我不认为我的问题是重复的,因为在我的实现中已经有了偏差。

Machine learning Erlang中的感知器训练后不学习 我不认为我的问题是重复的,因为在我的实现中已经有了偏差。,machine-learning,erlang,neural-network,artificial-intelligence,perceptron,Machine Learning,Erlang,Neural Network,Artificial Intelligence,Perceptron,我试图实现一个感知器及其训练来识别Erlang中的线性斜率。问题是它没有得到适当的训练。在50个时代之后,它猜测的值仍然大约有50%是正确的 起始权重在一个列表中提供[X\u-weight,Y\u-weight,Bias\u-weight]并且训练集在另一个列表中提供[X,Y,期望的猜测]中,其中X和Y是整数,如果坐标在直线下,期望的猜测是-1,如果坐标在直线上,则是1 首先是新权重的计算: % Exported starting clause % Inputs are - List of in

我试图实现一个感知器及其训练来识别Erlang中的线性斜率。问题是它没有得到适当的训练。在50个时代之后,它猜测的值仍然大约有50%是正确的

起始权重在一个列表中提供
[X\u-weight,Y\u-weight,Bias\u-weight]
并且训练集在另一个列表中提供
[X,Y,期望的猜测]
中,其中X和Y是整数,如果坐标在直线下,期望的猜测是-1,如果坐标在直线上,则是1

首先是新权重的计算:

% 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.
这是调用train_perceptron函数的函数

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).

一个解决方案是,如果有人给我提供了一个关于这种函数的训练集,每个历元有三个起始权重和输出。这可以帮助我自己调试它。

这确实有效。我提供的训练器材太小了。使用更大的训练集和大约20个历元,gobal误差收敛到0。

这实际上是可行的。我提供的训练器材太小了。使用更大的训练集和大约20个纪元,gobal错误收敛为0。

您是否可以查看/编辑代码,它非常难阅读,第二行有语法错误,如果您抑制额外的“')”@Pascal,则没有效果您是对的。当我从编辑器复制粘贴时,一行掉了下来。为了清晰起见,尝试对代码进行格式化和注释。请检查/编辑您的代码,这很难阅读,第二行有语法错误,如果您抑制额外的“')”@Pascal,则无效。您是对的。当我从编辑器复制粘贴时,一行掉了下来。为了清晰起见,尝试格式化和注释代码。您的train_perceptron/4和train_perceptron/5确实简化为一个2子句arity 4函数BTW:tp([IH],[WH |[]),LC,E)->[WH+LC*E];tp([IH | InT],[WH | WT],LC,E)->[WH+(LC*E)*IH | tp(InT,WT,LC,E)]。@Michael谢谢,这是一个很好的解决方案。我已经有一段时间没有用函数式语言做任何事情了。需要改进我的风格以摆脱我现在正在摸索的这个多余的懒散。你的训练感知机/4和训练感知机/5确实减少到一个单一的2子句arity 4函数BTW:tp([IH],[WH],[WH |[],LC,E)->[WH+LC*E];tp([IH | InT],[WH | WT],LC,E)->[WH+(LC*E)*IH | tp(InT,WT,LC,E)]。@Michael谢谢,这是一个很好的解决方案。我已经有一段时间没有用函数式语言做任何事情了。需要改进我的风格以摆脱我现在正在摸索的这种多余的懒散。