{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# V0.1.6 - Setting specific lags\n",
    "\n",
    "Example created by Wilson Rocha Lacerda Junior"
   ]
  },
  {
   "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": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from sysidentpy.polynomial_basis import PolynomialNarmax"
   ]
  },
  {
   "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": 7,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[   0],\n",
       "       [1001],\n",
       "       [1002],\n",
       "       [1003],\n",
       "       [1004],\n",
       "       [2001],\n",
       "       [2002],\n",
       "       [2003],\n",
       "       [2004]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = PolynomialNarmax(non_degree=1,\n",
    "                         order_selection=True,\n",
    "                         n_info_values=10,\n",
    "                         extended_least_squares=False,\n",
    "                         ylag=4, xlag=4,\n",
    "                         info_criteria='aic',\n",
    "                         estimator='least_squares',\n",
    "                         )\n",
    "\n",
    "model.regressor_code"
   ]
  },
  {
   "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."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[   0],\n",
       "       [1001],\n",
       "       [1004],\n",
       "       [2001],\n",
       "       [2004]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = PolynomialNarmax(non_degree=1,\n",
    "                         order_selection=True,\n",
    "                         n_info_values=10,\n",
    "                         extended_least_squares=False,\n",
    "                         ylag=[1, 4], xlag=[1, 4],\n",
    "                         info_criteria='aic',\n",
    "                         estimator='least_squares',\n",
    "                         )\n",
    "\n",
    "model.regressor_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.6 64-bit ('p-data-science': conda)",
   "language": "python",
   "name": "python37664bitpdatascienceconda518311c1ac6644f6a39b768ea8138c75"
  },
  "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.7.6-final"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
