Theory ====== The "Geophysical Domain Mapper" algorithm uses a "Convolutional Neural Network" (CNN) to classify geophysical data into different domains. This chapter aims to illustrate the concepts behind this technology. Machine Learning ~~~~~~~~~~~~~~~~ Deep Learning is a subset of "Machine Learning." Machine learning algorithms are statistical models that can "self-adjust" their parameters (known as **"weights"**) during a training phase. These parameters define the transformation of input values into output. During the training phase, the algorithm uses training data with known outputs to adjust these parameters, minimizing the error between the predicted and known outputs. :numref:`figure_machine_learning` presents the relationship between input, training output, and prediction. In this figure, training points of two classes are shown in a 2D space with the classes represented by different colors (red and blue). The prediction of the algorithm is presented as the background, with color intensity from red to blue representing the probability of a point belonging to one class or the other. As illustrated in the figure, the algorithm creates a "map" of the input space using its parameters, where every location in the input space is associated with a probability of belonging to one class or another. This map is defined by the algorithm during the training using the training points. .. _figure_machine_learning: .. figure:: ../../images/theory/machine_learning.png :align: center :scale: 60% *Mapping of the input space by a machine learning algorithm.* Deep-Learning ~~~~~~~~~~~~~ Deep Learning is a subset of machine learning algorithm. The difference between them is that deep learning algorithms learn to project the data into a new representation, a latent space, where they can perform their "mapping." This concept is illustrated in :numref:`figure_deep_learning`. The data, represented as points in a 2D space, are difficult to map into the categories to retrieve. Therefore, the algorithm projects these points into a new space where the mapping is easier to achieve. .. _figure_deep_learning: .. figure:: ../../images/theory/deep_learning.png :align: center :scale: 100% *Data re-projected in a latent space by a deep learning algorithm.* This new representation can be considered a latent space, where the input data are projected as points in an n-dimensional space. This representation encapsulates the information contained in the input. The nature of the input can be anything, such as images, sounds, or text, and deep learning algorithm can learn to transform these data into a latent space, where decisions are easier to make. However, such transformations are computationally expensive, involving thousands (millions) of operations. This complexity necessitates extensive training, requiring a large amount of data to adjust the model parameters effectively. Additionally, due to the numerous parameters and the significant data requirements, the training phase can be very long and computationally intensive. Convolutional Neural Networks ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Convolutional Neural Networks (CNNs) are a type of deep learning algorithm specialized in processing grid-like data, such as images. The main concept behind CNNs is the convolution operation. This mathematical operation is applied to the input data to extract features. This process is illustrated in :numref:`convolution`. As the figure shows, a convolution applies a filter locally to the input data. It multiplies the values of the filter with the local values of the input data and sums the results. This operation is applied to the entire input data, resulting in a new representation of the input data. .. _convolution: .. figure:: ../../images/theory/convolutions.gif :align: center :scale: 80% *Convolutional filter applied to an image.* A Convolutional Neural Network (CNN), as illustrated in :numref:`figure_cnn`, is a stack of convolutional layers. Each layer contains several convolutional filters that extract features from the input data. The second layer extracts features from the transformations made by the first layer, thus capturing more complex features. These transformations aim to convert the image into a new representation that the network will use to predict the output. .. _figure_cnn: .. figure:: ../../images/theory/convolutional_nn_illustrated.gif :align: center :scale: 100% *Convolutional neural network transforming images with stacked convolutional layers.* This structure of convolutional filters allows the network to consider not just the individual pixel values, but also the values of neighboring pixels. This is a key concept in image processing, as the information in an image lies not only in the pixel values but also in the relationships between pixels. Training a Model ^^^^^^^^^^^^^^^^ For a convolutional neural network to perform effectively, the values of the convolutional filters must be determined to extract the pertinent features from the data, thereby uncovering the information embedded in the images. This is achieved through training the model. The training phase is illustrated in :numref:`training`. During training, images are passed through the network, and a result is obtained. This result is compared to the known output, and a score, or "loss", is computed. This loss measures the error between the predicted output and the known output. The goal of the training is to minimize this loss by adjusting the values of the convolutional filters after each pass. .. _training: .. figure:: ../../images/theory/training_nn.gif :align: center :scale: 60% *Training a model by adjusting its weights to minimize the loss function.* Once the loss stops decreasing, the model is considered trained and can be used to predict the output of new data. However, the model should be tested on data that was not used during the training phase to ensure that it can generalize well to new data. Inference ^^^^^^^^^ Once a model is trained, a new input can be passed to it, and it will predict an output. However, as presented in :numref:`point_inference`, the output feature values should be within the range of values used during training. If the model tries to predict data that is too different from the training data, it will not be able to predict the output correctly. .. _point_inference: .. figure:: ../../images/theory/inference_principle.png :align: center :scale: 90% *Inference of a trained model on new data.* This limitation must be addressed during training, where a maximum variety of data should be included. Additionally, the scope of a trained model must be well defined to avoid using it on data that is too different from the data used during the training.