<jupyter_start><jupyter_text>Overview  Imports<jupyter_code>import numpy as np
from scipy.stats import norm, poisson
from scipy.interpolate import InterpolatedUnivariateSpline
from matplotlib.ticker import MultipleLocator
import matplotlib.pyplot as plt
%matplotlib inline

from plot_config import config_plots
config_plots()<jupyter_output><empty_output><jupyter_text>Figure 1- Sensitivity optimization: mean vs. median<jupyter_code>#bs = np.arange(0.01, 0.481, 0.01)
bs = np.arange(0.01, 0.51, 0.01)
bs
ss = np.linspace(1, 11, 20)
ss_med = np.linspace(1, 11, 1001)
ks = np.arange(0, 20, 1)
def meanNsigma(b, s, ks): 
    ps = poisson.pmf(k=ks, mu=s+b) 
    sigmas = np.array([norm.isf(poisson.sf(k=k_-1, mu=b), loc=0, scale=1) 
                       if k_ > 0 else norm.isf(poisson.sf(k=0, mu=b), loc=0, scale=1) for k_ in ks]) 
    return np.sum(ps*sigmas)/np.sum(ps)

def get_s_5sigma(b, ks=ks, ss=ss): 
    meanNsigs = np.array([meanNsigma(b, s_, ks) for s_ in ss]) 
    s5 = InterpolatedUnivariateSpline(ss, meanNsigs - 5).roots()[0] 
    return s5

def calc_mean_med_5sigma(b, ks=ks, ss=ss, ss_med=ss_med): 
    s = 0 
    n = s + b 
    s_mean = get_s_5sigma(b, ks, ss) 
    ndisc = poisson.isf(2.87e-7, mu=n)+1 
    sfs = poisson.sf(k=ndisc-1, mu=ss_med+b) 
    s_med = ss_med[np.argmin(abs(sfs-0.5))] 
    return s_mean, s_med 

s_means, s_meds = np.array([calc_mean_med_5sigma(b_, ks, ss, ss_med) for b_ in bs]).T 
# make plot
fig, ax = plt.subplots(figsize=(10, 6))
ax.plot(bs, s_meds, 'r-', linewidth=2, marker='.', mfc='black', mec='black', ms=1, zorder=10, label='median')
ax.plot(bs, s_means, 'k-', linewidth=1, marker='.', mfc='black', mec='black', ms=1, zorder=11, label='mean')
ax.xaxis.set_major_locator(MultipleLocator(0.1))
ax.xaxis.set_minor_locator(MultipleLocator(0.02))
ax.yaxis.set_minor_locator(MultipleLocator(0.2))
ax.tick_params(which='both', direction='in', top=True, right=True)
ax.set_xlim([0, 0.55])
ax.set_ylim([2.2, 7.7])
ax.legend()
fig.suptitle(r'S(median) vs. $\mu_\mathrm{B}$'+'\n(Classical Ordering)');
fig.savefig('S_vs_muB.png', transparent=False)
fig.savefig('S_vs_muB.pdf', transparent=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17012448132780084, 'fraction_numerical': 0.0396496081143384, 'mean_word_length': 4.880758807588076, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '655899', 'license': 'MIT', 'n_tokens_mistral': 1012, 'n_tokens_neox': 940, 'n_words': 180, 'path': 'stats/notebooks/SU2020/06-28-21_docdb-37812_Calculations.ipynb', 'repo_name': 'ckampa13/mu2e_utils', 'size': '2169'}