import numpy as np
from perceptron import Perceptron
from display import Display

PERCEPTRON = Perceptron(input_size=2, lr=0.01)

x_y = np.array((((0, 0), 1), ((1, 1), 0)))

for i in range(1000):
    for (x, y) in x_y:
        output = PERCEPTRON.forward(x)
        error = output - y
        PERCEPTRON.tune_parameters(x, error)

DISPLAY = Display()
DISPLAY.display(perceptron=PERCEPTRON)
testY = test['species'].astype('category')
testY = testY.cat.codes
testY = testY / testY.max()

trainX_flatten = trainX.reshape(trainX.shape[0], -1).T
testX_flatten = testX.reshape(testX.shape[0], -1).T

trainX_flatten = (trainX_flatten/trainX_flatten.max())
testX_flatten = (testX_flatten/testX_flatten.max())

#W, b, cost = p.fit(trainX_flatten, trainY, True)

x = np.arange(1, 51)

"""
np.savetxt("./save/weights.txt", W)
np.savetxt("./save/cost.txt", cost)
saveBias(b, "./save/bias.txt")
"""

W = np.loadtxt("./save/weights.txt")
cost = np.loadtxt("./save/cost.txt")
b = loadBias("./save/bias.txt")

predictions = p.forward(testX_flatten, W, b)

print("accuracy: ", accuracy(testY, predictions))

plt.plot(x, cost)
plt.show()