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
评论列表
文章目录