## 2 Materials and Methods
### Proposed Feature Selection Method  
The proposed Algorithm 1 is based on the combination of the modified weight-based feature selection of MLP (MLPW) coupled with a refinement pass for accurate feature rank generation, and an exhaustive search. The proposed algorithm aims to select two sets of feature spectra. These sets can then be utilized to create an aflatoxin B1 classification system for industrial quality control and in-line applications. The algorithm can be divided into three main parts, MLP weight-based spectral rank generation, spectral refinement, and exhaustive search-based spectral set selection. At first, MLPW was used, focusing on the spectral confidence matrix and voting-based spectral rank position to select the topmost important spectra among the generated rankings. Therefore, a new confidence matrix (\(C_{\mu}\)) and confidence position matrix (\(C_{p}\)) were established, which were used to rank spectra and update the rank. The proposed algorithm iteratively removed the least important spectra and generated an important ranked matrix. In weight-based spectral band selection, randomly initializing weights may result in a misleading spectral rank matrix [33]. Therefore, we developed a spectral refinement approach that identifies relatively important spectral bands among the removed ones and adds them to the important spectra list. In the final phase, the most significant spectra \(T_{e}\) were selected to create small spectra sets for in-line aflatoxin B1 detection. An exhaustive feature selection approach was implemented in this phase, combined with an SVM performance evaluation algorithm to assess and refine the selected features. The dataset \(\Phi_{n}\) is the collection of the hyperspectral responses of aflatoxin B1-contaminated and non-contaminated almonds of 224 spectra. The first and last several spectra of the SWIR hyperspectral image contain some noise to ramp up and down the imaging sensor [34]. Therefore, these feature spectra were not considered in the band selection process. The spectral data were normalized and partitioned for training, testing, and validation before being fed into the MLP classifier. The dataset was then trained, tested, and validated for '\(n\)' times of the same MLP network with two hidden layers. To avoid the possible biases of feature position among the spectral dataset, feature spectra were randomized for the MLP model. This process increases the diversity of spectral data and increases the reliability of the output model's weight. In the MLP classifier, a feature spectra selection layer was added between the input layer and the hidden layer, which is identical to the input layer. Multiple MLP classifiers were trained, tested, and validated using different learning parameters (\(\eta\) = 0.0001 to 0.1) to find an optimal learning rate, which was incorporated into the final models. In this experiment, a learning rate of 0.001 was used. The LeakyReLU activation function was applied in the feature spectra selection and hidden layers, while the SoftMax function was used in the output layer. In the first hidden layer, 256 nodes were utilized, while in the second layer, 128 nodes were employed, resulting in improved classification accuracy. To overcome the overfitting problem in the MLP models, L2 regularization was used to achieve optimal classification results [35]. The network was trained separately with a small number of randomized initial weights (\(\pm\)0.5) and bias value and backpropagation algorithms were used to update the weight in each node. The trained network provided an optimal weight matrix \(\psi\) for higher cross-validation accuracy, such that \(\psi\epsilon\mathbb{R}\). This matrix is normalized and creates a normalized vector \(\mu_{i}\) for each MLP model. The \(\mu_{i}\) matrix was used to create a spectral importance position matrix. The highest normalized weight archiving spectrum was the most important and obtained position 1, the second highest weight-containing spectra were position 2, and so on.