Feb-25-2019, 03:30 AM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import numpy as np #Input array X = np.array([[ 1 , 0 , 1 , 0 ],[ 1 , 0 , 1 , 1 ],[ 0 , 1 , 0 , 1 ]]) #Output y = np.array([[ 1 ],[ 1 ],[ 0 ]]) #Sigmoid Function def sigmoid (x): return 1 / ( 1 + np.exp( - x)) #Derivative of Sigmoid Function def derivatives_sigmoid(x): return x * ( 1 - x) #Variable initialization epoch = 5000 #Setting training iterations lr = 0.1 #Setting learning rate inputlayer_neurons = X.shape[ 1 ] #number of features in data set hiddenlayer_neurons = 3 #number of hidden layers neurons output_neurons = 1 #number of neurons at output layer #weight and bias initialization wh = np.random.uniform(size = (inputlayer_neurons,hiddenlayer_neurons)) bh = np.random.uniform(size = ( 1 ,hiddenlayer_neurons)) wout = np.random.uniform(size = (hiddenlayer_neurons,output_neurons)) bout = np.random.uniform(size = ( 1 ,output_neurons)) for i in range (epoch): #Forward Propogation hidden_layer_input1 = np.dot(X,wh) hidden_layer_input = hidden_layer_input1 + bh hiddenlayer_activations = sigmoid(hidden_layer_input) output_layer_input1 = np.dot(hiddenlayer_activations,wout) output_layer_input = output_layer_input1 + bout output = sigmoid(output_layer_input) #Backpropagation E = y - output slope_output_layer = derivatives_sigmoid(output) slope_hidden_layer = derivatives_sigmoid(hiddenlayer_activations) d_output = E * slope_output_layer Error_at_hidden_layer = d_output.dot(wout.T) d_hiddenlayer = Error_at_hidden_layer * slope_hidden_layer wout + = hiddenlayer_activations.T.dot(d_output) * lr bout + = np. sum (d_output, axis = 0 ,keepdims = True ) * lr wh + = X.T.dot(d_hiddenlayer) * lr bh + = np. sum (d_hiddenlayer, axis = 0 ,keepdims = True ) * lr print output |
File "nn_in_python.py", line 11
return 1/(1 + np.exp(-x))
^
IndentationError: expected an indented block
It says something about line 11 should be indented. But it is indented! So what is wrong and how to fix.
I am very new to python, but not to programming.
I just need to know what is wrong here. this code was taken directly from a tutorial, and it should run fine.
Any help appreciated.Thanks in advance.
respectfully,
ErnestTBass