# THz Data Analysis and Self-Organizing Map (SOM) for the Quality Assessment of Hazelnuts
## 4 Results
### Neural Networks Methods  
Using MATLAB software (R2023a) it was possible to classify the data set consisting of 212 hazelnuts by means of a SOM (self-organizing map). The use of an unsupervised neural network has been investigated for sorting hazelnuts. Such a neural network consists  
Figure 5: Each point represents the mean transmission value for each sample (\(x\)-axis). In blue and green are two possible thresholds to distinguish between samples with (lower values) or without defects (upper values) as emerged from the analysis of samples with the same shape and dimensions. of two layers of neurons, the input layer and the output layer. Specifically, our input is given by the nine transmission values, corresponding to the nine frequencies acquired for each hazelnut. A simplified image of the learning process is below (see Figure 6). Once the nine transmission values for each hazelnut have been acquired, they were used to feed the input layer (see Figure 6). Whereas in nature, communication between neurons takes place via synapses, in a neural network, this takes place via the so-called input weights of neurons. Looking closely at Figure 6, it is clear how each input neuron is connected to each output neuron via these weight vectors. The weight vectors in this case are a numerical value associated with a specific connection among neurons, representing the strength (importance) of that connection. In our case, the learning algorithm for the selection of hazelnuts through the creation of clusters follows three processes: a competitive process, a cooperative process and an adaptation process. In the competitive process, the neurons present in the output layer compete with each other to occupy specific areas of the map by configuring clusters in the best possible way. To do this, the nine transmission values associated with each hazelnut sample presented to the network are compared with the weight vector of each neuron present in the output. The output neuron that has the \"comparable\" weight vector to the input sample will be declared the winner of the competition (best matching unit, BMU). One of the most frequently used functions to determine the winning neuron is the Euclidean distance, as shown in the following formula:  
\[\mathrm{d_{i}(t)}=||\mathrm{x(t)}-\mathrm{w_{i}(t)}||=\sqrt{\sum_{j=1}^{m}{(x _{ij}-w_{ij})^{2}}}\,\mathrm{i}=1,2,3\ \ldots\mathrm{n} \tag{1}\]  
where (x) represents the input data, and (w\({}_{i}\)) represents the weight vectors at iteration (t). Once the Euclidean distance between the input neurons and all the weight vectors of the output neurons has been calculated, the winning neuron is the one with the lowest value:  
\[\mathrm{c(t)}=\mathrm{arg\ min}\{\,|\ |\ \mathrm{x(t)}-\mathrm{w_{i}}\,(t) \,|\ |\ \} \tag{2}\]  
During the cooperative process, the winning neuron can determine the spatial position within the output space; neighboring neurons can be influenced by the winning neuron. Finally, in the adaptation process, the winning neuron and its neighbors in the output space can update the weight vectors through the so-called weight adjustment process to emulate the characteristics of the input space. This process is repeated each time a new stimulus, and thus a new hazelnut, is presented to the network, resulting in a change in the weight vectors. The following formula is used to adjust the weights at each iteration:  
\[\mathrm{w_{i}}\ (t+1)=\mathrm{w_{i}}\ (t)+\alpha(t)[\mathrm{x(t)}-\mathrm{w_{i} (t)}] \tag{3}\]  
Figure 6: Learning scheme of an unsupervised neural network. where \(w_{i}(t)\) is the weight vector of the winning neuron at iteration \(t\), while \(w_{i}\) (\(t+1\)) is the updated weight vector at the next iteration (\(t+1\)), and finally, \(\alpha(t)\) is the learning rate. This last parameter controls the rate of change in the weight vectors (takes values between 0 and 1) and gradually decreases with increasing epochs or iterations (t). For this first test, a 2-by-2 grid with a number of neurons equal to four was used.