import numpy as np

'''
教材第45页
已知正实例点x1=(3，3)T,x2=[4,3]T,负实例点x3=(1,1)T
用感知机学习算法的对偶形式求感知机模型f(x)=sign(w·x+b)。
这里w=(w(1),w(2))T,x=(x(1),x(2))T
'''


def perceptron_antithesis():
    x = np.array([[3, 3], [4, 3], [1, 1]])
    y = np.array([1, 1, -1])
    aa = np.array([0, 0, 0])
    b = 0
    G = np.array([[18, 21, 6], [21, 25, 7], [6, 7, 2]])
    # print(np.matmul(x, x[0].T))
    for a in range(5):
        print('-----------第{}轮------------'.format(a + 1))
        for i in range(3):
            L = y[i] * (np.sum(aa * y * np.matmul(x, x[i].T)) + b)
            if L <= 0:
                print("x{},L={}".format(i + 1, L))
                aa[i] = aa[i] + 1
                print("a={}".format(aa))
                b = b + y[i]
                print("b={}".format(b))


if __name__ == "__main__":
    perceptron_antithesis()
