numerical_kernel_based_interdependence
Bases: interdependence
A numerical kernel-based interdependence function.
This class computes the interdependence matrix using a specified numerical kernel function.
Notes
Formally, given a data batch \(\mathbf{X} \in R^{b \times m}\), we define the numerical metric-based interdependence function as: $$ \begin{equation} \xi(\mathbf{X}) = \mathbf{A} \in R^{m \times m'} \text{, where } \mathbf{A}(i, j) = \text{kernel} \left(\mathbf{X}(:, i), \mathbf{X}(:, j)\right). \end{equation} $$ By convention, the resulting matrix \(\mathbf{A}\) is square, with dimensions \(m' = m\).
Attributes:
Name | Type | Description |
---|---|---|
kernel |
Callable
|
The kernel function used to compute the interdependence matrix. |
Methods:
Name | Description |
---|---|
__init__ |
Initializes the kernel-based interdependence function. |
calculate_A |
Computes the interdependence matrix using the specified kernel. |
Source code in tinybig/interdependence/numerical_kernel_interdependence.py
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 |
|
__init__(b, m, kernel, interdependence_type='attribute', name='kernel_based_interdependence', require_data=True, require_parameters=False, device='cpu', *args, **kwargs)
Initializes the kernel-based 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 |
kernel
|
Callable
|
The kernel function used to compute the interdependence matrix. |
required |
interdependence_type
|
str
|
Type of interdependence ('attribute', 'instance', etc.). Defaults to 'attribute'. |
'attribute'
|
name
|
str
|
Name of the interdependence function. Defaults to 'kernel_based_interdependence'. |
'kernel_based_interdependence'
|
require_data
|
bool
|
If True, requires input data for matrix computation. Defaults to True. |
True
|
require_parameters
|
bool
|
If True, requires parameters for matrix computation. Defaults to False. |
False
|
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 no kernel function is provided. |
Source code in tinybig/interdependence/numerical_kernel_interdependence.py
calculate_A(x=None, w=None, device='cpu', *args, **kwargs)
Computes the interdependence matrix using the specified kernel function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape |
None
|
w
|
Parameter
|
Parameter tensor. 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 interdependence matrix. |
Raises:
Type | Description |
---|---|
AssertionError
|
If |
ValueError
|
If required data or parameters are missing. |