示例#1
0
 def test_get_depth_threshold_mask_connections_both(self):
     conn = {
         0: {
             1: '1'
         },
         1: {
             0: '1',
             2: '1'
         },
         2: {
             1: '1',
             3: '1'
         },
         3: {
             2: '1',
             4: '1'
         },
         4: {
             3: '1'
         },
     }
     res = get_depth_threshold_mask_connections(conn,
                                                min_depth=2,
                                                max_depth=2)
     expected = numpy.array([
         [False, False, True, False, False],
         [False, False, False, True, False],
         [True, False, False, False, True],
         [False, True, False, False, False],
         [False, False, True, False, False],
     ])
     try:
         numpy.testing.assert_equal(res, expected)
     except AssertionError as e:
         self.fail(e)
示例#2
0
    def _para_transform(self, X, y=None):
        '''
        A single instance of the transform procedure

        This is formulated in a way that the transformations can be done
        completely parallel with map.

        Parameters
        ----------
        X : object
            An object to use for the transform

        Returns
        -------
        value : array, shape=(n_atoms, len(self._elements) * self.segments)
            The features extracted from the molecule
        '''
        if self._elements is None:
            msg = "This %s instance is not fitted yet. Call 'fit' first."
            raise ValueError(msg % type(self).__name__)

        try:
            smoothing_func = SMOOTHING_FUNCTIONS[self.smoothing]
        except KeyError:
            msg = "The value '%s' is not a valid spacing type."
            raise KeyError(msg % self.smoothing)

        pair_idxs = {key: i for i, key in enumerate(self._elements)}

        data = self.convert_input(X)

        vector = numpy.zeros((len(data.elements), len(self._elements),
                              3, self.segments))

        try:
            theta_func = SPACING_FUNCTIONS[self.spacing]
        except KeyError:
            msg = "The value '%s' is not a valid spacing type."
            raise KeyError(msg % self.spacing)

        theta = numpy.linspace(theta_func(self.start), theta_func(self.end),
                               self.segments)
        mat = get_depth_threshold_mask_connections(data.connections,
                                                   max_depth=self.max_depth)

	coords = numpy.array(data.coords)
        distances = coords - coords[:, None, :]
        for i, ele1 in enumerate(data.elements):
            for j, ele2 in enumerate(data.elements):
                if i == j or not mat[i, j]:
                    continue

                for k in xrange(3):
                    diff = theta - theta_func(distances[i, j, k])
                    value = smoothing_func(self.slope * diff)
                    vector[i, pair_idxs[ele2], k] += value
        return vector.reshape(len(data.elements), -1)
示例#3
0
 def test_get_depth_threshold_mask_connections_all(self):
     conn = {
         0: {1: '1'},
         1: {0: '1'},
         2: {3: '1'},
         3: {2: '1'},
     }
     res = get_depth_threshold_mask_connections(conn, max_depth=0)
     try:
         numpy.testing.assert_equal(res,
                                    numpy.ones((len(conn), len(conn))))
     except AssertionError as e:
         self.fail(e)
示例#4
0
 def test_get_depth_threshold_mask_connections_min(self):
     conn = {
         0: {1: '1'},
         1: {0: '1', 2: '1'},
         2: {1: '1', 3: '1'},
         3: {2: '1'},
     }
     res = get_depth_threshold_mask_connections(conn, min_depth=2)
     expected = numpy.array([
         [False, False, True, True],
         [False, False, False, True],
         [True, False, False, False],
         [True, True, False, False],
     ])
     try:
         numpy.testing.assert_equal(res, expected)
     except AssertionError as e:
         self.fail(e)