Hi!
First, thanks for making DOT available in Python.
While comparing the Python implementation against the R implementation, I noticed what appears to be a discrepancy in the computation of the spot-wise cosine similarity.
R implementation
In the R implementation, both the observed spatial expression and the reconstructed expression are normalized before computing the cosine similarity:
ST_Xn <- normalize(ST_X)
...
ST_Xt_n <- fast_sweep(ST_Xt, 1, ST_Xt_inorms, "/")
ST_XX <- ST_Xn * ST_Xt_n
csi <- rowSums(ST_XX)
This computes the standard cosine similarity.
Python implementation
In the Python implementation, only the reconstructed expression is normalized:
st_xt_n = st_xt / norms
...
csi = (Xsp_b * st_xt_n).sum(dim=1)
This computes $\left\langle x, \frac{\hat{x}}{\lVert\hat{x}\rVert_2} \right\rangle$ , instead of the cosine similarity.
Unless I'm missing something, the spatial expression should also be normalized before computing csi.
Hi!
First, thanks for making DOT available in Python.
While comparing the Python implementation against the R implementation, I noticed what appears to be a discrepancy in the computation of the spot-wise cosine similarity.
R implementation
In the R implementation, both the observed spatial expression and the reconstructed expression are normalized before computing the cosine similarity:
This computes the standard cosine similarity.
Python implementation
In the Python implementation, only the reconstructed expression is normalized:
This computes$\left\langle x, \frac{\hat{x}}{\lVert\hat{x}\rVert_2} \right\rangle$ , instead of the cosine similarity.
Unless I'm missing something, the spatial expression should also be normalized before computing csi.