Skip to content

Instantly share code, notes, and snippets.

@jonathan-taylor
Last active September 30, 2019 23:23
Show Gist options
  • Save jonathan-taylor/fd1b94507d47d42901d2584bfc2e4a9a to your computer and use it in GitHub Desktop.
Save jonathan-taylor/fd1b94507d47d42901d2584bfc2e4a9a to your computer and use it in GitHub Desktop.
Problem with _inference with constant weight
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from selectinf.learning.core import _inference\n",
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import statsmodels.api as sm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"weight_fn = lambda z: np.ones_like(z)\n",
"pivots = []\n",
"intervals = []\n",
"delta = 1\n",
"for _ in range(2000):\n",
" Z = np.random.standard_normal() + delta\n",
" result = _inference(Z, np.array([[1.]]), weight_fn, hypothesis=delta, alpha=0.05)\n",
" pivots.append(result[0])\n",
" intervals.append(result[1])\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=((8,8)))\n",
"U = np.linspace(0, 1, 101)\n",
"plt.plot(U, sm.distributions.ECDF(pivots)(U), linewidth=3)\n",
"plt.plot([0, 1], [0, 1], 'k--')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"intervals = np.array(intervals)\n",
"np.mean((intervals[:,0] < delta) * (intervals[:,1] > delta))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "all,-slideshow"
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment