Sample Code

This page has code examples for things we've talked about in class. These are good starting points for homework problems that ask for computer programs.

Random Walks: random_walks.py
This file contains code to simulate a single random walk with varying probabilities of going right or left
Metropolis-Hastings: metropolis.py
Classes to do Metropolis-Hastings Markov chains. To do something other than independence chains, need to define an appropriate CandidateDensity.
Metropolis-Hastings Examples: mpls_examples.py
Example of defining a conditional candidate distribution.
Simple 2D Markov chain: simple_chain.py
A simple 2D Markov chain for use in HW 3a.
Simple Monte Carlo Example: montecarlo.py
Sample Monte Carlo integration for estimating pi.
Matplotlib plotting: mpl_ex.py
Sample plotting commands in matplotlib.