Documentation for UOFR¶
Build NARMAX Models using UOFR algorithm.
Implementation Notes
This module implements the Ultra-Orthogonal Forward Regression (UOFR) algorithm as described in [1]. Some implementation decisions extend or interpret the original paper to handle practical edge cases:
-
Normalization of antisymmetric kernels (Eq. 20-21): The paper requires normalized test functions to satisfy both unit L2 norm (Eq. 20) and unit integral (Eq. 21). However, odd-order derivatives of symmetric functions (e.g., 1st and 3rd derivatives of B-splines) are antisymmetric and have zero integral by definition. This implementation applies L2 normalization and returns a separate area correction factor for cases where the integral is non-zero.
-
Length weighting for modulated signals: The convolution with 'valid' mode reduces the number of samples in modulated signals. To prevent derivative terms from being underweighted in the ULS criterion (Eq. 24), we apply a scaling factor of sqrt(N_original / N_modulated). This is not explicitly mentioned in the paper but ensures balanced contribution across all Sobolev orders.
-
Convolution vs. correlation (Eq. 25): The paper defines modulation as a sum that corresponds to cross-correlation. We implement this using np.convolve with a flipped kernel, which is mathematically equivalent to the correlation defined in Eq. 25.
-
B-spline derivatives: We use closed-form expressions for the cubic B-spline and its derivatives up to order 3, consistent with Appendix A of the paper. The cubic B-spline has continuous derivatives only up to order 2, so the 3rd derivative is piecewise constant.
References
.. [1] Guo, Y., Guo, L.Z., Billings, S.A., Wei, H.L. (2015). "Ultra-Orthogonal Forward Regression Algorithms for the Identification of Non-Linear Dynamic Systems". Neurocomputing. https://eprints.whiterose.ac.uk/107310/1/UOFR%20Algorithms%20R1.pdf
UOFR ¶
Bases: OFRBase
Ultra Orthogonal Forward Regression algorithm.
This class uses the UOFR algorithm ([1]) to build NARMAX models. The NARMAX model is described as:
where \(n_y\in \mathbb{N}^*\), \(n_x \in \mathbb{N}\), \(n_e \in \mathbb{N}\), are the maximum lags for the system output and input respectively; \(x_k \in \mathbb{R}^{n_x}\) is the system input and \(y_k \in \mathbb{R}^{n_y}\) is the system output at discrete time \(k \in \mathbb{N}^n\); \(e_k \in \mathbb{R}^{n_e}\) stands for uncertainties and possible noise at discrete time \(k\). In this case, \(\mathcal{F}\) is some nonlinear function of the input and output regressors and \(d\) is a time delay typically set to \(d=1\).
The UOFR algorithm extends the classic OFR by using the Ultra-Least Squares (ULS) criterion, which measures model fitness in the Sobolev space H^m instead of the standard L^2 space. This criterion considers not only the residuals but also the weak derivatives of the signals, providing a stricter measure of model quality.
The ULS criterion is defined as (Eq. 24 in [1]):
where \(\overline{y}^l\) and \(\overline{x}_i^l\) are the signals modulated by the normalized l-th derivative of the test function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ylag | int | The maximum lag of the output. | 2 |
xlag | int | The maximum lag of the input. | 2 |
elag | int | The maximum lag of the residues regressors. | 2 |
order_selection | bool | Whether to use information criteria for order selection. | True |
info_criteria | str | The information criteria method to be used. | "aic" |
n_terms | int | The number of the model terms to be selected. Note that n_terms overwrite the information criteria values. | None |
n_info_values | int | The number of iterations of the information criteria method. | 10 |
estimator | str | The parameter estimation method. | "least_squares" |
model_type | str | The user can choose "NARMAX", "NAR" and "NFIR" models | 'NARMAX' |
eps | float | Normalization factor of the normalized filters. | np.finfo(np.float64).eps |
alpha | float | Regularization parameter used in ridge regression. Ridge regression parameter that regularizes the algorithm to prevent over fitting. If the input is a noisy signal, the ridge parameter is likely to be set close to the noise level, at least as a starting point. Entered through the self data structure. | np.finfo(np.float64).eps |
sobolev_order | int | Number of weak derivatives included in the Ultra Least Squares (ULS) augmentation (m in the manuscript, Eq. 22). Set to zero to disable augmentation and use standard OFR. The paper recommends m=2 for most applications (using 1st and 2nd derivatives). | 2 |
test_support | int | Number of discrete samples used to represent the modulating function and its derivatives (n_0 in Eq. 25). An odd number is recommended so the kernel is centered. Larger values provide smoother modulation but reduce the number of valid samples after convolution. | 11 |
modulating_function | (bspline, gaussian) | Choice of test function used to smooth the signals before differentiating. The paper uses cubic B-spline (Appendix A) as it has finite support and continuous derivatives up to order 2. Options:
| "bspline" |
gaussian_sigma | float | Standard deviation used when | 1.0 |
Notes
Implementation decisions not explicitly covered in the paper:
-
Antisymmetric kernel normalization: Odd-order derivatives of symmetric test functions have zero integral, making Eq. 21 impossible to satisfy directly. We handle this by applying L2 normalization and tracking area correction separately.
-
Sample count balancing: Convolution reduces sample count. We scale modulated signals by sqrt(N_original/N_modulated) to maintain balanced contribution to the ULS criterion.
-
Parameter estimation: The paper states parameters should be estimated using least squares on the original problem (Step 8). This implementation uses the configured estimator on the selected model terms.
Examples:
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from sysidentpy.model_structure_selection import UOFR
>>> from sysidentpy.basis_function import Polynomial
>>> from sysidentpy.utils.display_results import results
>>> from sysidentpy.metrics import root_relative_squared_error
>>> from sysidentpy.utils.generate_data import get_siso_data
>>> x_train, x_valid, y_train, y_valid = get_siso_data(n=1000,
... colored_noise=True,
... sigma=0.2,
... train_percentage=90)
>>> basis_function = Polynomial(degree=2)
>>> model = UOFR(basis_function=basis_function,
... order_selection=True,
... n_info_values=10,
... extended_least_squares=False,
... ylag=2,
... xlag=2,
... info_criteria='aic',
... sobolev_order=2, # Use 1st and 2nd derivatives
... )
>>> model.fit(x_train, y_train)
>>> yhat = model.predict(x_valid, y_valid)
>>> rrse = root_relative_squared_error(y_valid, yhat)
>>> print(rrse)
0.001993603325328823
>>> r = pd.DataFrame(
... results(
... model.final_model, model.theta, model.err,
... model.n_terms, err_precision=8, dtype='sci'
... ),
... columns=['Regressors', 'Parameters', 'ERR'])
>>> print(r)
Regressors Parameters ERR
0 x1(k-2) 0.9000 0.0
1 y(k-1) 0.1999 0.0
2 x1(k-1)y(k-1) 0.1000 0.0
References
.. [1] Guo, Y., Guo, L.Z., Billings, S.A., Wei, H.L. (2015). "Ultra-Orthogonal Forward Regression Algorithms for the Identification of Non-Linear Dynamic Systems". Neurocomputing. https://eprints.whiterose.ac.uk/107310/1/UOFR%20Algorithms%20R1.pdf
Source code in sysidentpy/model_structure_selection/sobolev_orthogonal_forward_regression.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 | |
augment_uls_terms(y, psi, m=None) ¶
Augment the regression problem to form the ULS problem (Eq. 22-28).
Constructs the augmented matrices Y_ULS and Phi_ULS by stacking the original signals with their modulated versions for each derivative order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | ndarray | Output signal vector of shape (N,) or (N, 1). | required |
psi | ndarray | Regressor matrix of shape (N, num_terms). | required |
m | int | Sobolev order (number of derivative levels). Defaults to self.sobolev_order. | None |
Returns:
| Name | Type | Description |
|---|---|---|
y_augmented | ndarray | Augmented output vector Y_ULS as in Eq. 27. Shape: (N + m*(N-n_0), 1) |
psi_augmented | ndarray | Augmented regressor matrix Phi_ULS as in Eq. 28. Shape: (N + m*(N-n_0), num_terms) |
Notes
Implementation decisions:
-
Length weighting: The modulated signals have fewer samples (N - n_0) due to 'valid' convolution. To ensure balanced contribution to the ULS criterion, we scale by sqrt(N_original / N_modulated). This is not explicitly mentioned in the paper but prevents derivative terms from being underweighted.
-
Area correction: Applied after L2 normalization to approximate the unit integral requirement (Eq. 21) for symmetric kernels.
The augmented system has the form: [y; y_bar^1; ...; y_bar^m] = [psi; psi_bar^1; ...; psi_bar^m] * theta
where the semicolon denotes vertical stacking.
Source code in sysidentpy/model_structure_selection/sobolev_orthogonal_forward_regression.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |
compute_modulated_signal(signal, phi_bar_j) ¶
Apply discrete convolution matching Eq. 25 of the paper.
Computes the modulated signal: y_bar^l(k) = sum_{n=k}^{k+n_0} y(n) * phi_bar^l(n-k)
This is equivalent to cross-correlation, implemented via convolution with a flipped kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal | ndarray | The signal to modulate (y or x_i). | required |
phi_bar_j | ndarray | The normalized modulating kernel. | required |
Returns:
| Type | Description |
|---|---|
ndarray | Modulated signal with length N - n_0, where N is the original signal length and n_0 is the kernel support (test_support - 1). |
Raises:
| Type | Description |
|---|---|
ValueError | If the kernel is empty or larger than the signal. |
Notes
Implementation decision: We use np.convolve with mode='valid' and a flipped kernel. This is mathematically equivalent to the summation in Eq. 25:
np.convolve(signal, kernel[::-1], 'valid')[k] =
sum_{n=0}^{n_0} signal[k+n] * kernel[n]
The 'valid' mode ensures we only compute output where the full kernel overlaps with the signal, avoiding boundary effects.
Source code in sysidentpy/model_structure_selection/sobolev_orthogonal_forward_regression.py
fit(*, X=None, y) ¶
Fit polynomial NARMAX model.
This is an 'alpha' version of the 'fit' function which allows a friendly usage by the user. Given two arguments, x and y, fit training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X | ndarray of floats | The input data to be used in the training process. | None |
y | ndarray of floats | The output data to be used in the training process. | required |
Returns:
| Name | Type | Description |
|---|---|---|
model | ndarray of int | The model code representation. |
piv | array-like of shape = number_of_model_elements | Contains the index to put the regressors in the correct order based on err values. |
theta | array-like of shape = number_of_model_elements | The estimated parameters of the model. |
err | array-like of shape = number_of_model_elements | The respective ERR calculated for each regressor. |
info_values | array-like of shape = n_regressor | Vector with values of akaike's information criterion for models with N terms (where N is the vector position + 1). |
Source code in sysidentpy/model_structure_selection/sobolev_orthogonal_forward_regression.py
gaussian_test_function(t, order) ¶
Generate Gaussian-like test function and its derivatives.
Provides an alternative to B-splines with infinite smoothness, though truncated to finite support for practical computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t | ndarray | Grid points where to evaluate the function. | required |
order | int | Derivative order (0 = function itself). | required |
Returns:
| Type | Description |
|---|---|
ndarray | Gaussian or derivative values at the grid points. |
Notes
Unlike B-splines, the Gaussian has infinite derivatives. However, derivatives are computed numerically using np.gradient, which may introduce discretization errors for high orders. For high-order Sobolev spaces, consider using analytic Hermite polynomial expressions or a custom callable.
Source code in sysidentpy/model_structure_selection/sobolev_orthogonal_forward_regression.py
normalize_test_function(phi_j) ¶
Normalize test function derivative following Eq. 20-21.
The paper requires (Eq. 20): phi_bar^l = phi^(l) / ||phi^(l)||_2
And (Eq. 21): integral(phi_bar^l) = 1
However, for antisymmetric kernels (odd-order derivatives of symmetric functions), the integral is identically zero. This implementation returns the L2-normalized kernel and a separate area correction factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi_j | ndarray | The test function derivative to normalize. | required |
Returns:
| Name | Type | Description |
|---|---|---|
kernel | ndarray | L2-normalized kernel (satisfies Eq. 20). |
area_correction | float | Factor to scale signals so effective integration equals 1. For antisymmetric kernels, returns 1.0 (no correction possible). |
Raises:
| Type | Description |
|---|---|
ValueError | If the kernel has zero energy (all zeros). |
Notes
Implementation decision: The paper's Eq. 21 cannot be satisfied for antisymmetric kernels. We interpret this as follows:
- Apply L2 normalization (Eq. 20) to ensure balanced energy contribution.
- For symmetric kernels with non-zero integral, compute area correction.
- For antisymmetric kernels, use area_correction=1.0 and rely on the L2 normalization to balance the criterion.
This interpretation ensures that each derivative order contributes proportionally to the ULS criterion without amplifying noise.
Source code in sysidentpy/model_structure_selection/sobolev_orthogonal_forward_regression.py
predict(*, X=None, y, steps_ahead=None, forecast_horizon=None) ¶
Predict output using the fitted UOFR model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X | ndarray of floats | Input data for prediction. | None |
y | ndarray of floats | Output data (initial conditions for simulation). | required |
steps_ahead | int | Number of steps ahead for prediction. | None |
forecast_horizon | int | Forecast horizon for multi-step prediction. | None |
Returns:
| Name | Type | Description |
|---|---|---|
yhat | ndarray | Predicted output values. |
Source code in sysidentpy/model_structure_selection/sobolev_orthogonal_forward_regression.py
run_mss_algorithm(psi, y, process_term_number) ¶
Run the model structure selection algorithm.
This method overrides the base class to use the UOFR algorithm instead of standard OFR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi | ndarray | Regressor matrix. | required |
y | ndarray | Output signal. | required |
process_term_number | int | Maximum number of terms to select. | required |
Returns:
| Type | Description |
|---|---|
tuple | (err, piv, psi_selected, y_target) as returned by sobolev_error_reduction_ratio. |
Source code in sysidentpy/model_structure_selection/sobolev_orthogonal_forward_regression.py
sobolev_error_reduction_ratio(psi, y, process_term_number) ¶
Compute ERR on the ULS-augmented regression problem.
Implements Steps 5-7 of the UOFR algorithm: compute ERR significance for each term using the augmented ULS matrices and select terms in a forward greedy manner.
The ERR is computed as (Eq. 33 in the paper): ERR(phi_k) =
where w_k is the orthogonalized regressor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi | ndarray | Original regressor matrix of shape (N, num_terms). | required |
y | ndarray | Output signal of shape (N, 1). | required |
process_term_number | int | Maximum number of terms to select. | required |
Returns:
| Name | Type | Description |
|---|---|---|
err | ndarray | ERR values for each selected term (Eq. 33 computed on ULS problem). |
piv | ndarray | Indices of selected terms in order of selection. |
psi_orthogonal | ndarray | Augmented regressor matrix with selected columns. |
y_augmented | ndarray | Augmented output vector. |
Notes
The ERR is computed using the augmented matrices (Y_ULS, Phi_ULS), which means term significance is evaluated considering both the original fit and the derivative fits. This is the key difference from standard OFR: terms that appear significant under L2 may be less significant under the Sobolev norm, and vice versa.
The orthogonalization uses Householder reflections for numerical stability, as mentioned in the paper (any orthogonalization method is valid, but Householder is preferred for large problems).
Source code in sysidentpy/model_structure_selection/sobolev_orthogonal_forward_regression.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 | |