{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Set Specific Lags\n", "\n", "Example created by Wilson Rocha Lacerda Junior\n", "\n", "> **Looking for more details on NARMAX models?**\n", "> For comprehensive information on models, methods, and a wide range of examples and benchmarks implemented in SysIdentPy, check out our book:\n", "> [*Nonlinear System Identification and Forecasting: Theory and Practice With SysIdentPy*](https://sysidentpy.org/book/0%20-%20Preface/)\n", ">\n", "> This book provides in-depth guidance to support your work with SysIdentPy." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Different ways to set the maximum lag for input and output" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pip install sysidentpy" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from sysidentpy.model_structure_selection import FROLS\n", "from sysidentpy.basis_function import Polynomial" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setting lags using a range of values\n", "\n", "If you pass int values for *ylag* and *xlag*, the lags are defined as a range from 1-*ylag* and 1-*xlag*. \n", "\n", "For example: if *ylag=4* then the candidate regressors are $y_{k-1}, y_{k-2}, y_{k-3}, y_{k-4}$" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "scrolled": false }, "outputs": [], "source": [ "basis_function = Polynomial(degree=1)\n", "\n", "model = FROLS(\n", " order_selection=True,\n", " ylag=4,\n", " xlag=4,\n", " info_criteria=\"aic\",\n", " basis_function=basis_function,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setting specific lags using lists\n", "\n", "If you pass the *ylag* and *xlag* as a list, only the lags related to values in the list will be created.\n", "$y_{k-1}, y_{k-4}$, $x_{k-1}, x_{k-4}$" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "model = FROLS(\n", " order_selection=True,\n", " ylag=[1, 4],\n", " xlag=[1, 4],\n", " info_criteria=\"aic\",\n", " basis_function=basis_function,\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Setting lags for Multiple Input Single Output (MISO) models\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# The example considers a model with 2 inputs, but you can use the same for any amount of inputs.\n", "\n", "model = FROLS(\n", " order_selection=True,\n", " ylag=[1, 4],\n", " xlag=[[1, 2, 3, 4], [1, 7]],\n", " info_criteria=\"aic\",\n", " basis_function=basis_function,\n", ")\n", "# The lags defined are:\n", "# x1(k-1), x1(k-2), x(k-3), x(k-4)\n", "# x2(k-1), x1(k-7)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "interpreter": { "hash": "0e65fe37feb8ff9f7778552a28949e943d61f86c936833305e2c18cda5b438ac" }, "kernelspec": { "display_name": "Python 3.8.11 64-bit ('rd': conda)", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 4 }