hybrid_interdependence
Bases: interdependence
A hybrid interdependence class combining multiple interdependence functions.
This class enables the combination of multiple interdependence functions and applies a fusion function to aggregate the results. It supports configurations for both interdependence functions and the fusion function.
Notes
Formally, given the input data batch \(\mathbf{X} \in R^{b \times m}\), we can define a set of data and structural interdependence functions \(\xi_1, \xi_2, \cdots, \xi_k: R^{b \times m} \to R^{m \times m'}\) to measure the interdependence relationships among the attributes. These functions can be effectively fused together as follows:
\[ \begin{equation} \begin{aligned} \xi(\mathbf{X}) &= \text{fusion} \left( \xi_1(\mathbf{X}), \xi_2(\mathbf{X}), \cdots, \xi_k(\mathbf{X}) \right)\\ &= \text{fusion} \left( \mathbf{A}_1, \mathbf{A}_2, \cdots, \mathbf{A}_k \right)\\ &= \mathbf{A} \in R^{m \times m'}, \end{aligned} \end{equation} \]
where \(\mathbf{A}_i = \xi_i(\mathbf{X})\) denotes the interdependence matrix obtained by function \(\xi_i, \forall i \in \{1, 2, \cdots, k\}\). Different fusion strategies can be used to define the \(\text{fusion}(\cdot)\) operator used above, which will be introduced in the following subsection specifically.
Attributes:
Name | Type | Description |
---|---|---|
interdependence_functions |
list
|
List of interdependence function objects. |
fusion_function |
Callable
|
The fusion function used to combine the outputs of the interdependence functions. |
require_parameters |
bool
|
Indicates whether any interdependence or fusion function requires parameters. |
require_data |
bool
|
Indicates whether any interdependence or fusion function requires input data. |
Methods:
Name | Description |
---|---|
__init__ |
Initializes the hybrid interdependence function. |
get_function_parameter_numbers |
Retrieves the number of parameters required by each interdependence function and the fusion function. |
calculate_l |
Calculates the total number of parameters required for the hybrid interdependence. |
calculate_b_prime |
Computes the number of rows in the output tensor after applying interdependence. |
calculate_m_prime |
Computes the number of columns in the output tensor after applying interdependence. |
calculate_A |
Computes the hybrid interdependence matrix. |
Source code in tinybig/interdependence/hybrid_interdependence.py
22 23 24 25 26 27 28 29 30 31 32 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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 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 |
|
__init__(b, m, interdependence_type='attribute', name='hybrid_interdependence', interdependence_functions=None, interdependence_function_configs=None, fusion_function=None, fusion_function_config=None, device='cpu', *args, **kwargs)
Initializes the hybrid 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 ('attribute', 'instance', etc.). Defaults to 'attribute'. |
'attribute'
|
name
|
str
|
Name of the interdependence function. Defaults to 'hybrid_interdependence'. |
'hybrid_interdependence'
|
interdependence_functions
|
list
|
List of pre-initialized interdependence function objects. Defaults to None. |
None
|
interdependence_function_configs
|
list
|
List of configuration dictionaries for initializing interdependence functions. Defaults to None. |
None
|
fusion_function
|
Callable
|
Pre-initialized fusion function object. Defaults to None. |
None
|
fusion_function_config
|
dict
|
Configuration dictionary for initializing the fusion function. Defaults to None. |
None
|
device
|
str
|
Device for computation (e.g., 'cpu' or 'cuda'). Defaults to 'cpu'. |
'cpu'
|
*args
|
tuple
|
Additional positional arguments for the parent class. |
()
|
**kwargs
|
dict
|
Additional keyword arguments for the parent class. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If neither |
Source code in tinybig/interdependence/hybrid_interdependence.py
calculate_A(x=None, w=None, device='cpu', *args, **kwargs)
Computes the hybrid interdependence matrix.
Formally, given the input data batch \(\mathbf{X} \in R^{b \times m}\), we can define a set of data and structural interdependence functions \(\xi_1, \xi_2, \cdots, \xi_k: R^{b \times m} \to R^{m \times m'}\) to measure the interdependence relationships among the attributes. These functions can be effectively fused together as follows:
\[ \begin{equation} \begin{aligned} \xi(\mathbf{X}) &= \text{fusion} \left( \xi_1(\mathbf{X}), \xi_2(\mathbf{X}), \cdots, \xi_k(\mathbf{X}) \right)\\ &= \text{fusion} \left( \mathbf{A}_1, \mathbf{A}_2, \cdots, \mathbf{A}_k \right)\\ &= \mathbf{A} \in R^{m \times m'}, \end{aligned} \end{equation} \]
where \(\mathbf{A}_i = \xi_i(\mathbf{X})\) denotes the interdependence matrix obtained by the function \(\xi_i, \forall i \in \{1, 2, \cdots, k\}\). Different fusion strategies can be used to define the \(\text{fusion}(\cdot)\) operator used above, which will be introduced in the following subsection specifically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape |
None
|
w
|
Parameter
|
Parameter tensor. Required if interdependence or fusion functions need parameters. Defaults to None. |
None
|
device
|
str
|
Device for computation (e.g., 'cpu' or 'cuda'). Defaults to 'cpu'. |
'cpu'
|
*args
|
tuple
|
Additional positional arguments for interdependence functions. |
()
|
**kwargs
|
dict
|
Additional keyword arguments for interdependence functions. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
The computed hybrid interdependence matrix. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the parameter tensor |
ValueError
|
If neither input data nor parameters are provided when required. |
Source code in tinybig/interdependence/hybrid_interdependence.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 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 |
|
calculate_b_prime(b=None)
Computes the number of rows in the output tensor after applying interdependence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b
|
int
|
Number of rows in the input tensor. Defaults to |
None
|
Returns:
Type | Description |
---|---|
int
|
The number of rows in the output tensor. |
Source code in tinybig/interdependence/hybrid_interdependence.py
calculate_l()
Calculates the total number of parameters required for the hybrid interdependence.
Returns:
Type | Description |
---|---|
int
|
Total number of parameters required. |
Source code in tinybig/interdependence/hybrid_interdependence.py
calculate_m_prime(m=None)
Computes the number of columns in the output tensor after applying interdependence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
int
|
Number of columns in the input tensor. Defaults to |
None
|
Returns:
Type | Description |
---|---|
int
|
The number of columns in the output tensor. |
Source code in tinybig/interdependence/hybrid_interdependence.py
get_function_parameter_numbers()
Retrieves the number of parameters required by each interdependence function and the fusion function.
Returns:
Type | Description |
---|---|
list of int
|
A list containing the number of parameters for each interdependence function and the fusion function. |