Losses¶
manify.embedders._losses
¶
Implementation of metrics and loss functions for evaluating embedding quality.
This module provides various functions to measure the quality of embeddings in Riemannian manifolds, including distortion metrics, average distance error, and other evaluation measures for both graph and general embedding tasks.
distortion_loss(D_est, D_true, pairwise=False)
¶
Computes the distortion loss between estimated and true squared distances.
The distortion loss measures how well the pairwise distances in the embedding space match the true distances. It is calculated as
| Parameters: |
|
|---|
| Returns: |
|
|---|
Note
This is similar to the square_loss in HazyResearch hyperbolics repository:
https://github.com/HazyResearch/hyperbolics/blob/master/pytorch/hyperbolic_models.py#L178
Source code in manify/embedders/_losses.py
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 | |
d_avg(D_est, D_true, pairwise=False)
¶
Computes the average relative distance error (D_avg).
The average distance error is the mean relative error between the estimated and true distances: $$ D_{\text{avg}} = \frac{1}{N} \sum_{i,j} \frac{ |D_{\text{est}}(i,j) - D_{\text{true}}(i,j)| }{ D_{\text{true}}(i,j) }, $$ where \(N\) is the number of distances being considered. This metric provides a normalized measure of how accurately the embedding preserves the original distances.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in manify/embedders/_losses.py
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 | |
mean_average_precision(x_embed, graph)
¶
Computes the mean average precision (mAP) for graph embedding evaluation.
This metric is used to evaluate how well an embedding preserves the neighborhood structure of a graph, as described in Gu et al. (2019): "Learning Mixed-Curvature Representations in Product Spaces".
| Parameters: |
|
|---|
| Returns: |
|
|---|
Note
This function is currently not implemented.
Source code in manify/embedders/_losses.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
dist_component_by_manifold(pm, x_embed)
¶
Computes the proportion of variance in pairwise distances explained by each manifold component.
The contribution is calculated as the ratio of the sum of squared distances in each component to the total squared distance:
where \(D^2_k\) is the squared distance in the \(k\)-th manifold component.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in manify/embedders/_losses.py
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 | |