From ce21e13b379e1325c98009a25d622277fbca3108 Mon Sep 17 00:00:00 2001 From: Gerardo Marx Date: Thu, 16 May 2024 19:02:56 -0600 Subject: [PATCH] Adding the information for repo --- Readme.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/Readme.md b/Readme.md index 5673899..cbfa5f8 100644 --- a/Readme.md +++ b/Readme.md @@ -1,4 +1,23 @@ +# Introduction + +The present session will introduce the Python classes and how to create your own Artificial Neural Network (ANN) class. The class will implement the `__init__`, `feedforward`, and `backpropagation` methods. + +Each method will be described in detail to understand the ANN’s inner work. Then, the handwriting MNIST dataset will be used to train and test our ANN. + +# Objectives + +- Learn the basics of using Python Classes +- Create methods for: create, feedforward, and backpropagation +- Train the ANN +- Test the ANN + # Classes and methods +A class defines the structure, data and methods that an object will have. There is possible to have public and private variables to operate in the methods. + +- Argument +- Initialitation +- Methods +- Destroy ```python @@ -37,6 +56,8 @@ dog3.status() # ANN class implementation +The next chunk of code defines the Neural Network's basic structure. We are going to implement and define the methods one at time to understand them in a better way. + ```python class Neurona: @@ -51,7 +72,13 @@ class Neurona: pass ``` +## Initialization or creation Method + +Let’s begin with the initialization. We know we need to set the number of input, hidden and output layer nodes. That defines the shape and size of the neural network. Thus, we’ll let them be set when a new neural network object is created by using the class' parameters. That way we retain the choice to create new neural networks of different sizes with simple methods. +A good programmers, computer scientists and mathematicians, try to create more general code rather than specific code. It is a good habit, because it forces us to think about solving problems in a deeper and more general way. This means that our code can be used in more general scenarios. + +Then, let us see how our code should look like: ```python import numpy as np @@ -75,22 +102,37 @@ class Neurona: pass ``` +At this point were are only creating an object, but the class can't do any useful yet. Also, this is a good technique to start coding somethig, by keeping it small at the begining (make commits), and then grow the methods. +Next, we should add more code to allow our ANN class finish its initialization by creating the weight matrixes. -```python -inputs = np.array([0.21,0.39, 0.87],ndmin=2).T -inputs -``` + +## Feedfordward method + +So the next step is to create the network of nodes and links. The most important part of the network is the link weights. They’re used to calculate the signal being fed forward, the error as it’s propagated backwards, and it is the link weights themselves that are refined in an attempt to to improve the network. + +For the basic NN, the weight matrix consist of: + +- A matrix that links the input and hidden layers, $Wih$, of size hidden nodes by input nodes ($hn×in$) +- and another matrix for the links between the hidden and output layers, $Who$, of size $on×hn$ (output nodes by hidden nodes) + +$$X_h=W_{ih}I$$ +$$O_h=\sigma{X_h}$$ +So the next step is to create the network of nodes and links. The most important part of the network is the link weights. They’re used to calculate the signal being fed forward, the error as it’s propagated backwards, and it is the link weights themselves that are refined in an attempt to to improve the network. +For the basic NN, the weight matrix consist of: - array([[0.21], - [0.39], - [0.87]]) +- A matrix that links the input and hidden layers, $Wih$, of size hidden nodes by input nodes ($hn×in$) +- and another matrix for the links between the hidden and output layers, $Who$, of size $on×hn$ (output nodes by hidden nodes) +$$X_h=W_{ih}I$$ +$$O_h=\sigma{X_h}$$ +## Backpropagation +$$ \frac{\partial E}{\partial w*{jk}}= -e_j\cdot \sigma\left(\sum_i w*{ij} o*i\right) \left(1-\sigma\left(\sum_i w*{ij} o_i\right) \right) o_i $$ ```python import numpy as np