Python numpy.random.beta() Examples
The following are 7
code examples of numpy.random.beta().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy.random
, or try the search function
.
Example #1
Source File: distributions.py From particles with MIT License | 5 votes |
def rvs(self, size=None): return random.beta(self.a, self.b, size=size)
Example #2
Source File: distributions.py From particles with MIT License | 5 votes |
def logpdf(self, x): return stats.beta.logpdf(x, self.a, self.b)
Example #3
Source File: distributions.py From particles with MIT License | 5 votes |
def ppf(self, x): return stats.beta.ppf(x, self.a, self.b)
Example #4
Source File: bmh.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def plot_beta_hist(ax, a, b): ax.hist(beta(a, b, size=10000), histtype="stepfilled", bins=25, alpha=0.8, density=True)
Example #5
Source File: simulate_counts.py From WASP with Apache License 2.0 | 5 votes |
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
Example #6
Source File: simulate_counts.py From WASP with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: generate_data.py From lifetimes with MIT License | 4 votes |
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