题目:道理都懂,题目为模式识别这门课的小作业,题目是有错的,(1,1,1,1)是(1,1,1)

模式识别设计(Python编程):感知器固定增量法

代码:

import numpy as np

a = np.array([[0, 0],
              [0, 1],
              [1, 0],
              [1, 1]], dtype=np.float64)
b = np.array([1, 1, 1, 1], dtype=np.float64)
w = np.array([[1],
              [1],
              [1]], dtype=np.float64)
w2 = np.array([[1, 1, 1]], dtype=np.float64)
x = np.column_stack((a, b))
x[2] = -x[2]
x[3] = -x[3]
x_true = np.matrix(x)
w_true = np.matrix(w)
w2_true = np.matrix(w2)
tag = 0
while tag < 4:
    tag = 0
    for i in range(4):
        if int(x_true[i] * w_true) <= 0.:
            w2_true = x_true[i] + w2_true
            w_true = x_true[i].reshape(3, 1) + w_true
            print(w2_true, i+1)
        else:
            tag += 1
            print(w2_true, i+1)
print("the answer is: %f*x1 + %f*x2 = %f" % (w2_true[0, 0], w2_true[0, 1], w2_true[0, 2]))
#print(w2_true)
 

结果:嘤嘤嘤

模式识别设计(Python编程):感知器固定增量法

相关文章:

  • 2021-06-04
  • 2022-12-23
  • 2021-06-06
  • 2021-06-18
  • 2021-05-05
  • 2021-08-24
  • 2021-11-15
  • 2021-07-17
猜你喜欢
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
  • 2022-12-23
  • 2021-04-11
  • 2022-12-23
相关资源
相似解决方案