The ReLU function, in this case I used the leaky ReLU is giving me wrong output. But using the sigmoid function it gives me an acceptable output
Here is the code that I have:
import numpy as np
def relu(x):
return np.maximum(0.01 * x, x)
def relu_derivative(x):
x[x>0] = 1
x[x<0] = 0.01
return x
training_inputs = np.array([[1, 0],
[1, 1],
[0, 0],
[0, 1]])
training_outputs = np.array([[1, 0, 0, 1]]).T
weights = 2 * np.random.random((2, 1)) - 1
print('Weights before training: ')
print(weights)
for epochs in range(10000):
outputs = relu(np.dot(training_inputs, weights))
error = training_outputs - outputs
adjustment = error * relu_derivative(outputs)
weights += np.dot(training_inputs.T, adjustment)
print('Neuron Weights after training: ')
print(weights)
print('Outputs after training: ')
print(outputs)
Epochs = 10000
Outputs after training using the ReLU function = [0.01],[0.01],[0.01],[0.01],[0.01]
Outputs after training using the sigmoid function = [0.99],[0.01],[0.006],[0.99],[0.98]
The output given by the sigmoid function is better than ReLU's and I tested with epochs up to 100000 and the result for ReLU function is still the same. Is there something wrong with my function or code?