Python scipy.stats 模块,rv_continuous() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用scipy.stats.rv_continuous()

项目:enterprise    作者:nanograv    | 项目源码 | 文件源码
def sample(self, size=1, random_state=None):
        """Return a sample from probability distribution function.
        This calls the `rvs` method of the underlying
        `rv_continuous` class.

        :param size: Defining number of random variates (default is 1).
        :type size: int or tuple of ints
        :random_state: If int or RandomState, use it for drawing the random
                    variates. If None, rely on `self.random_state`.
                    Default is None.
        :type random_state: None or int or `np.random.RandomState` instance

        :return: random variate of size
        :rtype: ndarray or float
        """
        return self._rv.rvs(size=size, random_state=random_state)
项目:enterprise    作者:nanograv    | 项目源码 | 文件源码
def GaussianBoundedRV(loc=0., scale=1., lower=0., upper=1.):
    r"""A Gaussian prior between two finite bounds.
    This is a convenience function with more natural bound parameters
    than ``scipy.stats.truncnorm``.

    :param loc: location parameter, mean of distribution
    :type loc: float
    :param scale: standard deviation of distribution
    :type scale: float
    :param lower: lower bound of parameter range
    :type lower: float
    :param upper: upper bound of parameter range
    :type upper: float
    :return: a frozen rv_continuous instance with normalized Gaussian
               probability truncated to the range [lower, upper] and 0 outside
    """
    low, up = (lower - loc) / scale, (upper - loc) / scale
    nn = scipy.stats.truncnorm(loc=loc, scale=scale, a=low, b=up)
    return nn
项目:scrap    作者:BruceJohnJennerLawso    | 项目源码 | 文件源码
def sampleWebPageVisitLength():
    weibullPts = getWebPageWeibullPdfSample()

    class my_pdf(st.rv_continuous):
        def _pdf(self,x):
            ##return normalPdf(x)  # Normalized over its range, in this case [0,1]
            return interpolateFromPdfSamples(weibullPts, x)
    my_cv = my_pdf(a=0, b=190.0, name='my_pdf')

    return my_cv.rvs()
项目:mixedvines    作者:asnelt    | 项目源码 | 文件源码
def __init__(self, rv_mixed):
        self.rv_mixed = rv_mixed
        self.is_continuous = isinstance(rv_mixed.dist, rv_continuous)
项目:enterprise    作者:nanograv    | 项目源码 | 文件源码
def __init__(self, rv):
        """
        :param rv: rv_frozen Private member that holds an instance of
                      rv_frozen used to define the prior distribution.
                      It must be a 'frozen distribution', with all shape
                      parameters (i.e. a, b, loc, scale) set.

        For more info see `rv_continuous`_.
        For a list of functions suitable for use see
        `continuous-distributions`_.

        :Examples:

        .. code-block:: python

            # A half-bounded uniform prior on Agw, ensuring Agw >= 0.
            model.Agw.prior = Prior(UniformUnnormedRV(lower=0.))

            # A normalized uniform prior on Agw in [10^-18, 10^-12]
            model.Agw.prior = Prior(UniformBoundedRV(1.0e-18, 1.0e-12))

            # A Gaussian prior for gamma = 13/3 +/- 2/3
            mean, std = 13./3., 2./3.
            model.gamma.prior = Prior(scipy.stats.norm(loc=mean, scale=std))

            # A bounded Gaussian prior to ensure that eccentrity is in [0, 1]
            mean, std, low, up = 0.9, 0.1, 0.0, 1.0
            model.ecc.prior = Prior(GaussianBoundedRV(loc=mean, scale=std,
                                                      lower=low, upper=up))

        .. _rv_continuous: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html#scipy.stats.rv_continuous
        .. _continuous-distributions: https://docs.scipy.org/doc/scipy/reference/stats.html#continuous-distributions
        .. # noqa E501
        """
        self._rv = rv
        pass
项目:enterprise    作者:nanograv    | 项目源码 | 文件源码
def UniformUnnormedRV(lower=-np.inf, upper=np.inf):
    r"""An unnormalized uniform prior suitable for unbounded or
    half-bounded intervals.

    :param lower: lower bound of parameter range
    :type lower: float
    :param upper: upper bound of parameter range
    :type upper: float
    :return: a frozen rv_continuous instance with pdf equal to unity
               in the allowed interval and 0 elsewhere
    """
    return _UniformUnnormedRV_generator(name='unnormed_uniform',
                                        a=lower, b=upper)
项目:enterprise    作者:nanograv    | 项目源码 | 文件源码
def UniformBoundedRV(lower=0., upper=1.):
    r"""A uniform prior between two finite bounds.
    This is a convenience function with more natural bound parameters
    than ``scipy.stats.uniform``.

    :param lower: lower bound of parameter range
    :type lower: float
    :param upper: upper bound of parameter range
    :type upper: float
    :return: a frozen rv_continuous instance with normalized uniform
               probability inside the range [lower, upper] and 0 outside
    """
    uu = scipy.stats.uniform(lower, (upper - lower))
    return uu
项目:lhsmdu    作者:sahilm89    | 项目源码 | 文件源码
def inverseTransformSample(distribution, uniformSamples):
    ''' This function lets you convert from a standard uniform sample [0,1] to
    a sample from an arbitrary distribution. This is done by taking the cdf [0,1] of 
    the arbitrary distribution, and calculating its inverse to picking the sample."
    '''
    assert (isinstance(distribution, rv_continuous) or isinstance(distribution, rv_discrete) or isinstance(distribution,rv_frozen))
    newSamples = distribution.ppf(uniformSamples)
    return newSamples
项目:Bayesian-Optimisation    作者:hyperc54    | 项目源码 | 文件源码
def inverseTransformSample(distribution, uniformSamples):
    ''' This function lets you convert from a standard uniform sample [0,1] to
    a sample from an arbitrary distribution. This is done by taking the cdf [0,1] of 
    the arbitrary distribution, and calculating its inverse to picking the sample."
    '''
    assert (isinstance(distribution, rv_continuous) or isinstance(distribution, rv_discrete) or isinstance(distribution,rv_frozen))
    newSamples = distribution.ppf(uniformSamples)
    return newSamples