Follow ______ on twitter.

8.2.1 Advanced Monte Carlo Simulation Techniques

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "hconcat": [
    {
      "width": 300,
      "height": 250,
      "title": "PDFs and Importance Sampling Weights",
      "data": {
        "sequence": {
          "start": -4,
          "stop": 4,
          "step": 0.01,
          "as": "x"
        }
      },
      "transform": [
        {
          "calculate": "densityNormal(datum.x, 0, 1)",
          "as": "Normal"
        },
        {
          "calculate": "densityStudentT(datum.x, 3)",
          "as": "StudentT"
        },
        {
          "calculate": "datum.StudentT / datum.Normal",
          "as": "Weight"
        }
      ],
      "layer": [
        {
          "mark": {
            "type": "line",
            "color": "blue"
          },
          "encoding": {
            "x": {
              "field": "x",
              "type": "quantitative",
              "title": "x"
            },
            "y": {
              "field": "StudentT",
              "type": "quantitative",
              "title": "Density"
            }
          }
        },
        {
          "mark": {
            "type": "line",
            "color": "red",
            "opacity": 0.5
          },
          "encoding": {
            "x": {
              "field": "x",
              "type": "quantitative"
            },
            "y": {
              "field": "Normal",
              "type": "quantitative"
            }
          }
        },
        {
          "mark": {
            "type": "point",
            "color": "green",
            "filled": true
          },
          "transform": [
            {
              "sample": 100
            }
          ],
          "encoding": {
            "x": {
              "field": "x",
              "type": "quantitative"
            },
            "y": {
              "field": "Normal",
              "type": "quantitative"
            },
            "size": {
              "field": "Weight",
              "type": "quantitative",
              "scale": {
                "range": [
                  20,
                  200
                ]
              }
            }
          }
        }
      ]
    },
    {
      "width": 300,
      "height": 250,
      "title": "CDFs and Importance Sampling",
      "data": {
        "sequence": {
          "start": -4,
          "stop": 4,
          "step": 0.01,
          "as": "x"
        }
      },
      "transform": [
        {
          "calculate": "cumulativeNormal(datum.x, 0, 1)",
          "as": "NormalCDF"
        },
        {
          "calculate": "cumulativeStudentT(datum.x, 3)",
          "as": "StudentTCDF"
        },
        {
          "calculate": "densityNormal(datum.x, 0, 1)",
          "as": "Normal"
        },
        {
          "calculate": "densityStudentT(datum.x, 3)",
          "as": "StudentT"
        },
        {
          "calculate": "datum.StudentT / datum.Normal",
          "as": "Weight"
        }
      ],
      "layer": [
        {
          "mark": {
            "type": "line",
            "color": "blue"
          },
          "encoding": {
            "x": {
              "field": "x",
              "type": "quantitative",
              "title": "x"
            },
            "y": {
              "field": "StudentTCDF",
              "type": "quantitative",
              "title": "Cumulative Probability"
            }
          }
        },
        {
          "mark": {
            "type": "line",
            "color": "red",
            "opacity": 0.5
          },
          "encoding": {
            "x": {
              "field": "x",
              "type": "quantitative"
            },
            "y": {
              "field": "NormalCDF",
              "type": "quantitative"
            }
          }
        },
        {
          "mark": {
            "type": "point",
            "color": "green",
            "filled": true
          },
          "transform": [
            {
              "sample": 100
            }
          ],
          "encoding": {
            "x": {
              "field": "x",
              "type": "quantitative"
            },
            "y": {
              "field": "NormalCDF",
              "type": "quantitative"
            },
            "size": {
              "field": "Weight",
              "type": "quantitative",
              "scale": {
                "range": [
                  20,
                  200
                ]
              }
            }
          }
        }
      ]
    }
  ]
}