-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |