Esempio n. 1
0
    def _sample(self, shape=(), concentration1=None, concentration0=None):
        """
        Sampling.

        Args:
            shape (tuple): The shape of the sample. Default: ().
            concentration1 (Tensor): The concentration1 of the samples. Default: self._concentration1.
            concentration0 (Tensor): The concentration0 of the samples. Default: self._concentration0.

        Returns:
            Tensor, with the shape being shape + batch_shape.
        """
        shape = self.checktuple(shape, 'shape')
        concentration1, concentration0 = self._check_param_type(
            concentration1, concentration0)
        batch_shape = self.shape(concentration1 + concentration0)
        origin_shape = shape + batch_shape
        if origin_shape == ():
            sample_shape = (1, )
        else:
            sample_shape = origin_shape
        ones = self.fill(self.dtype, sample_shape, 1.0)
        sample_gamma1 = C.gamma(sample_shape,
                                alpha=concentration1,
                                beta=ones,
                                seed=self.seed)
        sample_gamma2 = C.gamma(sample_shape,
                                alpha=concentration0,
                                beta=ones,
                                seed=self.seed)
        sample_beta = sample_gamma1 / (sample_gamma1 + sample_gamma2)
        value = self.cast(sample_beta, self.dtype)
        if origin_shape == ():
            value = self.squeeze(value)
        return value
Esempio n. 2
0
    def _sample(self, shape=(), concentration=None, rate=None):
        """
        Sampling.

        Args:
            shape (tuple): The shape of the sample. Default: ().
            concentration (Tensor): The concentration of the samples. Default: self._concentration.
            rate (Tensor): The rate of the samples. Default: self._rate.

        Returns:
            Tensor, with the shape being shape + batch_shape.
        """
        shape = self.checktuple(shape, 'shape')
        concentration, rate = self._check_param_type(concentration, rate)
        batch_shape = self.shape(concentration + rate)
        origin_shape = shape + batch_shape
        if origin_shape == ():
            sample_shape = (1,)
        else:
            sample_shape = origin_shape
        sample_gamma = C.gamma(sample_shape, concentration, rate, self.seed)
        value = self.cast(sample_gamma, self.dtype)
        if origin_shape == ():
            value = self.squeeze(value)
        return value
Esempio n. 3
0
 def construct(self, alpha, beta):
     s1 = C.gamma(self.shape, alpha, beta, self.seed)
     s2 = C.gamma(self.shape, alpha, beta, self.seed)
     s3 = C.gamma(self.shape, alpha, beta, self.seed)
     return s1, s2, s3
Esempio n. 4
0
 def construct(self, alpha, beta):
     set_seed(20)
     return C.gamma(self.shape, alpha, beta, self.seed)