from JMSSNeural import *

file = open("sonar.training-data.csv", "r")
training = []

for rows in file:
    coloumns = rows.split(",")
    coloumns = [float(c) for c in coloumns]
    training.append(coloumns)
file.close()

learning_rate = 0.8
epochs = 50000


weights = train(training, learning_rate, epochs)

print("The trained weights are: ", weights)

test = open("sonar.testing-data.csv", "r")
testing = []

for rows in test:
    coloumns = rows.split(",")
    coloumns = [float(c) for c in coloumns]
    testing.append(coloumns)
test.close()
error = 0
for line in testing:
    x = perceptron_train(line, weights)
    error += (x - line[-1])**2
print(error)

