feat: ✨ Finish IA part
This commit is contained in:
parent
aa45331010
commit
4b2ab03dab
1
main.tex
1
main.tex
@ -6,6 +6,7 @@
|
||||
\usepackage{fancyhdr}
|
||||
\usepackage[table,xcdraw]{xcolor}
|
||||
\usepackage{float}
|
||||
\usepackage{fancyvrb}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
This section covers our research on artificial intelligence to develop an AI component for the project, particularly for the OCR.
|
||||
|
||||
Our first draft of the AI has not been integrated into the main project\footnote{You can find the project here: https://gitea.louisgallet.fr/lgallet/XOR-NeuralNetwork-C} because it is focused on our research on AI rather than the project itself.
|
||||
|
||||
Below, you will find the research we conducted for the AI.
|
||||
|
||||
|
||||
\subsubsection{Structure of a neuron}
|
||||
\input{sections/partie-technique/IA/structure-neuronne/structure-neuronne}
|
||||
|
||||
\subsubsection{Activation functions}
|
||||
\input{sections/partie-technique/IA/fonction-activation/fonction-activation}
|
||||
|
||||
\subsubsection{Weight initialization}
|
||||
\input{sections/partie-technique/IA/initialisation/initialisation}
|
||||
|
||||
\subsubsection{Feedforward and Backpropagation}
|
||||
\input{sections/partie-technique/IA/feedforward-backpropagation/feedfoward-backpropagation}
|
||||
|
||||
\subsubsection{Training}
|
||||
\input{sections/partie-technique/IA/entrainement/entrainement}
|
11
sections/partie-technique/IA/entrainement/entrainement.tex
Normal file
11
sections/partie-technique/IA/entrainement/entrainement.tex
Normal file
@ -0,0 +1,11 @@
|
||||
The network training uses a learning loop that iterates through the defined epochs (for example, \texttt{numEpochs = 1000000}). Each epoch begins by randomly shuffling the order of the training sets using the \texttt{shuffle} function:
|
||||
\begin{verbatim}
|
||||
shuffle(trainingSetOrder, NUM_TRAINING_SETS);
|
||||
\end{verbatim}
|
||||
For each training example, the network performs a forward pass, then applies backpropagation to adjust weights and biases based on the error. Once training is complete, the final weights can be saved to a file using the \texttt{backup\_weights} function.
|
||||
|
||||
The output results are displayed at each training step, allowing visualization of the final values of weights and biases.
|
||||
\begin{figure}[H]
|
||||
\caption{Example output of the training of the XOR neural network.}
|
||||
\includegraphics[scale=0.5]{sections/partie-technique/IA/entrainement/ia-train-demo.png}
|
||||
\end{figure}
|
BIN
sections/partie-technique/IA/entrainement/ia-train-demo.png
Normal file
BIN
sections/partie-technique/IA/entrainement/ia-train-demo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 84 KiB |
@ -0,0 +1,18 @@
|
||||
The network uses a \textit{feedforward} process to compute the activations of the hidden and output layers. Each neuron in the hidden layer applies the sigmoid activation function to the weighted sum of the inputs:
|
||||
\begin{verbatim}
|
||||
for (int j = 0; j < NUM_HIDDEN; j++) {
|
||||
double activation = hiddenLayerBias[j];
|
||||
for (int k = 0; k < NUM_INPUTS; k++) {
|
||||
activation += trainingInputs[i][k] * hiddenWeights[k][j];
|
||||
}
|
||||
hiddenLayer[j] = sigmoid(activation);
|
||||
}
|
||||
\end{verbatim}
|
||||
The same logic is applied in the output layer, using the activations of the hidden layer as inputs.
|
||||
|
||||
Backpropagation adjusts the weights based on the calculated errors. First, the output error is calculated relative to the expected output and the derivative of the sigmoid function:
|
||||
\begin{verbatim}
|
||||
double error = (trainingOutputs[i][j] - outputLayer[j]);
|
||||
deltaOutput[j] = error * sigmoid_derivative(outputLayer[j]);
|
||||
\end{verbatim}
|
||||
The error for each hidden neuron is then calculated based on the errors of the connected output neurons. The weights and biases are adjusted proportionally to the error and the learning rate \texttt{lr}.
|
@ -0,0 +1,15 @@
|
||||
The activation function used for each neuron in the hidden and output layers is the \textit{sigmoid}, defined by the \texttt{sigmoid} function:
|
||||
\begin{verbatim}
|
||||
double sigmoid(double x) {
|
||||
if (x > 20) return 1.0;
|
||||
if (x < -20) return 0.0;
|
||||
double z = exp(-x);
|
||||
return 1.0 / (1.0 + z);
|
||||
}
|
||||
\end{verbatim}
|
||||
This function is bounded between 0 and 1, allowing for normalization of the activation values for each neuron. The derivative of the sigmoid, \texttt{sigmoid\_derivative}, is used in backpropagation to compute gradients:
|
||||
\begin{verbatim}
|
||||
double sigmoid_derivative(double x) {
|
||||
return x * (1.0 - x);
|
||||
}
|
||||
\end{verbatim}
|
@ -0,0 +1,6 @@
|
||||
The network's weights and biases are initialized randomly using the \texttt{init\_weights} function, which returns a value between 0 and 1. This process is applied to all weights in \texttt{hiddenWeights} and \texttt{outputWeights}, as well as to the biases \texttt{hiddenLayerBias} and \texttt{outputLayerBias}:
|
||||
\begin{verbatim}
|
||||
double init_weights() {
|
||||
return ((double) rand()) / ((double) RAND_MAX);
|
||||
}
|
||||
\end{verbatim}
|
@ -0,0 +1 @@
|
||||
The structure of this neural network consists of an input layer, a hidden layer, and an output layer. The network is configured to solve the XOR problem, with binary input values and a binary output. The hidden layer, represented by the array \texttt{hiddenLayer}, is connected to the inputs through weights \texttt{hiddenWeights}, while the output layer, \texttt{outputLayer}, is connected to the hidden layer via the weights \texttt{outputWeights}. The biases for each layer are initialized in \texttt{hiddenLayerBias} and \texttt{outputLayerBias}.
|
@ -5,7 +5,7 @@ This section aims to explain each part of the project from a technical perspecti
|
||||
|
||||
\subsection{OCR}
|
||||
\input{sections/partie-technique/OCR/ocr.tex}
|
||||
|
||||
\newpage
|
||||
|
||||
\subsection{Artificial Intelligence}
|
||||
\input{sections/partie-technique/IA/IA.tex}
|
||||
|
Loading…
x
Reference in New Issue
Block a user