\chapter{Neurofuzzy Control}
In this chapter, we describe a neural-network-based fuzzy logic control strategy for uncertain dynamic systems. In the controller synthesis we will use numerical data rather than fuzzy IF-THEN rules. The above problem was considered by Lin and Lee in~\cite{lin91}, \cite{lin94}, and in~\cite{lin96}, and by Wang~\cite{lxwang97}. Related approaches to constructing fuzzy rule-based neural networks for control can be found in the papers by Higgins and Goodman~\cite{higgins94} and Nie and Linkens~\cite{nie94}.
\section{Controller Structure}

A typical fuzzy logic controller is composed of three basic components as depicted in Figure~\ref{fig:typflc}.
\begin{figure}
\vspace{3.5in}
\hskip1in\special{bmp:c:/fuzzy/typ_flc.bmp x=4.67in y=3.5in}
\caption{A diagram of a typical fuzzy logic controller}
\label{fig:typflc}
\end{figure}
The fuzzifier maps crisp inputs into fuzzy numbers. The decision making logic unit, the inference engine, uses fuzzy rules to infer fuzzy control actions. The defuzzifier maps the fuzzy outputs from the decision making logic block into crisp values.\\
In the previous chapter we discussed a method for designing a fuzzy logic controller using given to us fuzzy IF-THEN rules that describe in linguistic terms the given dynamic system operation. The availability of such rules is a basic requirement for implementing a fuzzy controller. However, there may be cases where neither a mathematical model of the process nor its linguistic description are available. In such cases we may try to extract fuzzy IF-THEN rules from example data, and then proceed with an implementation of a suitable controller. We will use the available data to train fuzzy feedforward neural-network-based controller shown in Figure~\ref{fig:hybrnn}.
\begin{figure}
\vspace{4.5in}
\special{bmp:c:/mybook/hybrnn.bmp x=6in y=4.5in}
\caption{Fuzzy neural-network-based controller structure}
\label{fig:hybrnn}
\end{figure}
The network consists of four layers. In the first layer the input signals $x_i$, $i=1,2,\ldots ,n$, are branched-off to the second, hidden, layer. We refer to this layer as the {\em input membership layer}. It implements the input membership functions. The membership functions are bell-shaped and are described as
\[
\mu_{ji}^h=\exp\left\{-\left(\frac{x_i-m_{ji}^h}{\sigma_{ji}^h}\right)^2\right\},
\]
where $j=1,2,\ldots, p$, the parameter $m_{ji}^h$ is the mean of $\mu_{ji}^h$, and the parameter $\sigma_{ji}^h$, the variance, is responsible for the shape of $\mu_{ji}^h$.\\
The outputs of the input membership function layer feed the {\em rule layer}. This layer contains one node for each rule. Each rule node of the layer performs a product of its inputs.
The outputs of the rule nodes are connected via {\em output membership functions} nodes to the {\em defuzzification layer} that generates crisp output signals of the form
\[
y=\frac{\sum_{k=1}^{r}u_k m_k^o/ \sigma_k^o}{\sum_{k=1}^{r}u_k /\sigma_k^o},
\]
where
\[
u_k=\prod_{j=1}^{p}\mu_{kj}^h
\] 
is the output from the $k$th output membership function node, and
\[
\mu_k^o=\exp \left\{-\left(\frac{v-m_k^o}{\sigma_k^o}\right)^2 \right\}.
\]
Observe that the above network implements the fuzzy logic controller discussed at the beginning of the section.\\
We now present an approach to training the above neural-network-based controller. We discuss the training process next.
\section{Training Algorithm}
To train the network we will use the back-propagation algorithm. The cost function to be minimized is
\[
E=\frac{1}{2}\left(y_d-y\right)^2,
\]
where $y_d$ is the desired output and $y$ is the actual output from the network. We will use a gradient algorithm to minimize $E$ over all
\[
\mb{\bm$w$}=\left\{m_{ji}^h, \: \sigma _{ji}^h,\: m_l^o,\:\sigma_l^o \right\}.
\]
The gradient algorithm we will use has the form
\[
\mb{\bm$w$}^{(k+1)}=\mb{\bm$w$}^{(k)}-\eta \nabla E\left(\mb{\bm$w$}^{(k)}\right),
\]
where $\eta$ is a fixed step size.\\
In order to be able to use the above algorithm we need to compute the partial derivatives of $E$ with respect to each component of $\mb{\bm$w$}$. For this we first fix indices $i$, $j$, and $l$. We first compute the partial derivatives of $E$ with respect to $m_s^o$ and $\sigma_s^o$. We obtain
\begin{eqnarray*}
\frac{\partial E}{\partial m_s^o}\left(\mb{\bm$w$}\right)&=&\frac{\partial}{\partial m_s^o}\left(\frac{1}{2}\left(y_d-y\right)^2\right)\\
&=&\frac{\partial}{\partial m_s^o}\left(\frac{1}{2}\left(y_d-\frac{\sum_{l=1}^{r}u_l m_l^o/ \sigma_l^o}{\sum_{l=1}^{r} u_l /\sigma_l^o}\right)^2\right)\\
&=&-\left(y_d-y\right)\frac{u_s/ \sigma_s^o}{\sum_{l=1}^{r}u_l / \sigma_l^o},
\end{eqnarray*}
and
\[
\frac{\partial E}{\partial \sigma_s^o}\left(\mb{\bm$w$}\right)=-\left(y_d-y\right)\frac{-\left(u_sm_s^o/\left(\sigma _s ^o \right)^2\right)\left(\sum_{l=1}^{r}u_l/ \sigma_l^o\right)+u_s/\left(\sigma _s^o\right)^2\sum_{l=1}^{r}u_lm_l^o /\sigma_l^o}{\left(\sum_{l=1}^{r}u_l / \sigma_l^o\right)^2}.
\]
For simplicity of notation, let
\[
\delta_s=\left(y_d-y\right)\frac{-\left(u_sm_s^o/\left(\sigma _s ^o \right)^2\right)\left(\sum_{l=1}^{r}u_l/ \sigma_l^o\right)+u_s/\left(\sigma _s^o\right)^2\sum_{l=1}^{r}u_lm_l^o /\sigma_l^o}{\left(\sum_{l=1}^{r}u_l / \sigma_l^o\right)^2}.
\]
Then
\[
\frac{\partial E}{\partial \sigma_s^o}\left(\mb{\bm$w$}\right)=-\delta_s.
\]
We next compute the partial derivatives of $E$ with respect to $m_{ji}^h$, and $\sigma _{ji}^h$. For this we represent $E$ as
\begin{eqnarray*}
E\left(\mb{\bm$w$}\right)&=&\frac{1}{2}\left(y_d-\frac{\sum_{l=1}^{r}u_l m_l^o / \sigma_l^o}{\sum_{l=1}^{r} u_l / \sigma_l^o}\right)^2\\
&=&\frac{1}{2}\left(y_d-\frac{\sum_{l=1}^{r}m_l^o / \sigma_l^o \prod_{j=1}^{p}\mu_{lj}^h}{\sum_{l=1}^{r}1/\sigma_l^o \prod_{j=1}^{p}\mu_{lj}^h}\right)^2\\
&=&\frac{1}{2}\left(y_d-\frac{\sum_{l=1}^{r}m_l^o / \sigma_l^o \prod_{j=1}^{p} \exp\left\{-\left(\frac{x_{j_i}-m_{lj}^h}{\sigma_{lj}^h}\right) ^2\right\}}{\sum_{l=1}^{r} 1/\sigma_l^o \prod_{j=1}^{p}\exp\left\{-\left(\frac{x_{j_i}-m_{lj}^h}{\sigma_{lj}^h}\right) ^2 \right\}}\right)^2,
\end{eqnarray*}
where the notation $x_{j_i}$ is used to indicate the way $x_i$s enter $\mu_{lj}^h$ in order to extract from example data a meaningful set of fuzzy IF-THEN rules.\\
Using the Chain Rule again, we now compute the partial derivative of $E$ with respect to $m_{st}^h$ to get
\begin{eqnarray*}
\frac{\partial E}{\partial m_{st}^h}\left(\mb{\bm$w$}\right)&=&-\left(y_d-y\right)\frac{\partial}{\partial u_s}\left( \frac{\sum_{l=1}^{r}u_l m_l^o /\sigma _l^o}{\sum_{l=1}^{r}u_l / \sigma_l^o} \right) \frac{\partial u_s}{\partial m_{st}^h}\\
&=&-\left(y_d-y\right)\frac{m_s^o/\sigma_s^o\left(\sum_{l=1}^{r}u_l /\sigma_l^o\right)-\left(1/\sigma_s^o \right)\left(\sum_{l=1}^{r}u_lm_l^o/ \sigma_l^o \right)}{\left(\sum_{l=1}^{r}u_l/ \sigma_l^o \right)^2}\frac{\partial u_s}{\partial m_{st}^h}.
\end{eqnarray*}
Let
\[
\delta_s^h=\left(y_d-y\right)\frac{m_s^o/\sigma_s^o\left(\sum_{l=1}^{r}u_l /\sigma_l^o\right)-\left(1/\sigma_s^o \right)\left(\sum_{l=1}^{r}u_lm_l^o/ \sigma_l^o \right)}{\left(\sum_{l=1}^{r}u_l/ \sigma_l^o \right)^2}.
\]
Then
\[
\frac{\partial E}{\partial m_{st}^h}\left(\mb{\bm$w$}\right)=-\delta_s^h\frac{\partial u_s}{\partial m_{st}^h}.
\]
We continue applying the chain rule to get
\begin{eqnarray*}
\frac{\partial E}{\partial m_{st}^h}\left(\mb{\bm$w$}\right)&=&-\delta_s^h\prod_{{j=1}\atop{j \ne t}}^{p}\mu_{sj} \, \frac{\partial}{\partial m_{st}^h}\left(\exp\left\{-\left(\frac{x_{j_i}-m_{st}^h}{\sigma_{st}^h}\right)^2\right\}\right)\\
&=&-2\delta_s^h u_s \frac{x_{j_i}-m_{st}^h}{\left(\sigma_{st}^h\right)^2}.
\end{eqnarray*}
Using the Chain Rule again, we compute the partial derivative of $E$ with respect to $\sigma_{st}^{h}$ to obtain
\[
\frac{\partial E}{\partial \sigma_{st}^h}\left(\mb{\bm$w$}\right)=-2\delta_s^h u_s \frac{\left(x_{ji}-m_{st}^h \right)^2}{\left(\sigma_{st}^h\right)^3}.
\] 
We are now ready to formulate the gradient algorithm for updating the weights of the fuzzy neural-network-based controller. We have
\begin{eqnarray*}
m_s^{o(k+1)}&=&m_s^{o(k)}+\eta \left(y_d-y^{(k)}\right)\frac{u_s^{(k)} / \sigma_s^{o(k)}}{\sum_{l=1}^{r}u_l^{(k)} /\sigma_l^{o(k)}},\\
\sigma_s^{o(k+1)}&=&\sigma_s^{(k)}+\eta \delta_s^{(k)},\\
m_{st}^{h(k+1)}&=&m_{st}^{h(k)}+2\eta\delta_s^{h(k)} u_s^{(k)} \frac{x_{j_i}-m_{st}^{h(k)}}{\left(\sigma_{st}^{h(k)}\right)^2},\\
\sigma_{st}^{h(k+1)}&=&\sigma_{st}^{h(k)}+2 \eta \delta_s^{h(k)} u_s^{(k)} \frac{\left(x_{ji}-m_{st}^{h(k)} \right)^2}{\left(\sigma_{st}^{h(k)}\right)^3}.
\end{eqnarray*}

\section{Notes}
\section{Exercises}
\begin{exercise}\rm
Show
\end{exercise}