Main Content

customRegressor

Specify custom regressor for nonlinear ARX model

Description

A custom regressor represents a single user-provided formula that operates on delayed input and output variables. For example,y(t–1)eu(t–1)is a custom regressor that you can construct using the formula@(x,y)x.*exp(y). AcustomRegressorobject encapsulates a set of custom regressors. UsecustomRegressorobjects when you create nonlinear ARX models usingidnlarxornlarx. You can specifycustomRegressorobjects along withlinearRegressor,polynomialRegressor, andperiodicRegressorobjects and combine them into a single combined regressor set.

Creation

Description

example

cReg= customRegressor(Variables,Lags,Fcn)creates acustomRegressorobject, with the output and input names inVariables, the corresponding lags inlags, and the function handle inFcn.Fcnsets theVariablesToRegressorFcnproperty. For example, ifVariablescontains'y',lagscontains the corresponding lag vector[2 4], and the custom function is@(x)sin(x), then the regressors that use'y'are sin(y(t–2)) and sin(y(t–4)).

cReg= customRegressor(变量、滞后Fcn矢量化)specifies whetherFcncan process a vector of inputs to return a vector of output values, based on the value ofVectorized.

Properties

expand all

Custom function that transforms a set of delayed variables into a numeric scalar output, specified as a function handle.

Example:@(x)sin(x)

Example:@(x,y)x.*exp(y)

Output and input variable names, specified as a cell array of strings or a cell array that references theOutputNameandInputNameproperties of aniddataobject. Each entry must be a string with no special characters other than white space.

Example:{'y1','u1'}

Example:[z.OutputName; z.InputName]

lags in each variable, specified as a 1-by-nvcell array of non-negative integer row vectors, wherenvis the total number of regressor variables. Each row vector containsnrintegers that specify thenr回归or lags for the corresponding variable. Whennr>1 for at least one of the variables, then the software generates a regressor for every lag combination. For instance, suppose that you want to create the formular(t) = sin(y1(ta))cos(u1(tb)), where lagacan be1or2and lagbcan be0or3. Specifylagsas{[1 2],[0 3]}, which corresponds to the variables{'y1','u1'}. This specification creates the following set of regressors:

  • 'sin(y1(t-1))*cos(u1(t))'

  • 'sin(y1(t-1))*cos(u1(t-3))'

  • 'sin(y1(t-2))*cos(u1(t))'

  • 'sin(y1(t-2))*cos(u1(t-3))'

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

Example:{1 1}

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

Vectorization indicator that determines whetherVariablesToRegressorFcnis vectorized , specified astrueorfalse.

For an example of setting this property, seeUse Absolute Value in Polynomial Regressor Set.

Example:[true,false]

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

Example:'ClockTime'

Examples

collapse all

Create a custom regressor that represents the formula x e y .

Specify the input variables as'u1' and'y1' and corresponding lags of1and3delays.

vars = {'y1','u1'}; lags = {1 3};

Specify the custom function.

fcn = @(x,y)x.*exp(y);

Create the regressor.

cReg = customRegressor(vars,lags,fcn)
cReg = Custom regressor: y1(t-1).*exp(u1(t-3)) VariablesToRegressorFcn: @(x,y)x.*exp(y) Variables: {'y1' 'u1'} Lags: {[1] [3]} Vectorized: 1 TimeVariable: 't' Regressors described by this set

Create a set of custom regressors in three variables, all based on the formula xy + sin ( z ) .

Specify the variable names and the lags.

vars = {'a','b','c'}; lags = {[1 5],[0 8],7};

Specify the custom function.

fcn = @(x,y,z)x.*y+sin(z);

Create the custom regressor set.

cReg = customRegressor(vars,lags,fcn)
cReg = Custom regressor: @(x,y,z)x.*y+sin(z) VariablesToRegressorFcn: @(x,y,z)x.*y+sin(z) Variables: {'a' 'b' 'c'} Lags: {[1 5] [0 8] [7]} Vectorized: 1 TimeVariable: 't' Regressors described by this set

cRegspecifies regressors for all possible lag combinations.

load the estimation dataz1, which has one input and one output, and obtain the output and input names.

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

Specifylas the set of linear regressors that represents y 1 ( t - 1 ) , u 1 ( t - 2 ) , and u 1 ( t - 5 ) .

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

SpecifyPas the polynomial regressor y 1 ( t - 1 ) 2 .

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

SpecifyCas the custom regressor y 1 ( t - 2 ) u 1 ( 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' Regressors described by this set

Combine the regressors in the column vectorR.

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' Regressors described by this set

Estimate a nonlinear ARX model withR.

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) List of all regressors 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