def test_transform(self): a = LocalEncodedBond() a.fit(ALL_DATA) m = a.transform(ALL_DATA) expected_results = numpy.array( [17.068978019300587, 54.629902544876572, 1006.4744899075993]) mm = numpy.array([x.sum() for x in m]) self.assertTrue((numpy.allclose(mm, expected_results)))
def test_transform(self): a = LocalEncodedBond() a.fit(ALL_DATA) m = a.transform(ALL_DATA) expected_results = numpy.array([17.068978019300587, 54.629902544876572, 1006.4744899075993]) mm = numpy.array([x.sum() for x in m]) self.assertTrue((numpy.allclose(mm, expected_results)))
def test_transform_max_depth1(self): a = LocalEncodedBond(max_depth=1) a.fit(ALL_DATA) m = a.transform(ALL_DATA) expected_results = numpy.array([6.82758723, 6.82758018, 88.75860423]) mm = numpy.array([x.sum() for x in m]) try: numpy.testing.assert_allclose(mm, expected_results) except AssertionError as e: self.fail(e)
def test_get_labels(self): a = LocalEncodedBond(segments=2, start=0., end=1.) m = a.fit_transform([METHANE]) labels = a.get_labels() self.assertEqual(m.shape[2], len(labels)) expected = ( 'C_0.0', 'C_1.0', 'H_0.0', 'H_1.0', ) self.assertEqual(labels, expected)
def test_small_to_large(self): a = LocalEncodedBond() a.fit([METHANE]) # This is a cheap test to prevent needing all the values here expected_results = numpy.array([ 0.016125813269, # mean 0.065471987297, # std 0., # min 0.398807098298, # max 29.02646388512, # sum ]) try: m = a.transform([MID]) val = numpy.array([ m.mean(), m.std(), m.min(), m.max(), m.sum(), ]) numpy.testing.assert_allclose(val, expected_results) except AssertionError as e: self.fail(e)
def test_fit(self): a = LocalEncodedBond() a.fit(ALL_DATA) self.assertEqual(a._elements, set(['N', 'C', 'O', 'H']))
def test_form(self): a = LocalEncodedBond(form=0) m = a.fit_transform([METHANE]) self.assertEqual(m.shape, (1, 5, 100))
def test_add_unknown(self): a = LocalEncodedBond(add_unknown=True) a.fit([METHANE]) m = a.transform([MID]) self.assertEqual(m.shape, (1, 9, 300))
def test_transform_invalid_spacing(self): a = LocalEncodedBond(spacing='not real"') with self.assertRaises(KeyError): a.fit_transform(ALL_DATA)
def test_transform_before_fit(self): a = LocalEncodedBond() with self.assertRaises(ValueError): a.transform(ALL_DATA)
def test_fit(self): a = LocalEncodedBond() a.fit(ALL_DATA) self.assertEqual(a._elements, (('C', ), ('H', ), ('N', ), ('O', )))
def test_fit(self): a = LocalEncodedBond() a.fit(ALL_DATA) self.assertEqual(a._elements, ('C', 'H', 'N', 'O'))