parameterized_bilinear_interdependence
Bases: interdependence
A parameterized bilinear interdependence function.
This class computes interdependence matrices using a bilinear transformation parameterized by custom fabrication methods or predefined structures.
Notes
Formally, given a data batch \(\mathbf{X} \in R^{b \times m}\), we can represent the parameterized bilinear form-based interdependence function as follows:
\[ \begin{equation}\label{equ:bilinear_interdependence_function} \xi(\mathbf{X} | \mathbf{w}) = \mathbf{X}^\top \mathbf{W} \mathbf{X} = \mathbf{A} \in R^{m \times m}, \end{equation} \]
where \(\mathbf{W} = \text{reshape}(\mathbf{w}) \in R^{b \times b}\) denotes the parameter matrix reshaped from the learnable parameter vector \(\mathbf{w} \in R^{l_{\xi}}\).
The required length of parameter vector of this interdependence function is \(l_{\xi} = b^2\).
Attributes:
Name | Type | Description |
---|---|---|
parameter_fabrication |
Callable
|
A callable function or object to fabricate parameters. |
Methods:
Name | Description |
---|---|
calculate_b_prime |
Computes the effective number of rows in the interdependence matrix. |
calculate_m_prime |
Computes the effective number of columns in the interdependence matrix. |
calculate_l |
Computes the total number of parameters needed. |
calculate_A |
Computes the parameterized bilinear interdependence matrix. |
Source code in tinybig/interdependence/parameterized_bilinear_interdependence.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 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 |
|
__init__(b, m, interdependence_type='instance', name='parameterized_bilinear_interdependence', require_parameters=True, require_data=True, device='cpu', *args, **kwargs)
Initializes the parameterized bilinear interdependence function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b
|
int
|
Number of rows in the input tensor. |
required |
m
|
int
|
Number of columns in the input tensor. |
required |
interdependence_type
|
str
|
Type of interdependence ('instance', 'attribute', etc.). Defaults to 'instance'. |
'instance'
|
name
|
str
|
Name of the interdependence function. Defaults to 'parameterized_bilinear_interdependence'. |
'parameterized_bilinear_interdependence'
|
require_parameters
|
bool
|
Whether parameters are required. Defaults to True. |
True
|
require_data
|
bool
|
Whether input data is required. Defaults to True. |
True
|
device
|
str
|
Device for computation ('cpu', 'cuda'). Defaults to 'cpu'. |
'cpu'
|
*args
|
tuple
|
Additional positional arguments for the parent class. |
()
|
**kwargs
|
dict
|
Additional keyword arguments for the parent class. |
{}
|
Source code in tinybig/interdependence/parameterized_bilinear_interdependence.py
calculate_A(x=None, w=None, device='cpu', *args, **kwargs)
Computes the parameterized bilinear interdependence matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape |
None
|
w
|
Parameter
|
Parameter tensor of shape |
None
|
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
|
The computed interdependence matrix. |
Raises:
Type | Description |
---|---|
ValueError
|
If the interdependence type is not supported. |
AssertionError
|
If input data or parameter tensor |
Source code in tinybig/interdependence/parameterized_bilinear_interdependence.py
calculate_b_prime(b=None)
Computes the effective number of rows in the interdependence matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b
|
int
|
Input number of rows. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
int
|
The effective number of rows in the matrix. |
Source code in tinybig/interdependence/parameterized_bilinear_interdependence.py
calculate_l()
Computes the total number of parameters required.
Returns:
Type | Description |
---|---|
int
|
The total number of parameters. |
Raises:
Type | Description |
---|---|
ValueError
|
If the interdependence type is not supported. |
Source code in tinybig/interdependence/parameterized_bilinear_interdependence.py
calculate_m_prime(m=None)
Computes the effective number of columns in the interdependence matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
int
|
Input number of columns. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
int
|
The effective number of columns in the matrix. |