Exemplo n.º 1
0
 def _check_abcd(true_vals, arr1, arr2):
     fp1 = Descriptor(arr1)
     fp1.label_ = 'arbitrary_fingerprint'
     fp2 = Descriptor(arr2)
     fp2.label_ = 'arbitrary_fingerprint'
     abcd_calc = similarity_measure._get_abcd(fp1, fp2)
     for var_id, var in enumerate(['a', 'b', 'c', 'd']):
         self.assertEqual(
             true_vals[var], abcd_calc[var_id],
             f'Expected true {var} to match calculated val '
             f'for arrays {arr1}, {arr2}')
Exemplo n.º 2
0
    def test_fingerprint_folding(self):
        """Create arbitrary fingerprint vector to check fold method"""
        # Case 1
        arbit_vector = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
        arbit_label = 'arbitrary'
        desc = Descriptor()
        desc.label_ = arbit_label
        desc.numpy_ = arbit_vector
        with self.assertRaises(ValueError):
            desc.get_folded_fprint(fold_to_length=2)

        # Case 2
        arbit_vector = np.array([1, 0, 1, 0, 1, 0])
        folded_vector = np.array([1, 1, 1])
        arbit_label = 'arbitrary_fingerprint'
        desc = Descriptor()
        desc.label_ = arbit_label
        desc.numpy_ = arbit_vector
        with self.assertRaises(InvalidConfigurationError):
            desc.get_folded_fprint(fold_to_length=4)
        with self.assertRaises(InvalidConfigurationError):
            desc.get_folded_fprint(fold_to_length=10)
        self.assertTrue(((desc.get_folded_fprint(
            fold_to_length=3) == folded_vector).all()))

        # Case 3
        arbit_vector = np.array([1, 0, 1, 0, 0, 0, 0, 0])
        folded_once_vector = np.array([1, 0, 1, 0])
        folded_twice_vector = np.array([1, 0])
        arbit_label = 'arbitrary_fingerprint'
        desc = Descriptor()
        desc.label_ = arbit_label
        desc.numpy_ = arbit_vector
        with self.assertRaises(InvalidConfigurationError):
            desc.get_folded_fprint(fold_to_length=3)
        with self.assertRaises(InvalidConfigurationError):
            desc.get_folded_fprint(fold_to_length=10)
        self.assertTrue(((desc.get_folded_fprint(
            fold_to_length=4) == folded_once_vector).all()))
        self.assertTrue(((desc.get_folded_fprint(
            fold_to_length=2) == folded_twice_vector).all()))

        # Case 3
        arbit_vector = np.array([0, 0, 0, 0, 0, 0, 0, 0])
        folded_once_vector = np.array([0, 0, 0, 0])
        folded_twice_vector = np.array([0, 0])
        arbit_label = 'arbitrary_fingerprint'
        desc = Descriptor()
        desc.label_ = arbit_label
        desc.numpy_ = arbit_vector
        with self.assertRaises(InvalidConfigurationError):
            desc.get_folded_fprint(fold_to_length=3)
        with self.assertRaises(InvalidConfigurationError):
            desc.get_folded_fprint(fold_to_length=10)
        self.assertTrue(((desc.get_folded_fprint(
            fold_to_length=4) == folded_once_vector).all()))
        self.assertTrue(((desc.get_folded_fprint(
            fold_to_length=2) == folded_twice_vector).all()))

        # Case 4
        arbit_vector = np.array([1, 1, 1, 1, 1, 1, 1, 1])
        folded_once_vector = np.array([1, 1, 1, 1])
        folded_twice_vector = np.array([1, 1])
        arbit_label = 'arbitrary_fingerprint'
        desc = Descriptor()
        desc.label_ = arbit_label
        desc.numpy_ = arbit_vector
        with self.assertRaises(InvalidConfigurationError):
            desc.get_folded_fprint(fold_to_length=3)
        with self.assertRaises(InvalidConfigurationError):
            desc.get_folded_fprint(fold_to_length=10)
        self.assertTrue(((desc.get_folded_fprint(
            fold_to_length=4) == folded_once_vector).all()))
        self.assertTrue(((desc.get_folded_fprint(
            fold_to_length=2) == folded_twice_vector).all()))