-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetwork.py
36 lines (28 loc) · 900 Bytes
/
Network.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
import os
import numpy as np
import matplotlib.pyplot as plt
import scipy.special
import random
class Network:
def __init__(self, layers):
self.num_layers = len(layers)
self.sizes = layers
self.biases = [np.random.randn(y, 1) for y in layers[1:]]
self.weights = [np.random.randn(y, x)
for x, y in zip(layers[:-1], layers[1:])]
def sigmoid(self,z):
return 1.0/(1.0+np.exp(-z))
def sigmoid_prime(self,z):
return sigmoid(z)*(1-sigmoid(z))
def feedforward(self, a):
for b, w in zip(self.biases, self.weights):
a = sigmoid(np.dot(w, a)+b)
return a
listw = [1,2,1,1]
network = Network([1,2,1,1])
parameters = network.initialize_parameters([2,2,1])
print(parameters)
# print("------")
# print(np.random.randn(1, 2))
# print(np.random.randn(1, 1))
# print(np.random.randn(2, 1))