├── Episode 02 ├── program.py └── neuralnetwork.py ├── README.md └── LICENSE /Episode 02/program.py: -------------------------------------------------------------------------------- 1 | import neuralnetwork as nn 2 | import numpy as np 3 | 4 | layer_sizes = (3,5,10) 5 | x = np.ones((layer_sizes[0],1)) 6 | 7 | net = nn.NeuralNetwork(layer_sizes) 8 | prediction = net.predict(x) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Neural-Network-python 2 | 3 | Code for the tutorial series: [Neural Networks](https://www.youtube.com/playlist?list=PLFt_AvWsXl0frsCrmv4fKfZ2OQIwoUuYO "Youtube playlist") 4 | 5 | Based on: http://neuralnetworksanddeeplearning.com/ 6 | -------------------------------------------------------------------------------- /Episode 02/neuralnetwork.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | class NeuralNetwork: 4 | 5 | def __init__(self, layer_sizes): 6 | weight_shapes = [(a,b) for a,b in zip(layer_sizes[1:],layer_sizes[:-1])] 7 | self.weights = [np.random.standard_normal(s)/s[1]**.5 for s in weight_shapes] 8 | self.biases = [np.zeros((s,1)) for s in layer_sizes[1:]] 9 | 10 | def predict(self, a): 11 | for w,b in zip(self.weights,self.biases): 12 | a = self.activation(np.matmul(w,a) + b) 13 | return a 14 | 15 | @staticmethod 16 | def activation(x): 17 | return 1/(1+np.exp(-x)) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Sebastian 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------