You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
weight_matrix with n_nearest_neighbors and n_neighbors #5
where $d_{ij}$ is the geographical distance between spot $i$ and $j$ (i.e., Euclidean distance on spatial coordinates), $W$ is the sum of $w_{ij}^{(0)}$, and $n$ is the number of spots.
This indicates like the full distance matrix is calculated, Gaussian kernel is applied, then values are filtered based on the cut-off.
However, in the implementation with sklearn to calculate Nearest Neighbors, the output distance matrix isn't symmetric for low n_neighbor_layers (which is logical for ligand -> receptor directed interaction). But, when n_neighbors is large and l produces a kernel surface where n_neighbors captures points beyond the cut-off values, the matrix is symmetric and remains symmetric after applying the cut-off.
The difference arises in the standardization step due to the summation of W being less in the first instance ("ECM/cell-cell contact" mentioned above). Can you comment on:
whether or not it's believed this deviation matters (it produces different Global Bivariate Moran's I values), and
why the full $w_{ij}^{(0)}$ matrix is summed and divided from $n$ rather than row standardization which seems to be the common theme in other implementations of Moran's I?
Edit: Through working, it seems like if there are 6 nearest neighbors being requested for the ECM/direct cell-cell interaction and there are ties in distance between the 6th and 7th nearest neighbor, the current implementation can cause ambiguous selection of the nearest neighbor for which to calculate 'communication' between.
Activity
leeyoyohku commentedon Jan 11, 2023
n_neighbors is for secreted (long-distance) signaling, while n_nearest_neighbors is for adjacent signaling (ECM or cell-cell contact).
ACSoupir commentedon Jul 23, 2025
Is it expected to not apply the cut-off to both weight matrices?
rbf_dhas it applied but notrbf_d0:SpatialDM/spatialdm/stats.py
Lines 98 to 101 in 9b0f559
Or am I missing a piece?
ACSoupir commentedon Jul 24, 2025
There also appears to be an implementation deviation from what is mentioned in the manuscript associated with weights:
This indicates like the full distance matrix is calculated, Gaussian kernel is applied, then values are filtered based on the cut-off.
However, in the implementation with
sklearnto calculate Nearest Neighbors, the output distance matrix isn't symmetric for lown_neighbor_layers(which is logical for ligand -> receptor directed interaction). But, whenn_neighborsis large andlproduces a kernel surface wheren_neighborscaptures points beyond the cut-off values, the matrix is symmetric and remains symmetric after applying the cut-off.The difference arises in the standardization step due to the summation of W being less in the first instance ("ECM/cell-cell contact" mentioned above). Can you comment on:
Edit: Through working, it seems like if there are 6 nearest neighbors being requested for the ECM/direct cell-cell interaction and there are ties in distance between the 6th and 7th nearest neighbor, the current implementation can cause ambiguous selection of the nearest neighbor for which to calculate 'communication' between.