tp2fd#

fastcan.narx.tp2fd(time_shift_ids, poly_ids)#

Convert time_shift_ids and poly_ids to feat_ids and delay_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:
  • time_shift_ids (array-like of shape (n_variables, 2)) – The unique id numbers of time shift variables, which are (feature_idx, delay).

  • poly_ids (array-like of shape (n_polys, degree)) – 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.

Returns:

  • 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.

Examples

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