【问题标题】:Perceptron in Erlang not learning after trainingErlang中的感知器在训练后没有学习
【发布时间】:2016-01-12 19:47:00
【问题描述】:

我不认为我的问题与this one 重复,因为我在实施中已经存在偏见。

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

起始权重在列表[X_weight, Y_Weight, Bias_weight] 中提供,训练集在另一个列表[X,Y,Desired_guess] 中提供,其中X 和Y 是整数,如果坐标在线下,则Desired_guess 为-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).

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

【问题讨论】:

  • 你能不能查看/编辑你的代码,它很难阅读,第二行有语法错误,如果你取消额外的')'没有效果
  • @Pascal 你是对的。当我从我的编辑器复制粘贴时,一条线掉了下来。为了清楚起见,尝试格式化和注释代码。

标签: machine-learning erlang neural-network artificial-intelligence perceptron


【解决方案1】:

这确实有效。我提供的训练套件太小了。使用更大的训练集和大约 20 个 epoch,全局误差收敛到 0。

【讨论】:

  • 您的 train_perceptron/4 和 train_perceptron/5 确实减少到单个 2 子句 arity 4 函数顺便说一句: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 谢谢,一个不错的解决方案。自从我用函数式语言做任何事情以来已经有一段时间了。需要改进我的风格,以摆脱我现在正在摸索的这种多余的呆滞。
猜你喜欢
  • 2021-01-14
  • 1970-01-01
  • 2014-07-03
  • 2016-03-02
  • 2013-12-23
  • 2020-05-06
  • 1970-01-01
  • 1970-01-01
  • 2011-02-15
相关资源
最近更新 更多