From 3f92552927cb9bdf9fe00783bbb28fab2ff12714 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 May 2021 13:45:23 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../notebooks/learn/details_cls.ipynb | 402 ++++++++++-------- 1 file changed, 225 insertions(+), 177 deletions(-) diff --git a/docs/examples/notebooks/learn/details_cls.ipynb b/docs/examples/notebooks/learn/details_cls.ipynb index 8e66d16ef6..b218db5e5f 100644 --- a/docs/examples/notebooks/learn/details_cls.ipynb +++ b/docs/examples/notebooks/learn/details_cls.ipynb @@ -12,50 +12,55 @@ "import pyhf.contrib.viz.brazil\n", "from pyhf.infer.calculators import AsymptoticCalculator\n", "import scipy.stats\n", - "plt.rcParams['savefig.facecolor']='white'\n", "\n", + "plt.rcParams['savefig.facecolor'] = 'white'\n", + "\n", + "\n", + "def gpdf(qq, muprime, sig, mu):\n", + " cut = mu ** 2 / sig ** 2\n", "\n", - "def gpdf(qq,muprime,sig,mu):\n", - " cut = mu**2/sig**2\n", - " \n", " # 1/√(2π)\n", - " standard_pre = 1/np.sqrt(2*np.pi)\n", + " standard_pre = 1 / np.sqrt(2 * np.pi)\n", "\n", " # compute the arg of the exponential\n", - " muprime_muhat1_minus_over_sig = (qq - (mu**2/sig**2 - (2*mu*muprime/sig**2)) )/(2*mu/sig)\n", - " muprime_muhat2_minus_over_sig = (np.sqrt(qq)-(mu-muprime)/sig) \n", + " muprime_muhat1_minus_over_sig = (\n", + " qq - (mu ** 2 / sig ** 2 - (2 * mu * muprime / sig ** 2))\n", + " ) / (2 * mu / sig)\n", + " muprime_muhat2_minus_over_sig = np.sqrt(qq) - (mu - muprime) / sig\n", "\n", " # chose which one\n", - " muhat_over_sig = np.where(qq>cut,muprime_muhat1_minus_over_sig,muprime_muhat2_minus_over_sig)\n", + " muhat_over_sig = np.where(\n", + " qq > cut, muprime_muhat1_minus_over_sig, muprime_muhat2_minus_over_sig\n", + " )\n", "\n", " # exp(-0.5 (mu^-mu'))\n", - " arg = -0.5*(muhat_over_sig)**2\n", + " arg = -0.5 * (muhat_over_sig) ** 2\n", "\n", - " # compute the jacobian \n", + " # compute the jacobian\n", " # 1/ sigma * dµ^/dq\n", - " oos_j1 = 1/(2*mu/sig)\n", - " oos_j2 = 1/(2*np.sqrt(qq))\n", - " \n", + " oos_j1 = 1 / (2 * mu / sig)\n", + " oos_j2 = 1 / (2 * np.sqrt(qq))\n", + "\n", " # chose which one\n", - " one_over_sig_jacobian = np.where(qq>cut,oos_j1,oos_j2)\n", + " one_over_sig_jacobian = np.where(qq > cut, oos_j1, oos_j2)\n", "\n", " # compute the reparametrized gaussian\n", - " return standard_pre * np.exp(arg)*one_over_sig_jacobian\n", + " return standard_pre * np.exp(arg) * one_over_sig_jacobian\n", "\n", - "def testrail_parab(muhat,mu,sigma):\n", - " return (muhat-mu)**2/sigma**2\n", "\n", - "def testrail_flat(muhat,mu,sigma):\n", + "def testrail_parab(muhat, mu, sigma):\n", + " return (muhat - mu) ** 2 / sigma ** 2\n", + "\n", + "\n", + "def testrail_flat(muhat, mu, sigma):\n", " return np.where(\n", - " muhat<0,\n", - " (muhat-mu)**2/sigma**2 - muhat**2/sigma**2,\n", - " np.where(muhat < mu,\n", - " (muhat-mu)**2/sigma**2,\n", - " 0.0\n", - " )\n", + " muhat < 0,\n", + " (muhat - mu) ** 2 / sigma ** 2 - muhat ** 2 / sigma ** 2,\n", + " np.where(muhat < mu, (muhat - mu) ** 2 / sigma ** 2, 0.0),\n", " )\n", "\n", - "def get_toy_results(test_poi,toys):\n", + "\n", + "def get_toy_results(test_poi, toys):\n", " qmu_tilde = np.asarray(\n", " [\n", " pyhf.infer.test_statistics.qmu_tilde(\n", @@ -77,15 +82,21 @@ " )\n", "\n", " muhat = pars[:, model.config.poi_index]\n", - " return muhat,qmu_tilde \n", + " return muhat, qmu_tilde\n", + "\n", "\n", "model = pyhf.simplemodels.hepdata_like(\n", " signal_data=[30.0], bkg_data=[50.0], bkg_uncerts=[7.0]\n", ")\n", "data = [55.0] + model.config.auxdata\n", "\n", - "asimov_data = pyhf.infer.calculators.generate_asimov_data(0.0,data,model,\n", - " model.config.suggested_init(),model.config.suggested_bounds(),model.config.suggested_fixed()\n", + "asimov_data = pyhf.infer.calculators.generate_asimov_data(\n", + " 0.0,\n", + " data,\n", + " model,\n", + " model.config.suggested_init(),\n", + " model.config.suggested_bounds(),\n", + " model.config.suggested_fixed(),\n", ")" ] }, @@ -104,42 +115,51 @@ } ], "source": [ - "muhatmin, muhatmax = -5,5\n", - "mumin, mumax = 1e-2,1.2\n", + "muhatmin, muhatmax = -5, 5\n", + "mumin, mumax = 1e-2, 1.2\n", "maxsigma = 4\n", "\n", - "qqspan = np.linspace(0,maxsigma**2,10001)\n", - "muspan = np.linspace(mumin, mumax,31)\n", - "muhatspan = np.linspace(muhatmin, muhatmax,1001)\n", + "qqspan = np.linspace(0, maxsigma ** 2, 10001)\n", + "muspan = np.linspace(mumin, mumax, 31)\n", + "muhatspan = np.linspace(muhatmin, muhatmax, 1001)\n", "test_stats = []\n", "vals = []\n", "prll_and_sigmas = []\n", "\n", "\n", "def collect_data_at_test(mu_test):\n", - " calc = AsymptoticCalculator(data,model)\n", + " calc = AsymptoticCalculator(data, model)\n", " ts = calc.teststatistic(mu_test)\n", - " ds,db = calc.distributions(mu_test)\n", - " cl_sb,cl_b,cl_s = calc.pvalues(ts,ds,db)\n", + " ds, db = calc.distributions(mu_test)\n", + " cl_sb, cl_b, cl_s = calc.pvalues(ts, ds, db)\n", "\n", " obs_pllr_ts = pyhf.infer.test_statistics.qmu_tilde(\n", - " mu_test,data,model,\n", - " model.config.suggested_init(),model.config.suggested_bounds(),model.config.suggested_fixed()\n", + " mu_test,\n", + " data,\n", + " model,\n", + " model.config.suggested_init(),\n", + " model.config.suggested_bounds(),\n", + " model.config.suggested_fixed(),\n", " )\n", "\n", " asimov_pllr_ts = pyhf.infer.test_statistics.qmu_tilde(\n", - " mu_test,asimov_data,model,\n", - " model.config.suggested_init(),model.config.suggested_bounds(),model.config.suggested_fixed()\n", + " mu_test,\n", + " asimov_data,\n", + " model,\n", + " model.config.suggested_init(),\n", + " model.config.suggested_bounds(),\n", + " model.config.suggested_fixed(),\n", " )\n", - " sigma = np.sqrt(mu_test**2/asimov_pllr_ts)\n", + " sigma = np.sqrt(mu_test ** 2 / asimov_pllr_ts)\n", + "\n", + " tstats = [ds.shift, db.shift, ts]\n", + " pvals = [cl_sb, cl_b, cl_s]\n", + " prll_and_sig = [obs_pllr_ts, asimov_pllr_ts, sigma]\n", + " return tstats, pvals, prll_and_sig\n", "\n", - " tstats = [ds.shift,db.shift,ts]\n", - " pvals = [cl_sb,cl_b,cl_s]\n", - " prll_and_sig = [obs_pllr_ts,asimov_pllr_ts,sigma]\n", - " return tstats,pvals,prll_and_sig\n", "\n", "for mu_test in muspan:\n", - " tstats,pvals,prll_and_sig = collect_data_at_test(mu_test)\n", + " tstats, pvals, prll_and_sig = collect_data_at_test(mu_test)\n", " test_stats.append(tstats)\n", " vals.append(pvals)\n", " prll_and_sigmas.append(prll_and_sig)\n", @@ -151,18 +171,17 @@ "unbounded_bounds = model.config.suggested_bounds()\n", "unbounded_bounds[model.config.poi_index] = (-10, 10)\n", "\n", - "empirial_muhat = pyhf.infer.mle.fit(\n", - " data,model,\n", - " par_bounds = unbounded_bounds\n", - ")[model.config.poi_index] \n", + "empirial_muhat = pyhf.infer.mle.fit(data, model, par_bounds=unbounded_bounds)[\n", + " model.config.poi_index\n", + "]\n", + "\n", "\n", "def getv(mu_test):\n", - " calc = AsymptoticCalculator(data,model)\n", + " calc = AsymptoticCalculator(data, model)\n", " ts = calc.teststatistic(mu_test)\n", - " ds,db = calc.distributions(mu_test)\n", - " cl_sb,cl_b,cl_s = calc.pvalues(ts,ds,db)\n", - " return [cl_sb,cl_b,cl_s]\n", - "\n" + " ds, db = calc.distributions(mu_test)\n", + " cl_sb, cl_b, cl_s = calc.pvalues(ts, ds, db)\n", + " return [cl_sb, cl_b, cl_s]" ] }, { @@ -387,186 +406,214 @@ " vals,\n", "):\n", "\n", - "\n", " mutest_at_index = muspan[index]\n", - " means_at_index = -test_stats[index,[1,0]]\n", - " ts_at_index = -test_stats[index,2]\n", + " means_at_index = -test_stats[index, [1, 0]]\n", + " ts_at_index = -test_stats[index, 2]\n", " vals_at_index = vals[index]\n", "\n", - "\n", " tail_span = np.linspace(muhatmin, ts_at_index, 1001)\n", "\n", - "\n", " obs_pllr_ts, asimov_pllr_ts, sigma = prll_and_sigmas[index]\n", "\n", " ###\n", - " toys_bkg = model.make_pdf(pyhf.tensorlib.astensor([0.0,1.0])).sample((150,))\n", - " toys_sig = model.make_pdf(pyhf.tensorlib.astensor([mutest_at_index,1.0])).sample((150,))\n", - " muhat_s,qmu_tilde_s = get_toy_results(mutest_at_index,toys_sig)\n", + " toys_bkg = model.make_pdf(pyhf.tensorlib.astensor([0.0, 1.0])).sample((150,))\n", + " toys_sig = model.make_pdf(pyhf.tensorlib.astensor([mutest_at_index, 1.0])).sample(\n", + " (150,)\n", + " )\n", + " muhat_s, qmu_tilde_s = get_toy_results(mutest_at_index, toys_sig)\n", "\n", - " muhat_b,qmu_tilde_b = get_toy_results(mutest_at_index,toys_bkg)\n", + " muhat_b, qmu_tilde_b = get_toy_results(mutest_at_index, toys_bkg)\n", "\n", " print(mutest_at_index)\n", - " print(muhat_s.mean(),muhat_b.mean())\n", - " print(muhat_s.std(),muhat_b.std())\n", + " print(muhat_s.mean(), muhat_b.mean())\n", + " print(muhat_s.std(), muhat_b.std())\n", "\n", " ###\n", "\n", + " tsrail_parab = testrail_parab(muhatspan, mutest_at_index / sigma, sigma=1)\n", + " tsrail_flat = testrail_flat(muhatspan, mutest_at_index / sigma, sigma=1)\n", "\n", - " tsrail_parab = testrail_parab(muhatspan,mutest_at_index/sigma, sigma = 1)\n", - " tsrail_flat = testrail_flat(muhatspan,mutest_at_index/sigma, sigma = 1)\n", - "\n", - "\n", - "\n", - "\n", - " tail_span_qq = np.linspace(obs_pllr_ts, maxsigma**2, 1001)\n", - "\n", + " tail_span_qq = np.linspace(obs_pllr_ts, maxsigma ** 2, 1001)\n", "\n", " empirial_muhat_over_sigma = empirial_muhat / sigma\n", "\n", + " muhat_pdfs = scipy.stats.norm(np.array(means_at_index)).pdf(\n", + " np.tile(muhatspan.reshape(-1, 1), (1, 2))\n", + " )\n", "\n", - "\n", - " muhat_pdfs = scipy.stats.norm(np.array(means_at_index)).pdf(np.tile(muhatspan.reshape(-1,1),(1,2)))\n", - "\n", - " muhat_pdfs_tail = scipy.stats.norm(np.array(means_at_index)).pdf(np.tile(tail_span.reshape(-1,1),(1,2)))\n", - "\n", - "\n", - "\n", - "\n", - "\n", + " muhat_pdfs_tail = scipy.stats.norm(np.array(means_at_index)).pdf(\n", + " np.tile(tail_span.reshape(-1, 1), (1, 2))\n", + " )\n", "\n", " ax = axarr['A']\n", " ax.set_ylabel(r'$\\tilde{q}_\\mu$')\n", - " ax.set_xlim(muhatmin,muhatmax)\n", - "\n", - " ax.plot(muhatspan,tsrail_parab, c = 'grey', linestyle = 'dashed')\n", - " ax.plot(muhatspan,tsrail_flat, c = 'grey')\n", - " ax.vlines(0,0,maxsigma**2,colors = 'green', linestyles = 'dashed')\n", - " ax.vlines(means_at_index[1],0,maxsigma**2,colors = 'red', linestyles = 'dashed')\n", - " ax.vlines(ts_at_index,0,maxsigma**2,colors = 'black', linestyles = 'dashed')\n", - " ax.vlines(empirial_muhat_over_sigma,0,maxsigma**2,colors = 'orange', linestyles = 'dashed')\n", - "\n", - "\n", - " ax.scatter(muhat_b/sigma,qmu_tilde_b, alpha = 0.2, c = 'green', s = 20)\n", - " ax.scatter(muhat_s/sigma,qmu_tilde_s, alpha = 0.2, c = 'red', s = 20)\n", - " ax.scatter(0.0,asimov_pllr_ts, c = 'green')\n", - "\n", - " ax.hlines(asimov_pllr_ts,0.0,muhatmax, colors = 'green', linestyles='dashed')\n", + " ax.set_xlim(muhatmin, muhatmax)\n", + "\n", + " ax.plot(muhatspan, tsrail_parab, c='grey', linestyle='dashed')\n", + " ax.plot(muhatspan, tsrail_flat, c='grey')\n", + " ax.vlines(0, 0, maxsigma ** 2, colors='green', linestyles='dashed')\n", + " ax.vlines(means_at_index[1], 0, maxsigma ** 2, colors='red', linestyles='dashed')\n", + " ax.vlines(ts_at_index, 0, maxsigma ** 2, colors='black', linestyles='dashed')\n", + " ax.vlines(\n", + " empirial_muhat_over_sigma,\n", + " 0,\n", + " maxsigma ** 2,\n", + " colors='orange',\n", + " linestyles='dashed',\n", + " )\n", "\n", + " ax.scatter(muhat_b / sigma, qmu_tilde_b, alpha=0.2, c='green', s=20)\n", + " ax.scatter(muhat_s / sigma, qmu_tilde_s, alpha=0.2, c='red', s=20)\n", + " ax.scatter(0.0, asimov_pllr_ts, c='green')\n", "\n", - " ax.hlines(obs_pllr_ts,ts_at_index,muhatmax, colors = 'black', linestyles='dashed')\n", - " ax.scatter(empirial_muhat_over_sigma,obs_pllr_ts,c = 'orange')\n", - " ax.scatter(ts_at_index,obs_pllr_ts,c = 'black')\n", - " ax.scatter(mutest_at_index/sigma,0.0,c = 'grey')\n", + " ax.hlines(asimov_pllr_ts, 0.0, muhatmax, colors='green', linestyles='dashed')\n", "\n", - " ax.set_ylim(-1,maxsigma**2)\n", + " ax.hlines(obs_pllr_ts, ts_at_index, muhatmax, colors='black', linestyles='dashed')\n", + " ax.scatter(empirial_muhat_over_sigma, obs_pllr_ts, c='orange')\n", + " ax.scatter(ts_at_index, obs_pllr_ts, c='black')\n", + " ax.scatter(mutest_at_index / sigma, 0.0, c='grey')\n", "\n", + " ax.set_ylim(-1, maxsigma ** 2)\n", "\n", " ax = axarr['B']\n", " ax.set_xlabel(r'$p(\\tilde{q}_\\mu)$')\n", - " pqq_s = gpdf(qqspan,mutest_at_index,sigma,mutest_at_index)\n", - " pqq_b = gpdf(qqspan,0.0,sigma,mutest_at_index)\n", - "\n", - " ax.hist(qmu_tilde_b, bins = np.linspace(0.0,maxsigma**2,30), density = True, histtype = 'step', edgecolor = 'green', alpha = 0.5, orientation = 'horizontal')\n", - " ax.hist(qmu_tilde_s, bins = np.linspace(0.0,maxsigma**2,30), density = True, histtype = 'step',edgecolor = 'red', alpha = 0.5, orientation = 'horizontal')\n", - "\n", + " pqq_s = gpdf(qqspan, mutest_at_index, sigma, mutest_at_index)\n", + " pqq_b = gpdf(qqspan, 0.0, sigma, mutest_at_index)\n", + "\n", + " ax.hist(\n", + " qmu_tilde_b,\n", + " bins=np.linspace(0.0, maxsigma ** 2, 30),\n", + " density=True,\n", + " histtype='step',\n", + " edgecolor='green',\n", + " alpha=0.5,\n", + " orientation='horizontal',\n", + " )\n", + " ax.hist(\n", + " qmu_tilde_s,\n", + " bins=np.linspace(0.0, maxsigma ** 2, 30),\n", + " density=True,\n", + " histtype='step',\n", + " edgecolor='red',\n", + " alpha=0.5,\n", + " orientation='horizontal',\n", + " )\n", "\n", - " pqq_s_tail = gpdf(tail_span_qq,mutest_at_index,1.0,mutest_at_index)\n", - " pqq_b_tail = gpdf(tail_span_qq,0.0,1.0,mutest_at_index)\n", + " pqq_s_tail = gpdf(tail_span_qq, mutest_at_index, 1.0, mutest_at_index)\n", + " pqq_b_tail = gpdf(tail_span_qq, 0.0, 1.0, mutest_at_index)\n", "\n", - " ax.plot(pqq_b,qqspan, c = 'green')\n", - " ax.plot(pqq_s,qqspan, c = 'red')\n", + " ax.plot(pqq_b, qqspan, c='green')\n", + " ax.plot(pqq_s, qqspan, c='red')\n", "\n", - " ax.fill_betweenx(tail_span_qq,pqq_b_tail, facecolor = 'green', alpha = 0.2)\n", - " ax.fill_betweenx(tail_span_qq,pqq_s_tail, facecolor = 'red', alpha = 0.2)\n", + " ax.fill_betweenx(tail_span_qq, pqq_b_tail, facecolor='green', alpha=0.2)\n", + " ax.fill_betweenx(tail_span_qq, pqq_s_tail, facecolor='red', alpha=0.2)\n", " ax.set_xscale('log')\n", "\n", - " ax.hlines(obs_pllr_ts,0.0,10.0, colors = 'black', linestyles='dashed')\n", - " ax.hlines(asimov_pllr_ts,0.0,10.0, colors = 'green', linestyles='dashed')\n", - " ax.set_xlim(1e-3,1e1)\n", - " ax.set_ylim(-1,maxsigma**2)\n", - "\n", - "\n", + " ax.hlines(obs_pllr_ts, 0.0, 10.0, colors='black', linestyles='dashed')\n", + " ax.hlines(asimov_pllr_ts, 0.0, 10.0, colors='green', linestyles='dashed')\n", + " ax.set_xlim(1e-3, 1e1)\n", + " ax.set_ylim(-1, maxsigma ** 2)\n", "\n", " ax = axarr['F']\n", "\n", " ax.set_ylabel(r'$p(\\hat{\\mu}/\\sigma)$')\n", - " ax.hist(muhat_b/sigma, bins = np.linspace(muhatmin,muhatmax,30), density = True, histtype = 'step', edgecolor = 'green', alpha = 0.5)\n", + " ax.hist(\n", + " muhat_b / sigma,\n", + " bins=np.linspace(muhatmin, muhatmax, 30),\n", + " density=True,\n", + " histtype='step',\n", + " edgecolor='green',\n", + " alpha=0.5,\n", + " )\n", "\n", - " ax.plot(muhatspan,muhat_pdfs[:,0], c = 'green')\n", - " ax.fill_between(tail_span,muhat_pdfs_tail[:,0], facecolor = 'green', alpha = 0.2)\n", + " ax.plot(muhatspan, muhat_pdfs[:, 0], c='green')\n", + " ax.fill_between(tail_span, muhat_pdfs_tail[:, 0], facecolor='green', alpha=0.2)\n", "\n", - " ax.vlines(0,0,.5,colors = 'green', linestyles = 'dashed')\n", - " ax.vlines(means_at_index[1],0,.5,colors = 'red', linestyles = 'dashed')\n", - " ax.vlines(ts_at_index,0,.5,colors = 'black', linestyles = 'dashed')\n", - " ax.vlines(empirial_muhat_over_sigma,0,.5,colors = 'orange', linestyles = 'dashed')\n", - " ax.set_xlim(muhatmin,muhatmax)\n", - " ax.set_ylim(0,.5)\n", + " ax.vlines(0, 0, 0.5, colors='green', linestyles='dashed')\n", + " ax.vlines(means_at_index[1], 0, 0.5, colors='red', linestyles='dashed')\n", + " ax.vlines(ts_at_index, 0, 0.5, colors='black', linestyles='dashed')\n", + " ax.vlines(empirial_muhat_over_sigma, 0, 0.5, colors='orange', linestyles='dashed')\n", + " ax.set_xlim(muhatmin, muhatmax)\n", + " ax.set_ylim(0, 0.5)\n", "\n", " ax = axarr['C']\n", " ax.set_ylabel(r'$p(\\hat{\\mu}/\\sigma)$')\n", - " ax.hist(muhat_s/sigma, bins = np.linspace(muhatmin,muhatmax,30), density = True, histtype = 'step', edgecolor = 'red', alpha = 0.5)\n", - "\n", + " ax.hist(\n", + " muhat_s / sigma,\n", + " bins=np.linspace(muhatmin, muhatmax, 30),\n", + " density=True,\n", + " histtype='step',\n", + " edgecolor='red',\n", + " alpha=0.5,\n", + " )\n", "\n", - " ax.plot(muhatspan,muhat_pdfs[:,1], c = 'red')\n", - " ax.fill_between(tail_span,muhat_pdfs_tail[:,1], facecolor = 'red', alpha = 0.2)\n", - " ax.vlines(0,0,.5,colors = 'green', linestyles = 'dashed')\n", - " ax.vlines(means_at_index[1],0,.5,colors = 'red', linestyles = 'dashed')\n", - " ax.vlines(ts_at_index,0,.5,colors = 'black', linestyles = 'dashed')\n", - " ax.vlines(empirial_muhat_over_sigma,0,.5,colors = 'orange', linestyles = 'dashed')\n", - " ax.set_xlim(muhatmin,muhatmax)\n", - " ax.set_ylim(0,.5)\n", + " ax.plot(muhatspan, muhat_pdfs[:, 1], c='red')\n", + " ax.fill_between(tail_span, muhat_pdfs_tail[:, 1], facecolor='red', alpha=0.2)\n", + " ax.vlines(0, 0, 0.5, colors='green', linestyles='dashed')\n", + " ax.vlines(means_at_index[1], 0, 0.5, colors='red', linestyles='dashed')\n", + " ax.vlines(ts_at_index, 0, 0.5, colors='black', linestyles='dashed')\n", + " ax.vlines(empirial_muhat_over_sigma, 0, 0.5, colors='orange', linestyles='dashed')\n", + " ax.set_xlim(muhatmin, muhatmax)\n", + " ax.set_ylim(0, 0.5)\n", "\n", " ax = axarr['D']\n", " ax.set_ylabel(r'$\\mu_\\mathrm{test}$')\n", " ax.set_xlabel(r'$\\hat{\\mu}/\\sigma$')\n", "\n", - " ax.scatter(empirial_muhat_over_sigma,mutest_at_index, c = 'orange')\n", - " ax.plot(-test_stats[:,0],muspan, c = 'red')\n", - " ax.plot(-test_stats[:,1],muspan, c = 'green')\n", - " ax.scatter(means_at_index[1],mutest_at_index, c = 'red')\n", - " ax.vlines(means_at_index[1],mutest_at_index,5,colors = 'red', linestyles = 'dashed')\n", - "\n", - " ax.plot(-test_stats[:,2],muspan, c = 'black')\n", - " ax.scatter(ts_at_index,mutest_at_index, c = 'black')\n", - " ax.vlines(ts_at_index,mutest_at_index,mumax,colors = 'black', linestyles = 'dashed')\n", - " ax.vlines(empirial_muhat_over_sigma,mumin,mumax,colors = 'orange', linestyles = 'dashed')\n", - " ax.hlines(empirial_muhat,empirial_muhat_over_sigma,muhatmax,colors = 'orange', linestyles = 'dashed')\n", + " ax.scatter(empirial_muhat_over_sigma, mutest_at_index, c='orange')\n", + " ax.plot(-test_stats[:, 0], muspan, c='red')\n", + " ax.plot(-test_stats[:, 1], muspan, c='green')\n", + " ax.scatter(means_at_index[1], mutest_at_index, c='red')\n", + " ax.vlines(means_at_index[1], mutest_at_index, 5, colors='red', linestyles='dashed')\n", + "\n", + " ax.plot(-test_stats[:, 2], muspan, c='black')\n", + " ax.scatter(ts_at_index, mutest_at_index, c='black')\n", + " ax.vlines(ts_at_index, mutest_at_index, mumax, colors='black', linestyles='dashed')\n", + " ax.vlines(\n", + " empirial_muhat_over_sigma, mumin, mumax, colors='orange', linestyles='dashed'\n", + " )\n", + " ax.hlines(\n", + " empirial_muhat,\n", + " empirial_muhat_over_sigma,\n", + " muhatmax,\n", + " colors='orange',\n", + " linestyles='dashed',\n", + " )\n", "\n", - " ax.scatter(means_at_index[0],mutest_at_index, c = 'green')\n", + " ax.scatter(means_at_index[0], mutest_at_index, c='green')\n", "\n", - " ax.set_xlim(muhatmin,muhatmax)\n", + " ax.set_xlim(muhatmin, muhatmax)\n", " ax.set_ylim(mumin, mumax)\n", "\n", " ax = axarr['E']\n", " ax.set_xlabel(r'CL')\n", "\n", - " ax.plot(vals[:,0],muspan,c = 'red')\n", - " ax.plot(vals[:,1],muspan,c = 'green')\n", - " ax.plot(vals[:,2],muspan,c = 'grey')\n", - "\n", - "\n", - " ax.scatter(vals_at_index[0],mutest_at_index, c = 'red')\n", - " ax.scatter(vals_at_index[1],mutest_at_index, c = 'green')\n", - " ax.scatter(vals_at_index[2],mutest_at_index, c = 'grey')\n", + " ax.plot(vals[:, 0], muspan, c='red')\n", + " ax.plot(vals[:, 1], muspan, c='green')\n", + " ax.plot(vals[:, 2], muspan, c='grey')\n", "\n", - " ax.hlines(empirial_muhat,0,1.0,colors = 'orange', linestyles = 'dashed')\n", + " ax.scatter(vals_at_index[0], mutest_at_index, c='red')\n", + " ax.scatter(vals_at_index[1], mutest_at_index, c='green')\n", + " ax.scatter(vals_at_index[2], mutest_at_index, c='grey')\n", "\n", - " ax.set_ylim(mumin,mumax)\n", - " ax.set_xlim(0,1)\n", + " ax.hlines(empirial_muhat, 0, 1.0, colors='orange', linestyles='dashed')\n", "\n", + " ax.set_ylim(mumin, mumax)\n", + " ax.set_xlim(0, 1)\n", "\n", "\n", "for index in range(len(muspan)):\n", - "# for index in [15]:\n", - " f,axarr = plt.subplot_mosaic(\"\"\"\n", + " # for index in [15]:\n", + " f, axarr = plt.subplot_mosaic(\n", + " \"\"\"\n", " AAABBB\n", " AAABBB\n", " FFF...\n", " CCC...\n", " DDDEEE\n", " DDDEEE\n", - " \"\"\")\n", + " \"\"\"\n", + " )\n", "\n", " plot_explanation(\n", " axarr,\n", @@ -578,10 +625,10 @@ " )\n", "\n", " f.set_tight_layout(True)\n", - " f.set_size_inches(10,10)\n", + " f.set_size_inches(10, 10)\n", " f.savefig(f'scan{str(index).zfill(5)}.png')\n", " plt.show()\n", - " plt.clf()\n" + " plt.clf()" ] }, { @@ -609,8 +656,8 @@ } ], "source": [ - "plt.plot(prll_and_sigmas[:,2])\n", - "plt.ylim(0.0,1)" + "plt.plot(prll_and_sigmas[:, 2])\n", + "plt.ylim(0.0, 1)" ] }, { @@ -629,6 +676,7 @@ ], "source": [ "import scipy.stats\n", + "\n", "scipy.stats.norm.ppf(0.05)" ] }, @@ -638,12 +686,12 @@ "metadata": {}, "outputs": [], "source": [ - "data_at_muhat = collect_data_at_test(empirial_muhat)\n", - "blevel = data_at_muhat[1][1]\n", + "data_at_muhat = collect_data_at_test(empirial_muhat)\n", + "blevel = data_at_muhat[1][1]\n", "sigma_at_muhat = data_at_muhat[-1][-1]\n", - "starget = 0.05*blevel\n", - "starget_delta_in_muhat_over_sigma = abs(scipy.stats.norm.ppf(starget))\n", - "guessed_up = empirial_muhat + starget_delta_in_muhat_over_sigma * sigma_at_muhat" + "starget = 0.05 * blevel\n", + "starget_delta_in_muhat_over_sigma = abs(scipy.stats.norm.ppf(starget))\n", + "guessed_up = empirial_muhat + starget_delta_in_muhat_over_sigma * sigma_at_muhat" ] }, { @@ -691,4 +739,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +}