當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。