{
  "schema": "ml-prep/item@1",
  "item": {
    "id": "original-ml-sgd",
    "area": "machine-learning",
    "topic": "gradient-descent",
    "origin": "original",
    "title": "Full gradient versus stochastic gradient",
    "skills": [
      "gradient-update",
      "sgd",
      "convergence"
    ],
    "priority": "core",
    "difficulty": "easy",
    "estimated_minutes": 7,
    "prerequisites": [
      "expectation"
    ],
    "prompt": "For losses $\\ell_1(w)=(w-1)^2$ and $\\ell_2(w)=(w+1)^2$, compute the full empirical gradient at $w=2$ and each per-example gradient. Explain why an unbiased uniformly sampled stochastic gradient can still have variance.\n",
    "answer": "The per-example gradients are $2$ and $6$. The mean, or full, gradient is $4$. A uniformly sampled per-example gradient has expectation $4$ but takes values $2$ or $6$, so it has nonzero variance.\n",
    "check": {
      "kind": "numeric",
      "id": "original-ml-sgd",
      "values": [
        2,
        6,
        4,
        4
      ]
    }
  }
}