-
Notifications
You must be signed in to change notification settings - Fork 0
/
multilayer.py
47 lines (36 loc) · 1.04 KB
/
multilayer.py
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
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 24 18:10:19 2017
@author: Toshiharu
"""
import numpy as np
def sigmoid(x):
"""
Calculate sigmoid
"""
return 1/(1+np.exp(-x))
def sigmoid_prime(x):
temp = sigmoid(x)
return temp*(1-temp)
# Network size
N_input = 4
N_hidden = 3
N_output = 2
np.random.seed(42)
# Make some fake data
X = np.random.randn(4)
weights_input_to_hidden = np.random.normal(0, scale=0.1, size=(N_input, N_hidden))
weights_hidden_to_output = np.random.normal(0, scale=0.1, size=(N_hidden, N_output))
#print(weights_input_to_hidden.T)
#print(X[:,None])
#print(weights_hidden_to_output.T)
# TODO: Make a forward pass through the network
#hidden_layer_in = np.dot(weights_input_to_hidden.T,X[:,None])
hidden_layer_in = np.dot(X,weights_input_to_hidden)
hidden_layer_out = sigmoid(hidden_layer_in)
print('Hidden-layer Output:')
print(hidden_layer_out.T)
output_layer_in = np.dot(hidden_layer_out,weights_hidden_to_output)
output_layer_out = sigmoid(output_layer_in)
print('Output-layer Output:')
print(output_layer_out)