#!/usr/bin/env python3
# -*- coding:utf-8 -*-

# import the necessary packages
from neuralnetwork import  NeuralNetwork
import numpy as np


# construct the XOR dataset
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y = np.array([[0], [1], [1], [0]])

# define our 2-2-1 neural network and train it
nn = NeuralNetwork([2,2,1], alpha=0.5)
nn.fit(X, y, epochs=20000)

# Now that our network is trained, loop over the XOR data points
for (x, target) in zip(X, y):
    # make a prediction on the data point and display the result
    # to our console
    pred = nn.predict(x)[0][0]
    step = 1 if pred > 0.5 else 0
    print("[INFO] data={}, ground-truth={}, pred={:.4f}, step={}".format(x, target[0], pred, step))

"""
    Demonstrating that our multi-layer neural network is capable of learning nonlinear function
"""