gegenbauer_expansion
Bases: transformation
The gegenbauer expansion function.
Applies Gegenbauer polynomial expansion to input data.
Notes
The Gegenbauer polynomials, named after mathematician Leopold Gegenbauer, are orthogonal polynomials that generalize both the Legendre and Chebyshev polynomials, and are special cases of Jacobi polynomials.
Formally, the Gegenbauer polynomials are particular solutions of the Gegenbauer differential equation:
\[ \begin{equation} (1 - x^2) y'' - (2 \alpha + 1) x y' + d(d+2 \alpha) y = 0, \end{equation} \]
where \(y = y(x)\) is a function of variable \(x\) and \(d \in N\) is a non-negative integer.
When \(\alpha = \frac{1}{2}\), the Gegenbauer polynomials reduce to the Legendre polynomials introduced earlier; when \(\alpha = 1\), they reduce to the Chebyshev polynomials of the second kind.
The Gegenbauer polynomials can be recursively defined as follows:
Base cases \(n=0\) and \(n=1\):
\[ \begin{equation} P^{(\alpha)}_0(x) = 1 \text{, and } P^{(\alpha)}_1(x) = 2 \alpha x. \end{equation} \]
High-order cases with degree \(n \ge 2\):
\[ \begin{equation} P^{(\alpha)}_n(x) = \frac{2x(n-1+\alpha) P^{(\alpha)}_{n-1}(x) - (n+2\alpha -2) P^{(\alpha)}_{n-2}(x) }{n} \end{equation} \]
Based on the Gegenbauer polynomials, we can define the expansion function as follows:
\[ \begin{equation} \kappa(\mathbf{x} | d, \alpha) = \left[ P^{(\alpha)}_1(\mathbf{x}), P^{(\alpha)}_2(\mathbf{x}), \cdots, P^{(\alpha)}_d(\mathbf{x}) \right] \in R^D, \end{equation} \]
where the output dimension \(D = md\).
Attributes:
Name | Type | Description |
---|---|---|
d |
int
|
The degree of Gegenbauer polynomial expansion. |
alpha |
float
|
Parameter controlling the Gegenbauer polynomial. |
Methods:
Name | Description |
---|---|
calculate_D |
Calculates the output dimension after expansion. |
forward |
Performs Gegenbauer polynomial expansion on the input tensor. |
Source code in tinybig/expansion/orthogonal_polynomial_expansion.py
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 |
|
__init__(name='gegenbauer_polynomial_expansion', d=2, alpha=1.0, *args, **kwargs)
Initializes the Gegenbauer polynomial expansion transformation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the transformation. Defaults to 'gegenbauer_polynomial_expansion'. |
'gegenbauer_polynomial_expansion'
|
d
|
int
|
The maximum order of Gegenbauer polynomials for expansion. Defaults to 2. |
2
|
alpha
|
float
|
The alpha parameter for Gegenbauer polynomials. Defaults to 1.0. |
1.0
|
*args
|
tuple
|
Additional positional arguments. |
()
|
**kwargs
|
dict
|
Additional keyword arguments. |
{}
|
Source code in tinybig/expansion/orthogonal_polynomial_expansion.py
calculate_D(m)
Calculates the output dimension after Gegenbauer polynomial expansion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
int
|
Input dimension. |
required |
Returns:
Type | Description |
---|---|
int
|
Output dimension after expansion. |
Source code in tinybig/expansion/orthogonal_polynomial_expansion.py
forward(x, device='cpu', *args, **kwargs)
Performs Gegenbauer polynomial expansion on the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape |
required |
device
|
str
|
Device for computation ('cpu', 'cuda'). Defaults to 'cpu'. |
'cpu'
|
*args
|
tuple
|
Additional positional arguments. |
()
|
**kwargs
|
dict
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
Expanded tensor of shape |
Raises:
Type | Description |
---|---|
AssertionError
|
If the output tensor shape does not match the expected dimensions. |