Пример #1
0
    def random_uniform(self, n_samples=1, bound=0.5):
        """
        Sample in the Hypersphere with the uniform distribution.

        Parameters
        ----------
        n_samples : int, optional
        bound: float, optional

        Returns
        -------
        point : array-like, shape=[n_samples, dimension + 1]
        """
        size = (n_samples, self.dimension)

        if bound is None:
            spherical_coord = gs.random.rand(*size) * gs.pi
            spherical_coord[:, -1] *= 2

            point = gs.zeros((n_samples, self.dimension + 1))
            for i in range(self.dimension):
                point[:,
                      i] = (gs.prod(gs.sin(spherical_coord[:, :i]), axis=1) *
                            gs.cos(spherical_coord[:, i]))
            point[:, -1] = gs.prod(gs.sin(spherical_coord), axis=1)

        else:
            assert bound <= 0.5
            point = bound * (2 * gs.random.rand(*size) - 1)
            point = self.intrinsic_to_extrinsic_coords(point)

        return point
Пример #2
0
    def random_uniform(self, n_samples=1, bound=0.5):
        """
        Sample in the Hypersphere with the uniform distribution.
        """
        size = (n_samples, self.dimension)

        if bound is None:
            spherical_coord = gs.random.rand(*size) * gs.pi
            spherical_coord[:, -1] *= 2

            point = gs.zeros((n_samples, self.dimension+1))
            for i in range(self.dimension):
                point[:, i] = gs.prod(gs.sin(spherical_coord[:, :i]), axis=1)\
                            * gs.cos(spherical_coord[:, i])
            point[:, -1] = gs.prod(gs.sin(spherical_coord), axis=1)

        else:
            point = bound * (2*gs.random.rand(*size) - 1)
            point = self.intrinsic_to_extrinsic_coords(point)

        return point
Пример #3
0
    def corr(self, x):
        """Compute the correlation matrix of the topology with edge weights ``weights``.

        Parameters
        ----------
        x : array-like
            Takes a vector of length 'number of total splits' of the structure.

        Returns
        -------
        corr : array-like, shape=[n, n]
            Returns the corresponding correlation matrix.
        """
        corr = gs.zeros((self.n_labels, self.n_labels))
        for path_dict in self.paths:
            for (u, v), path in path_dict.items():
                corr[u][v] = gs.prod([1 - x[self.where[split]] for split in path])
                corr[v][u] = corr[u][v]

        corr = gs.array(corr)
        return corr + gs.eye(corr.shape[0])
Пример #4
0
 def test_prod(self):
     vec = gs.random.rand(10)
     result = gs.prod(vec)
     expected = gs.cumprod(vec)[-1]
     self.assertAllClose(result, expected)
Пример #5
0
 def __init__(self, shape, **kwargs):
     if "dim" not in kwargs.keys():
         kwargs["dim"] = int(gs.prod(gs.array(shape)))
     super(VectorSpace, self).__init__(shape=shape, **kwargs)
     self.shape = shape
Пример #6
0
 def __init__(self, shape, default_point_type='vector', **kwargs):
     if 'dim' not in kwargs.keys():
         kwargs['dim'] = int(gs.prod(gs.array(shape)))
     super(VectorSpace,
           self).__init__(default_point_type=default_point_type, **kwargs)
     self.shape = shape
Пример #7
0
 def __init__(self, shape, **kwargs):
     kwargs.setdefault("dim", int(gs.prod(gs.array(shape))))
     super(VectorSpace, self).__init__(shape=shape, **kwargs)
     self.shape = shape
     self._basis = None