-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from JuliaTrustworthyAI/79-revisit-sample-corr…
…ection
- Loading branch information
Showing
25 changed files
with
2,809 additions
and
2,447 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
_freeze/docs/src/explanation/finite_sample_correction/execute-results/md.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"hash": "f6be6dff987885f970c8b1d4c7f00f62", | ||
"result": { | ||
"markdown": "---\ntitle: Finite-sample Correction\n---\n\n\n\n\n\n\nWe follow the convention used in @angelopoulos2021gentle and @barber2021predictive to correct for the finite-sample bias of the empirical quantile. Specifically, we use the following definition of the $(1-\\alpha)$ empirical quantile:\n\n```math\n\\hat{q}_{n,\\alpha}^{+}\\{v\\} = \\frac{\\lceil (n+1)(1-\\alpha)\\rceil}{n}\n```\n\n@barber2021predictive further define as the $\\alpha$ empirical quantile:\n\n```math\n\\hat{q}_{n,\\alpha}^{-}\\{v\\} = \\frac{\\lfloor (n+1)\\alpha \\rfloor}{n} = - \\hat{q}_{n,\\alpha}^{+}\\{-v\\}\n```\n\nBelow we test this equality numerically by generating a large number of random vectors and comparing the two quantiles. We then plot the density of the difference between the two quantiles. While the errors are small, they are not negligible for small $n$. In our computations, we use $\\hat{q}_{n,\\alpha}^{-}\\{v\\}$ exactly as it is defined above, rather than relying on $- \\hat{q}_{n,\\alpha}^{+}\\{-v\\}$.\n\n::: {.cell execution_count=2}\n``` {.julia .cell-code}\nusing ConformalPrediction: qplus, qminus\nnobs = [100, 1000, 10000]\nn = 1000\nalpha = 0.1\nplts = []\nΔ = Float32[]\nfor _nobs in nobs\n for i in 1:n\n v = rand(_nobs)\n δ = qminus(v, alpha) - (-qplus(-v, 1-alpha))\n push!(Δ, δ)\n end\n plt = density(Δ)\n vline!([mean(Δ)], color=:red, label=\"mean\")\n push!(plts, plt)\nend\nplot(plts..., layout=(1,3), size=(900, 300), legend=:topleft, title=[\"nobs = 100\" \"nobs = 1000\" \"nobs = 10000\"])\n```\n\n::: {.cell-output .cell-output-display execution_count=11}\n![](finite_sample_correction_files/figure-commonmark/cell-3-output-1.svg){}\n:::\n:::\n\n\nSee also this related [discussion](https://github.com/JuliaTrustworthyAI/ConformalPrediction.jl/discussions/17).\n\n## References\n\n", | ||
"supporting": [ | ||
"finite_sample_correction_files" | ||
], | ||
"filters": [] | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
.../src/explanation/finite_sample_correction/figure-commonmark/cell-3-output-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
_freeze/docs/src/tutorials/classification/execute-results/md.json
Large diffs are not rendered by default.
Oops, something went wrong.
2,315 changes: 1,156 additions & 1,159 deletions
2,315
_freeze/docs/src/tutorials/classification/figure-commonmark/cell-10-output-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 50 additions & 50 deletions
100
...ze/docs/src/tutorials/classification/figure-commonmark/fig-setsize-output-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Finite-sample Correction | ||
|
||
We follow the convention used in Angelopoulos and Bates (2021) and Barber et al. (2021) to correct for the finite-sample bias of the empirical quantile. Specifically, we use the following definition of the (1−*α*) empirical quantile: | ||
|
||
``` math | ||
\hat{q}_{n,\alpha}^{+}\{v\} = \frac{\lceil (n+1)(1-\alpha)\rceil}{n} | ||
``` | ||
|
||
Barber et al. (2021) further define as the *α* empirical quantile: | ||
|
||
``` math | ||
\hat{q}_{n,\alpha}^{-}\{v\} = \frac{\lfloor (n+1)\alpha \rfloor}{n} = - \hat{q}_{n,\alpha}^{+}\{-v\} | ||
``` | ||
|
||
Below we test this equality numerically by generating a large number of random vectors and comparing the two quantiles. We then plot the density of the difference between the two quantiles. While the errors are small, they are not negligible for small *n*. In our computations, we use *q̂*_(*n*, *α*)⁻{*v*} exactly as it is defined above, rather than relying on − *q̂*_(*n*, *α*)⁺{ − *v*}. | ||
|
||
``` julia | ||
using ConformalPrediction: qplus, qminus | ||
nobs = [100, 1000, 10000] | ||
n = 1000 | ||
alpha = 0.1 | ||
plts = [] | ||
Δ = Float32[] | ||
for _nobs in nobs | ||
for i in 1:n | ||
v = rand(_nobs) | ||
δ = qminus(v, alpha) - (-qplus(-v, 1-alpha)) | ||
push!(Δ, δ) | ||
end | ||
plt = density(Δ) | ||
vline!([mean(Δ)], color=:red, label="mean") | ||
push!(plts, plt) | ||
end | ||
plot(plts..., layout=(1,3), size=(900, 300), legend=:topleft, title=["nobs = 100" "nobs = 1000" "nobs = 10000"]) | ||
``` | ||
|
||
![](finite_sample_correction_files/figure-commonmark/cell-3-output-1.svg) | ||
|
||
See also this related [discussion](https://github.com/JuliaTrustworthyAI/ConformalPrediction.jl/discussions/17). | ||
|
||
## References | ||
|
||
Angelopoulos, Anastasios N., and Stephen Bates. 2021. “A Gentle Introduction to Conformal Prediction and Distribution-Free Uncertainty Quantification.” <https://arxiv.org/abs/2107.07511>. | ||
|
||
Barber, Rina Foygel, Emmanuel J. Candès, Aaditya Ramdas, and Ryan J. Tibshirani. 2021. “Predictive Inference with the Jackknife+.” *The Annals of Statistics* 49 (1): 486–507. <https://doi.org/10.1214/20-AOS1965>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Finite-sample Correction | ||
|
||
```{julia} | ||
#| echo: false | ||
include("$(pwd())/docs/setup_docs.jl") | ||
eval(setup_docs) | ||
``` | ||
|
||
We follow the convention used in @angelopoulos2021gentle and @barber2021predictive to correct for the finite-sample bias of the empirical quantile. Specifically, we use the following definition of the $(1-\alpha)$ empirical quantile: | ||
|
||
```math | ||
\hat{q}_{n,\alpha}^{+}\{v\} = \frac{\lceil (n+1)(1-\alpha)\rceil}{n} | ||
``` | ||
|
||
@barber2021predictive further define as the $\alpha$ empirical quantile: | ||
|
||
```math | ||
\hat{q}_{n,\alpha}^{-}\{v\} = \frac{\lfloor (n+1)\alpha \rfloor}{n} = - \hat{q}_{n,\alpha}^{+}\{-v\} | ||
``` | ||
|
||
Below we test this equality numerically by generating a large number of random vectors and comparing the two quantiles. We then plot the density of the difference between the two quantiles. While the errors are small, they are not negligible for small $n$. In our computations, we use $\hat{q}_{n,\alpha}^{-}\{v\}$ exactly as it is defined above, rather than relying on $- \hat{q}_{n,\alpha}^{+}\{-v\}$. | ||
|
||
```{julia} | ||
#| output: true | ||
using ConformalPrediction: qplus, qminus | ||
nobs = [100, 1000, 10000] | ||
n = 1000 | ||
alpha = 0.1 | ||
plts = [] | ||
Δ = Float32[] | ||
for _nobs in nobs | ||
for i in 1:n | ||
v = rand(_nobs) | ||
δ = qminus(v, alpha) - (-qplus(-v, 1-alpha)) | ||
push!(Δ, δ) | ||
end | ||
plt = density(Δ) | ||
vline!([mean(Δ)], color=:red, label="mean") | ||
push!(plts, plt) | ||
end | ||
plot(plts..., layout=(1,3), size=(900, 300), legend=:topleft, title=["nobs = 100" "nobs = 1000" "nobs = 10000"]) | ||
``` | ||
|
||
See also this related [discussion](https://github.com/JuliaTrustworthyAI/ConformalPrediction.jl/discussions/17). | ||
|
||
## References |
Oops, something went wrong.