{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Definition\n\nLet $S$ be a countable set and let $\\pi$ be a probability distribution on $S$ with $\\pi(x) \u003e 0$ for all $x \\in S$.\nLet $Q = (Q(x, y))_{x, y \\in S}$ be a [[transition matrix|0F462493EA]], the *proposal*, such that $Q(x, y) \u003e 0$ if and only if $Q(y, x) \u003e 0$.\nFor $x \\ne y$ with $Q(x, y) \u003e 0$, the *acceptance probability* is\n$$\\alpha(x, y) = \\min\\left(1, \\frac{\\pi(y) \\, Q(y, x)}{\\pi(x) \\, Q(x, y)}\\right).$$\nThe *Metropolis–Hastings chain* is the [[Markov chain|033TJBZDG0]] $(X_n)$ built as follows.\nGiven $X_n = x$, draw $Y$ from $Q(x, \\cdot)$.\nWith probability $\\alpha(x, Y)$ set $X_{n+1} = Y$; otherwise set $X_{n+1} = x$.\nIts transition matrix has $P(x, y) = Q(x, y) \\, \\alpha(x, y)$ for $y \\ne x$ and $P(x, x) = 1 - \\sum_{y \\ne x} P(x, y)$.\n\n## Remarks\n\nFor $x \\ne y$, $\\pi(x) P(x, y) = \\min\\left(\\pi(x) Q(x, y), \\pi(y) Q(y, x)\\right)$, which is symmetric in $x$ and $y$.\nSo $P$ satisfies [[detailed balance|CTGN6CK1ZS]] with respect to $\\pi$, and $\\pi$ is a [[stationary distribution|0KRH5157WP]].\nOnly the ratio $\\pi(y)/\\pi(x)$ is used, so $\\pi$ may be known up to a constant factor.\nExample: if $Q$ is symmetric, $\\alpha(x, y) = \\min(1, \\pi(y)/\\pi(x))$; this special case is the Metropolis algorithm.\nNon-example: the chain that always accepts the proposal has transition matrix $Q$, whose stationary law is in general not $\\pi$; it skips the acceptance step.\nThe chain is a [[Markov chain Monte Carlo|ZGNBR2SPZ0]] method when it is also irreducible.\nThe same construction works on general state spaces with densities in place of $\\pi$ and $Q$.\n",
  "commit": "547b6eddb8f2feb8d579f2d633d22a27b7e132fc",
  "front": {
    "defines": "MKHF449E22",
    "kind": "definition",
    "msc": [
      "65C05",
      "60J22",
      "65C40"
    ],
    "name": "Metropolis–Hastings algorithm",
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Metropolis%E2%80%93Hastings_algorithm"
      }
    ],
    "tag": "A02K3MKQ3Q",
    "uses": [
      "033TJBZDG0",
      "0F462493EA",
      "CTGN6CK1ZS",
      "0KRH5157WP",
      "ZGNBR2SPZ0"
    ]
  },
  "kind": "definition",
  "link": "https://math2.tamnd.com/node/A02K3MKQ3Q/",
  "links": [
    {
      "field": "defines",
      "target": "MKHF449E22"
    },
    {
      "field": "uses",
      "target": "033TJBZDG0"
    },
    {
      "field": "uses",
      "target": "0F462493EA"
    },
    {
      "field": "uses",
      "target": "CTGN6CK1ZS"
    },
    {
      "field": "uses",
      "target": "0KRH5157WP"
    },
    {
      "field": "uses",
      "target": "ZGNBR2SPZ0"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/A02K3MKQ3Q.md",
  "msc": [
    "65C05",
    "60J22",
    "65C40"
  ],
  "name": "Metropolis–Hastings algorithm",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/A02/A02K3MKQ3Q.md",
  "status": null,
  "tag": "A02K3MKQ3Q",
  "uri": "m2://A02K3MKQ3Q",
  "url": "https://math2.tamnd.com/wiki/metropolis-hastings-algorithm-definition/",
  "writing": {
    "tag": "A02K3MKQ3Q",
    "kind": "definition",
    "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
      }
    ]
  }
}
