def cb_update(val): """ Slider Event Callback Func. """ dist = ds.Beta(sAlpha.val, sBeta.val) line2dObj.set_ydata(dist.pdf(x)) fig.canvas.draw_idle()
def run_bayesian_test(probs, config): t_start = time.time() beta = config.get("beta", 0.3) prior = d.Beta(config["prior"]["params"][0], config["prior"]["params"][1]) if beta < 0: beta = (1-prior.cdf(config["s"])) * 0.9 config["adaptive"] = 1 else: config["adaptive"] = 0 test = binomial_bayesian_test( config["s"], prior, alpha=config["alpha"], beta=beta, N=config["N"], steps=config.get("steps", 1)) output = run_experiment(test, probs, config) output["beta"] = beta output["time"] = time.time() - t_start return output
def run_fixed_test_early_stopping_experiment(probs, config): t_start = time.time() prior = d.Beta(config["prior"]["params"][0], config["prior"]["params"][1]) test = fixed_test_early_stopping(config["N"], config["s"], prior, alpha=config["alpha"]) output = run_experiment(test, probs, config) output["time"] = time.time() - t_start return output
def run_msprt_experiment(probs, config): t_start = time.time() prior = d.Beta(config["prior"]["params"][0], config["prior"]["params"][1]) test = lambda p: binomial_msprt_test(p, config["s"], prior, alpha=config["alpha"], N=config["N"], steps=config.get("steps", 10)) output = run_experiment(test, probs, config) output["time"] = time.time() - t_start return output
def run_optimal_boundary_experiment(probs, config): t_start = time.time() prior = d.Beta(config["prior"]["params"][0], config["prior"]["params"][1]) print("Finding boundary...") boundary, ET = solve_binomial(config["s"], prior, config["N"], ET=config.get("ET", 5000), alpha=config["alpha"], verbose=True) test = lambda p: boundary_test(p, boundary, slack=0) output = run_experiment(test, probs, config) output["ET"] = ET output["time"] = time.time() - t_start return output
def run_heuristic_boundary_experiment(probs, config): t_start = time.time() prior = d.Beta(config["prior"]["params"][0], config["prior"]["params"][1]) T = config.get("ET", 2000) beta = config.get("beta", 0.3) print("Finding boundary...") boundary = binomial_heuristic(config["s"], prior, config["N"], T=T, alpha=config["alpha"], beta=beta) test = lambda p: boundary_test(p, boundary, slack=0) output = run_experiment(test, probs, config) output["ET"] = T output["time"] = time.time() - t_start output["beta"] = beta return output
n_s = 1.5 n_prior = d.Gaussian(0, 1) n_data = d.Gaussian(0, 3) normal_boundaries, normal_ET = solve_normal(n_s, n_prior, n_data, N, ET=307, lb=300, ub=310, verbose=True) n_heuristic = normal_heuristic(n_s, n_prior, n_data, N, normal_ET, beta=0.4) bin_s = 0.4 bin_prior = d.Beta(3, 10) bin_boundaries, bin_ET = solve_binomial(bin_s, bin_prior, N, ET=200, verbose=True, adaptive=False) bin_heuristic = binomial_heuristic(bin_s, bin_prior, N, bin_ET, beta=0.3) f, axes = plt.subplots(1, 2, figsize=(7, 3)) ax = axes[0] gamma = (n_prior.tau / n_data.tau)**2 ax.plot([bdy.n for bdy in normal_boundaries],
beta_min, beta_max, beta0 = 0, max_param, 1.0 # Drawing range of Beta distribution x_min, x_max = 0, 1 y_min, y_max = 0, 12 x_step = 0.01 x = np.arange(x_min, x_max, x_step) fig, ax = plt.subplots(figsize=(6,6)) plt.subplots_adjust(left=0.1, bottom=0.25) ax.grid() ax.set_xlim(x_min, x_max) ax.set_ylim(y_min, y_max) dist = ds.Beta(alpha0, beta0) line2dObj, = plt.plot(x, dist.pdf(x), lw=2, color='red') # Slider, Button, RadioButton のfaceの色 axcolor = 'lightgoldenrodyellow' # # Slider # Left Btm Wid Hight axAlpha = plt.axes([0.1, 0.15, 0.8, 0.03], facecolor=axcolor) axBeta = plt.axes([0.1, 0.10, 0.8, 0.03], facecolor=axcolor) #sAlpha = Slider(axAlpha, 'Alpha', alpha_min, alpha_max, valinit=alpha0) #sBeta = Slider(axBeta , 'Beta', beta_min, beta_max, valinit=beta0) sAlpha = Slider(axAlpha, r'$\alpha$', alpha_min, alpha_max, valinit=alpha0) sBeta = Slider(axBeta , r'$\beta$', beta_min, beta_max, valinit=beta0)
ax.fill_between(sdf[x], sdf[y] - sdf[err], sdf[y] + sdf[err], alpha=0.2) if legend: ax.legend() min_AB = 200 alpha = 0.05 batting = load_baseball_data(min_AB) probs = batting["H/AB"] ahat, bhat = util.beta_mom(probs) betahat = d.Beta(ahat, bhat) df = pd.read_csv("../data/experiment_summary.csv") df >>= mutate(efficiency=X.n_discoveries / (X.avg_samples * X.n_tests)) df >>= mutate(efficacy=1 / X.efficiency) df["fdp_err"] = 2 * np.sqrt(df.fdp * (1 - df.fdp) / df.n_discoveries) df["power_err"] = 2 * np.sqrt(df.power * (1 - df.power) / df.true_effects) plot_df = df >> mask(X.alpha == alpha, X.min_AB == min_AB, X.s < 0.33, X.n_tests == 572100, X.n_discoveries > 0) plot_df = plot_df.sort_values("s") f, ax = plt.subplots(2, 2, figsize=(10, 6.25)) hist_ax = ax[0][0]