Main Content

linearRegressor

Specify linear regressor for nonlinear ARX model

Since R2021a

Description

A linear regressor is a lagged output or input variable, such as y(t-1) or u(t-2). Here, the y term has a lag of 1 sample and the u term has a lag of 2 samples. A linearRegressor object encapsulates a set of linear regressors. Use linearRegressor objects when you create nonlinear ARX models using idnlarx or nlarx. linearRegressor generalizes the concept of orders in ARX models, or in other words, the [na nb nk] matrix, to allow absolute values and noncontiguous lags. Using linearRegressor objects also lets you combine linear regressors with polynomialRegressor, periodicRegressor, and customRegressor objects in a single regressor set.

Creation

Description

lReg = linearRegressor(Variables,Lags) creates a linearRegressor object that contains output and input names in Variables and the corresponding lags in Lags.

example

lreg = linearRegressor(Variables,Lags,useAbsolute) specifies in UseAbsolute whether to use the absolute values of the variables to create the regressors.

example

Properties

expand all

Output and input variable names, specified as a cell array of strings or a cell array that references the OutputName and InputName properties of an iddata object. Each entry must be a string with no special characters other than white space. For an example of using this property, see Estimate Nonlinear ARX Model Using Linear Regressor Set.

Example: {'y1','u1'}

Example: [z.OutputName; z.InputName]'

Lags in each variable, specified as a 1-by-nv cell array of non-negative integer row vectors, where nv is the total number of regressor variables. Each row vector contains nr integers that specify the nr regressor lags for the corresponding variable. For instance, suppose that you want the following regressors:

  • Output variable y1: y1(t–1) and y1(t–2)

  • Input variable u1: u1(t–3)

To obtain these lags, set Lags to {[1 2],3}.

If a lag corresponds to an output variable of an idnlarx model, the minimum lag must be greater than or equal to 1.

For an example of using this property, see Estimate Nonlinear ARX Model Using Linear Regressor Set.

Example: {1 1}

Example: {[1 2],[1,3,4]}

Absolute value indicator that determines whether to use the absolute value of a regressor variable instead of the signed value, specified as a logical vector with a length equal to the number of variables. For an example of setting this property, see Use Absolute Value in Linear Regressor Set.

Example: [true,false]

Name of the time variable, specified as a valid MATLAB® variable name that is distinct from values in Variables.

Example: 'ClockTime'

Examples

collapse all

Specify a linear regressor that is equivalent to an ARX model order matrix of [4 4 1].

An order matrix of [4 4 1] specifies that both input and output regressor sets contain four regressors with lags ranging from 1 to 4. For example, u1(t-2) represents the second input regressor.

Specify the output and input names.

output_name = 'y1';
input_name = 'u1';
names = {output_name,input_name};

Specify the output and input lags.

output_lag = [1 2 3 4];
input_lag = [1 2 3 4];
lags = {output_lag,input_lag};

Create the linear regressor object.

lreg = linearRegressor(names,lags)
lreg = 
Linear regressors in variables y1, u1
       Variables: {'y1'  'u1'}
            Lags: {[1 2 3 4]  [1 2 3 4]}
     UseAbsolute: [0 0]
    TimeVariable: 't'

Load the estimation data and create an iddata object.

load twotankdata
z = iddata(y,u,0.2);

Estimate the nonlinear ARX model.

sys = nlarx(z,lreg)
sys =

Nonlinear ARX model with 1 output and 1 input
  Inputs: u1
  Outputs: y1

Regressors:
  Linear regressors in variables y1, u1

Output function: Wavelet network with 11 units
Sample time: 0.2 seconds

Status:                                          
Estimated using NLARX on time domain data "z".   
Fit to estimation data: 96.84% (prediction focus)
FPE: 3.482e-05, MSE: 3.431e-05

View the regressors.

getreg(sys)
ans = 8x1 cell
    {'y1(t-1)'}
    {'y1(t-2)'}
    {'y1(t-3)'}
    {'y1(t-4)'}
    {'u1(t-1)'}
    {'u1(t-2)'}
    {'u1(t-3)'}
    {'u1(t-4)'}

Compare the model output to the estimation data.

compare(z,sys)

Figure contains an axes object. The axes object with ylabel y1 contains 2 objects of type line. These objects represent Validation data (y1), sys: 82.73%.

Create a linear regressor set that uses lags of 3, 10, and 100 in variable y1 and lags of 0 and 4 in variable u1.

vars = {'y1','u1'};
lags = {[3 10 100],[0,4]};

Specify that the y1 regressor use the absolute value of y1.

UseAbs = [true,false];

Create the linear regressor.

reg = linearRegressor(vars,lags,UseAbs)
reg = 
Linear regressors in variables y1, u1
       Variables: {'y1'  'u1'}
            Lags: {[3 10 100]  [0 4]}
     UseAbsolute: [1 0]
    TimeVariable: 't'

Load the estimation data z1, which has one input and one output, and obtain the output and input names.

load iddata1 z1;
names = [z1.OutputName z1.InputName]
names = 1x2 cell
    {'y1'}    {'u1'}

Specify L as the set of linear regressors that represents y1(t-1), u1(t-2), and u1(t-5).

L = linearRegressor(names,{1,[2 5]});

Specify P as the polynomial regressor y1(t-1)2.

P = polynomialRegressor(names(1),1,2);

Specify C as the custom regressor y1(t-2)u1(t-3). Use an anonymous function handle to define this function.

C = customRegressor(names,{2 3},@(x,y)x.*y)
C = 
Custom regressor: y1(t-2).*u1(t-3)
    VariablesToRegressorFcn: @(x,y)x.*y
                  Variables: {'y1'  'u1'}
                       Lags: {[2]  [3]}
                 Vectorized: 1
               TimeVariable: 't'

Combine the regressors in the column vector R.

R = [L;P;C]
R = 
[3 1] array of linearRegressor, polynomialRegressor, customRegressor objects.
------------------------------------
1. Linear regressors in variables y1, u1
       Variables: {'y1'  'u1'}
            Lags: {[1]  [2 5]}
     UseAbsolute: [0 0]
    TimeVariable: 't'

------------------------------------
2. Order 2 regressors in variables y1
               Order: 2
           Variables: {'y1'}
                Lags: {[1]}
         UseAbsolute: 0
    AllowVariableMix: 0
         AllowLagMix: 0
        TimeVariable: 't'

------------------------------------
3. Custom regressor: y1(t-2).*u1(t-3)
    VariablesToRegressorFcn: @(x,y)x.*y
                  Variables: {'y1'  'u1'}
                       Lags: {[2]  [3]}
                 Vectorized: 1
               TimeVariable: 't'

 

Estimate a nonlinear ARX model with R.

sys = nlarx(z1,R)
sys =

Nonlinear ARX model with 1 output and 1 input
  Inputs: u1
  Outputs: y1

Regressors:
  1. Linear regressors in variables y1, u1
  2. Order 2 regressors in variables y1
  3. Custom regressor: y1(t-2).*u1(t-3)

Output function: Wavelet network with 1 units
Sample time: 0.1 seconds

Status:                                          
Estimated using NLARX on time domain data "z1".  
Fit to estimation data: 59.73% (prediction focus)
FPE: 3.356, MSE: 3.147

View the full regressor set.

getreg(sys)
ans = 5x1 cell
    {'y1(t-1)'         }
    {'u1(t-2)'         }
    {'u1(t-5)'         }
    {'y1(t-1)^2'       }
    {'y1(t-2).*u1(t-3)'}

Version History

Introduced in R2021a