hw1.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:ML_NTU 作者: LeoTsui 项目源码 文件源码
def native_pla(x_d, y_d, is_rand=False, repeat=1, eta=1.0):
    total_update = 0

    for rpt in range(0, repeat):
        w = np.zeros(len(x_d[0]))
        update_count = 0
        all_pass = False

        index = [i for i in range(len(x_d))]
        if is_rand:
            random.shuffle(index)

        while not all_pass:
            all_pass = True
            for t in index:
                if np.sign(np.inner(x_d[t], w)) != y_d[t]:
                    w += eta * y_d[t] * x_d[t]
                    all_pass = False
                    update_count += 1

        total_update += update_count

    return w, total_update / repeat
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号