疑惑感知器

Doubts perceptron

我正在自己研究机器学习,我遇到了以下感知器签名:

def ClassicPerceptron(W,X,Y,maxiter=1000,reorder=True):
    """ClassicPerceptron function implements the most basic perceptron. 

    This algorithm starts by reordering the training samples and their labels
    if reorder is equal to True. Then, it iterates for all the samples, as many
    times as it takes, to correctly classify all the samples, or until the number 
    of iterations reaches maxiter.

    Parameters
    ----------
    W : numpy array of floats
        The initial set of weights for the perceptron classificator.
    X : numpy array of floats
        The dataset with the bias (first column is equal to 1.0).
    Y : numpy array of floats
        The labels (-1.0, ou 1.0) for each line of X.
    maxiter : integer
        The maximum number of iterations allowed before stopping.
    reorder : boolean
        reorder the training samples and their labels.

    Returns
    -------
    W : numpy array of floats
        The last set of weights for the perceptron classificator.
    niter : integer
        The current number of iterations until success, or maxiter. 
        This is just to have an idea on how many iterations it took 
        to converge.

    """

我觉得很好奇,因为算法不尊重权重的更新,因为我们现在都看到了使用权重的更新,其实我不太理解那个定义,我想这个重新排序会洗牌训练样例,但我有点迷茫,想知道这个算法是怎么顶的。 PS: 请不要回复代码,只是喜欢一个解释。

嗯,在我看来,既然你可以通过 reorder=False,重新排序步骤是可选的,所以当它说

Then, it iterates for all the samples, as many times as it takes, to correctly classify all the samples, or until the number of iterations reaches maxiter.

它似乎是 updating/adjusting 权重,直到它正确找到最佳解决方案(用超平面将 类 分开)或直到达到 maxiter。换句话说,似乎尊重权重的更新

如果可能的话,如果您能向我们提供方法实现,那将会很有帮助,这样可以理解重新排序训练集背后的概念或想法。

除此训练方法外,还可以通过求解线性方程组来计算biasweights,如:X * W = Y。其中 X 训练样本 加上附加偏差列, W 权重数组 加上偏差权重和 Y 训练标签。其实我第一眼还以为是方法意图呢

在这种情况下,重新排序步骤将有助于获得交错形式的矩阵或获得 lower triangular matrix。两者都使用集合中的 d 个样本,其中 d 是维度(特征量加一,用于偏差)

请注意,为了解决这个线性系统,您需要考虑 X * W 个单独的结果(即:来自 X 的单行和来自 W 的唯一列)为 1 或 -1。您可以通过将 limiar 以上的每个结果都视为 1 来实现这一点。否则,-1.