本文整理匯總了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)
示例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)
示例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)
示例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)
示例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
示例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)
示例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