Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
70904c3
Create power_ppi.py
Michael-Howes Aug 6, 2024
12ece40
Update power_ppi.py
Michael-Howes Aug 6, 2024
03199e9
create power analysis function mean estimation
Michael-Howes Aug 6, 2024
eb7c7bd
Update power_ppi.py
Michael-Howes Aug 6, 2024
c307a5a
Create power_analysis.ipynb
Michael-Howes Aug 6, 2024
90bad83
update power analysis to return dict
Michael-Howes Aug 6, 2024
a27fb59
add ols power analysis
Michael-Howes Aug 8, 2024
904f410
add ols example
Michael-Howes Aug 8, 2024
4edb6b9
Update power_analysis.ipynb
Michael-Howes Aug 8, 2024
42fb6f4
add logisitic regression power analysis
Michael-Howes Aug 8, 2024
faa8703
moved power analysis
Michael-Howes Aug 13, 2024
00973f0
Update power_ppi.py
Michael-Howes Aug 13, 2024
8139a8f
add poisson power
Michael-Howes Aug 13, 2024
6eb4f2d
add Poisson examples
Michael-Howes Aug 13, 2024
3b2bd86
added ppi_power for user supplied rho
Michael-Howes Sep 19, 2024
88957c3
Update power_analysis.ipynb
Michael-Howes Sep 19, 2024
6635528
update .gitignore
Michael-Howes Sep 19, 2024
a46b0b3
added n_max constraint
Michael-Howes Oct 8, 2024
d06f02d
add warning for cheapest pair
Michael-Howes Oct 8, 2024
9c0c822
run notebook
Michael-Howes Oct 8, 2024
4899ace
Update power_ppi.py
Michael-Howes Oct 8, 2024
6d4a77d
Merge branch 'aangelopoulos:main' into main
Michael-Howes Oct 8, 2024
7a4f608
update power analysis
Michael-Howes Oct 8, 2024
a923b87
update notebook
Michael-Howes Oct 9, 2024
9289979
init notebook
davidbroska Oct 9, 2024
51e4f3f
update power analysis notebook
Michael-Howes Oct 9, 2024
06d72d4
Merge branch 'main' of https://github.com/Michael-Howes/ppi_py
Michael-Howes Oct 9, 2024
0f1e951
add power tests
Michael-Howes Oct 11, 2024
2b7fa2f
add moral machine data and notebook with AMCE function
davidbroska Oct 11, 2024
6f75e73
move AMCE function to utils
davidbroska Oct 11, 2024
797643f
Update test_power_analysis.py
Michael-Howes Oct 14, 2024
357eae5
Update power_ppi.py
Michael-Howes Oct 14, 2024
48385b1
Update power_analysis.ipynb
Michael-Howes Oct 14, 2024
3e03df0
add seed value
Michael-Howes Oct 15, 2024
b2f04b2
reformatting with black
Michael-Howes Oct 15, 2024
d6b0056
reformat with black
Michael-Howes Oct 15, 2024
56d8f06
Work on documentation
Michael-Howes Oct 16, 2024
6f59ea3
update documentation
Michael-Howes Oct 16, 2024
40753d8
fix typos
Michael-Howes Oct 16, 2024
1296f02
small edits
davidbroska Oct 16, 2024
29aec95
unify terminology
davidbroska Oct 16, 2024
606d415
reformat with black
Michael-Howes Oct 17, 2024
34833c4
reformat with black
Michael-Howes Oct 17, 2024
9066071
remove moral machine notebook
Michael-Howes Oct 17, 2024
244e4f6
remove moral machine function from utils
Michael-Howes Oct 17, 2024
d1703c0
update gitignore
Michael-Howes Oct 17, 2024
ddabddb
update .gitignore
Michael-Howes Oct 17, 2024
cbb0951
add example .gitignore
Michael-Howes Oct 17, 2024
295cb82
remove moral machine function from utils
Michael-Howes Oct 17, 2024
3b0387b
use safe_expit
Michael-Howes Oct 17, 2024
b820440
update references
Michael-Howes Oct 17, 2024
21b8252
update power analysis
Michael-Howes Oct 18, 2024
7c727d3
update power analysis example
Michael-Howes Oct 18, 2024
b342d32
update power analysis
Michael-Howes Oct 18, 2024
425b798
update power analysis example
Michael-Howes Oct 18, 2024
76d4b8c
rename power_ppi to ppi_power_analysis
Michael-Howes Oct 18, 2024
46f16ab
reformat with black
Michael-Howes Oct 18, 2024
775e35a
update power analysis to used desired effective sample size instead o…
Michael-Howes Dec 2, 2024
0d412d7
update power analysis tests
Michael-Howes Dec 2, 2024
37cb62f
reformat with black
Michael-Howes Dec 2, 2024
cbe850c
[black for formatting]
aangelopoulos Dec 22, 2024
5b801f0
[minor] made a quick fix to the notebook and also added credit to the…
aangelopoulos Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ There is also a file, ```./ppi_py/baselines.py```, which implements several base
Finally, the file ```./ppi_py/datasets/datasets.py``` handles the loading of the sample datasets.

The folder ```./examples``` contains notebooks for implementing prediction-powered inference on several datasets and estimands. These are listed [above](https://github.com/aangelopoulos/ppi_py/tree/main#examples). There is also an additional subfolder, ```./examples/baselines```, which contains comparisons to certain baseline algorithms, as in the appendix of the original PPI paper.
There is an additional notebook, [```./examples/ppi_power_analysis.py```](https://github.com/aangelopoulos/ppi_py/blob/main/examples/power_analysis.ipynb), which shows how to choose the optimal labeled and unlabeled dataset sizes subject to a constraint on the budget.

The folder ```./tests``` contains unit tests for each function implemented in the ```ppi_py``` package. The tests are organized by estimand, and can be run by executing ```pytest``` in the root directory. Some of the tests are stochastic, and therefore, have some failure probability, even if the functions are all implemented correctly. If a test fails, it may be worth running it again. Debugging the tests can be done by adding the ```-s``` flag and using print statements or ```pdb```. Note that in order to be recognized by ```pytest```, all tests must be preceded by ```test_```.

Expand Down Expand Up @@ -141,3 +142,5 @@ The repository currently implements the methods developed in the following paper
[Cross-Prediction-Powered Inference](https://arxiv.org/abs/2309.16598)

[Prediction-Powered Bootstrap](https://arxiv.org/abs/2405.18379)

[The Mixed Subjects Design: Treating Large Language Models as (Potentially) Informative Observations](https://osf.io/preprints/socarxiv/j3bnt)
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ Each notebook runs a simulation that forms a dataframe containing confidence int
- the average interval width for PPI and the classical method, together with a scatterplot of the widths from the five random draws.

Each notebook also compares PPI and classical inference in terms of the number of labeled examples needed to reject a natural null hypothesis in the analyzed problem.

Finally, there is a notebook that shows how to compute the optimal `n` and `N` given a cost constraint ([```power_analysis.ipynb```](https://github.com/aangelopoulos/ppi_py/blob/main/examples/power_analysis.ipynb)).
20 changes: 17 additions & 3 deletions examples/census_education.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
"data = load_dataset(dataset_folder, \"census_education\")\n",
"Y_total = data[\"Y\"]\n",
"Yhat_total = data[\"Yhat\"]\n",
"X_total = data[\"X\"]/10000 # scale X to avoid numerical issues; interpretation is \"per 10,000 dollars\""
"X_total = (\n",
" data[\"X\"] / 10000\n",
") # scale X to avoid numerical issues; interpretation is \"per 10,000 dollars\""
]
},
{
Expand Down Expand Up @@ -152,7 +154,13 @@
" )\n",
"\n",
" ppi_ci = ppi_poisson_ci(\n",
" _X, _Y, _Yhat, _X_unlabeled, _Yhat_unlabeled, alpha=alpha, optimizer_options=optimizer_options\n",
" _X,\n",
" _Y,\n",
" _Yhat,\n",
" _X_unlabeled,\n",
" _Yhat_unlabeled,\n",
" alpha=alpha,\n",
" optimizer_options=optimizer_options,\n",
" )\n",
"\n",
" # Classical interval\n",
Expand Down Expand Up @@ -289,7 +297,13 @@
" )\n",
"\n",
" ppi_ci = ppi_poisson_ci(\n",
" _X, _Y, _Yhat, _X_unlabeled, _Yhat_unlabeled, alpha=alpha, optimizer_options=optimizer_options\n",
" _X,\n",
" _Y,\n",
" _Yhat,\n",
" _X_unlabeled,\n",
" _Yhat_unlabeled,\n",
" alpha=alpha,\n",
" optimizer_options=optimizer_options,\n",
" )\n",
"\n",
" if ppi_ci[0][coordinate] > null_to_reject:\n",
Expand Down
31 changes: 13 additions & 18 deletions examples/census_healthcare_ppboot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
"data = load_dataset(dataset_folder, \"census_healthcare\")\n",
"Y_total = data[\"Y\"]\n",
"Yhat_total = data[\"Yhat\"]\n",
"X_total = data[\"X\"][:,0] # first coordinate is income; second is constant term"
"X_total = data[\"X\"][\n",
" :, 0\n",
"] # first coordinate is income; second is constant term"
]
},
{
Expand Down Expand Up @@ -94,10 +96,13 @@
" int\n",
") # Test for different numbers of labeled ballots\n",
"num_trials = 100\n",
"\n",
"\n",
"# define Pearson correlation coefficient\n",
"def pearson(X, Y):\n",
" return np.corrcoef(X, Y)[0,1]\n",
" \n",
" return np.corrcoef(X, Y)[0, 1]\n",
"\n",
"\n",
"# Compute ground truth\n",
"true_theta = pearson(X_total, Y_total)"
]
Expand Down Expand Up @@ -151,13 +156,7 @@
" )\n",
"\n",
" ppi_ci = ppboot(\n",
" pearson,\n",
" _Y,\n",
" _Yhat,\n",
" _Yhat_unlabeled,\n",
" _X,\n",
" _X_unlabeled,\n",
" alpha=alpha\n",
" pearson, _Y, _Yhat, _Yhat_unlabeled, _X, _X_unlabeled, alpha=alpha\n",
" )\n",
"\n",
" # Classical interval\n",
Expand Down Expand Up @@ -192,7 +191,9 @@
" ]\n",
"\n",
"# Imputed CI\n",
"imputed_ci = classical_bootstrap_ci(pearson, X_total, (Yhat_total > 0.5).astype(int), alpha=alpha)\n",
"imputed_ci = classical_bootstrap_ci(\n",
" pearson, X_total, (Yhat_total > 0.5).astype(int), alpha=alpha\n",
")\n",
"results += [\n",
" pd.DataFrame(\n",
" [\n",
Expand Down Expand Up @@ -290,13 +291,7 @@
" )\n",
"\n",
" ppi_ci = ppboot(\n",
" pearson,\n",
" _Y,\n",
" _Yhat,\n",
" _Yhat_unlabeled,\n",
" _X,\n",
" _X_unlabeled,\n",
" alpha=alpha\n",
" pearson, _Y, _Yhat, _Yhat_unlabeled, _X, _X_unlabeled, alpha=alpha\n",
" )\n",
" if ppi_ci[0] > 0.15:\n",
" nulls_rejected += 1\n",
Expand Down
24 changes: 15 additions & 9 deletions examples/census_income_covshift.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@
" _Yhat = Yhat_inD[rand_idx[:n]]\n",
" importance_weights = np.array(\n",
" [\n",
" weights[0] / inD_weights[0]\n",
" if z == 0\n",
" else weights[1] / inD_weights[1]\n",
" (\n",
" weights[0] / inD_weights[0]\n",
" if z == 0\n",
" else weights[1] / inD_weights[1]\n",
" )\n",
" for z in _Z\n",
" ]\n",
" )\n",
Expand Down Expand Up @@ -341,9 +343,11 @@
" _Yhat = Yhat_inD[rand_idx[:n]]\n",
" importance_weights = np.array(\n",
" [\n",
" weights[0] / inD_weights[0]\n",
" if z == 0\n",
" else weights[1] / inD_weights[1]\n",
" (\n",
" weights[0] / inD_weights[0]\n",
" if z == 0\n",
" else weights[1] / inD_weights[1]\n",
" )\n",
" for z in _Z\n",
" ]\n",
" )\n",
Expand All @@ -369,9 +373,11 @@
" _Yhat = Yhat_inD[rand_idx[:n]]\n",
" importance_weights = np.array(\n",
" [\n",
" weights[0] / inD_weights[0]\n",
" if z == 0\n",
" else weights[1] / inD_weights[1]\n",
" (\n",
" weights[0] / inD_weights[0]\n",
" if z == 0\n",
" else weights[1] / inD_weights[1]\n",
" )\n",
" for z in _Z\n",
" ]\n",
" )\n",
Expand Down
971 changes: 971 additions & 0 deletions examples/power_analysis.ipynb

Large diffs are not rendered by default.

Loading