Skip to content

marcos-venicius/ML-hello-world

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ML hello world

Notice this code is only to educational purposes, do not use it to any type of production ready application

Explanation

$$a_1 = x_1 \cdot w_{11} + x_2 \cdot w_{12} + b_1$$ $$a_2 = x_1 \cdot w_{21} + x_2 \cdot w_{22} + b_2$$

The activation from the first layer:

$$\sigma \begin{pmatrix} \begin{bmatrix} x_{11} & x_{12} \end{bmatrix} \cdot \begin{bmatrix} w_{11} & w_{12} \\\ w_{21} & w_{22} \end{bmatrix} + \begin{bmatrix} b_{11} & b_{12} \end{bmatrix} \end{pmatrix} = \begin{bmatrix} a_{11} & a_{12} \end{bmatrix}$$

The activation to the second layer:

$$\sigma \begin{pmatrix} \begin{bmatrix} a_{11} & a_{12} \end{bmatrix} \cdot \begin{bmatrix} w_{11} \\\ w_{12} \end{bmatrix} + \begin{bmatrix} b_{11} \end{bmatrix} \end{pmatrix} = y$$

we can only multiply matrices if the number of columns of the first matrix is equal to the number of rows of the second matrix.

The main.c file has a basic ML algorithm that can learn OR, AND and NAND operations.

This algorithms is not capable to learn XOR because XOR cannot be linearly separated.

So, to do this job, we need more neurons.

So, the deep-learning.c file has a "more complex" ML algorithm with 3 neurons and 9 parameters that can handle OR, AND, NAND and XOR.

We also have the dynamic-deep-learning.c, that is a "improved" neural network that you can change the number of neurons dynamically by changing NUMBER_OF_NEURONS.

Another improvement is that in dynamic-deep-learning.c we don't need to forward the neural network mannualy, we do this by iteration over the network.

How to run?

Running main.c:

gcc main.c -lm -o main && ./main

Output demonstration:

image

Running deep-learning.c:

gcc deep-learning.c -lm -o deep-learning && ./deep-learning

Output demonstration:

image

Running dynamic-deep-learning.c:

gcc dynamic-deep-learning.c -lm -o dynamic-deep-learning && ./dynamic-deep-learning

Output demonstration:

image

About

A hello world in Machine learning with a small ML framework with methods like "mat_dot", "mat_sum", "mat_alloc", ...

Topics

Resources

License

Stars

Watchers

Forks

Languages