Skip to content

Commit

Permalink
rev #1
Browse files Browse the repository at this point in the history
  • Loading branch information
qai222 committed Feb 22, 2022
1 parent 0887445 commit d561416
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
6 changes: 0 additions & 6 deletions cacgan/gans/tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ def tune(dataset, chk=None, n_calls=50, nepochs=10002):
"""
hparam tune aug cycgan using gaussian process
the objective is the mean of "mindist" from "prior" mode of cv runs
:param dataset:
:param chk:
:param n_calls:
:param nepochs:
:return:
"""

def objective(hparams):
Expand Down
3 changes: 0 additions & 3 deletions scripts/emd_test.py

This file was deleted.

13 changes: 13 additions & 0 deletions scripts/imbalanced_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from cacgan.data import AtmoStructureGroup

if __name__ == '__main__':
mg = AtmoStructureGroup.from_csv()
amine_gs = mg.group_by("amine")
amine_gs = sorted(amine_gs, key=lambda x: len(x), reverse=True)
namines = len(amine_gs)
namines_unpopular = 0
for g in amine_gs:
print(g.first_amine, len(g))
if len(g) < 5:
namines_unpopular += 1
print(namines, namines_unpopular)
28 changes: 28 additions & 0 deletions scripts/test_emd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import unittest


class EmdTest(unittest.TestCase):

def test_aginst_pyemd(self):
from cacgan.sinkhornOT import dummy_distance_matrix, np, torch, DEVICE, emdloss_detach
from pyemd import emd
from sklearn.preprocessing import normalize
a = np.random.random((4, 6))
b = np.random.random((4, 6))
a = normalize(a, axis=1, norm="l1")
b = normalize(b, axis=1, norm="l1")
d = dummy_distance_matrix(a.shape[1])
pyemd_results = []
for i in range(a.shape[0]):
pyemd_results.append(emd(a[i], b[i], d))

ta = torch.tensor(a).to(DEVICE, dtype=torch.float32)
tb = torch.tensor(b).to(DEVICE, dtype=torch.float32)
td = torch.tensor(d).to(DEVICE, dtype=torch.float32)
sinkhorn_results = emdloss_detach(ta, tb, td).cpu().detach().numpy()
same = np.allclose(sinkhorn_results, np.array(pyemd_results))
self.assertTrue(same)


if __name__ == '__main__':
unittest.main()
24 changes: 24 additions & 0 deletions scripts/test_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest


class LayerTest(unittest.TestCase):

def test_filter(self):
from cacgan.gans.networks import ConditionalResnetGenerator, torch
from cacgan.utils import DEVICE
input_size = 6
ninput = 3
zero_columns = [2, 3]
generator_input = torch.rand((ninput, input_size), device=DEVICE)
for icol in zero_columns:
generator_input[:, icol] = 0
crg = ConditionalResnetGenerator(6, input_size, input_size)
crg.model.to(device=DEVICE)
noise = torch.rand((ninput, input_size), device=DEVICE)
out = crg.forward(generator_input, noise)
for icol in zero_columns:
self.assertTrue(all(out[:, icol] == 0))


if __name__ == '__main__':
unittest.main()

0 comments on commit d561416

Please sign in to comment.