Setting specific lags¶
Example created by Wilson Rocha Lacerda Junior
Different ways to set the maximum lag for input and output
In [ ]:
Copied!
pip install sysidentpy
pip install sysidentpy
In [1]:
Copied!
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sysidentpy.model_structure_selection import FROLS
from sysidentpy.basis_function._basis_function import Polynomial
from sysidentpy.metrics import root_relative_squared_error
from sysidentpy.utils.generate_data import get_siso_data
from sysidentpy.utils.display_results import results
from sysidentpy.utils.plotting import plot_residues_correlation, plot_results
from sysidentpy.residues.residues_correlation import (
compute_residues_autocorrelation,
compute_cross_correlation,
)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from sysidentpy.model_structure_selection import FROLS from sysidentpy.basis_function._basis_function import Polynomial from sysidentpy.metrics import root_relative_squared_error from sysidentpy.utils.generate_data import get_siso_data from sysidentpy.utils.display_results import results from sysidentpy.utils.plotting import plot_residues_correlation, plot_results from sysidentpy.residues.residues_correlation import ( compute_residues_autocorrelation, compute_cross_correlation, )
Setting lags using a range of values¶
If you pass int values for ylag and xlag, the lags are defined as a range from 1-ylag and 1-xlag.
For example: if ylag=4 then the candidate regressors are $y_{k-1}, y_{k-2}, y_{k-3}, y_{k-4}$
In [2]:
Copied!
basis_function = Polynomial(degree=1)
model = FROLS(
order_selection=True,
extended_least_squares=False,
ylag=4,
xlag=4,
info_criteria="aic",
estimator="least_squares",
basis_function=basis_function,
)
basis_function = Polynomial(degree=1) model = FROLS( order_selection=True, extended_least_squares=False, ylag=4, xlag=4, info_criteria="aic", estimator="least_squares", basis_function=basis_function, )
c:\Users\wilso\Desktop\projects\GitHub\sysidentpy\sysidentpy\utils\deprecation.py:37: FutureWarning: Passing a string to define the estimator will rise an error in v0.4.0. You'll have to use FROLS(estimator=LeastSquares()) instead. The only change is that you'll have to define the estimator first instead of passing a string like 'least_squares'. This change will make easier to implement new estimators and it'll improve code readability. warnings.warn(message, FutureWarning)
Setting specific lags using lists¶
If you pass the ylag and xlag as a list, only the lags related to values in the list will be created.
In [3]:
Copied!
model = FROLS(
order_selection=True,
extended_least_squares=False,
ylag=[1, 4],
xlag=[1, 4],
info_criteria="aic",
estimator="least_squares",
basis_function=basis_function,
)
model = FROLS( order_selection=True, extended_least_squares=False, ylag=[1, 4], xlag=[1, 4], info_criteria="aic", estimator="least_squares", basis_function=basis_function, )
Setting lags for Multiple Input Single Output (MISO) models¶
The following example shows how to define specific lags for each input. One should notice that we have to use a nested list in that case.
In [4]:
Copied!
# The example considers a model with 2 inputs, but you can use the same for any amount of inputs.
model = FROLS(
order_selection=True,
extended_least_squares=False,
ylag=[1, 4],
xlag=[[1, 2, 3, 4], [1, 7]],
info_criteria="aic",
estimator="least_squares",
basis_function=basis_function,
)
# The lags defined are:
# x1(k-1), x1(k-2), x(k-3), x(k-4)
# x2(k-1), x1(k-7)
# The example considers a model with 2 inputs, but you can use the same for any amount of inputs. model = FROLS( order_selection=True, extended_least_squares=False, ylag=[1, 4], xlag=[[1, 2, 3, 4], [1, 7]], info_criteria="aic", estimator="least_squares", basis_function=basis_function, ) # The lags defined are: # x1(k-1), x1(k-2), x(k-3), x(k-4) # x2(k-1), x1(k-7)