fd2tp#

fastcan.narx.fd2tp(feat_ids, delay_ids)#

Convert feat_ids and delay_ids to time_shift_ids and poly_ids. The polynomial terms, e.g., x0(k-1)^2, x0(k-2)x1(k-3), can be represented by two ways:

  1. feat_ids and delay_ids, e.g., [[0, 0], [0, 1]] and [[1, 1], [2, 3]]

  2. time_shift_ids and poly_ids, e.g., [[0, 1], [0, 2], [1, 3]] and [[1, 1], [2, 3]]

For feat_ids, [0, 0] and [0, 1] represent x0*x0 and x0*x1, while for delay_ids, [1, 1] and [2, 3] represent the delays of features in feat_ids.

For time_shift_ids, [0, 1], [0, 2], and [1, 3] represents x0(k-1), x0(k-2), and x1(k-3), respectively. For poly_ids, [1, 1] and [2, 3] represent the first variable multiplying the first variable given by time_shift_ids, i.e., x0(k-1)*x0(k-1), and the second variable multiplying the third variable, i.e., x0(k-1)*x1(k-3).

Parameters:
  • feat_ids (array-like of shape (n_terms, degree), default=None) – The unique id numbers of features to form polynomial terms. The id -1 stands for the constant 1. The id 0 to n are the index of features.

  • delay_ids (array-like of shape (n_terms, degree), default=None) – The delays of each feature in polynomial terms. The id -1 stands for empty. The id 0 stands for 0 delay. The positive integer id k stands for k-th delay.

Returns:

  • time_shift_ids (array-like of shape (n_variables, 2), default=None) – The unique id numbers of time shift variables, which are (feature_idx, delay).

  • poly_ids (array-like of shape (n_polys, degree), default=None) – The unique id numbers of polynomial terms, excluding the intercept. The id -1 stands for the constant 1. The id 0 to n-1 are the index of time_shift_ids.

Examples

>>> from fastcan.narx import fd2tp
>>> # Encode x0(k-1), x0(k-2)x1(k-3)
>>> feat_ids = [[-1, 0], [0, 1]]
>>> delay_ids = [[-1, 1], [2, 3]]
>>> time_shift_ids, poly_ids = fd2tp(feat_ids, delay_ids)
>>> print(time_shift_ids)
[[0 1]
 [0 2]
 [1 3]]
>>> print(poly_ids)
[[-1  0]
 [ 1  2]]