Abstract
Recently, the Adaptive-Network-Based Fuzzy Inference System (ANFIS) is applied in many areas of knowledge, and there are multiple optimization algorithms for its learning. This work shows the design of a novel optimization algorithm for an ANFIS system that learns and classifies the behavior of brain signals between normal and abnormal. For this goal, different types of optimization algorithms for the learning of an ANFIS system are evaluated, such as the backpropagation, the mini-lots, and the Adam algorithm (adaptive moment estimation). As a result, utilizing the ANFIS with Adam and mini-lots provides the most accurate, fastest, and with least computational costs results.
Introduction
In the human brain, neurons can be compared to a set of bioelectric impulse generators that are transmitted from one neuron to another. In a complex network that transmits, processes and stores information, these neurons can be altered producing different abnormal behaviors of brain signals. Consequently, these altered neurons can generate diseases that result in psychomotor failures or decreased alertness of people. This produces loss of consciousness, falls, and blows to the head in affected people that sometimes lead to brain injuries.
This research is the result of the classification of brain signals by their normal and abnormal behaviors in order to provide an alarm device for patients. This alarm device has the goal to anticipate an epileptic crisis and avoid falls or head injuries. To achieve this goal, it is necessary to use brain signals of a healthy person and through simulation generate data that represent an epileptic crisis. The data is managed by an intelligent algorithm that possess the ability to learn and classify some behaviors.
There exists some studies of intelligent algorithms applied to interesting applications. In [1–3], and [4], the fault diagnosis via classification is considered. Evolving classifiers are studied in [5–8]. In [9–12], evolving fuzzy classifiers are designed. Fuzzy classifiers are discussed in [13–16]. In [17–20], neural network classifies are described. Neuro-fuzzy classifiers are addressed in [21–24]. Since intelligent algorithms are widely used for the classification in several processes, it is justified to make some proposals about this issue.
There is an interesting intelligent algorithm called Adaptive-Network-Based Fuzzy Inference System (ANFIS) which is uses the backpropagation for nonlinear learning [25]. Later, the mini-lots are utilized for the learning of an ANFIS system [26]. It would be interesting to apply the ANFIS system for the classification, and also it would be interesting to propose an optimization algorithm for the ANFIS system with the goal to obtain a better learning and classification.
In this article, the classification issue is addressed, we train an ANFIS system with different kind of optimization algorithms to learn and classify between normal and abnormal brain signals. The design process is implemented through the next steps: Mini-lots. We can separate the training set into small subsets, as if they are smaller training sets, it is applied to the inputs and outputs, these fragments of the set are called mini-lots. The training set is divided into mini-lots, and all mini-lots are traversed by updating the parameters in each mini-lot. A tour of all the mini-lots is called epoch. ANFIS system. An ANFIS system consists in increasing the number of rules layers, and decreasing the number of rules in each rules layer, such as the computational cost is better distributed and the data processing is accelerated. The ANFIS uses the principles of forward and backward propagation in each rules layer. Backpropagation. The idea is that if in several iterations we have observed movements in consistent directions, we should move in those consistent directions, and we reduce our movement in the direction of the mini-lot that could lead us to a bad direction. The result is to soften the learning curves. Adam algorithm (adaptive moment estimation). First, we define the root mean square method used to slow down the parameters of the second rules layer and to accelerate the parameters of the first rules layer. Later, we define the Adaptive moment estimation (Adam) as one of the optimization algorithms that best adapt to almost any issue, basically, it is the combination of the backpropagation and root mean square.
The remainder of this article is organized in the next sentence. Section 2 presents the acquisition device and the portable ANFIS system. The optimization algorithms are compared for the classification of brain signals in Section 3. In Section 4, conclusions and forthcoming work are detailed.
Device for the application
This section consists of two important issues, the acquisition device to store brain signals and the embedded device for programming of the ANFIS system.
Acquisition device to obtain brain signals
We require an acquisition device of biological signals to store the electroencephalographic signals. We have the potential difference in a membrane through its ions, the neurons have a potential difference between their internal part and their external part. This potential represents constant changes due to the impulses provided by the neighbors neurons. We measure these potential differences in the cerebral cortex using electrodes that convert the flow of the ion into the electrical flow.
The characteristic of electroencephalographic signals is 5 - 30μV in amplitude and 0 - 150Hz in frequency. The electroencephalographic signals are similar to the periodic signals but with the ability of changing from one moment to another, and have the characteristic that allow their estimation, such as amplitude, frequency, morphology, rhythm and duration.
Figure 1 shows the electronic circuit that allows us to acquire electroencephalographic signals. We digitize the electroencephalographic signals and send to a personal computer, for this we use the NI myDAQ signal acquisition device from National Instruments. Figure 2 shows the program designed in the Labview software to store the signals in an .xml file.

Electronic circuit of the acquisition device to store brain signals.

The Labview program to store brain signals.
The first goal of this study is to achieve the learning and classification of brain signals in order to describe abnormalities in the brain behavior, and the second goal is to place these skills in an embedded device to notify the people suffering from a disease of affected brain. Since the programming time is of importance, we use the flow diagram in Fig. 3 to reach our goal.

Flow diagram of the portable ANFIS system.
The brain signals x are taken from a focal part of one person; consequently, our goal is to classify these brain signals x between normal and abnormal. Initially we must consider the visualization of the grain signals, then it is necessary to place the characteristics of x in two dimensions to make the graphic description where x1 are the odd terms of x and x2 are the even terms of x.
By means of supervised learning, it is possible to assign a binary classification such that the ANSFIS system learns and classifies between normal and abnormal brain signals. Figure 4 allows us to visualize this classification, now we must train an ANFIS system capable of creating a decision border to discriminate the values that are considered normal and alert when there is an abnormality. That is, at the same time that the ANFIS system classifies it must be able to describe a crisis and send an alarm to prevent a bad situation.

The classification of brain signals.
The decision boundary is the line that separates the areas where the output to learn takes the value y = 0 from those in which the output to learn takes the value y = 1. This ANFIS system is part of an engineering system and considering that it must perform its tasks in a portable device, we select a printed circuit target capable of transporting the ANFIS system.
In this research we use the Raspberry to program our ANFIS system as an embedded device. The Raspberry is a microcontroller developed by a board that is equipped with a RAM processor of 1 GB, 64 bits, with 4 cores at 1.4 GHz, with a graphic environment capabilities and standard hardware ports, and has a very intuitive operating system called Rasbian. The Raspberry does not have internal storage, it allows us to acquire the desired storage that goes from 8 GB to 128 GB.
We use the Python programming language to program our Raspberry. Python is a program and a compiler, with this it can receive a file with a whole program to implement a process, to translate the high level source code to machine code, and to store the result for a later execution. Python demonstrates great advantages when it uses libraries of intelligent algorithms. This language offers two useful advantages in the development of an ANFIS system, the vectorization and the BroadCasting.
The vectorization is a tool used to reduce the number of loops and to make the codes more efficient, allowing the implementation with large data sets and avoiding infinite loops. It consists in reducing the number of explicit cycles in order that the code works quickly.
BroadCasting is another technique to execute a faster code, if we have a dimension matrix (m, n) and we want to add, subtract, multiply, or divide with a matrix of (1, n), the BroadCasting copies n times within a matrix (n, n) before it considers the matrix operations.
For the execution of an ANFIS system, it is not sufficient just to program, the program time for the learning depends of the velocity of processing, and of the computational cost. By handling more than 2000 data lines the whole file has about 2500 code lines, it means more computational cost and more training time. The expandable ROM processing and memory capabilities of the Raspberry microcontroller are optimal for working a Python file, it helps to decrease lines of code via the vectorization and BradCasting.
For the execution of an ANFIS system, it is not sufficient just to program, the time it takes for the learning depends on the velocity of processing, and on the computational cost required by the algorithm to implement its task. By handling more than 2000 lines of data the whole file has about 2500 lines of code, which means more computational cost and more training time. The expandable ROM processing and memory capabilities that the Raspberry microcontroller are optimal for running a Python file, which helps to decrease lines of code via vectorization and BradCasting techniques.
The implementation of backpropagation in the ANFIS system is not sufficient for an acceptable classification, much less for a crisis detection. The cost function shown in Fig. 5 converges to a value of 0.55, which indicates that it is paralyzed at a local minimum. For this reason, optimizing algorithms are required to improve the classification results.

Cost function limited by a local minimum.
Parameters such as the number of rules layers, the number of rules in the rules layers, and other parameters employed in the different types of optimization algorithms to reach the learning and classification in an ANFIS system are explained in this section.
Mini-lots
Mini-lots is an optimization algorithm that allows us to training the ANFIS system faster. This is because a single example of training is taken and coupled to a matrix x. Vectorization allows us to process the examples quickly, but for a larger m, a slower process.
When an optimization algorithm is implemented in the whole training set, the whole training set must be processed to achieve a small step and to reach the global or local optimum, then again it takes the whole training set and repeatedly takes a small step. If the size of m increases, then this process becomes slow.
We can separate the training set into small subsets, they are smaller training sets, it should be done both to the inputs to process and to the outputs to learn, these fragments of the set are called mini-lots.
To implement mini-lots on the training set, the cycle for t = 1, . . . , m/128 is implemented. Within the for cycle, an optimization step is basically implemented using a mini-lot, if we have a training set of 3200 examples, it is divided into small samples of 128 examples, the optimization algorithm is developed in 128 training examples instead of having the whole training set. Then the next cost function can be calculated:
If we have 1 lot, we have y(i) = y as the output to learn which takes binary values of 0 or 1, y(i) = y as the output of the ANFIS system, and x(1) = x as the inputs of the ANFIS system which are brain signals.
An ANFIS system consists in increasing the number of rules layers and decreasing the number of rules in each rules layer, in such a way that the computational cost is better distributed and the processing of the data is accelerated. The ANFIS uses the principles of forward and backward propagation in each rules layer.
We show the ANFIS system utilized in this study in Fig. 6.

The ANFIS system.
We describe the ANFIS system as:
The membership function of the first rules layer uses a Gaussian function as:
The membership function of the second rules layer is the linear function as:
Finally, the output of the ANFIS system is a binary function with threshold of 0.5:
It is an optimization algorithm that works faster with the mini-lots, the basic idea is to calculate an exponentially weighted average of the backpropagation and use it to update the parameters.
Particularly, if we have a big learning factor, the steps of the backpropagation are long, having an excessive learning and with the possibility of reach a divergence, for this reason we want a slower learning, but at the same time, we want a stronger learning in the direction of the global minimum.
To calculate the backpropagation, it is necessary to calculate the average value of the derivatives θ1 (dθ1), θ2 (dθ2) and include them to update the value of θ1, θ2. In each iteration it is calculated as:
The equation (5.3) is updated as:
To have acceptable results, it must be guaranteed that Vdθ1 is a matrix with the same dimension than dθ1 and θ1, the same happens when relating Vdθ2 with dθ2 and θ2.
When implementing the backpropagation does not have any effect on the decision boundary by itself, the cost function seems to be suspended in the same way in a local minimum. However, the use of mini-lots together with the backpropagation delivers better results, but the cost function becomes clumsy by having several divisions between zero.
By the use of an ANFIS system with backpropagation and mini-lots, the cost function goes to a global minimum using 32 rules in the first rules layer and 12 rules in the second rules layer, and the required iterations are 7000 epochs, and its learning takes an programming time of 120 seconds. The decision boundary of the ANFIS with backpropagation and mini-lots in Fig. 7 shows an acceptable performance of the difference between the areas of normal data and abnormal data.

Decision boundary of the ANFIS with backpropagation and mini-lots.
Figure 8 and Table 1 show the comparison of the cost functions between the ANFIS with backpropagation of [25], the ANFIS with mini-lots of [26], and the ANFIS with backpropagation and mini-lots of this section.

Cost function of the ANFIS with backpropagation and mini-lots.
Cost functions for the ANFIS system
We define the method of the root mean square which is used to slow down the parameters of the second rules layer θ2 and to accelerate the parameters of the first rules layer θ1. In each iteration the root mean square is calculated as:
The root mean square updates the parameters as:
Adaptive moment estimation (Adam) is one of the optimization algorithms that best solves almost any issue, basically, it is the combination of the two previous optimization methods, the backpropagation and the root mean square.
We initialize the parameters with zero, Vdθ1 = 0, Vdθ2 = 0, Sdθ1 = 0, Sdθ2 = 0. In each iteration we update:
In its implementation, it is necessary to make a correction of the sequences due to the affectations that may occur, such as noise, elongation, or displacement. This correction is:
Finally, the parameters θ1 and θ2 are updated as:
By the use of an ANFIS system with Adam and mini-lots, the cost function goes to a global minimum using 20 rules in the first rules layer and 5 rules in the second rules layer, and the required iterations are 50 epochs, the learning takes a programming time of 20 seconds. The decision boundary of the ANFIS with Adam and mini-lots in Fig. 9 shows an exellent performance of the difference between the areas of normal data and abnormal data.

Decision boundary of the ANFIS with Adam and mini-lots.
Figure 10 and Table 2 show the comparison of the cost functions between the ANFIS with mini-lots of [26], the ANFIS with backpropagation and mini-lots of the past section, and the ANFIS with Adam and mini-lots of this section. It is evident the increase in the velocity of the proposed method yields the possibility to learn and classify the brain signals.

Cost function of the ANFIS with Adam and mini-lots.
Cost functions for the ANFIS system
The goal of this work is the application of an ANFIS system for the classification of brain signals between normal and abnormal. In the classification issue, we observed that by optimization algorithms it is not only possible to decrease the number of rules significantly, but jointly it is feasible to reduce the number of training epochs, thus reducing the training time of the ANFIS system, as well as the computational cost that supposes. It is also convenient to manage more than one optimization algorithm to improve the results where the accuracy achieved in the classification was 97%, using the ANFIS with Adam and mini-lots of two rules layers that have 20 and 5 rules. In the forthcoming work, we will try to achieve the online learning and classification of brain signals and to detect abnormal behaviors that could damage the patients circumstances.
Footnotes
Acknowledgements
Authors thank to editors and reviewers for important suggestions and comments to improve this research. Authors thank the Instituto Politécnico Nacional, the Consejo Nacional de Ciencia y Tecnología, the Secretaría de Investigación y Posgrado, and the Comisión de Operación y Fomento de Actividades Académicas for their support.
