Metadata-Version: 2.5
Name: nn_simulator
Version: 0.1.0
Summary: Basic Neural Network simulation for the machine learning course final project
License-File: LICENSE
Requires-Dist: numpy
Description-Content-Type: text/markdown

# TODO
## Main library:
- [ ] Reflect on the possibility of switching error/loss
    calc for classification tasks
- [ ] Implement external stopping criteria (Early stopping)
    and the use of a VL set during training
- [ ] Fix comments english (plurals and such)
## Meta library:
- [ ] Introduce a meta library that uses the main library to:
    - Manage VL set
    - Easely create plots
    - Perform encoding

# Computing the NN
The key idea to achive a simple and efficient code is to use matrix computation (highly optimized in NumPy).

## Forward pass
We should look at the NN as multiple layers interconnected:
- $\vec{x}$ is the input vector for the previous layer
- $W$ is the weight matrix of the layer, e.g.:
    if we have $\dim (\vec{x}) = 3$ and the layer is composed of 4 units, we got:
    $\begin{pmatrix}
    w_{1,1} & w_{2,1} & w_{3,1} & w_{4,1}\\
    w_{1,2} & w_{2,2} & w_{3,2} & w_{4,2}\\
    w_{1,3} & w_{2,3} & w_{3,3} & w_{4,3}\\
    \end{pmatrix}$
- Thus we can easely computed the net of all the units in a layer trough:
    $O=x\cdot W + b$
    $(1\times n)\cdot(n\times m)=1 \times m$
    where $b$ is the bias of a particular unit.
    In NumPy:
    ```code
    x = np.array([2, 3, 1], dtype=np.float32)
    W = np.array([
        [0.5,  1.0],
        [-1.0, 0.25],
        [2.0, -0.5],
    ], dtype=np.float32)
    b = np.array([0.5, -1.0], dtype=np.float32)

    z = x @ W + b
    ```
- We can now compute the output of the entire layer applying the activation function to the previously computed net:
    $A=f_{act}(O)$
- Now we can do the same for the next layer:
    $O'=A \cdot W' + b'$
    $A'=f_{act}'(O')$
    and so on.

Using matricial computing allows us to directly propagate for batch of data. Let $l$ be the number of examples, now we don't have a simple input vector $\vec x$ $(1 \times n)$ but a matrix $X$ $(l \times n)$. The huge advantage is being able to keep the computation phase same as before:
$O=X \cdot W + b$
```code
O = X @ W + b
```

Could be wise to always add a fixed input to each node equal to one, so that the bias can be absorbed in the weight matrix, simplyfing all the formulas.

## Back-propagation
To the best of my understanding we NEED to kwon what kind of activation function we want to use to correctly perform the back-propagation (no general way to perform the back-prop for any activation function).

# Implementation
Once the library is coded we could use it trough a jupyter notebook with examples and benchmarks instead of a generic _main.py_ script. This approach could also facilitate the project final report and the presentation.

Important to use the correct numpy arreys

To implement:
- Neural network architecture
- Forwarding
- Back-prop
- Training
- Data-set management

Decide how to manage the data sets (maybe sci-kit learn?)

**Key rules** (to not go completly nuts):
- always comment the code!
- keep the project structured
- try to keep script files separated and short
- use tests

## Structure
A NN is a class with certain parameters (like the architecture) and it initializes the different layer matrices, that represent the whole network connections. We should have methods to performer the forwarding and backpropagation, should those methods belogn to the NN class or to a separate Layer class (this class could store valuable info of the layer, like gradient info for the back-prop).