wsingular.utils
- wsingular.utils.check_uniqueness(A: torch.Tensor, B: torch.Tensor, C: torch.Tensor, D: torch.Tensor) bool
Check uniqueness of singular vectors using the graph connectivity criterion described in the paper.
- Parameters:
A (torch.Tensor) – The samples.
B (torch.Tensor) – The features.
C (torch.Tensor) – The ground cost.
D (torch.Tensor) – The pairwise distance.
- Returns:
Whether the criterion is verified.
- Return type:
bool
- wsingular.utils.hilbert_distance(D_1: torch.Tensor, D_2: torch.Tensor) float
Compute the Hilbert distance between two distance-like matrices.
- Parameters:
D_1 (torch.Tensor) – The first matrix
D_2 (torch.Tensor) – The second matrix
- Returns:
The distance
- Return type:
float
- wsingular.utils.normalize_dataset(dataset: torch.Tensor, dtype: str, device: str, normalization_steps: int = 1, small_value: float = 1e-06) Tuple[torch.Tensor, torch.Tensor]
Normalize the dataset and return the normalized dataset A and the transposed dataset B.
- Parameters:
dataset (torch.Tensor) – The input dataset, samples as rows.
normalization_steps (int, optional) – The number of Sinkhorn normalization steps. For large numbers, we get bistochastic matrices. Defaults to 1 and should be larger or equal to 1.
small_value (float) – Small addition to the dataset to avoid numerical errors while computing OT distances. Defaults to 1e-6.
- Returns:
The normalized matrices A and B.
- Return type:
Tuple[torch.Tensor, torch.Tensor]
- wsingular.utils.random_distance(size: int, dtype: str, device: str) torch.Tensor
Return a random distance-like matrix, i.e. symmetric with zero diagonal. The matrix is also divided by its maximum, so as to have infty norm 1.
- Parameters:
size (int) – Will return a matrix of dimensions size*size
dtype (str) – The dtype to be returned
device (str) – The device to be returned
- Returns:
The random distance-like matrix
- Return type:
torch.Tensor
- wsingular.utils.regularization_matrix(A: torch.Tensor, p: int, dtype: str, device: str) torch.Tensor
Return the regularization matrix
- Parameters:
A (torch.Tensor) – The dataset, with samples as rows
p (int) – order of the norm
dtype (str) – The dtype to be returned
device (str) – The device to be returned
- Returns:
The regularization matrix
- Return type:
torch.Tensor
- wsingular.utils.silhouette(D: torch.Tensor, labels: Iterable) float
Return the average silhouette score, given a distance matrix and labels.
- Parameters:
D (torch.Tensor) – Distance matrix n*n
labels (Iterable) – n labels
- Returns:
The average silhouette score
- Return type:
float
- wsingular.utils.viz_TSNE(D: torch.Tensor, labels: Optional[Iterable] = None) None
Visualize a distance matrix using a precomputed distance matrix.
- Parameters:
D (torch.Tensor) – Distance matrix
labels (Iterable, optional) – The labels, if any. Defaults to None.