Skip to content

Instantly share code, notes, and snippets.

@5hyn3
Last active October 27, 2017 01:20
Show Gist options
  • Save 5hyn3/2cb73b26e94702a6208bb46602a51a0f to your computer and use it in GitHub Desktop.
Save 5hyn3/2cb73b26e94702a6208bb46602a51a0f to your computer and use it in GitHub Desktop.
Python Simple Feed Forward NeuralNetwork

概要

 「ゼロから作るDeep Learning ―Pythonで学ぶディープラーニングの理論と実装」を参考にpythonで制作した簡単な順方向ニューラルネットワークです。 重みはKerasを用いてXORを学習したものを使っています。

import numpy as np
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def init_network():
network = {}
network['W1'] = np.array([[-3.7, -3.9, -1.8], [-3.8, -3.4, -1.8]])
network['W2'] = np.array([[-3.0], [-2.5], [2.9]])
network['b1'] = np.array([-0.4, -0.6, 1.9])
network['b2'] = np.array([-0.4])
return network
def forward(network, x):
W1, W2 = network['W1'], network['W2']
b1, b2 = network['b1'], network['b2']
a1 = np.dot(x, W1) + b1
z1 = sigmoid(a1)
a2 = np.dot(z1, W2) + b2
y = a2
return y
network = init_network()
x = np.array([0, 1])
y = forward(network, x)
print(y)

ゼロから作るDeep Learning ―Pythonで学ぶディープラーニングの理論と実装

  • Author
    • 斎藤 康毅
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment