Skip to content

Commit

Permalink
Merge pull request #1 from KrishnaswamyLab/safe_normalization
Browse files Browse the repository at this point in the history
add safe normalization
  • Loading branch information
Aarthi Venkat authored Jul 24, 2024
2 parents 7ed6f49 + 0ac6f2f commit 6b45eb6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gspa/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import numpy as np

def project(signals, cell_dictionary):
signals = signals / np.linalg.norm(signals, axis=1).reshape(-1,1)
return(np.dot(signals, cell_dictionary))
norms = np.linalg.norm(signals, axis=1).reshape(-1, 1)
norms[norms == 0] = 1 # Avoid division by zero by setting zero norms to one
signals = signals / norms
return np.dot(signals, cell_dictionary)

def svd(signals, random_state=1234, n_components=2048):
n_components = min(n_components, signals.shape[0], signals.shape[1])
Expand Down

0 comments on commit 6b45eb6

Please sign in to comment.