legendre_expansion
Bases: transformation
The legendre expansion function.
Applies Legendre polynomial expansion to input data.
Notes
The Legendre polynomials, named after mathematician Adrien-Marie Legendre, are defined as an orthogonal system over the interval \([-1, 1]\), where the polynomial term \(P_n(x)\) of degree \(n\) satisfies the following equation:
\[ \begin{equation} \int_{-1}^{+1} P_m(x) P_n(x) dx = 0, \text{ if } m \neq n. \end{equation} \]
Specifically, according to Bonnet's formula, the Legendre polynomials can be recursively represented as follows:
Base cases \(n=0\) and \(n=1\):
\[ \begin{equation} P_0(x) = 1 \text{, and } P_1(x) = x. \end{equation} \]
High-order cases with degree \(n \ge 2\):
\[ \begin{equation} P_n(x) = \frac{x(2n-1) P_{n-1}(x) - (n-1) P_{n-2}(x) }{n} \end{equation} \]
The Legendre polynomials help define the data expansion function as follows:
\[ \begin{equation} \kappa(\mathbf{x} | d) = \left[ P_1(\mathbf{x}), P_2(\mathbf{x}), \cdots, P_d(\mathbf{x}) \right] \in R^D, \end{equation} \]
where the output dimension \(D = md\).
Attributes:
Name | Type | Description |
---|---|---|
d |
int
|
The degree of Legendre polynomial expansion. |
Methods:
Name | Description |
---|---|
calculate_D |
Calculates the output dimension after expansion. |
forward |
Performs Legendre polynomial expansion on the input tensor. |
Source code in tinybig/expansion/orthogonal_polynomial_expansion.py
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 |
|
__init__(name='legendre_polynomial_expansion', d=2, *args, **kwargs)
Initializes the Legendre polynomial expansion transformation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the transformation. Defaults to 'legendre_polynomial_expansion'. |
'legendre_polynomial_expansion'
|
d
|
int
|
The maximum order of Legendre polynomials for expansion. Defaults to 2. |
2
|
*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 Legendre 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 Legendre 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. |