def qq_comp_binom_poiss_comp_determn_poiss(l,p,poisson_mu=4.0,n_sim=1000,\ alpha_hats = np.arange(0.0001,1.0,1e-3)): alphas = np.zeros(len(alpha_hats)) isfs = int(l * p) * poisson.isf(alpha_hats, poisson_mu) for _ in range(n_sim): comp_binom_rv = CompoundPoisson.rvs_s(poisson_mu, l, p, compound='binom') alphas += (comp_binom_rv > isfs) / n_sim return alphas, alpha_hats
def plot_alpha_beta(n=32,p=.3): dist_rvs_compound = lambda lmb,t: CompoundPoisson.rvs_s(lmb*t,n,p,compound='log') dist_rvs_poisson = lambda lmb,t: poisson.rvs(lmb*t) alphas1,betas1,alpha_hats1 = run_simulns(fn=dist_rvs_poisson) alphas2,betas2,alpha_hats2 = run_simulns(fn=dist_rvs_compound, n_sim=50000) plt.plot(alpha_hats1,alphas1,label='UMP poisson on poisson') plt.plot(alpha_hats2,alphas2,label='UMP poisson on compound poisson') plt.xlabel('Alpha') plt.ylabel('Beta') plt.legend(facecolor="black", edgecolor="black") fig.savefig("C:\\Users\\ropandey\\OneDrive\\MSFTProj\\HypothTestAIR\\alpha_hat_w_alpha.png", \ facecolor=fig.get_facecolor(), transparent=True) plt.close()
def binom_comp_poisson_alpha_beta(): dist_rvs_poisson = lambda lmb,t: poisson.rvs(lmb*t) alphas1,betas1,alpha_hats1 = run_simulns(fn=dist_rvs_poisson) print("Poisson done!") dist_rvs_compound = lambda lmb,t: CompoundPoisson.rvs_s(lmb*t,2,.4,compound='binom') alphas2,betas2,alpha_hats2 = run_simulns(fn=dist_rvs_compound, n_sim=50000) print("l=2 done") dist_rvs_compound = lambda lmb,t: CompoundPoisson.rvs_s(lmb*t,3,.4,compound='binom') alphas3,betas3,alpha_hats3 = run_simulns(fn=dist_rvs_compound, n_sim=5000) print("l=3 done") dist_rvs_compound = lambda lmb,t: CompoundPoisson.rvs_s(lmb*t,4,.4,compound='binom') alphas4,betas4,alpha_hats4 = run_simulns(fn=dist_rvs_compound, n_sim=5000) print("l=4 done") dist_rvs_compound = lambda lmb,t: CompoundPoisson.rvs_s(lmb*t,5,.4,compound='binom') alphas5,betas5,alpha_hats5 = run_simulns(fn=dist_rvs_compound, n_sim=5000) print("l=5 done") dist_rvs_compound = lambda lmb,t: CompoundPoisson.rvs_s(lmb*t,6,.4,compound='binom') alphas6,betas6,alpha_hats6 = run_simulns(fn=dist_rvs_compound, n_sim=5000) print("l=5 done") dist_rvs_compound = lambda lmb,t: CompoundPoisson.rvs_s(lmb*t,10,.4,compound='binom') alphas10,betas10,alpha_hats10 = run_simulns(fn=dist_rvs_compound, n_sim=5000) print("l=10 done") dist_rvs_compound = lambda lmb,t: CompoundPoisson.rvs_s(lmb*t,20,.4,compound='binom') alphas20,betas20,alpha_hats20 = run_simulns(fn=dist_rvs_compound, n_sim=5000) print("all done") color_list = sns.color_palette("RdBu_r", 20) color_list = color_list.as_hex() plt.plot(alphas1,betas1,label='UMP poisson on poisson',color='black') plt.plot(alphas2,betas2,label='UMP poisson on compound poisson l=2',color=color_list[1]) plt.plot(alphas3,betas3,label='UMP poisson on compound poisson l=3',color=color_list[2]) plt.plot(alphas4,betas4,label='UMP poisson on compound poisson l=4',color=color_list[3]) plt.plot(alphas5,betas5,label='UMP poisson on compound poisson l=5',color=color_list[4]) plt.plot(alphas6,betas6,label='UMP poisson on compound poisson l=6',color=color_list[5]) plt.plot(alphas10,betas10,label='UMP poisson on compound poisson l=10',color=color_list[9]) plt.plot(alphas20,betas20,label='UMP poisson on compound poisson l=20',color=color_list[19]) plt.xlabel('Alpha') plt.ylabel('Beta') plt.legend() plt.show() plt.plot(alpha_hats1,alphas1,label='UMP poisson on poisson') plt.plot(alpha_hats2,alphas2,label='UMP poisson on compound poisson l=2',color=color_list[1]) plt.plot(alpha_hats3,alphas3,label='UMP poisson on compound poisson l=3',color=color_list[2]) plt.plot(alpha_hats4,alphas4,label='UMP poisson on compound poisson l=4',color=color_list[3]) plt.plot(alpha_hats5,alphas5,label='UMP poisson on compound poisson l=5',color=color_list[4]) plt.plot(alpha_hats6,alphas6,label='UMP poisson on compound poisson l=6',color=color_list[5]) plt.plot(alpha_hats10,alphas10,label='UMP poisson on compound poisson l=10',color=color_list[9]) plt.plot(alpha_hats20,alphas20,label='UMP poisson on compound poisson l=20',color=color_list[19]) plt.xlabel('Type-1 error') plt.ylabel('False positive rate') plt.legend() plt.show()
def tst_ump_poisson_on_comp_poisson(): ## Only works for l=1! l = 1 p = .3 beta_1 = UMPPoisson.beta_on_poisson_closed_form(t1=25,t2=25,\ lmb_base=12*l*p,effect=1*l*p,alpha=0.1) dist_rvs_compound = lambda lmb, t: CompoundPoisson.rvs_s( lmb * t, l, p, compound='binom') alphas, betas, alpha_hats = alpha_beta_curve(dist_rvs_compound,n_sim=10000, lmb=12, t1=25, t2=25, \ scale=1.0, dellmb = 1) ix = np.argmin((alpha_hats - 0.1)**2) print(alpha_hats[ix]) beta_2 = betas[ix] assert (beta_2 - beta_1) / beta_1 < 1e-3
def tst_ump_poisson_on_determinist_cmpnd_alpha(plot=False): alphas,alpha_hats,pois_mas = xtst.UMPPoisson.alpha_on_determinist_compound_closed_form(\ lmb=10.0,t1=10,t2=10,l=3) ix = np.argmin((alpha_hats - 0.05)**2) print(alpha_hats[ix]) alpha = alphas[ix] l = 3 p = 1.0 dist_rvs_compound = lambda lmb, t: CompoundPoisson.rvs_s( lmb * t, l, p, compound='binom') alphas1, betas1, alpha_hats1 = alpha_beta_curve(dist_rvs_compound,n_sim=10000, \ lmb=10, t1=10, t2=10, scale=1.0, dellmb = 0) ix = np.argmin((alpha_hats1 - 0.05)**2) print(alpha_hats1[ix]) alpha1 = alphas1[ix] if plot: plt.plot(alpha_hats, alphas, label='Closed form') plt.plot(alpha_hats1, alphas1, label='Simulated') plt.legend() plt.show() assert abs(alpha1 - alpha) / alpha1 < 1e-3
def alpha_plots(n=32,p=.3): dist_rvs_compound = lambda lmb,t: CompoundPoisson.rvs_s(lmb*t,n,p,compound='log') dist_rvs_poisson = lambda lmb,t: poisson.rvs(lmb*t) alphas1,betas1,alpha_hats1 = run_simulns(fn=dist_rvs_compound, n_sim=5000, t1=10.0,t2=3.0) alphas2,betas2,alpha_hats2 = run_simulns(fn=dist_rvs_compound, n_sim=5000, t1=3.0,t2=10.0) alphas3,betas3,alpha_hats3 = run_simulns(fn=dist_rvs_compound, n_sim=5000, t1=10.0,t2=10.0) alphas4,betas4,alpha_hats4 = run_simulns(fn=dist_rvs_compound, n_sim=5000, t1=3.0,t2=3.0) alphas5,betas5,alpha_hats5 = run_simulns(fn=dist_rvs_compound, n_sim=5000, lmb=5.0, t1=10.0,t2=10.0) plt.plot(alpha_hats1,alphas1,label="t1=10; t2=3; lmb=20") plt.plot(alpha_hats2,alphas2,label="t1=3; t2=10; lmb=20")s plt.plot(alpha_hats3,alphas3,label="t1=10; t2=10; lmb=20") plt.plot(alpha_hats4,alphas4,label="t1=3; t2=3; lmb=20") plt.plot(alpha_hats5,alphas5,label="t1=10; t2=10; lmb=5") plt.xlabel('Alpha you set') plt.ylabel('Alpha you get') plt.legend(facecolor="black", edgecolor="black") fig.savefig("C:\\Users\\rohit\\OneDrive\\MSFTProj\\HypothTestAIR\\alpha_mapping_no_change.png", \ facecolor=fig.get_facecolor(), transparent=True) plt.close()
from stochproc.hypothesis.hypoth_tst_simulator import run_simulns from stochproc.count_distributions.compound_poisson import CompoundPoisson # mpl.rcParams.update({'text.color' : "white", # 'axes.labelcolor' : "white", # 'xtick.color' : "white", # 'ytick.color' : "white", # "axes.edgecolor" : "white"}) # fig, ax = plt.subplots(facecolor='black') # #ax.set_axis_bgcolor("black") # ax.set_facecolor("black") #fig, ax = plt.subplots() dist_rvs_compound = lambda lmb,t: CompoundPoisson.rvs_s(lmb*t,32,.3,compound='binom') dist_rvs_poisson = lambda lmb,t: poisson.rvs(lmb*t) def plot_tests_on_distributions(): alphas1,betas1,alpha_hats1 = run_simulns(fn=dist_rvs_poisson) alphas2,betas2,alpha_hats2 = run_simulns(fn=dist_rvs_compound, n_sim=50000) alphas3,betas3,alpha_hats3 = run_simulns(fn=dist_rvs_interarrivalw, n_sim=5000) alphas4,betas4,alpha_hats4 = run_simulns(fn=dist_rvs_interarrivalw, n_sim=5000, scale=25.0) alphas5,betas5,alpha_hats5 = run_simulns(fn=dist_rvs_interarrivalw, n_sim=5000, scale=1/10.0) plt.plot(alphas1,betas1,label='UMP poisson on poisson') plt.plot(alphas2,betas2,label='UMP poisson on compound poisson') plt.plot(alphas3,betas3,label='UMP poisson on interarrival weibull') plt.plot(alphas4,betas4,label='UMP poisson sc:25.0 on interarrival weibull') plt.plot(alphas5,betas5,label='UMP poisson sc:0.1 on interarrival weibull') plt.xlabel('Alpha')