# pem

Prediction error minimization for refining linear and nonlinear models

## Syntax

``sys = pem(data,init_sys)``
``sys = pem(data,init_sys,opt)``

## Description

example

````sys = pem(data,init_sys)` updates the parameters of an initial model `init_sys` to fit the estimation data in `data`. `data` can be a timetable, a comma-separated pair of matrices, or a data object.The function uses prediction-error minimization algorithm to update the parameters of the initial model. Use this command to refine the parameters of a previously estimated model.```

example

````sys = pem(data,init_sys,opt)` specifies estimation options using an option set.```

## Examples

collapse all

Estimate a discrete-time state-space model using `n4sid`, which applies the subspace method.

Load the data and extract the first 300 points for the estimation data.

```load sdata7 tt7; tt7e = tt7(1:300,:);```

Estimate the model `init_sys`, setting the `'Focus'` option to `'simulation'`.

```opt = n4sidOptions('Focus','simulation'); init_sys = n4sid(tt7e,4,opt);```

Show the estimation fit.

`init_sys.Report.Fit.FitPercent`
```ans = 73.8490 ```

Use `pem` to improve the closeness of the fit.

`sys = pem(tt7e,init_sys);`

Analyze the results.

`compare(tt7e,sys,init_sys);`

Using `pem` improves the fit to the estimation data.

Estimate the parameters of a nonlinear grey-box model to fit DC motor data.

Load the experimental data, and specify the signal attributes such as start time and units.

```load(fullfile(matlabroot,'toolbox','ident','iddemos','data','dcmotordata')); data = iddata(y, u, 0.1); data.Tstart = 0; data.TimeUnit = 's';```

Configure the nonlinear grey-box model (`idnlgrey`) model.

For this example, use `dcmotor_m.m` file. To view this file, type `edit dcmotor_m.m` at the MATLAB® command prompt.

```file_name = 'dcmotor_m'; order = [2 1 2]; parameters = [1;0.28]; initial_states = [0;0]; Ts = 0; init_sys = idnlgrey(file_name,order,parameters,initial_states,Ts); init_sys.TimeUnit = 's'; setinit(init_sys,'Fixed',{false false});```

`init_sys` is a nonlinear grey-box model with its structure described by `dcmotor_m.m`. The model has one input, two outputs and two states, as specified by `order`.

`setinit(init_sys,'Fixed',{false false})` specifies that the initial states of `init_sys` are free estimation parameters.

Estimate the model parameters and initial states.

`sys = pem(data,init_sys);`

`sys` is an `idnlgrey` model, which encapsulates the estimated parameters and their covariance.

Analyze the estimation result.

`compare(data,sys,init_sys);`

`sys` provides a 98.34% fit to the estimation data.

Create a process model structure and update its parameter values to minimize prediction error.

Initialize the coefficients of a process model.

```init_sys = idproc('P2UDZ'); init_sys.Kp = 10; init_sys.Tw = 0.4; init_sys.Zeta = 0.5; init_sys.Td = 0.25; init_sys.Tz = 0.01;```

The `Kp`, `Tw`, `Zeta`, `Td`, and `Tz` coefficients of `init_sys` are configured with their initial guesses.

Use `init_sys` to configure the estimation of a prediction error minimizing model using measured data. Because `init_sys` is an `idproc` model, use `procestOptions` to create the option set.

```load iddata1 z1; opt = procestOptions('Display','on','SearchMethod','lm'); sys = pem(z1,init_sys,opt);```
```Process Model Identification Estimation data: Time domain data z1 Data has 1 outputs, 1 inputs and 300 samples. Model Type: {'P2DUZ'} Algorithm: Levenberg-Marquardt search <br> ------------------------------------------------------------------------------------------ <br> Norm of First-order Improvement (%) <br> Iteration Cost step optimality Expected Achieved Bisections <br>------------------------------------------------------------------------------------------ 0 29.7194 - 260 2.57 - - 1 28.6801 6 98.9 2.57 3.5 0 2 8.38196 4.91 42.2 2.72 70.8 0 3 8.2138 0.704 41.3 1.37 2.01 12 4 8.00237 0.528 48.3 2.89 2.57 9 5 7.65577 0.588 73.1 2.02 4.33 9 6 6.851 0.809 196 4.51 10.5 9 7 5.72335 1.08 459 4.59 16.5 8 8 3.3434 2.11 1.63e+03 11.4 41.6 7 9 1.80724 0.701 504 14.2 45.9 0 10 1.6812 0.122 12 4.24 6.97 0 11 1.68092 0.014 1.11 0.309 0.0168 0 12 1.68092 0.00179 0.0215 0.3 0.000101 0 13 1.68092 0.000112 0.00634 0.3 8.26e-07 0 14 1.68092 1.36e-05 0.000382 0.3 7.62e-09 0 15 1.68092 1.18e-06 5.01e-05 0.3 7.28e-11 0 16 1.68092 1.23e-07 4.29e-06 0.3 7e-13 0 17 1.68092 1.17e-08 4.56e-07 0.3 2.64e-14 0 ------------------------------------------------------------------------------------------ Termination condition: No improvement along the search direction with line search.. Number of iterations: 18, Number of function evaluations: 115 Status: Estimated using PEM Fit to estimation data: 70.57%, FPE: 1.7379 ```

Examine the model fit.

`sys.Report.Fit.FitPercent`
```ans = 70.5666 ```

`sys` provides a 70.63% fit to the measured data.

## Input Arguments

collapse all

Uniformly sampled estimation data, specified as a timetable, a comma-separated matrix pair, or a data object, as the following sections describe. For multiexperiment data, `data` can also be a 1-by-Ne cell array of timetables or matrix pairs, where Ne is the number of experiments. Data objects accommodate multiexperiment data within the object.

#### Timetable

Specify `data` as a `timetable` that uses a regularly spaced time vector. `tt` contains variables representing input and output channels. `pem` derives the input and output channel variables from the model passed as an input argument.

#### Comma-Separated Matrix Pair

Specify `data` as a comma-separated pair of real-valued matrices that contain input and output time-domain signal values.

• For SISO systems, specify `data` as a pair of Ns-by-1 real-valued matrices that contain uniformly sampled input and output time-domain signal values. Here, Ns is the number of samples.

• For MIMO systems, specify `u`,`y` as an input/output matrix pair with the following dimensions:

• `u`Ns-by-Nu, where Nu is the number of inputs.

• `y`Ns-by-Ny, where Ny is the number of outputs.

#### Data Object

Specify data as an `iddata`, `idfrd`, or `frd` object.

If the model passed as an input arguments is:

• A parametric model such as `idss`, then `data` can be an `iddata`, `idfrd`, or `frd` model object.

• A frequency-response data model (either an `idfrd`, or `frd` model object), then `data` must also be a frequency-response data model.

• An `iddata` object, then `data` must be an `iddata` object with matching domain, number of experiments and time or frequency vectors.

For more information about working with estimation data types, see Data Domains and Data Types in System Identification Toolbox.

Identified model that configures the initial parameterization of `sys`, specified as a linear, or nonlinear model. You can obtain `init_sys` by performing an estimation using measured data or by direct construction.

`init_sys` must have finite parameter values. You can configure initial guesses, specify minimum/maximum bounds, and fix or free for estimating any parameter of `init_sys`:

• For linear models, use the `Structure` property. For more information, see Imposing Constraints on Model Parameter Values.

• For nonlinear grey-box models, use the `InitialStates` and `Parameters` properties. Parameter constraints cannot be specified for nonlinear ARX and Hammerstein-Wiener models.

Estimation options that configure the algorithm settings, handling of estimation focus, initial conditions, and data offsets, specified as an option set. The command used to create the option set depends on the initial model type:

## Output Arguments

collapse all

Identified model, returned as the same model type as `init_sys`. The model is obtained by estimating the free parameters of `init_sys` using the prediction error minimization algorithm.

## Algorithms

PEM uses numerical optimization to minimize the cost function, a weighted norm of the prediction error, defined as follows for scalar outputs:

`${V}_{N}\left(G,H\right)=\sum _{t=1}^{N}{e}^{2}\left(t\right)$`

where e(t) is the difference between the measured output and the predicted output of the model. For a linear model, the error is defined as:

`$e\left(t\right)={H}^{-1}\left(q\right)\left[y\left(t\right)-G\left(q\right)u\left(t\right)\right]$`

where e(t) is a vector and the cost function ${V}_{N}\left(G,H\right)$ is a scalar value. The subscript N indicates that the cost function is a function of the number of data samples and becomes more accurate for larger values of N. For multiple-output models, the previous equation is more complex. For more information, see chapter 7 in System Identification: Theory for the User, Second Edition, by Lennart Ljung, Prentice Hall PTR, 1999.

## Alternative Functionality

You can achieve the same results as `pem` by using dedicated estimation commands for the various model structures. For example, use `ssest(data,init_sys)` for estimating state-space models.

## Version History

Introduced before R2006a