-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmlp.py
More file actions
55 lines (42 loc) · 1.27 KB
/
mlp.py
File metadata and controls
55 lines (42 loc) · 1.27 KB
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
53
54
55
# MLP 3 layer network: input - hidden - outer
# based on:
# http://iamtrask.github.io/2015/07/12/basic-python-network/
import numpy as np
def activation(x,deriv=False):
'''activation function, values for sigmoid'''
if(deriv==True):
return x*(1-x) # derivative of sigmoid*
return 1/(1+np.exp(-x))
# inputs (X)
inputs = np.array([[0,0],
[0,1],
[1,0],
[1,1]])
# targets (y) - presently for AND, change for OR and XOR
targets = np.array([[0],
[0],
[0],
[1]])
## make network geometry
#nodes_input =
#nodes_hidden =
#nodes_target =
## initialize weights (-1.0 to 1.0)
#Wxh = 2*np.random.uniform(size=( , )) - 1
#Why = 2*np.random.uniform(size=( , )) - 1
## simulation parameters
#np.random.seed(1)
#alpha = 1 # learning rate
#num_epochs =
# training pseudo code
# for each epoch:
# for each row of X, y in inputs, targets
# Feed forward to find values of:
# H
# yp (the prediction)
# Back propogate to find the gradient of the loss with respect to:
# Why
# Wxh
# Use gradient descent to update the weights
# for this epoch, print training error
# print final comparison between target and predictions