1 Introduction

Coconut is a wonderfully versatile raw material. Coconut can be classified as a fruit (nut or seed), but it is also a type of berry. Coconut is a raw material used in sweet and salty cooking. The natural habitats of coconut include islands, coastal areas, and humid tropical regions with relatively large rainfall. Coconut palms are cultivated in more than ninety countries and zones worldwide, with a total production of more than 59 million tons in 2021 [1,2,3].

Coconut is a very beneficial fruit that is used in a wide range of products. Most production of coconut is in tropical areas of Asia (Indonesia, the Philippines, and India), accounting for more than 72% of the overall production. Mexico is ranked eighth in coconut production of 0.25M Tons in 2023 [4], with a production area of 190,000 ha [5]. Currently, global coconut products account for a share of more than US$20.24 billion in 2022. There is anticipated to be an increase in the compound annual growth rate (CAGR) of 8.4 percent between 2023 and 2030 [6]. Tropical coconuts are not native to Egypt due to the limited rainfall there. There are, however, some giant coconut palms on Kitchener’s Island in Aswan, where the British planted exotic and non-native flora [7, 8]. Further investigations of coconut cultivation in Egypt are needed. Coconut water is the liquid found in the center of a young, green coconut. It helps nourish the fruit. As the coconut matures, which takes around 10–12 months, some liquid remains while the rest ripens into the solid white flesh known as coconut meat. [9].

The coconut kernel has an edible skin, and coconut water is delicious and used to rehydrate the human body after exercise due to its high content of sugar and minerals. Additionally, the coconut husk has strong fibers. The coconut (Cocos nucifera L.) fruit can be processed for use in a variety of beverages and foods, such as coconut milk, which is derived from the solid endosperm, coconut water, which is from the aqueous part of the coconut endosperm, and the “meat” of the coconut which is from trimmed young coconuts [10]. The liquid endosperm (coconut water) in the coconut kernel cavity of coconut fruit is a highly valued beverage used as a natural source of carbohydrates and suitable for rehydration after physical activity [11].

Coconut water is a fragile liquid found in the center of a young, green coconut and rapidly deteriorates [12, 13]; consequently, assessing its quality during storage and processing remains a challenge [14]. According to the coconut maturity, the coconut water volume and nutrients vary. Each beverage is produced considering the specific characteristics of coconut water. There are determinant factors for coconut water selection. For example, minerals and sugars are varied and affected by the development stage of coconuts, soil characteristics, and farming practices [15]. The water of very mature coconuts has higher concentrations of magnesium and potassium than the water of very tender coconuts, but the calcium concentration dramatically decreases with age [16]. The coconut water volume also varies with coconut age; for example, the volume increases at ages of 7 to 9 months old and then declines before being converted to jelly [16]. Depending on the maturity stage of the coconut, the uses of coconut water can vary as follows: (1) Young coconut water, known for its high electrolyte content, is a popular drink for athletes and people who are dehydrated. It possesses anti-inflammatory and anti-bacterial properties. According to [17], young coconut water can have a strong anti-inflammatory effect. In contrast, mature coconut water may have a more moderate anti-inflammatory effect. It can be applied topically to alleviate skin irritations, (2) Mature coconut water is less sweet than young coconut water but is still rich in nutrients. According to [18, 19], the maturity stage influences sugar levels. As maturity increased, the sucrose content increased, while fructose and glucose levels decreased. It is a popular ingredient in smoothies, juices, and other beverages. It is also known to have antioxidant properties, making it a popular drink for people looking to improve their skin health and (3) Overripe coconut water is found in coconuts that have started to spoil. Although overripe coconut water is unsuitable for drinking, it can be used in cooking. It is often used as a natural flavoring in curries, stews, and other dishes. It can also be used as a natural tenderizer for meat. Separating the coconut water extracted from very mature fruits from that of very young fruits is essential. This process is useful for utilizing all the water extracted from the fruits, whether for nutrition or later sale to pharmaceutical companies. Therefore, it is necessary to grade and classify types of coconut water according to their intended use. Coconut fruit classification is insignificant because the extraction process is needed for all coconut fruits and be punched as one batch.

There are many challenges to sorting coconut water. [20] characterized the volatile compounds/profiles of five different tender varieties of coconut water for further discrimination using the headspace solid-phase microextraction technique. The dissolved oxygen concentration of natural coconut water varies according to the coconut maturity stage; at the 7-month growth stage, the dissolved oxygen content of coconut water increases from 6 to 9 \({{\rm mg}}\,{{\rm l}}^{-1}\) after 3 h of extraction and remains constant for 4 h. After 10 h, the content declines to zero. In contrast, the coconut water of 9-month-old coconuts has a maximum dissolved oxygen concentration of 6 \({{\rm mg}}\,{{\rm l}}^{-1}\), which in different experiments decreased to zero after 7 h [20] and stayed constant for 4 h before dropping to zero after 10 h.

In the past ten years, artificial intelligence has been increasingly applied to solve multiple problems associated with coconut cultivation. Notable developments in expert systems and machine learning [21] have prompted new discoveries and led to solutions for many problems in coconut cultivation and production [22]. ANN [23] relies on intelligent mathematical models and parameterless features, and these networks are biological nervous system-inspired. In the past thirty years, the ANN has been widely implemented in regression, forecasting, classification, and pattern recognition problems [24, 25]. The proficiency of an ANN is deeply affected by the number and effectiveness of the corresponding learning stages [26]. Multilayer perceptron (MLP) neural networks are the most commonly used and implemented ANNs [27]. The appropriate supervised training methods can be classified into two main categories: stochastic processes and gradient-based methods [28]. The back-propagation algorithm and its variants are examples of gradient-based methods, and researchers commonly use them. However, gradient-based methods are associated with three main problems: slow convergence, initial parameter dependency, and local minima [29, 30].

Swarm Intelligence (SI)-based algorithms have been utilized in many applications due to their robustness to initial requirements, global search efficiency, and accuracy. The main objective of SI algorithms is to improve the performance of computations that can assist in solving complex optimization problems with other techniques, such as FNN. SWO, one of the most powerful SI algorithms, has not been fully investigated for selecting optimal weights for fuzzy bases [31, 32].

[33] exploited the Harris Hawks optimizer with a recurrent gated unit to discover various infections in coconut trees. The empirical investigation was conducted on the suggested model, and the results demonstrated the adequate performance of the presented model over recent approaches. [34] reported sixteen texture and color attributes for 1265 damaged images of coconut pests by extracting the texture and color attributes of the damaged images in the grey and color domain after damage segmentation utilizing a thresholding approach. They implemented the gray level run length matrix and the gray level co-occurrence matrix to discover the texture attributes of the damages, and they reported two ANN models to categorize the extracted data attributes of the damages into five various classes. The experimental results showed that ANN and SVM outperformed the others in all performance measures, and their proposed model can be used as a baseline model for additional studies to determine coconut pest damage using deep learning methods. [35] utilized seven CNN structures (VGG19, VGG16, MobileNet, Xception, InceptionResNetV2, InceptionV3, and ResNet50) to identify two main maturity stages of the coconut (mature and tender). Recognizing the maturity level of the coconut plants is difficult because of the external lighting with challenging background conditions. Their empirical outcomes showed that the ResNet50 method effectively identified two main stages of coconut maturity with an accuracy of 98.32%. [36] utilized YOLOv5 approach to identify the on-tree mature coconut fruits With an accuracy of 88.4%. [37] introduced a dataset containing the general differences of the coconuts in terms of their maturity statuses through their acoustic characteristics. Their dataset can also help develop an intelligent classification system of coconut through deep learning and machine learning models.

In the literature, very few works consider using SI algorithms in this direction since many improved SI algorithms have been developed [38, 39].

1.1 Motivations

This investigation aims to develop a precise detector to sort and classify coconut water from coconuts in three different development stages: tender, mature, and very mature, with green, greenish-brown or yellowish-brown, and completely brown colors, respectively. The SWO algorithm is developed to choose the optimal weights for the fuzzy rules to obtain the coconut water maturity prediction, and a prototype sorter is implemented based on the information on the actual times and dissolved oxygen level acquired from an optimized ANN to evaluate the anticipated values of coconut water maturity with an acceptable error margin.

1.2 Contributions

The fundamental contributions of this paper can be summarized in the following:

  • A new model, called FNN–SWO, for predicting coconut water maturity is established based on clustering the input data and data fuzzification to estimate the appropriate stage of maturity of coconut water.

  • The proposed FNN–SWO model is trained and tested utilizing fuzzy rules with an adaptive network. In contrast, the SWO algorithm is adopted to determine the optimal weights for the fuzzy rules.

  • Compare the proposed model with the state-of-the-art models and evaluate their performance.

1.3 Structure

This paper is structured as follows. Section 2 presents the theories and methods used, that is, the components of the FNN system and the SWO algorithm. The proposed FNN–SWO assessment model is discussed in Sect. 3. Section 4 presents the experimental results and performance analysis. Lastly, concluding remarks are given in Sect. 5.

2 Fundamental preliminaries

This section concisely describes the methods and materials used in this paper: the components of the FNN system and the SWO algorithm.

2.1 ANNs

Neural networks [21, 26, 40] are modeled after the human brain and imitate the way biological neurons communicate with each other. Node (neuron) layers, including input, hidden, and output layers, make up neural networks. The nodes are components used in information processing. The number of nodes in the input and output layers relates to the dataset’s input and output variables. At the same time, the experiment must determine the appropriate number of nodes in the hidden layer.

Each node (neuron) links to others in a specific pattern through a connection link. That link is associated with a corresponding weight, which contains details about the input signal and provides helpful information about input to address the problems. Each node can access various inputs but only one output. It takes in the inputs from nearby neurons, elaborates them, and then sends the output to adjacent neurons, giving the inputs the proper weight using the connective values [41].

Neural networks are effective tools that classify and cluster data at a high rate. The ability of neural networks to learn from examples (training data, input, and output samples) is their primary property for improving their accuracy over time. For setting, the required I/O relationship that depicts the behavior of the designed system with an acceptable level of error for the application, neural networks compute outputs from input data, compare the measured and calculated outcomes, and then adjust their internal structure and the weights of the connections between artificial neurons to reduce the discrepancy between the measured and calculated values. It’s essential to watch out throughout training to prevent over-fitting. Over-training causes the network to get so used to the example training patterns that it cannot generalize to new data.

2.2 Fuzzy systems

There are several reasons to deal with fuzzy events, which are hard to classify. First, fuzzy logic can represent human knowledge more naturally and appropriately. Second, it is widely recognized that many real-world situations are intrinsically fuzzy. Third, fuzzy quantity is simple and easy to use [42, 43]. Fuzzy systems are provided to study fuzzy events and interpret the subjective human knowledge of the actual processes. The main specialized paper, which proposed the foundations and mathematics of the fuzzy set theory, was published by [44]. This theory suggested using the continuous interval [0, 1] instead of the discrete set [0, 1] for the membership function (values of true and false). There are three stages in the technique of fuzzy inference:

  • Fuzzification: a function sets the numeric inputs’ values based on the degree to which related fuzzy sets agree.

  • Processing: rules are processed by the fuzzy system in line with the inputs’ firing strengths.

  • De-fuzzification: the consequent fuzzy values are returned to scalar values.

2.3 FNN system

In neural networks [45], the principle of fuzzy systems is used to enable a system to handle real-life situations in a manner more like humans, which helps in accelerating network processes or improving parameters. In FNN, there is a combination of the neural network’s capacity to provide the learning’s computational features, generalize to untrained samples, and its simplicity in implementation for any complex problem, as well as the fuzzy systems’ capacity to clarify the ambiguous data that is so common in real-world situations.

Different FNN systems include combinations between neural networks and fuzzy systems according to the stage at which the neural networks are used. FNN systems can be either concurrent, cooperative, or hybrid [46].

Concurrent FNN systems are competing systems that take the output from each other, and a neural network can work on one task without affecting other parameters [47]. These systems are not FNN systems in the strict sense because the fuzzy system and the neural network interact continually. Cooperative (or parallel) FNN systems are pre-processors for fuzzy systems in which the parameters are set using neural networks in an initial phase using training data. Once the fuzzy rules have been produced, the neural networks are taken out, and the fuzzy system is left to operate independently [48]. Hybrid (or integrated) FNN systems combine fuzzy logic and neural networks in a strict sense to determine the parameters iteratively. Hybrid FNN systems are the most suitable for solving diagnostic problems [49].

The advantage of FNN systems is that they can learn through patterns and are simple in interpreting their operations [50]. Recently, the applications of FNN systems have expanded to cover all branches of knowledge, including data classification, data analysis, error detection, and decision-making support.

The five-layer network is recommended for usage in the FNN system of this study. The suggested FNN system is depicted in Fig. 1. An input space \(x\in R^n\) is mapped to an output space \(K\in R\) using this FNN system. The FNN uses the following inference rule, namely, rule \(R^j\).

$$\begin{aligned} R^j:\text {If } \, \, x_1 \text { is } \mu _{1j} (x_1) \, \text {, } x_2 \text { is } \mu _{2j} (x_2)\text {, } \, \dotsc \, \text {, } x_i \hbox { is } \mu _{ij}(x_i) \,\,\,\,\,\,\text { then y is}\ w_j. \end{aligned}$$
(1)

Where \(x_i (i=1,2,\dotsc ,n)\) is an input with a membership \(\mu _{i j} (i=1,2,\dotsc ,m)\), and wj denotes the weight of the \(j^{th}\) consequence link.

Fig. 1
figure 1

Structure of the suggested FNN system

A specific procedure must be used to update the parameters, which is summarized as a five-layer network [51], as shown in Fig. 1. Firstly, the input layer that initializes the training stage set \(<x, k>\) by determining the minimum and maximum values signs. Then the second layer is called the membership function layer and is defined as:

$$\begin{aligned} k^2_{i j}=\mu _{ij} (x_i)= \exp \left( -\frac{1}{2} \, \left( \frac{x_i - c_{i j}}{\sigma _{ij}}\right) ^2 \right) . \end{aligned}$$
(2)

Where the membership \(k^2_{ij}\) consists of the present \(j^{th}\) neuron with the \(i^{th}\) input from the former layer as the subscript and the layer number as the superscript. \(x_i\) denotes the value of \(i^{th}\) input. \(c_{ij}\) and \(\sigma _{ij}\) stand for the center and width of a Gaussian distribution for a set that is assigned to \(\mu _{ij}\), respectively.

The third layer is dubbed the rule layer. In this layer, the precedents’ membership values for each rule are multiplied by each other to acquire the rule’s firing strength, which is used to determine the volume of each neuron’s output as follows:

$$\begin{aligned} k^3_j = k^2_{1 j} \text { } \varPi \text { } k^2_{2 j} \text { }\varPi \text { } \dotsc \text { } \varPi \text { } k^2_{n j}. \end{aligned}$$
(3)

Subsequently, the resulting layer is the fourth layer. Its outputs are fuzzified values of the outputs from the rule layer. This layer is determined as follows:

$$\begin{aligned} u(v) \equiv k^4= \sum _{i=1}^r w_i \, \varphi _i\,\,, \,\,\,\,\,\,\,\,\varphi _i = \frac{k^3_i}{\sum ^r_{i=1} k^3 _i}. \end{aligned}$$
(4)

Where \(\varphi _i\) means the normalized degree of individual rules’ firing.

The connection weights can be determined as follows:

$$\begin{aligned} w_i(v + 1) = w_i(v) + \varDelta w_i(v) =w_i(v) - \eta \, \frac{\partial E_u}{\partial w_i}. \end{aligned}$$
(5)

Where \(\eta \in [0, 1]\) is a given rate of constant learning for the neural network, weights are changed in proportion to the negative of the error derivative with respect to each weight.

The fuzzy set values can be calculated, as:

$$\begin{aligned}& c_{i j}(v+1) = c_{ij} (v) + \varDelta c_{ij} (v) \\& \quad\quad\quad\quad\; = c_{ij} (v) - \eta \, \frac{\partial E_u}{\partial k^4} \, \frac{\partial k^4}{\partial k^3_i} \, \frac{\partial k^3_i}{\partial c_{i j}} \\ & \quad\quad\quad\quad\; = c_{i j} (v) + \eta \, e_u \, \varphi _i \, \{ w_i(v) - k^4 \} \times \left[ \frac{x_i - c_{i j}(v)}{\{\sigma _{i j} \, (v)\}^2} \right] , \end{aligned}$$
(6)
$$\begin{aligned}{} & {} \sigma _{i j} (v + 1)=\sigma _{i j} (v) + \eta \, e_u \, \varphi _i \, \{ w_i(v) - k^4 \} \nonumber \\{} & {} \quad \times \left[ \, \frac{\{x_i - c_{i j}(v)\}^2}{\{\sigma _{i j}(v)\}^3} \right] . \end{aligned}$$
(7)

An adaptive approach is provided to train the FNN system. During the training procedure, it will look for the value of u(v) until the most negligible value for \(\vert y_d(v+1)-y(v+1)\vert\) is obtained. The value of \({\hat{y}}(v+1,t)\) will get closer to \(y_d(v+1)\) as the desired value of the manipulated variable is reached. Hence:

$$\begin{aligned}{} & {} \frac{\varDelta {\hat{y}} (v + 1)}{\varDelta u (v)} =\frac{y_d \, (v + 1) - {\hat{y}} \, (v + 1 \,, \, t)}{u (v) - u (v - 1)} = \frac{\partial {\hat{y}}}{\partial u}, \end{aligned}$$
(8)
$$\begin{aligned}{} & {} e_u(v)=u(v) - u(v-1) =(\frac{\partial {\hat{y}}}{\partial u} )^{-1} \, {\{y_d \, (v + d) - {\hat{y}} \, (v +1,t)\}}. \end{aligned}$$
(9)

In FNN training, the value of \(e_u (v)\) is employed, and the plant model makes sure that \({\hat{y}} (v+1)\) closely approximates \(y_d (v+1)\).

There are two ways to assess the learning algorithm mentioned above. At first, the forward way in which the current degree of rules’ firing is computed, and the FNN’s output is projected. The second way is either optimizing the weight in the resultant layer or concurrently modifying the membership functions and weights.

2.4 SWO algorithm

An effective nature-inspired optimization algorithm termed SWO algorithm [52] is introduced to imitate the sperm whale’s natural behaviors to live. Breathing and feeding for sperm whales consider two inverse cyclical processes; as they provide on squids but should descend to the depths of the water at about 2000–3000 m to catch squids where they live; while they need to surface to breathe, they can halt breathing for about 90 min [53].

Each solution in the SWO algorithm indicates a sperm whale. Firstly, a sperm whale’s initial population is formed, assessed, and arranged. After that, to maintain the global optimum and avoid falling into local optima, this sperm whale’s initial population is separated into n distinct Temporal Sub-Groups (TSGs), each of which has m members. For each new Master Sub-Group (MSG), one member is arbitrarily chosen from each Temporal Sub-Group (TSG) [53], as illustrated in Fig. 2.

Fig. 2
figure 2

Gathering process in SWO algorithm

As mentioned before, in the breathing-feeding cycle, sperm whales pass through two contrasting locations. Hence, there are two solutions for each sperm whale are taken into consideration, one for its certain location and the other for its opposite location, and the two solutions’ objective functions are evaluated. Additionally, only the worst solution is reflected because the best solution’s opposite impression does not help determine the optimal solution. SWO transfers the worst solution to an arbitrary point on the line connecting the worst and the best solutions for ensuring that the search space’s central reflection \(x_{c}\) transmits the point within the wanted solution area. As a result, \(x_{c}\) and the acquired reflection position \(x_{r}\) can be formulated mathematically as follows:

$$\begin{aligned}{} & {} x_{c} = x_{w} + c \times x_{b}, \end{aligned}$$
(10)
$$\begin{aligned}{} & {} c = r \times c_i, \end{aligned}$$
(11)
$$\begin{aligned}{} & {} x_{r} = 2 x_{c} - x_{w}. \end{aligned}$$
(12)

Where \(x_{w}\) is the worst whale’s position, \(x_{b}\) is the best whale’s position. c denotes the center factor, which might be any number, \(c_i\) is the beginning center factor, and r is the shrinking coefficient, which has a value smaller than 1. Equation 11 is applied only in the case of \(x_{r}\) is beyond the search space for lessening the value of c.

When dealing with global optimization problems that are bound-constrained, the parameter’s range c can be chosen so that \(x_{r}\) does not go outside the bounds of the search space. Assume \({\mathfrak {C}}\) be a vector with a \(1 \times n\) dimension. In this case:

$$\begin{aligned} c = \textrm{rand} \times \textrm{Min}({\mathfrak {C}}). \end{aligned}$$
(13)

Where rand is an arbitrary number chosen from a uniform distribution within the [0, 1] range, in this instance, it is not necessary to confirm whether or not \(x_{r}\) is beyond the search, which speeds up the process of finding a solution. As there would be no need to specify r and c, this also reduces the number of parameters.

From each MSG, a selection of q whales with more satisfactory objective functions are chosen as the Good Gang group. Then, a local search is conducted on this Good Gang group’s members by altering the solutions within a specified radius; if the altered solutions are improved, they will replace the originals in the Good Gang group. The best solution from the Good Gang group then crosses over with the remaining solutions in the MSG, and between two created children, one (randomly) replaces the mother solution; this procedure is repeated a specific number of times. At last, all of the subgroups’ solutions are set next to each other in the sperm whales group and arranged them. These steps are repeated until the optimum solution is obtained. The pseudo-code defining the SWO algorithm is offered in Appendix A after presenting the stages of the SWO algorithm outlined above.

3 A proposed model based on FNN and SWO (FNN–SWO) for coconut water maturity assessment

This paper suggests an effective modeling process, dubbed FNN–SWO, for forecasting coconut water maturity. The proposed modeling process consists of the following stages: clustering the data, fuzzy analysis including SWO, machine learning, FNN–SWO training, and FNN–SWO testing. An overview of the suggested model is presented in the following Subsections, which provide a detailed explanation of each modeling stage and an illustration of the dataset utilized in the case study.

Two key components make up the prediction of coconut water maturity. The first component is the dataset’s real-time values, which are utilized to analyze the prediction model. Specifically, the actual times and dissolved oxygen contents are used to compute the predicted values of coconut water maturity based on the appropriate model parameters. All phases of coconut maturation are represented in the model by the values in the dataset, which are derived from the real-time monitoring sensors. The second component is the mechanism that integrates the data and actual timings to calculate the anticipated value of coconut water maturity based on the analyses with a reasonable margin of error.

3.1 Data clustering stage

In this stage, all values input into the training dataset are clustered into an n vector space based on the following parameters chosen for clustering:

  • Effective domain: assign the areas of cluster center for all dimensions of the training dataset.

  • Parameters used: the first parameter determines the neighborhood of a cluster center.

  • Acceptance probability: this parameter specifies the threshold above which data points are regarded as cluster centers.

  • Refusal probability: this parameter sets the threshold below which data points are not considered cluster centers.

The inner vector V of cluster centers is generated during the clustering process. The positions of the cluster centers are included in all rows of vector V. The feedback from vector V contains the values of v, which assign the effective domain of each clustering center for all the dimensions of data, as shown in Algorithm in Appendix B.

3.2 Fuzzification stage

A fuzzy block [54] is an extracted group of rules depending on the number of clusters. The rules are grouped in the IF-THEN structure as input–output relationships. This paper proposes a fuzzy and fast machine-learning method based on reinforcement learning. The suggested fuzzy blocks are dependent on two factors.

  • The input factor: the parameters of each fuzzy block are updated using a fitness function and the network output.

  • The critical metric factor: evaluates the signal based on the actual signal. The neural network determines the critical metric. The critical weights are updated using the SWO algorithm, which is explained in Sect. 2.4. Furthermore, the Lyapunov stability function [55] is employed to select the status of the learning rates and guarantee the stability of the proposed model.

3.3 Prediction stage

The rules of the membership function are calculated for all values of the input training dataset. The membership rules function is determined using the parameter centroids \((c_{ij}\) and domain area \(B_{ij})\). The fuzzification stage transforms the input values into membership values and then computes the output using the relevant rules. The outcome of the forecasting region is calculated for making a proper decision.

Figure. 3 shows the five-layer FNN recommended in the proposed FNN–SWO model. A first-order fuzzy logic model transforms the fuzzy rules into the desired outputs. The FNN consists of five layers. The first layer is associated with the membership function of the actual value. The second layer represents the degree of membership, which is constructed from the function (ranging from the minimum to the maximum) of the incoming real value. The third layer represents the optimal weight \(w_i\) ratio of the membership’s degree of the ith rule. The fourth layer is the defuzzification layer. The fifth layer calculates the total output as the summation of all real values incoming from the fourth layer.

All parameters in the prediction stage of coconut water maturity are optimized using the SWO algorithm. The proposed model uses fuzzy rules as inputs to the ANN and chooses the optimal weight using the SWO algorithm to obtain the coconut water maturity prediction.

Fig. 3
figure 3

The structure of the proposed FNN–SWO model

Finally, after describing the stages of the suggested FNN–SWO model in the preceding Subsections for evaluating the maturity of coconut water, Fig. 4 provides the flowchart of the stages in structure determination, training, and testing for the suggested FNN–SWO model.

  • The first stage involves determining the data parameters and initially clustering the values.

  • The second stage is the clustering operation.

  • The third stage includes training the clustered data in the model considering the allowable Mean Squared Error (MSE).

  • The fourth stage involves testing the model and calculating the average absolute difference between x and Y Mean Absolute Error (MAE), as follows:

    $$\begin{aligned} \textrm{MAE} =\frac{1}{n} \, \sum _{i=1}^n \vert y_i - {\hat{y}}_i\vert \end{aligned}$$
    (14)
Fig. 4
figure 4

Flowchart of the proposed FNN–SWO model for coconut water maturity assessment

4 Results and discussions

The experimental results for SVM with Genetic Algorithm (GA)(SVM-GA), ANN, FNN, ANN-GA, NB, FNN with Particle Swarm Optimization (FNN-PSO), FNN with Differential Evolution (FNN-DE), ANN-SWO and the proposed FNN–SWO are presented in this section. The models were evaluated using training and testing datasets. The final findings were derived using the evaluation metrics’ average value. The datasets used to verify the efficacy of the proposed model are described in Sect. 4.1, the parameters that are utilized in working environments are presented in Sect. 4.2, the performance metrics are shown in Sect. 4.3, and comparative analysis is explained in Sect. 4.4.

4.1 Dataset description

Two hundred fruits of coconut from the 7-month development stage and older were gathered after inflorescence emerged from two Pacific coast fields. Coconut water was emptied from a 15-mm hole with a drill. All coconuts were categorized into three classes: tender, mature, and very mature, with green, greenish-brown, or yellowish-brown and completely brown colors, respectively. Dissolved oxygen concentration measurements were made for each class of coconut maturity. The continuous measurements of the oxygen concentration were recorded with a data logger each second in the air and the coconut water to identify the transient response of oxygen in the coconut water from coconuts of each stage. Dissolve oxygen measurements for coconut water can be obtained through three different techniques. First, the transducer is introduced to the coconut water for one minute. Then, the transducer is removed from the coconut water (in the air) for three intervals of 5, 7, and 10 s in different techniques. Three other peak measurements were obtained from each period of transducer contact with the air.

The dissolved oxygen measurements’ reference points were specified as condition states. The dissolved oxygen concentrations in the air after 5, 7, and 10 s according to the measurement technique, were used to establish the maximum dissolved oxygen (DOmax). The measurements were taken 5, 10, and 60 s after transducer insertion in coconut water and were subsequently denoted as DO5, DO10, and DO60, respectively. The automatic sorter constructed by Hahn [56] was applied in the newly developed model to obtain an exact sorting process, as shown in Fig. 5. Hahn [56] described the main components of the sorter and the operation of the sorter in detail. A dissolved oxygen sensor with a resolution of 0.1 mg of \({O_2\mid }^{-1}\) (HI 76410/4, Hanna Instruments, USA) was connected to an analyzer panel (HI 8410, Hanna Instruments, USA). The analyzer panel provides an output current of 4-20 mA based on the amount of dissolved oxygen measured by a microcontroller (Fig. 5b).

The curtain valve, as shown in Fig. 5, has a diameter of 150 mm, and the coconut water discharge rate is 75 ml/s. The dissolved oxygen sensor starts to take measurements after 4 s. The microcontroller receives the measurement data for the incoming coconut water class and sends a signal to one of the four solenoid valves, as shown in Fig. 5.

Fig. 5
figure 5

Coconut water sorter system with funnels (a, c), the embedded system (b), four solenoid valves (d), the sensors (e), and curtain valve f cited from [56]

Figure 6 shows the dissolved oxygen values for three different samples of the tender class of coconut water. Figure 7 shows the dissolved oxygen values for three different samples of the mature class of coconut water. Figure 8 shows the dissolved oxygen values for three samples of the very mature class of coconut water.

Fig. 6
figure 6

Dissolved oxygen values for different samples of each type of coconut water (Tender class)

Fig. 7
figure 7

Dissolved oxygen values for different samples of each type of coconut water (Mature class)

Fig. 8
figure 8

Dissolved oxygen values for different samples of each type of coconut water (Very mature class)

4.2 Working environment

The suggested FNN–SWO method was compared against five state-of-the-art techniques, including SVM-GA, ANN, FNN, ANN-GA, and NB, executed in this paper. To implement all experiments in this paper, Python was utilized on a computing environment with a Dual Intel® Xeon® Gold 5115 2.4 GHz CPU and 128 GB of RAM on the operating system Microsoft Windows Server 2019. In the proposed approach, the optimality of the results was validated by using the hold-out strategy, where the training and test sets are realized by randomly dividing each dataset into two parts, where the training phase is done on 80% of the dataset while the remaining 20% is for testing purposes. The configuration parameters of the proposed methodology are set considering the original variants and the data presented in their first publications [57, 58].

4.3 Evaluation metrics

Accuracy, precision, recall, F-Score, sensitivity, and Specificity metrics were selected to validate the proposed model’s performance in this study. These metrics depend on True Positive (\(T_P\)), True Negative (\(T_N\)), False Positive (\(F_P\)) and False Negative (\(F_N\)) which are common evaluation parameters for predictive models [59, 60]. Accuracy is expressed as in Eq. (15):

$$\begin{aligned} \textrm{Accuracy} = \frac{T_P+T_N}{T_P+T_N+F_P+F_N} \end{aligned}$$
(15)

Precision [61] is formulated as in Eq. (16):

$$\begin{aligned} \textrm{Precision} =\frac{T_P}{{T_P} + {F_P}} \end{aligned}$$
(16)

Recall [62] is defined mathematically as in Eq. (17):

$$\begin{aligned} \textrm{Recall}=\frac{T_P}{{T_P} + {F_N}} \end{aligned}$$
(17)

F-Score [63] is expressed as Eq. (18):

$$\begin{aligned} F-\textrm{Score}=2 * \frac{\textrm{Precision} \times \textrm{Recall}}{\textrm{Precision} + \textrm{Recall}} \end{aligned}$$
(18)

Sensitivity [64] is written as in Eq. (19):

$$\begin{aligned} \textrm{Sensitivity}=\frac{T_P}{T_P+F_N} \end{aligned}$$
(19)

Specificity [64] is formulated as in Eq. (20):

$$\begin{aligned} \textrm{Specificity}=\frac{T_N}{T_N+F_P} \end{aligned}$$
(20)

4.4 Comparative analysis

This paper’s coconut water dataset comprises real-time data collected over 3 months. The FNN parameters were optimized based on the learning factor and learning coefficient. An experimental method to determine the parameters was developed. A structure of 1 to 8 neurons in the hidden layer, a learning factor from 0.01 to 1, and a learning factor step of 0.01 were selected. Different training and validation steps were performed for each factor, covering the entire range. Then, the number of weights and iterations needed for network training, the prediction error (MAE), and the correlation between the real and predicted values and time data were analyzed for each sample.

4.4.1 Experimental results with partial derivatives (Gradients) and with SWO Optimizer

To show the effectiveness of the proposed framework, an experiment is conducted With partial derivatives (Gradients) and with SWO Optimizer. The obtained results for accuracy, recall, precision, and F1-score are presented in Table 1, in which boldface numbers indicate the best results. It can be noted from Table 1 that the use of SWO leads to a massive improvement in all of the performance metrics by substantial percentages.

Table 1 Experiment results with partial derivatives (Gradients) and with SWO Optimizer

4.4.2 Training results

Table 2 shows the accuracy, precision, recall, and F-Score of the three training subsets of the collected coconut water data and the performance of the proposed FNN–SWO against different algorithms from the literature, including SVM-GA, ANN, FNN, ANN-GA, NB, FNN-PSO, FNN-DE, ANN-SWO, and FNN–SWO, in which boldface numbers indicate the best results. The proposed method and its competitors were performed under the same experimental settings. It is evident from Table 2 that the proposed FNN–SWO method obtained the best performance regarding accuracy, recall, and F-score for 50, 100, and 500 subsets in the training phase. ANN-SWO reached the best performance regarding precision for 50, 100, and 500 subsets in the training phase.

Table 2 Accuracy, precision, recall and F-Score for 50, 100, and 500 subsets in the training phase

It should be noted that for the 50 subsets, the proposed FNN–SWO ranked first for all performance measures except precision. ANN-SWO achieved first place in precision and second in accuracy, recall, and F-score. Finally, NB achieved the worst accuracy, recall, and F-score results. For 100 subsets, the proposed FNN–SWO ranked first for all performance measures except precision. ANN-SWO reached first place in precision. FNN achieved second place in accuracy, precision, recall, and F-score. Finally, NB achieved the worst accuracy, precision, and recall results.

Regarding 500 subsets, the proposed FNN–SWO ranked first for all performance measures except precision. ANN-SWO achieved first place in precision and second place in accuracy. ANN-GA achieved second place in terms of recall and F-score. Finally, NB achieved the worst accuracy, precision, recall, and F-score results. Therefore, the proposed FNN–SWO method could be considered a well-regarded and proficient heuristic for discovering optimal or near-optimal solutions to classification problems.

Meanwhile, Fig. 9 shows the values of each of the four metrics utilized in that competition. Based on the values recorded (as depicted in Fig. 9), the proposed FNN–SWO approach exceeded others for all performance metrics except precision for the 50 subsets in the training phase. Figure 10 shows the values of each of the four metrics utilized in that competition for 100 subsets in the training phase. Based on the values recorded, the proposed FNN–SWO performed the best for all performance measures except precision. Based on the values recorded in Fig. 11, the proposed FNN–SWO achieved the best for all performance measures except precision for 500 subsets in the training phase. Regarding Figs. 9, 10, and 11, ANN-SWO ranked first in precision for 50, 100, and 500 subsets in the training phase.

Fig. 9
figure 9

Accuracy, precision, recall and F-score values for all competitors regarding 50 subset in the training phase

Fig. 10
figure 10

Accuracy, precision, recall and F-score values for all competitors with respect to 100 subset in the training phase

Fig. 11
figure 11

Accuracy, precision, recall and F-score values for all competitors with respect to 500 subset in the training phase

4.4.3 Testing results

Table 3 shows the accuracy, precision, recall, and F-Score for three subset data periods of the collected coconut water data, in which boldface numbers indicate the best results. For 50 subsets, the proposed FNN–SWO ranked first in accuracy and precision. ANN-GA ranked first in terms of sensitivity. FNN ranked first in terms of Specificity.

Regarding 75 subsets, the proposed FNN–SWO achieved the best for all performance measures except sensitivity. FNN performed the best for sensitivity. Finally, the proposed FNN–SWO ranked first for all performance measures in 120 subsets.

Table 3 Accuracy, sensitivity, specificity, and precision for 50, 75, and 120 subsets in the testing phase

Meanwhile, Fig. 12 shows the accuracy, sensitivity, Specificity, and precision values for the proposed method and their counterparts with respect to 50 subsets in the testing phase. Based on the recorded values, the proposed FNN–SWO achieved the best accuracy and precision. ANN-GA achieved the best in terms of sensitivity. FNN ranked first in terms of Specificity. Figure 13 shows the performance measures obtained by the proposed method and their counterparts for 75 subsets in the testing phase. Based on the values registered, the proposed FNN–SWO achieved the best for all performance measures except sensitivity. FNN performed the best for sensitivity. Figure 14 shows the evaluation metrics obtained by the proposed method and their competitors concerning 120 subsets in the testing phase.

Fig. 12
figure 12

Accuracy, sensitivity, Specificity, and precision values for all competitors regarding 50 subsets in the testing phase

Fig. 13
figure 13

Accuracy, sensitivity, Specificity and precision values for all competitors regarding 75 subset in the testing phase

Fig. 14
figure 14

Accuracy, sensitivity, Specificity, and precision values for all competitors regarding 120 subsets in the testing phase

The proposed FNN–SWO achieved the best for all performance measures based on the values registered. The actual and predicted values data for three subset data periods of the collected coconut water data in the testing phase are compared and presented in Figures. 15, 16, and 17. Figure 15 shows the tender class, Fig. 16 represents the mature class, and Fig. 15 reveals the very mature class. The predicted data are consistent with the actual data shown in these figures, which also reveals that the proposed FNN–SWO method could be considered a well-regarded and proficient heuristic for discovering optimal or near-optimal solutions to classification problems.

Fig. 15
figure 15

The real and predicted values of coconut water maturity for the data subsets (Tender class)

Fig. 16
figure 16

The real and predicted values of coconut water maturity for the data subsets (Mature class)

Fig. 17
figure 17

The real and predicted values of coconut water maturity for the data subsets (Very mature class)

4.4.4 MAE and MSE values

The prediction model is run with the training and testing subsets, and the worst, average, and best MAE and MSE values are computed for each subset of data, as shown in Table. 4, in which boldface numbers indicate the best results. Based on the values of MAE and MSE shown in Table. 4, the proposed FNN–SWO obtained the least value for MSE (1.30E-01) for the training phase and (1.48E−01) for the testing phase. Regarding MAE values, the proposed FNN–SWO recorded the minimum average MAE value (0.33E+00) for the training phase and (2.32E-02) for the testing phase.

Table 4 MAE and MSE values obtained by the proposed method and their counterparts in training and testing phases for the coconut dataset

Based on the MAE and MSE values shown in Fig. 18, the proposed FNN–SWO obtained the least MAE and MSE values in the training phase for the coconut dataset. Based on the MAE and MSE values shown in Fig. 19, the proposed FNN–SWO obtained the least MAE and MSE values in the testing phase for the coconut dataset.

Fig. 18
figure 18

MAE and MSE values obtained by the proposed method and their counterparts in the training phase for the coconut dataset

Fig. 19
figure 19

MAE and MSE values obtained by the proposed method and their counterparts in the testing phase for the coconut dataset

4.4.5 Managerial implication of the proposed model

The proposed FNN–SWO method employs the SWO algorithm to select the optimum weights for the fuzzy rules. Our proposed FNN–SWO can achieve high accuracy in terms of training and testing compared to other models. It plays an essential role as a tool for predicting the maturity level of coconut water. This tool can be combined with coconut water extraction machines in manufacturing to separate coconut water into three maturity levels (i.e., tender, mature, and very mature).

5 Conclusion and future work

The main problem addressed in this study is how to accurately evaluate the maturity level of coconut water, a time-consuming task in the beverage industry. Therefore, to solve this problem, an integrated model called FNN–SWO has been proposed to evaluate the maturity of coconut water. The SWO method has been incorporated into this approach along with FNN techniques, which can be utilized as an essential building block in the beverage industry. The proposed FNN–SWO model is trained and tested using fuzzy rules with an adaptive network, whereas the SWO algorithm is utilized to select the optimum weights for the fuzzy rules. Multiple evaluation measures (precision, recall, F1-score, specificity, sensitivity, and accuracy) were adopted to estimate its performance. Based on the findings, The noticeable outcomes were: (i) the FNN–SWO model had the best prediction results for recall, F1-score, specificity, and accuracy and was ranked second in terms of precision and sensitivity; and (ii) The SWO algorithm had a significant impact on improving the prediction of the maturity of coconut water. These results revealed that integrating both methods has an inherent advantage over other methods for distinguishing between different maturity classes of coconut water. Compared with other methods, the FNN–SWO model outcomes performed best. Overall, these findings could pave the way for the future design and development of robust prediction algorithms for specific datasets. Furthermore, the results recorded from the dataset would greatly benefit the scientific community interested in coconut water assessment.

To expedite this process, surrogate-assisted models could be investigated in the future. Furthermore, other SI and meta-heuristic algorithms could be tested, such as the ant colony and sparrow search. Also, adopting other datasets in the proposed approach could be considered.