{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Statement\n\nLet $F \\colon \\R \\to [0, 1]$ be a [[cumulative distribution function|0H8H7ZTHW2]], that is, non-decreasing, right-continuous, with limits $0$ at $-\\infty$ and $1$ at $+\\infty$.\nLet $F^{-1} \\colon (0, 1) \\to \\R$ be its generalized inverse, the [[quantile function|0X60VE98HN]]\n$$F^{-1}(u) = \\inf \\set{x \\in \\R : F(x) \\ge u}.$$\nLet $U$ be a [[random variable|0PNRKMRC55]] with the [[uniform distribution|0AREFQ9Z65]] on $(0, 1)$.\nThen the random variable $X = F^{-1}(U)$ has cumulative distribution function $F$.\n\n## Remarks\n\nThe key fact is that for $u \\in (0, 1)$ and $x \\in \\R$, $F^{-1}(u) \\le x$ if and only if $u \\le F(x)$; this uses right-continuity of $F$, which makes the infimum attained.\nHence $P(X \\le x) = P(U \\le F(x)) = F(x)$.\nExample: the [[exponential distribution|0E99F51GVB]] with rate $\\lambda \u003e 0$ has $F(x) = 1 - e^{-\\lambda x}$ for $x \\ge 0$, so $F^{-1}(u) = -\\ln(1 - u)/\\lambda$; since $1 - U$ is also uniform, $-\\ln(U)/\\lambda$ is exponential too.\nExample: for a discrete distribution with values $x_1 \u003c x_2 \u003c \\cdots$ and probabilities $p_1, p_2, \\ldots$, the method returns $x_k$ when $p_1 + \\cdots + p_{k-1} \u003c U \\le p_1 + \\cdots + p_k$.\nThe generalized inverse is needed: when $F$ has jumps or flat parts, the ordinary inverse does not exist.\nA converse holds when $F$ is continuous: then $F(X)$ is uniform on $(0, 1)$, the probability integral transform.\n\n## Explanations\n\n### L1 human\n\nA computer can produce uniform random numbers between $0$ and $1$.\nTo get random numbers with any other distribution, feed each uniform number into the inverse of the distribution function.\nValues of $u$ near $0$ give values from the lower tail, values near $1$ give the upper tail, and the shape of the distribution comes out exactly right.\nFor the exponential distribution this means $-\\ln(u)/\\lambda$.\n\n### L2 human\n\nThe method is exact and uses one uniform number per sample, so it is the first choice whenever $F^{-1}$ has a closed form or a fast accurate approximation.\nFor the normal distribution there is no closed form, and one uses numerical approximations of $F^{-1}$ or other methods such as the Box–Muller transform or the ziggurat algorithm.\nBeing monotone in $U$, it preserves the order of the uniform inputs, which is useful for antithetic variates, for quasi-Monte Carlo and for coupling arguments.\nIt also explains copulas: any multivariate distribution is obtained from its copula by applying the marginal quantile functions coordinatewise.\n",
  "commit": "ff8a40749dc16545e3d2fc637f6b0196e81d0bfa",
  "front": {
    "about": [
      "0X60VE98HN"
    ],
    "kind": "statement",
    "msc": [
      "65C10",
      "60E05"
    ],
    "name": "Inverse transform sampling",
    "role": "theorem",
    "same_as": {
      "wikidata": "Q1377019",
      "wikipedia": "Inverse transform sampling"
    },
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Inverse_transform_sampling"
      }
    ],
    "tag": "2KX7W1TG7T",
    "uses": [
      "0H8H7ZTHW2",
      "0X60VE98HN",
      "0AREFQ9Z65",
      "0PNRKMRC55",
      "0E99F51GVB"
    ]
  },
  "kind": "statement",
  "link": "https://tamnd.github.io/math2/node/2KX7W1TG7T/",
  "links": [
    {
      "field": "about",
      "target": "0X60VE98HN"
    },
    {
      "field": "uses",
      "target": "0H8H7ZTHW2"
    },
    {
      "field": "uses",
      "target": "0X60VE98HN"
    },
    {
      "field": "uses",
      "target": "0AREFQ9Z65"
    },
    {
      "field": "uses",
      "target": "0PNRKMRC55"
    },
    {
      "field": "uses",
      "target": "0E99F51GVB"
    }
  ],
  "markdown": "https://tamnd.github.io/math2/node/2KX7W1TG7T.md",
  "msc": [
    "65C10",
    "60E05"
  ],
  "name": "Inverse transform sampling",
  "prov": null,
  "role": "theorem",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/2KX/2KX7W1TG7T.md",
  "status": null,
  "tag": "2KX7W1TG7T",
  "uri": "m2://2KX7W1TG7T",
  "url": "https://tamnd.github.io/math2/wiki/inverse-transform-sampling/",
  "writing": {
    "tag": "2KX7W1TG7T",
    "kind": "statement",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      },
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
