diff --git a/main.pdf b/main.pdf index f524983..f9a69c3 100644 --- a/main.pdf +++ b/main.pdf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c91e75fe3e64df1791590c85ff2b86be6c4d243b5d585812139e281256a66fb0 -size 169083 +oid sha256:eb04400082bb7bbbe8ccd7954160ef474549a3ce667023747548d9fb184fd603 +size 291930 diff --git a/main.tex b/main.tex index 06b6527..81f4261 100644 --- a/main.tex +++ b/main.tex @@ -6,6 +6,7 @@ \usepackage{fancyhdr} \usepackage[table,xcdraw]{xcolor} \usepackage{float} +\usepackage{fancyvrb} diff --git a/sections/partie-technique/IA/IA.tex b/sections/partie-technique/IA/IA.tex index e69de29..7a2a993 100644 --- a/sections/partie-technique/IA/IA.tex +++ b/sections/partie-technique/IA/IA.tex @@ -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} diff --git a/sections/partie-technique/IA/entrainement/entrainement.tex b/sections/partie-technique/IA/entrainement/entrainement.tex new file mode 100644 index 0000000..4663401 --- /dev/null +++ b/sections/partie-technique/IA/entrainement/entrainement.tex @@ -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} diff --git a/sections/partie-technique/IA/entrainement/ia-train-demo.png b/sections/partie-technique/IA/entrainement/ia-train-demo.png new file mode 100644 index 0000000..a82f1e8 Binary files /dev/null and b/sections/partie-technique/IA/entrainement/ia-train-demo.png differ diff --git a/sections/partie-technique/IA/feedforward-backpropagation/feedfoward-backpropagation.tex b/sections/partie-technique/IA/feedforward-backpropagation/feedfoward-backpropagation.tex new file mode 100644 index 0000000..f6575af --- /dev/null +++ b/sections/partie-technique/IA/feedforward-backpropagation/feedfoward-backpropagation.tex @@ -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}. diff --git a/sections/partie-technique/IA/fonction-activation/fonction-activation.tex b/sections/partie-technique/IA/fonction-activation/fonction-activation.tex new file mode 100644 index 0000000..94b3a28 --- /dev/null +++ b/sections/partie-technique/IA/fonction-activation/fonction-activation.tex @@ -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} diff --git a/sections/partie-technique/IA/initialisation/initialisation.tex b/sections/partie-technique/IA/initialisation/initialisation.tex new file mode 100644 index 0000000..9e14e29 --- /dev/null +++ b/sections/partie-technique/IA/initialisation/initialisation.tex @@ -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} diff --git a/sections/partie-technique/IA/structure-neuronne/structure-neuronne.tex b/sections/partie-technique/IA/structure-neuronne/structure-neuronne.tex new file mode 100644 index 0000000..6a68657 --- /dev/null +++ b/sections/partie-technique/IA/structure-neuronne/structure-neuronne.tex @@ -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}. diff --git a/sections/partie-technique/partie-technique.tex b/sections/partie-technique/partie-technique.tex index 3fa054f..b69dda5 100644 --- a/sections/partie-technique/partie-technique.tex +++ b/sections/partie-technique/partie-technique.tex @@ -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}