https://github.com/marcos-venicius/ml-hello-world
A hello world in Machine learning with a small ML framework with methods like "mat_dot", "mat_sum", "mat_alloc", ...
https://github.com/marcos-venicius/ml-hello-world
deep-learning framework ia machine-learning
Last synced: about 1 year ago
JSON representation
A hello world in Machine learning with a small ML framework with methods like "mat_dot", "mat_sum", "mat_alloc", ...
- Host: GitHub
- URL: https://github.com/marcos-venicius/ml-hello-world
- Owner: marcos-venicius
- License: mit
- Created: 2023-12-07T20:30:43.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-11T11:34:16.000Z (over 2 years ago)
- Last Synced: 2025-03-26T00:51:23.585Z (over 1 year ago)
- Topics: deep-learning, framework, ia, machine-learning
- Language: C
- Homepage:
- Size: 25.4 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ML hello world
**Notice this code is only to educational purposes, do not use it to any type of production ready application**
## Explanation
```math
a_1 = x_1 \cdot w_{11} + x_2 \cdot w_{12} + b_1
```
```math
a_2 = x_1 \cdot w_{21} + x_2 \cdot w_{22} + b_2
```
The activation from the first layer:
```math
\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:
```math
\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`:
```shell
gcc main.c -lm -o main && ./main
```
Output demonstration:

Running `deep-learning.c`:
```shell
gcc deep-learning.c -lm -o deep-learning && ./deep-learning
```
Output demonstration:

Running `dynamic-deep-learning.c`:
```shell
gcc dynamic-deep-learning.c -lm -o dynamic-deep-learning && ./dynamic-deep-learning
```
Output demonstration:
