當前位置: 首頁>>代碼示例>>Python>>正文


Python random.beta方法代碼示例

本文整理匯總了Python中numpy.random.beta方法的典型用法代碼示例。如果您正苦於以下問題:Python random.beta方法的具體用法?Python random.beta怎麽用?Python random.beta使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.random的用法示例。


在下文中一共展示了random.beta方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: rvs

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import beta [as 別名]
def rvs(self, size=None):
        return random.beta(self.a, self.b, size=size) 
開發者ID:nchopin,項目名稱:particles,代碼行數:4,代碼來源:distributions.py

示例2: logpdf

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import beta [as 別名]
def logpdf(self, x):
        return stats.beta.logpdf(x, self.a, self.b) 
開發者ID:nchopin,項目名稱:particles,代碼行數:4,代碼來源:distributions.py

示例3: ppf

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import beta [as 別名]
def ppf(self, x):
        return stats.beta.ppf(x, self.a, self.b) 
開發者ID:nchopin,項目名稱:particles,代碼行數:4,代碼來源:distributions.py

示例4: plot_beta_hist

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import beta [as 別名]
def plot_beta_hist(ax, a, b):
    ax.hist(beta(a, b, size=10000), histtype="stepfilled",
            bins=25, alpha=0.8, density=True) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:5,代碼來源:bmh.py

示例5: simulate_BNB

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import beta [as 別名]
def simulate_BNB(mean, sigma, n):
    # sys.stderr.write("%g %g %g\n" % (mean, sigma, n))
    mean_p = np.float64(n) / (n+mean)
    sigma = (1 / sigma)**2
    a = mean_p * (sigma)+1
    b = (1 - mean_p)*sigma
    
    p = beta(a, b)
    #sys.stderr.write("%f %f\n"%(n,p))
    counts = negative_binomial(n, p)
    return counts 
開發者ID:bmvdgeijn,項目名稱:WASP,代碼行數:13,代碼來源:simulate_counts.py

示例6: simulate_BB

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import beta [as 別名]
def simulate_BB(tot, mean_p, sigma):
    a = mean_p * (1/sigma**2 - 1)
    b = (1-mean_p) * (1/sigma**2 - 1)

    p = beta(a, b)
    counts = binomial(tot, p)
    #sys.stderr.write("%f %f %i\n"%(mean_p,p,counts))
    return counts, (tot-counts) 
開發者ID:bmvdgeijn,項目名稱:WASP,代碼行數:10,代碼來源:simulate_counts.py

示例7: beta_geometric_beta_binom_model

# 需要導入模塊: from numpy import random [as 別名]
# 或者: from numpy.random import beta [as 別名]
def beta_geometric_beta_binom_model(N, alpha, beta, gamma, delta, size=1):
    """
    Generate artificial data according to the Beta-Geometric/Beta-Binomial
    Model.

    You may wonder why we can have frequency = n_periods, when frequency excludes their
    first order. When a customer purchases something, they are born, _and in the next
    period_ we start asking questions about their alive-ness. So really they customer has
    bought frequency + 1, and been observed for n_periods + 1

    Parameters
    ----------
    N: array_like
        Number of transaction opportunities for new customers.
    alpha, beta, gamma, delta: float
        Parameters in the model. See [1]_
    size: int, optional
        The number of customers to generate

    Returns
    -------
    DataFrame
        with index as customer_ids and the following columns:
        'frequency', 'recency', 'n_periods', 'lambda', 'p', 'alive', 'customer_id'

    References
    ----------
    .. [1] Fader, Peter S., Bruce G.S. Hardie, and Jen Shang (2010),
       "Customer-Base Analysis in a Discrete-Time Noncontractual Setting,"
       Marketing Science, 29 (6), 1086-1108.

    """

    if type(N) in [float, int, np.int64]:
        N = N * np.ones(size)
    else:
        N = np.asarray(N)

    probability_of_post_purchase_death = random.beta(a=alpha, b=beta, size=size)
    thetas = random.beta(a=gamma, b=delta, size=size)

    columns = ["frequency", "recency", "n_periods", "p", "theta", "alive", "customer_id"]
    df = pd.DataFrame(np.zeros((size, len(columns))), columns=columns)
    for i in range(size):
        p = probability_of_post_purchase_death[i]
        theta = thetas[i]

        # hacky until I can find something better
        current_t = 0
        alive = True
        times = []
        while current_t < N[i] and alive:
            alive = random.binomial(1, theta) == 0
            if alive and random.binomial(1, p) == 1:
                times.append(current_t)
            current_t += 1
        # adding in final death opportunity to agree with [1]
        if alive:
            alive = random.binomial(1, theta) == 0
        df.iloc[i] = len(times), times[-1] + 1 if len(times) != 0 else 0, N[i], p, theta, alive, i
    return df 
開發者ID:CamDavidsonPilon,項目名稱:lifetimes,代碼行數:63,代碼來源:generate_data.py


注:本文中的numpy.random.beta方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。