当前位置: 首页>>代码示例>>Python>>正文


Python beta.ppf方法代码示例

本文整理汇总了Python中scipy.stats.beta.ppf方法的典型用法代码示例。如果您正苦于以下问题:Python beta.ppf方法的具体用法?Python beta.ppf怎么用?Python beta.ppf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats.beta的用法示例。


在下文中一共展示了beta.ppf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _clopper_pearson_confint

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def _clopper_pearson_confint(self, counts: int, shots: int, alpha: float
                                 ) -> Tuple[float, float]:
        """Compute the Clopper-Pearson confidence interval for `shots` i.i.d. Bernoulli trials.

        Args:
            counts: The number of positive counts.
            shots: The number of shots.
            alpha: The confidence level for the confidence interval.

        Returns:
            The Clopper-Pearson confidence interval.
        """
        lower, upper = 0, 1

        # if counts == 0, the beta quantile returns nan
        if counts != 0:
            lower = beta.ppf(alpha / 2, counts, shots - counts + 1)

        # if counts == shots, the beta quantile returns nan
        if counts != shots:
            upper = beta.ppf(1 - alpha / 2, counts + 1, shots - counts)

        return lower, upper 
开发者ID:Qiskit,项目名称:qiskit-aqua,代码行数:25,代码来源:iqae.py

示例2: plot

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def plot(self, data, size, newdata=None):

        data = np.array(data)
        numsample = len(data)

        colmean = np.mean(data, axis=0)
        matcov = np.cov(data.T)
        matinv = np.linalg.inv(matcov)

        values = []
        for sample in data:
            dif = sample - colmean
            value = matinv.dot(dif.T).dot(dif)
            values.append(value)

        cl = ((numsample - 1)**2) / numsample
        lcl = cl * beta.ppf(0.00135, size / 2, (numsample - size - 1) / 2)
        center = cl * beta.ppf(0.5, size / 2, (numsample - size - 1) / 2)
        ucl = cl * beta.ppf(0.99865, size / 2, (numsample - size - 1) / 2)

        return (values, center, lcl, ucl, self._title) 
开发者ID:carlosqsilva,项目名称:pyspc,代码行数:23,代码来源:hotelling.py

示例3: get_probility

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def get_probility(x, N, a=0.05):
    '''
    计算 N 此重复实验,事件 A 发生 x 次时,事件 A 的发生概率

    Args:
        x : 事件发生次数
        N : 总实验次数
        a : 设置显著性水平 1-a,默认 0.05

    Returns:
        P, E, std, (low, high)
        事件 A 发生概率 P 的最概然取值、期望、以及其置信区间
    '''
    P = 1.0 * x / N
    E = (x + 1.0) / (N + 2.0)
    std = np.sqrt(E * (1 - E) / (N + 3))
    low = beta.ppf(0.5 * a, x + 1, N - x + 1)
    high = beta.ppf(1 - 0.5 * a, x + 1, N - x + 1)
    return P, E, std, (low, high) 
开发者ID:feihoo87,项目名称:QuLab,代码行数:21,代码来源:func.py

示例4: _clopper_pearson_interval

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def _clopper_pearson_interval(self):
        r"""
        Computes the Clopper-Pearson 'exact' confidence interval.

        References
        ----------
        Wikipedia contributors. (2018, July 14). Binomial proportion confidence interval.
            In Wikipedia, The Free Encyclopedia. Retrieved 00:40, August 15, 2018,
            from https://en.wikipedia.org/w/index.php?title=Binomial_proportion_confidence_interval&oldid=850256725

        """
        p = self.x / self.n

        if self.alternative == 'less':
            lower_bound = 0.0
            upper_bound = beta.ppf(1 - self.alpha, self.x + 1, self.n - self.x)
        elif self.alternative == 'greater':
            upper_bound = 1.0
            lower_bound = beta.ppf(self.alpha, self.x, self.n - self.x + 1)
        else:
            lower_bound = beta.ppf(self.alpha / 2, self.x, self.n - self.x + 1)
            upper_bound = beta.ppf(1 - self.alpha / 2, self.x + 1, self.n - self.x)

        clopper_pearson_interval = {
            'probability of success': p,
            'conf level': 1 - self.alpha,
            'interval': (lower_bound, upper_bound)
        }

        return clopper_pearson_interval 
开发者ID:aschleg,项目名称:hypothetical,代码行数:32,代码来源:hypothesis.py

示例5: transform_normal

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def transform_normal(x,hyperparameters):
    mu,sigma = hyperparameters
    return norm.ppf(x,loc=mu,scale=sigma) 
开发者ID:nespinoza,项目名称:juliet,代码行数:5,代码来源:utils.py

示例6: transform_beta

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def transform_beta(x,hyperparameters):
    a,b = hyperparameters
    return beta.ppf(x,a,b) 
开发者ID:nespinoza,项目名称:juliet,代码行数:5,代码来源:utils.py

示例7: transform_exponential

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def transform_exponential(x,hyperparameters):
    a = hyperparameters
    return gamma.ppf(x, a) 
开发者ID:nespinoza,项目名称:juliet,代码行数:5,代码来源:utils.py

示例8: transform_truncated_normal

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def transform_truncated_normal(x,hyperparameters):
    mu, sigma, a, b = hyperparameters
    ar, br = (a - mu) / sigma, (b - mu) / sigma
    return truncnorm.ppf(x,ar,br,loc=mu,scale=sigma) 
开发者ID:nespinoza,项目名称:juliet,代码行数:6,代码来源:utils.py

示例9: transform_normal

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def transform_normal(x,mu,sigma):
    return norm.ppf(x,loc=mu,scale=sigma) 
开发者ID:nespinoza,项目名称:juliet,代码行数:4,代码来源:utils.py

示例10: transform_exponential

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def transform_exponential(x,a=1.):
    return gamma.ppf(x, a) 
开发者ID:nespinoza,项目名称:juliet,代码行数:4,代码来源:utils.py

示例11: transform_truncated_normal

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def transform_truncated_normal(x,mu,sigma,a=0.,b=1.):
    ar, br = (a - mu) / sigma, (b - mu) / sigma
    return truncnorm.ppf(x,ar,br,loc=mu,scale=sigma) 
开发者ID:nespinoza,项目名称:juliet,代码行数:5,代码来源:utils.py

示例12: binom_interval

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def binom_interval(success, total, confint=0.95):
    """
    Compute two-sided binomial confidence interval in Python. Based on R's binom.test.
    """

    from scipy.stats import beta

    quantile = (1 - confint) / 2.
    lower = beta.ppf(quantile, success, total - success + 1)
    upper = beta.ppf(1 - quantile, success + 1, total - success)
    return (lower, upper) 
开发者ID:pandas-ml,项目名称:pandas-ml,代码行数:13,代码来源:stats.py

示例13: __init__

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def __init__(self, n, x, p=0.5, alternative='two-sided', alpha=0.05, continuity=True):

        if x > n:
            raise ValueError('number of successes cannot be greater than number of trials.')

        if p > 1.0:
            raise ValueError('expected probability of success cannot be greater than 1.')

        if alternative not in ('two-sided', 'greater', 'less'):
            raise ValueError("'alternative must be one of 'two-sided' (default), 'greater', or 'less'.")

        self.n = n
        self.x = x
        self.p = p
        self.q = 1.0 - self.p
        self.alpha = alpha
        self.alternative = alternative
        self.continuity = continuity
        self.p_value = self._p_value()

        if self.alternative == 'greater':
            self.z = norm.ppf(self.alpha)
        elif self.alternative == 'less':
            self.z = norm.ppf(1 - self.alpha)
        else:
            self.z = norm.ppf(1 - self.alpha / 2)

        self.clopper_pearson_interval = self._clopper_pearson_interval()
        self.wilson_score_interval = self._wilson_score_interval()
        self.agresti_coull_interval = self._agresti_coull_interval()
        self.arcsine_transform_interval = self._arcsine_transform_interval()

        self.test_summary = {
            'Number of Successes': self.x,
            'Number of Trials': self.n,
            'p-value': self.p_value,
            'alpha': self.alpha,
            'intervals': {
                'Clopper-Pearson': self.clopper_pearson_interval,
                'Wilson Score': self.wilson_score_interval,
                'Agresti-Coull': self.agresti_coull_interval,
                'Arcsine Transform': self.arcsine_transform_interval
            }
        } 
开发者ID:aschleg,项目名称:hypothetical,代码行数:46,代码来源:hypothesis.py

示例14: _conf_int

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def _conf_int(self):
        r"""
        Computes the confidence interval.

        Returns
        -------
        intervals : tuple
            Tuple containing the low and high confidence interval.

        Notes
        -----
        Confidence intervals are reported as a proportion, denoted by :math:`1 - \alpha`, which
        represents the ratio of intervals that would contain the population parameter if samples
        were redrawn and tested with the same procedure. A confidence level is the interval reported
        as a percentage, :math:`(1 - \alpha) * 100\%`. The width of the :math:`(1 - \alpha) * 100\%`
        interval has several dependencies:

        1. The confidence level. As :math:`1 - \alpha` increases, so does the width of the interval.
        2. As the sample size :math:`n` increases, the smaller the standard error and thus a narrower interval.
        3. If the standard deviation is large, then the interval will also be large.

        The computation of the intervals uses Welch's t-interval which extends the two-sample pooled
        t-interval for unequal population variances and sample sizes.

        .. math::

            \left(\bar{X_1} - \bar{X_2}\right) \pm t_{\alpha / 2, r} \sqrt{\frac{s_{x_1}^2}{n_1} + \frac{s_{x_2}^2}{n_2}}

        References
        ----------
        Rencher, A. C., & Christensen, W. F. (2012). Methods of multivariate analysis (3rd Edition).

        """
        xn, xvar, xbar = self.sample_statistics[self._y1_summary_stat_name]['obs'], \
                         self.sample_statistics[self._y1_summary_stat_name]['variance'], \
                         self.sample_statistics[self._y1_summary_stat_name]['mean']

        if self.y2 is not None:
            yn, yvar, ybar = self.sample_statistics['Sample 2']['obs'], \
                             self.sample_statistics['Sample 2']['variance'], \
                             self.sample_statistics['Sample 2']['mean']

            low_interval = (xbar - ybar) + t.ppf(self.alpha / 2., self.parameter) * np.sqrt(xvar / xn + yvar / yn)
            high_interval = (xbar - ybar) - t.ppf(self.alpha / 2., self.parameter) * np.sqrt(xvar / xn + yvar / yn)

        else:
            low_interval = xbar + 1.96 * np.sqrt(xvar / xn)
            high_interval = xbar - 1.96 * np.sqrt(xvar / xn)

        if self.alternative == 'greater':
            intervals = np.inf, float(high_interval)
        elif self.alternative == 'less':
            intervals = -np.inf, float(low_interval)
        else:
            intervals = float(low_interval), float(high_interval)

        return intervals 
开发者ID:aschleg,项目名称:hypothetical,代码行数:59,代码来源:hypothesis.py

示例15: beta_confidence_intervals

# 需要导入模块: from scipy.stats import beta [as 别名]
# 或者: from scipy.stats.beta import ppf [as 别名]
def beta_confidence_intervals(ci_X, ntrials, ci=0.95):
    """
    Compute confidence intervals of beta distributions.

    Parameters
    ----------
    ci_X : numpy.array
        Computed confidence interval estimate from `ntrials` experiments
    ntrials : int
        The number of trials that were run.
    ci : float, optional, default=0.95
        Confidence interval to report (e.g. 0.95 for 95% confidence interval)

    Returns
    -------
    Plow : float
        The lower bound of the symmetric confidence interval.
    Phigh : float
        The upper bound of the symmetric confidence interval.

    Examples
    --------

    >>> ci_X = np.random.rand(10,10)
    >>> ntrials = 100
    >>> [Plow, Phigh] = beta_confidence_intervals(ci_X, ntrials)

    """
    # Compute low and high confidence interval for symmetric CI about mean.
    ci_low = 0.5 - ci/2;
    ci_high = 0.5 + ci/2;

    # Compute for every element of ci_X.
    from scipy.stats import beta
    Plow = ci_X * 0.0;
    Phigh = ci_X * 0.0;
    for i in range(ci_X.shape[0]):
        for j in range(ci_X.shape[1]):
            Plow[i,j] = beta.ppf(ci_low, a = ci_X[i,j] * ntrials, b = (1-ci_X[i,j]) * ntrials);
            Phigh[i,j] = beta.ppf(ci_high, a = ci_X[i,j] * ntrials, b = (1-ci_X[i,j]) * ntrials);

    return [Plow, Phigh] 
开发者ID:bhmm,项目名称:bhmm,代码行数:44,代码来源:analysis.py


注:本文中的scipy.stats.beta.ppf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。