Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions tests/test_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
def setup_function(fn):
print("torch version:", torch.__version__, "torchvision version:", torchvision.__version__)

def test_cov():
x = np.random.randn(10, 10)
cov_np = np.cov(x)
cov_t = torchstain.torch.utils.cov(torch.tensor(x))

np.testing.assert_almost_equal(cov_np, cov_t.numpy())

def test_percentile():
x = np.random.randn(10, 10)
p = 20
Expand Down
4 changes: 2 additions & 2 deletions torchstain/torch/augmentors/macenko.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch
from torchstain.base.augmentors.he_augmentor import HEAugmentor
from torchstain.torch.utils import cov, percentile
from torchstain.torch.utils import percentile

"""
Source code ported from: https://github.com/schaugf/HEnorm_python
Expand Down Expand Up @@ -66,7 +66,7 @@ def __compute_matrices(self, I, Io, alpha, beta):
OD, ODhat = self.__convert_rgb2od(I, Io=Io, beta=beta)

# compute eigenvectors
_, eigvecs = torch.linalg.eigh(cov(ODhat.T))
_, eigvecs = torch.linalg.eigh(torch.cov(ODhat.T))
eigvecs = eigvecs[:, [1, 2]]

HE = self.__find_HE(ODhat, eigvecs, alpha)
Expand Down
4 changes: 2 additions & 2 deletions torchstain/torch/normalizers/macenko.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch
from torchstain.base.normalizers.he_normalizer import HENormalizer
from torchstain.torch.utils import cov, percentile
from torchstain.torch.utils import percentile

"""
Source code ported from: https://github.com/schaugf/HEnorm_python
Expand Down Expand Up @@ -61,7 +61,7 @@ def __compute_matrices(self, I, Io, alpha, beta):
OD, ODhat = self.__convert_rgb2od(I, Io=Io, beta=beta)

# compute eigenvectors
_, eigvecs = torch.linalg.eigh(cov(ODhat.T))
_, eigvecs = torch.linalg.eigh(torch.cov(ODhat.T))
eigvecs = eigvecs[:, [1, 2]]

HE = self.__find_HE(ODhat, eigvecs, alpha)
Expand Down
8 changes: 4 additions & 4 deletions torchstain/torch/normalizers/multitarget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import torch
from torchstain.torch.utils import cov, percentile
from torchstain.torch.utils import percentile

"""
Implementation of the multi-target normalizer from the paper: https://arxiv.org/pdf/2406.02077
Expand Down Expand Up @@ -50,7 +50,7 @@ def __compute_matrices_single(self, I, Io, alpha, beta):
OD, ODhat = self.__convert_rgb2od(I, Io=Io, beta=beta)

# _, eigvecs = torch.symeig(cov(ODhat.T), eigenvectors=True)
_, eigvecs = torch.linalg.eigh(cov(ODhat.T), UPLO='U')
_, eigvecs = torch.linalg.eigh(torch.cov(ODhat.T), UPLO='U')
eigvecs = eigvecs[:, [1, 2]]

HE = self.__find_HE(ODhat, eigvecs, alpha)
Expand All @@ -77,7 +77,7 @@ def fit(self, Is, Io=240, alpha=1, beta=0.15):
OD = torch.cat(ODs, dim=0)
ODhat = torch.cat(ODhats, dim=0)

eigvecs = torch.symeig(cov(ODhat.T), eigenvectors=True)[1][:, [1, 2]]
eigvecs = torch.symeig(torch.cov(ODhat.T), eigenvectors=True)[1][:, [1, 2]]

HE = self.__find_HE(ODhat, eigvecs, alpha)

Expand All @@ -91,7 +91,7 @@ def fit(self, Is, Io=240, alpha=1, beta=0.15):
for I in Is
))

eigvecs = torch.stack([torch.symeig(cov(ODhat.T), eigenvectors=True)[1][:, [1, 2]] for ODhat in ODhats]).mean(dim=0)
eigvecs = torch.stack([torch.symeig(torch.cov(ODhat.T), eigenvectors=True)[1][:, [1, 2]] for ODhat in ODhats]).mean(dim=0)

OD = torch.cat(ODs, dim=0)
ODhat = torch.cat(ODhats, dim=0)
Expand Down
1 change: 0 additions & 1 deletion torchstain/torch/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from torchstain.torch.utils.cov import cov
from torchstain.torch.utils.percentile import percentile
from torchstain.torch.utils.stats import *
from torchstain.torch.utils.split import *
Expand Down
9 changes: 0 additions & 9 deletions torchstain/torch/utils/cov.py

This file was deleted.