kernel
Selects and applies a specific kernel function based on the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kernel_name
|
str
|
Name of the kernel function to be used. Options include: 'pearson_correlation', 'kl_divergence', 'rv_coefficient', 'mutual_information', 'custom_hybrid', and their batch counterparts. |
'pearson_correlation'
|
x
|
Tensor
|
The first input tensor for the kernel function. |
None
|
x2
|
Tensor
|
The second input tensor for pairwise kernel functions. |
None
|
*args
|
Additional arguments for specific kernel functions. |
()
|
|
**kwargs
|
Additional arguments for specific kernel functions. |
()
|
Returns:
Type | Description |
---|---|
Tensor
|
The result of the selected kernel function. |
Raises:
Type | Description |
---|---|
ValueError
|
If the specified kernel function is not supported. |
Source code in tinybig/koala/statistics/kernel.py
Computes the KL Divergence between distributions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor representing probabilities. |
required |
x2
|
Tensor
|
Second tensor representing probabilities for pairwise divergence. |
None
|
dim
|
int
|
Dimension along which divergence is calculated. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
KL Divergence value or matrix. |
Raises:
Type | Description |
---|---|
ValueError
|
If inputs are invalid or have mismatched dimensions. |
Source code in tinybig/koala/statistics/kernel.py
Computes the KL Divergence for a batch of distributions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape (n_samples, n_features). |
required |
dim
|
int
|
Dimension along which divergence is calculated. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
KL Divergence matrix. |
Raises:
Type | Description |
---|---|
ValueError
|
If input tensor is invalid or dimensions are incorrect. |
Source code in tinybig/koala/statistics/kernel.py
Computes the Pearson correlation coefficient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor for correlation computation. |
required |
x2
|
Tensor
|
Second input tensor for pairwise correlation. If None, computes for a batch. |
None
|
dim
|
int
|
Dimension along which to compute the correlation. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
Pearson correlation coefficient or matrix. |
Raises:
Type | Description |
---|---|
ValueError
|
If input dimensions are invalid or inputs are empty. |
Source code in tinybig/koala/statistics/kernel.py
Computes the Pearson correlation coefficient matrix for a batch of inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape (n_samples, n_features). |
required |
dim
|
int
|
Dimension along which to compute correlation. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
Matrix of Pearson correlation coefficients. |
Raises:
Type | Description |
---|---|
ValueError
|
If the input tensor is invalid or dimension is incorrect. |
Source code in tinybig/koala/statistics/kernel.py
Computes the RV Coefficient for tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor for correlation computation. |
required |
x2
|
Tensor
|
Second tensor for pairwise coefficient computation. |
None
|
dim
|
int
|
Dimension along which the coefficient is computed. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
RV Coefficient value or matrix. |
Raises:
Type | Description |
---|---|
ValueError
|
If inputs are invalid or dimensions are mismatched. |
Source code in tinybig/koala/statistics/kernel.py
Computes the RV Coefficient matrix for a batch of inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape (n_samples, n_features). |
required |
dim
|
int
|
Dimension along which coefficients are computed. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
RV Coefficient matrix. |
Raises:
Type | Description |
---|---|
ValueError
|
If input tensor is invalid or dimensions are incorrect. |
Source code in tinybig/koala/statistics/kernel.py
Computes the Mutual Information for tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor for correlation computation. |
required |
x2
|
Tensor
|
Second tensor for pairwise computation. |
None
|
dim
|
int
|
Dimension along which the information is computed. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
Mutual Information value or matrix. |
Raises:
Type | Description |
---|---|
ValueError
|
If inputs are invalid or dimensions are mismatched. |
Source code in tinybig/koala/statistics/kernel.py
Computes the Mutual Information matrix for a batch of inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
Input tensor of shape (n_samples, n_features). |
required |
dim
|
int
|
Dimension along which information is computed. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
Mutual Information matrix. |
Raises:
Type | Description |
---|---|
ValueError
|
If input tensor is invalid or dimensions are incorrect. |
Source code in tinybig/koala/statistics/kernel.py
Combines multiple kernel functions into a custom hybrid kernel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
First input tensor. |
required |
x2
|
Tensor
|
Second input tensor for pairwise kernels. |
None
|
kernels
|
list of callables
|
Kernel functions to combine. |
None
|
weights
|
list, tuple, or float
|
Weights for combining the kernel functions. |
None
|
dim
|
int
|
Dimension for applying the kernels. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
Combined hybrid kernel output. |
Raises:
Type | Description |
---|---|
ValueError
|
If the number of kernels and weights do not match or inputs are invalid. |
Source code in tinybig/koala/statistics/kernel.py
Combines multiple kernel functions to compute a hybrid kernel matrix for a batch of 2D tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input tensor, must be 2D with shape (n_samples, n_features). |
required |
kernels
|
list of callable
|
A list of kernel functions to combine. |
required |
weights
|
list, tuple, or float
|
Weights for combining the kernel functions. If None, equal weights are assigned to all kernels. |
None
|
dim
|
int
|
The dimension for applying the kernels. Must be 0 or 1. Default is 0. |
0
|
Returns:
Type | Description |
---|---|
Tensor
|
The combined hybrid kernel matrix. |
Raises:
Type | Description |
---|---|
ValueError
|
If the input tensor is None, empty, or not 2D.
If |