本文整理汇总了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