代码拉取完成,页面将自动刷新
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import pandas as pd
import random
import time
'''initialize weight'''
ww = [0, 0]
b = 0
positive_x = [3,4]
positive_y = [3,3]
negative_x = [1]
negative_y = [1]
label = [1,1,-1]
label_select = [0,0,0]
data_size = 3
data_x = positive_x + negative_x
data_y = positive_y + negative_y
c_pos = [positive_x,positive_y]
c_pos = np.asarray(c_pos).T
d_neg = [negative_x,negative_y]
d_neg = np.asarray(d_neg).T
data = [data_x,data_y]
data = np.asarray(data).T
for iteration in range(1000):
i = random.randint(0,data_size-1)
print('iteration=', iteration)
print('i=',i)
plt.show()
time.sleep(1)
st = label[i]*(np.matmul(ww,data[i].T+b)+b)
if st <= 0:
ww = ww +label[i] * data[i]
b = b + label[i]
w = ww[0]+0.0001/(ww[1]+0.0001)
fig, ax = plt.subplots()
ax.scatter(positive_x,positive_y,c='b',marker='o')
ax.scatter(negative_x,negative_y,c='r',marker='x')
ax.plot([w*i + b for i in list(range(-5,5,1))])
fig.suptitle('perception')
plt.show()
else:
label_select[i]=1
an = 1
for j in label_select:
an = an & j
print(an)
if an == 1:
break
'''for i in range(len(data_x)):
st = label[i]*(np.matmul(ww,data[i].T+b)+b)
if st <= 0:
ww = ww +label[i] * data[i]
b = b + label[i]
w = ww[0]+0.0001/(ww[1]+0.0001)
fig, ax = plt.subplots()
ax.scatter(positive_x,positive_y,c='b',marker='o')
ax.scatter(negative_x,negative_y,c='r',marker='x')
ax.plot([w*i + b for i in list(range(-5,5,1))])
fig.suptitle('perception')
plt.show()'''
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。