### Proposed structure for ANFIS

#### Adaptive neuro-fuzzy inference system (ANFIS)

A fuzzy logic system is capable of mapping nonlinear relationships between an input vector and a scalar output; moreover it can handle both numerical values and human-like linguistic knowledge or variables.

Fuzzy logic system consists of four main components: fuzzifier, rules, inference engine and defuzzifier. Fuzzifier converts a non-fuzzy (crisp) input variable into a fuzzy variable representation, where membership functions assign the degree of belongingness of the variable to a specified attribute. Fuzzy rules are simple “if-then” type, and can be obtained from numerical data relationships or from expert linguistic experience. Sugeno and Mamdani inference engines are the two main kinds of inference mechanisms used in fuzzy logic systems [15].

The Mamdani engine type merges together fuzzy rules into a mapping from fuzzy sets to fuzzy output sets and then apply defuzzification to the output fuzzy set to obtain crisp outputs, while the Takagi-Sugeno directly relates fuzzy inputs and crisp outputs using *singleton spikes* output membership function. The defuzzification step is the final stage of the fuzzy inference process which is accomplished by the defuzzifier by converting the output fuzzy set into a crisp number using different methods such as: centroid of area, bisector of area, mean of maxima, or maximum criteria.

ANNs have the advantage over the fuzzy inference systems that knowledge is automatically gained during the training process by updating the connection weights between neurons [21]. But, this knowledge cannot be taken out from the trained network acting as a black box. On the other hand, fuzzy inference systems can be distinguished by their rules, but these rules are tricky to define when the system has many variables and their relationships are even more complex [22].

A hybrid of NNs and fuzzy inference systems has the advantages of each of them and better performances than any one of them. In a neuro-fuzzy system, NNs automatically extract fuzzy rules from the numerical data and, through the training process, the parameters of the membership functions are adaptively attuned.

ANFIS is a type of adaptive multi-layered feedforward networks [23], applied to nonlinear prediction where past data samples are utilized to predict the data samples ahead. ANFIS adopts the self-learning ability of neural networks with the linguistic expression function of fuzzy inference system [24].

The ANFIS architecture is shown in Fig. 2. The ANFIS network considered is a Takagi-Sugeno fuzzy inference system mapped onto a neural network structure with five layers. Every layer contains a number of nodes characterized by the node function. This node function is discussed as follows. Suppose O_{i} represents the output of the *i*
^{th} node in layer j.

In layer 1, each node *i* is an adaptive node with the following node function:

$$ {O}_{1, i}=\mu {A}_i(x), i = 1,\ 2, $$

(1)

or

$$ {O}_{1, i}=\mu {B}_{i-2}(y), i = 3,\ 4 $$

(2)

Here, either *x* or *y* is the input to the *i*
^{th} node and A_{i} (or B_{i-2}) is a linguistic label associated with this specific node.

Hence, O_{1,i} is the membership value of a fuzzy set A (A_{1}, A_{2}, B_{1}, or B_{2}) and it indicates the degree to which the specified input *x* (or *y*) satisfies the quantifier A. The membership functions for A and B are frequently described by a generalized bell functions as follows:

$$ \mu {A}_i(x)=\frac{1}{1+{\left|\frac{x-{r}_i}{p_i}\right|}^{2{q}_i}} $$

(3)

where *p*
_{
i
}, *q*
_{
i
}, and *r*
_{
i
} are the parameters of the membership function. When the values of these parameters vary, the bell-shaped membership function changes accordingly, thus illustrating various forms of membership functions on linguistic label *A*
_{
i
}
*.*

Actually, any continuous and piecewise differentiable functions, like triangular-shaped functions, are also eligible candidates for the node function in this layer [25]. Parameters of this layer are called premise parameters.

In layer 2, each node**Π**is fixed whose output representing the rule firing strength is the product of the incoming input signals:

$$ {O}_{2, i}={w}_i={\displaystyle {\prod}_j{\mu}_j}=\mu {A}_i(x).\mu {B}_i(x), i = 1,\ 2 $$

(4)

In layer 3, every node N calculates the ratio of the *i*
^{th} rule’s firing strength to the total sum of all rules’ firing strengths (normalization):

$$ {O}_{3, i}={\overline{w}}_i=\frac{w_i}{{\displaystyle {\sum}_j{w}_j}}=\frac{w_i}{w_1+{w}_2}, i = 1,\ 2 $$

(5)

The results of this layer are referred to as normalized firing strengths.

In layer 4, every node is adaptive and determines the role of the *i*
^{th} rule to the overall total output:

$$ {O}_{4, i}={\overline{w}}_i{f}_i={\overline{w}}_i\left({a}_i x+{b}_i x+{c}_i\right) $$

(6)

where \( {\overline{w}}_i \) is the outcome of layer 3, and (*a*
_{
i
}
*, b*
_{
i
} and *c*
_{
i
}) is the parameter set. Parameters in this layer are said to be consequent parameters.

In layer 5, the single node calculates the final output by summing up all the incoming input signals to this layer:

$$ {O}_{5, i}={\displaystyle \sum_i{\overline{w}}_i{f}_i}=\frac{{\displaystyle \sum_i{w}_i{f}_i}}{{\displaystyle \sum_i{w}_i}} $$

(7)

Hence, an adaptive network is equivalent to a Sugeno-type fuzzy inference system from functionality point of view.

### Optimization of ANFIS membership function parameters

In this paper, the two-stage hierarchical ANFIS networks utilize BP algorithm to tune the parameters of the membership functions. The fuzzy membership functions considered in this research paper are triangular-shaped type.

As aforementioned, fundamentally, ANFIS network is a fuzzy inference system mapped onto a neural network structure whose membership function parameters are tuned with a BP algorithm based on some collection of input–output data. This allows the ANFIS network to learn. BP carries out a gradient descent within the solution’s vector space towards a global minimum value along the steepest vector of the error surface.

BP learning algorithms are fast and thus suits for wind power predictions which can be utilized in real-time applications such as energy management, dynamic dispatching and scheduling in large interconnected power systems or microgrids. ANFIS membership functions’ parameters are formed as variables of the BP and the mean squared error is utilized as a cost function in BP. The objective of proposed approach is to reach a minimum value for this cost function. Figure 3 shows the general scheme of the forecasting system.