# -*- coding: utf-8 -*-
"""
Created on Mon Apr 19 00:31:59 2021

@author: Nouman Ahmad
"""

import numpy as np

#Step 01
#Variables

#independent variables
training_set = np.array([[0,1,0],[0,0,1],[1,0,0],[1,1,0],[1,1,1],[0,1,1],[0,1,0]])

# dependent variables

labels =np.array([[1,0,0,1,1,0,1]])

labels=labels.reshape(7,1)


#Step 02
#heyper-paprameters

np.random.seed(42)

weights=np.random.rand(3,1)
bias=np.random.rand(1)
lr=0.05

#Step 03

#methods
def sigmoid(x):  
    return 1/(1+np.exp(x))

def sigmoid_derivation(x):
    return sigmoid(x)*(1-sigmoid(x))


#Step 04

#training our model

for epoch in range(10):
    inputs =training_set
    XW=np.dot(inputs,weights)+bias
    print(epoch)
    z=sigmoid(XW)
    error=z-labels
    print(error.sum())
    dcost=error
    dpred=sigmoid_derivation(z)
    z_del=dcost * dpred
    inputs= training_set.T
    weights = weights - lr* np.dot(inputs,z_del)
    for num in z_del:
        bias=bias-lr*num
        
inputs = training_set        
    

# #feed forward

# XW =np.dot(inputs,weights)+bias
# z=sigmoid(XW)


# #error
# error =z-labels

# #determining slope

# slope = inputs *dcost * dpred

# dcost=error


# dpred=sigmoid_derivation(z)
# z_del=dcost * dpred
# inputs= training_set.T
# weights = weights - lr* np.dot(inputs,z_del)
# for num in z_del:
#     bias=bias-lr*num

    
#Step 05

# single_pt=np.array([1,0,0])

# result=sigmoid(np.dot(single_pt,weights)+bias)

# print(result)   


single_pt=np.array([0,1,0])
result=sigmoid(np.dot(single_pt,weights)+bias)
print(result)   