fibonacci_expansion
Bases: transformation
The fibonacci expansion function.
Applies Fibonacci polynomial expansion to input data.
Notes
Formally, the Fibonacci polynomials are a polynomial sequence that can be considered a generalization of the Fibonacci numbers, which can be recursively represented as follows:
Base cases \(n=0\) and \(n=1\):
\[ \begin{equation} F_0(x) = 0 \text{, and } F_1(x) = 1. \end{equation} \]
High-order cases with degree \(n \ge 2\):
\[ \begin{equation} F_n(x) = x F_{n-1}(x) + F_{n-2}(x). \end{equation} \]
Based on these recursive representations, we can illustrate some examples of the Fibonacci polynomials as follows:
\[ \begin{equation} \begin{aligned} F_0(x) &= 0 \\ F_1(x) &= 1 \\ F_2(x) &= x \\ F_3(x) &= x^2 + 1 \\ F_4(x) &= x^3 + 2x \\ F_5(x) &= x^4 + 3x^2 + 1 \\ \end{aligned} \end{equation} \]
Based on the above Fibonacci polynomials, we can define the data expansion functions as follows: $$ \begin{equation} \kappa(\mathbf{x} | d) = \left[ F_1(\mathbf{x}), F_2(\mathbf{x}), \cdots, F_d(\mathbf{x}) \right] \in R^D, \end{equation} $$ where the output dimension \(D = md\).
Attributes:
Name | Type | Description |
---|---|---|
d |
int
|
The degree of Fibonacci polynomial expansion. |
Methods:
Name | Description |
---|---|
calculate_D |
Calculates the output dimension after expansion. |
forward |
Performs Fibonacci polynomial expansion on the input tensor. |
Source code in tinybig/expansion/orthogonal_polynomial_expansion.py
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 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 |
|
__init__(name='fibonacci_polynomial_expansion', d=2, *args, **kwargs)
Initializes the Fibonacci polynomial expansion transformation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the transformation. Defaults to 'fibonacci_polynomial_expansion'. |
'fibonacci_polynomial_expansion'
|
d
|
int
|
The maximum order of Fibonacci 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 Fibonacci 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 Fibonacci 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. |