This topic describes how the software evaluates the output
of nonlinearity estimators and uses this output to compute the response
of a nonlinear ARX model.

### Simulation and Prediction of Sigmoid Network

This example shows how the software computes the simulated and
predicted output of a nonlinear ARX model as a result of evaluating
the output of its nonlinearity estimator for given regressor values.

Estimating and Exploring a Nonlinear ARX Model

Estimate nonlinear ARX model with sigmoid network nonlinearity.

Inspect the model properties and estimation result.

Nonlinear ARX model with 1 output and 1 input
Inputs: u1
Outputs: y1
Regressors:
Linear regressors in variables y1, u1
Output function: Sigmoid Network with 10 units
Sample time: 0.2 seconds
Status:
Estimated using NLARX on time domain data "estData".
Fit to estimation data: 96.31% (prediction focus)
FPE: 4.804e-05, MSE: 4.666e-05

This command provides information about input and output variables, regressors, and nonlinearity estimator.

Inspect the nonlinearity estimator.

NL =
Sigmoid Network
Inputs: y1(t-1), u1(t)
Output: y1
Nonlinear Function: Sigmoid network with 10 units.
Linear Function: initialized to [-0.161 -0.105]
Output Offset: initialized to 0.271
Input: [1x1 idpack.Channel]
Output: [1x1 idpack.Channel]
LinearFcn: [1x1 nlident.internal.UseProjectedLinearFcn]
NonlinearFcn: [1x1 nlident.internal.RidgenetFcn]
Offset: [1x1 nlident.internal.ChooseableOffset]

Inspect the sigmoid network parameter values.

Prediction of Output

The model output is:

*y1(t)= f(y1(t-1),u1(t))*

where *f* is the sigmoid network function. The model regressors *y1(t-1)* and *u1(t)* are inputs to the nonlinearity estimator. Time *t* is a discrete variable representing *kT* , where `k = 0, 1, ... ,`

and *T* is the sampling interval. In this example, `T=0.2`

second.

The output prediction equation is:

*yp(t)=f(y1_meas(t-1),u1_meas(t))*

where *yp(t)* is the predicted value of the response at time *t*. *y1_meas(t-1)* and *u1_meas(t)* are the measured output and input values at times *t-1* and *t*, respectively.

Computing the predicted response includes:

To compute the predicted value of the response using initial conditions and current input:

Estimate model from data and get nonlinearity parameters.

Specify zero initial states.

The model has one state because there is only one delayed term `y1(t-1)`

. The number of states is equal to `sum(getDelayInfo(M))`

.

Compute the predicted output at time *t*=0.

`RegValue`

is the vector of regressors at `t=0`

. The predicted output is *yp(t=0)=f(y1_meas(t=-1),u1_meas(t=0))*. In terms of MATLAB variables, this output is `f(0,estData.u(1))`

, where

*y1_meas(t*=0) is the measured output value at `t=0`

, which is to `estData.y(1)`

.

*u1_meas(t* =1) is the second input data sample `estData.u(2)`

.

Perform one-step-ahead prediction at all time values for which data is available.

This code obtains a matrix of regressors `RegMat`

for all the time samples using `getreg`

. `RegMat`

has as many rows as there are time samples, and as many columns as there are regressors in the model - two, in this example.

These steps are equivalent to the predicted response computed in a single step using predict:

Simulation of Output

The model output is:

*y1(t)=f(y1(t-1),u1(t))*

where *f* is the sigmoid network function. The model regressors *y1(t-1)* and *u1(t)* are inputs to the nonlinearity estimator. Time *t* is a discrete variable representing *kT* , where *k*= 0, 1,.., and *T* is the sampling interval. In this example, *T*=0.2 second.

The simulated output is:

*ys(t) = f(ys(t-1),u1_meas(t))*

where *ys(t)* is the simulated value of the response at time *t*. The simulation equation is the same as the prediction equation, except that the past output value `ys(t-1)`

results from the simulation at the previous time step, rather than the measured output value.

Computing the simulated response includes:

To compute the simulated value of the response using initial conditions and current input:

Estimate model from data and get nonlinearity parameters.

Specify zero initial states.

The model has one state because there is only one delayed term *y1(t-1)*. The number of states is equal to `sum(getDelayInfo(M))`

.

Compute the simulated output at time *t* =0, *ys(t=0)*.

RegValue is the vector of regressors at *t*=0. *ys(t=0)=f(y1(t=-1),u1_meas(t=0))*. In terms of MATLAB variables, this output is `f(0,estData.u(1))`

, where

*y1(t=-1)* is the initial state `x0 (=0)`

.

*u1_meas(t=0)* is the value of the input at *t* =0, which is the first input data sample `estData.u(1)`

.

Compute the simulated output at time *t*=1, *ys(t*=1).

The simulated output *ys(t=1)=f(ys(t=0),u1_meas(t=1))*. In terms of MATLAB variables, this output is `f(ys_0,estData.u(2))`

, where

Compute the simulated output at time *t*=2.

Unlike for output prediction, you cannot use `getreg`

to compute regressor values for all time values. You must compute regressors values at each time sample separately because the output samples required for forming the regressor vector are available iteratively, one sample at a time.

These steps are equivalent to the simulated response computed in a single step using `sim(idnlarx)`

:

Nonlinearity Evaluation

This examples performs a low-level computation of the nonlinearity response for the `sigmoidnet`

network function:

$$\begin{array}{l}F(x)=(x-r)PL+{a}_{1}f\left(\left(x-r\right)Q{b}_{1}+{c}_{1}\right)+\dots \\ +{a}_{n}f\left(\left(x-r\right)Q{b}_{n}+{c}_{n}\right)+d\end{array}$$

where *f* is the sigmoid function, given by the following equation:

$$f(z)=\frac{1}{{e}^{-z}+1}$$

In `F(x)`

, the input to the sigmoid function is `x-r`

. `x`

is the regressor value and `r`

is regressor mean, computed from the estimation data. $${a}_{n}$$ , $${n}_{n}$$, and $${c}_{n}$$ are the network parameters stored in the model property `M.nl.par`

, where `M`

is an `idnlarx`

object.

Compute the output value at time t=1, when the regressor values are `x=[estData.y(1),estData.u(2)]`

:

Estimate model from sample data.

Assign values to the parameters in the expression for `F(x)`

.

Compute the linear portion of the response (plus offset).

Compute the nonlinear portion of the response.

Compute total response `y = F(x) = yLinear + yNonlinear`

.

`y`

is equal to `evaluate(NL,x)`

.