gpt4 book ai didi

machine-learning - Erlang 中的感知器在训练后不学习

转载 作者:行者123 更新时间:2023-11-30 09:21:54 28 4
gpt4 key购买 nike

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

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

起始权重在列表[X_weight, Y_Weight, Bias_weight]中提供,训练集在另一个列表[X,Y,Desired_guess]中提供,其中X 和 Y 是整数,如果坐标在线下,则 Desired_guess 为 -1;如果在线上,则 Desired_guess 为 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 个时期,全局误差收敛到 0。

关于machine-learning - Erlang 中的感知器在训练后不学习,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33130120/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com