Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a regression test for hardmax Needleman-Wunsch #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions deepblast/tests/test_nw.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,32 @@ def test_hessian_needlemanwunsch_function_Arand(self):
gradgradcheck(needle, inputs, eps=1e-2)


class TestRegressNeedlemanWunsch(unittest.TestCase):
def setUp(self):
torch.manual_seed(2)
# initialize random replacement costs [0,1]
self.theta = torch.rand(1,
4,
6,
requires_grad=True,
dtype=torch.float32).squeeze()
# define gap costs as -3, for theta + max... trick: compute A as follow
self.A = (torch.ones_like(self.theta) * -3) - self.theta
# external knowledge, only works for manual_seed(2)
self.exp_hardmax = -3.2049

def test_hardmax(self):
# TODO: use_numba is a global variable and I don't know how to change
# it to False for this test from this method.
needle = NeedlemanWunschDecoder('hardmax')
obs = needle(self.theta, self.A).detach().numpy()
self.assertAlmostEqual(self.exp_hardmax, obs, places=5)

def test_hardmax_numba(self):
needle = NeedlemanWunschDecoder('hardmax')
obs = needle(self.theta, self.A).detach().numpy()
self.assertAlmostEqual(self.exp_hardmax, obs, places=5)


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