linear_expansion
Bases: transformation
The linear data expansion function.
It performs the linear expansion of the input vector, and returns the expansion result. The class inherits from the base expansion class (i.e., the transformation class in the module directory).
...
Notes
For input vector \(\mathbf{x} \in R^m\), its linear expansion can be based on one of the following equations: $$ \begin{align} \kappa(\mathbf{x}) &= c \mathbf{x} \in {R}^D, \\ \kappa(\mathbf{x}) &= \mathbf{x} \mathbf{C}_{post} \in {R}^D,\\ \kappa(\mathbf{x}) &= \mathbf{C}_{pre} \mathbf{x} \in {R}^{D}, \end{align} $$ where \(c \in {R}\), \(\mathbf{C}_{post}, \mathbf{C}_{pre} \in {R}^{m \times m}\) denote the provided constant scalar and linear transformation matrices, respectively. Linear data expansion will not change the data vector dimensions, and the output data vector dimension \(D=m\).
By default, the input and output can also be processed with the optional pre- or post-processing functions in the linear expansion function.
Attributes:
Name | Type | Description |
---|---|---|
name |
str, default = 'linear_expansion'
|
Name of the expansion function. |
Methods:
Name | Description |
---|---|
__init__ |
It performs the initialization of the expansion function. |
calculate_D |
It calculates the expansion space dimension D based on the input dimension parameter m. |
forward |
It implements the abstract forward method declared in the base expansion class. |
Source code in tinybig/expansion/basic_expansion.py
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 |
|
__init__(name='linear_expansion', c=None, pre_C=None, post_C=None, *args, **kwargs)
The initialization method of the linear expansion function.
It initializes a linear expansion object based on the input function name. This method will also call the initialization method of the base class as well.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
The name of the linear expansion function. |
'linear_expansion'
|
|
c
|
The scalar \(c\) of the linear expansion. |
None
|
|
pre_C
|
The \(\mathbf{C}_{pre}\) matrix of the linear expansion. |
None
|
|
post_C
|
The \(\mathbf{C}_{post}\) matrix of the linear expansion. |
None
|
Returns:
Type | Description |
---|---|
transformation
|
The linear expansion function. |
Source code in tinybig/expansion/basic_expansion.py
calculate_D(m)
The expansion dimension calculation method.
It calculates the intermediate expansion space dimension based on the input dimension parameter m. For the linear expansion function, the expansion space dimension equals to the input space dimension, i.e., $$ D = m. $$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
int
|
The dimension of the input space. |
required |
Returns:
Type | Description |
---|---|
int
|
The dimension of the expansion space. |
Source code in tinybig/expansion/basic_expansion.py
forward(x, device='cpu', c=None, pre_C=None, post_C=None, *args, **kwargs)
The forward method of the data expansion function.
It performs the linear data expansion of the input data and returns the expansion result according to one of the following equation: $$ \begin{align} \kappa(\mathbf{x}) &= c \mathbf{x} \in {R}^D, \\ \kappa(\mathbf{x}) &= \mathbf{x} \mathbf{C}_{post} \in {R}^D,\\ \kappa(\mathbf{x}) &= \mathbf{C}_{pre} \mathbf{x} \in {R}^{D}, \end{align} $$ where \(c \in {R}\), \(\mathbf{C}_{post}, \mathbf{C}_{pre} \in {R}^{m \times m}\) denote the provided constant scalar and linear transformation matrices, respectively.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input data vector. |
required |
device
|
The device to perform the data expansion. |
'cpu'
|
|
c
|
The scalar \(c\) of the linear expansion. |
None
|
|
pre_C
|
The \(\mathbf{C}_{pre}\) matrix of the linear expansion. |
None
|
|
post_C
|
The \(\mathbf{C}_{post}\) matrix of the linear expansion. |
None
|
Returns:
Type | Description |
---|---|
Tensor
|
The expanded data vector of the input. |