# Monte Carlo Methods and Applications ### CMU 21-387 | 15-327 | 15-627 | 15-860 FALL 2023 **[geometry.cs.cmu.edu/montecarlo](http://geometry.cs.cmu.edu/montecarlo)** [Home](index.html) — [Course Info](#info) — [Schedule](#schedule) — [Assignments](#assignments) — [Resources](#resources) — [Course Policies](#policies) **Instructors:** Keenan Crane (CSD/RI) and Gautam Iyer (MSC) **Location:** Doherty Hall (DH) A302map **Date and time:** Tuesday / Thursday, 9:30am–10:50am **Units:** **9** (3 in-class/6 outside) ### Course Info The Monte Carlo method uses random sampling to solve computational problems that would otherwise be intractable, and enables computers to model complex systems in nature that are otherwise too difficult to simulate. This course provides a first introduction to Monte Carlo methods from complementary theoretical and applied points of view, and will include implementation of practical algorithms. Topics include random number generation, sampling, Markov chains, Monte Carlo integration, stochastic processes, and applications in computational science. Students need a basic background in probability, multivariable calculus, and some coding experience in any language. Coding assignments will be done in [Python 🐍](https://www.python.org/). **Key Topics:** definitions of randomness, random number generation, randomness testing and quality measures, curse of dimensionality, sampling and aliasing, Markov chains, Monte Carlo methods, stochastic processes, sample generation algorithms, applications of random numbers in computation #### Course Overview Random numbers are a basic tool for achieving robustness, scalability, and correctness in the design of algorithms. Moreover, randomness is an essential part of models used to describe the behavior of systems found throughout science, technology, and engineering. The Monte Carlo method in particular was recognized by SIAM as one of the [most important 10 algorithms of the 20th century](http://pi.math.cornell.edu/~web6140/). This course complements the existing curriculum, helping to better prepare students to apply randomness to problem solving in both academic and industrial settings. The goal of this course is to enable students to identify situations where random sampling provides the best solution to a computational/algorithmic problem, and to train them in the practical implementation of associated methods. Students should also acquire the mathematical background needed to derive new algorithms from first principles, rather than purely applying existing techniques, and to analyze the correctness and efficiency of these algorithms. (For example, they should be able to determine whether a given Monte Carlo estimator is unbiased, and measure the empirical efficiency of such algorithms in terms of statistics such as variance.) A secondary goal of this course is to expose students to a collection of application areas in computer science and the broader sciences where randomness can be profitably applied. In computer science, this set includes problems in computer systems/networking, programming languages, theoretical computer science, artificial intelligence/machine learning, and computer graphics. In the broader sciences, this includes partial differential equations arising in physics/chemistry/biology/etc., and stochastic models appearing in mathematical finance. #### Learning Objectives * Identify situations where random sampling provides the best solution to a computational/algorithmic problem. * Implement the associated methods. * Acquire the mathematical background needed to derive new algorithms from first principles. * Analyze the correctness and efficiency of these algorithms. * Become familiar with a collection of application areas in computer science and the broader sciences where randomness can be profitably applied. #### Prerequisite Knowledge _What prior knowledge must students have in order to be successful in this course?_ Students must have basic knowledge of coding (in any language), as well as basic knowledge of probability and multivariable calculus. CMU courses satisfy the prerequisites are listed below; please contact the instructors if you believe you've taken a different course that fulfills the requirement. **Probability:** 15-259 or 21-325 or 36-218 or 36-219 or 36-225 or 36-235 or 18-465 **Multivariable Calculus:** 21-254 or 21-256 or 21-259 or 21-266 or 21-268 or 21-269 ### Lecture Schedule _[Lecture titles link to slides, if available. Note that some lectures are chalkboard only—if you have nicely written/typed notes for these lectures that you'd be willing to share, we'd be glad to post them here!]_ - **29 Aug (Tue)** — [Overview](slides/Lecture01-Overview-CMUMonteCarloFA23.pdf) broad picture of Monte Carlo methods, historical comments, motivating applications, problems with deterministic sampling, course outline framed via Monte Carlo estimator - **31 Aug (Thu)** — [Monte Carlo Integration I](slides/Lecture02-BasicMonteCarlo-CMUMonteCarloFA23.pdf) Review of basic probability, definition of Monte Carlo estimator, bias vs. consistency, measures of quality, sample variance, convergence rate, numerical demonstrations. - **05 Sep (Tue)** — Coding Monte Carlo Methods: [First example](first-mc-example.html) ([download](first-mc-example.ipynb)), [Fun second example](substitution-cipher.html) setting up Python, implementing basic Monte Carlo methods, estimating &mpi;, evaluating sample variance/RMSE - **07 Sep (Thu)** — Monte Carlo Integration II Cost of quadrature / Monte Carlo integration, variance estimates, law of large numbers, central limit theorem - **12 Sep (Tue)** — [Variance Reduction I](slides/Lecture05-VarianceReduction-CMUMonteCarloFA23.pdf) definition of efficiency, control variates, stratified sampling, importance sampling, quasi-Monte Carlo - **14 Sep (Thu)** — [Variance Reduction II](slides/Lecture05-VarianceReduction-CMUMonteCarloFA23.pdf) uniform sampling, pseudorandom number generation, tests of randomness, sampling discrete distributions (CDF, inversion) - **19 Sep (Tue)** — [Sample Generation](slides/Lecture06-BasicSampleGeneration-CMUMonteCarloFA23.pdf) , sampling continuous distributions, special distributions (normal, exponential), rejection sampling, stratified sampling, curse of dimensionality revisited - **21 Sep (Thu)** — [Introduction to Markov Chain Monte Carlo](pdf/mc-mcex.pdf) ([lecture notes](notes/Lecture08-MCMC-intro/Lecture08-MCMC-intro.pdf)) Examples of sampling in high dimensions, the Metropolis-Hastings algorithm - **26 Sep (Tue)** — [Markov Chains I](pdf/mc-mc1.pdf) ([lecture notes](notes/Lecture09-MarkovChainsI/Lecture09.pdf)) Markov chains, stationary distribution, irreducibility - **28 Sep (Thu)** — [Markov Chains II](pdf/mc-mc2.pdf) ([lecture notes](notes/Lecture10-MarkovChainsII/Lecture10.pdf)) Aperiodicity, convergence, detailed balance, Metropolis chains - **03 Oct (Tue)** — [Stochastic Differential Equations I](slides/Lecture11-StochasticDifferentialEquations-CMUMonteCarloFA23.pdf) ordinary differential equations (ODEs), Brownian motion & basic properties, drifted motion, basic stochastic differential equations (SDEs), numerical integrators (forward Euler, Euler-Maruyama), application: molecular dynamics simulation - **05 Oct (Thu)** — Partial Differential Equations definition of PDEs, elliptic/parabolic/hyperbolic, linearity, order, boundary conditions, finite difference methods, finite element methods, challenges with meshing - **10 Oct (Tue)** — Stochastic Calculus I quadratic variation, Itô integration - **12 Oct (Thu)** — Stochastic Calculus II Itô formula - **24 Oct (Tue)** — Stochastic Calculus III continuation of previous days' topics - **26 Oct (Thu)** — Stochastic Differential Equations II Langevin equation, stationary distribution - **31 Oct (Tue)** — Walk on Spheres I TODO - **02 Nov (Thu)** — Walk on Spheres II TODO - **09 Nov (Thu)** — Algorithms in High Dimensions I Langevin Monte Carlo (LMC), simulated annealing - **14 Nov (Tue)** — Algorithms in High Dimensions II Hamiltonian Monte Carlo (HMC), Metropolis Adjusted Langevin Monte Carlo (MALA) - **16 Nov (Thu)** — TBD TBD - **21 Nov (Tue)** — TBD TBD - **28 Nov (Tue)** — Guest Lecture ([Xiaoyue Cui and Maureen Stolzer](http://www.cs.cmu.edu/~durand/Lab/personnel2.html)): MCMC Protein Evolution - **30 Nov (Thu)** — Guest Lecture ([Ioannis Gkioulekas](https://www.cs.cmu.edu/~igkioule/)): Differentiable Monte Carlo - **05 Dec (Tue)** — Guest Lecture ([Gilbert Bernstein](http://www.gilbertbernstein.com/)): Probabilistic Programming Languages - **07 Dec (Thu)** — Guest Lecture ([Jun-Yan Zhu](https://www.cs.cmu.edu/~junyanz/)): Diffusion Models / Generative AI ### Assignments **All assignments are due at 8:29am Eastern time (NOT midnight!)** The distribution of the scores on the homework can be found [here](https://www.math.cmu.edu/~mcm-cmu/auth/) - [Assignment 1](assignments/Assignment01.html) (due 9/5) — Getting Set Up - [Assignment 2](assignments/Assignment02.html) (due 9/12) — Monte Carlo Integration ([Solutions](https://www.math.cmu.edu/~mcm-cmu/auth/Assignment02-SolutionsForStudents.html)) - [Assignment 3](assignments/Assignment03.html) (due 9/19) — Variance Reduction - [Assignment 4](assignments/Assignment04.html) (due 9/26) — Sample Generation - [Assignment 5](assignments/Assignment05.html) (due 10/03) — Markov Chain Monte Carlo ### Resources #### Office Hours - Mondays 11am–1pm by [Jiannan Jiang](https://www.linkedin.com/in/jiannan-jiang-943197169) (TA) in Wean Hall 6213. - Mondays 2:30–4:30PM by Nathan Glover (TA) in Baker Hall 237B. - Tuesdays 3–5pm by [Keenan Crane](http://www.cs.cmu.edu/~kmcrane/) (instructor) in 217 Smith Hall. - Wednesdays 11:50am–1:50pm by [Loïc Lescoat](https://github.com/loic-lescoat) (TA) in GHC Commons, Table 6. - Thursdays 1–3PM by [Gautam Iyer](https://www.math.cmu.edu/~gautam/sj/index.html) (instructor) in 6121 Wean Hall. - Thursdays 4–6pm by [Nicole Feng](https://nzfeng.github.io/) (TA) — Graphics Lounge, 2nd floor Smith Hall (EDSH). - Fridays 11am–1pm by SJ Son (TA) in Wean Hall 6203. - Fridays 2pm–4pm by Yuan Meng (TA) in GHC 5th floor Commons, Table 7. #### Infrastructure - **General announcements** — sent via email. If you joined late, please [add yourself to the mailing list](https://lists.andrew.cmu.edu/mailman/listinfo/math-cs-montecarlo). - **Discussion** — via the [CMU Math Discourse server](https://zym.math.cmu.edu/c/f2023-387). You will need to log in via your AndrewID to post. - **Live chat** — via the [Monte Carlo CMU FA23](https://www.math.cmu.edu/~mcm-cmu/auth/) Discord server. #### Notes and References ##### Notes - [Lecture notes for black board lectures](pdf/mc.pdf) (This only contains statements of important results from the blackboard lectures by Gautam; explanations, motivations and proofs will be done in class and are not in these notes.) ##### Recommended References - [Monte Carlo Theory, Methods and Examples](https://artowen.su.domains/mc/), Art Owens - Simulation and the Monte Carlo Method by Rubinstein and Kroese. - [Markov Chains](https://www.statslab.cam.ac.uk/~james/Markov/), James Norris - [Stochastic Differential Equations](https://link.springer.com/book/10.1007/978-3-642-14394-6), Bernt Øksendal - [Physically Based Rendering](https://www.pbr-book.org/) _Chapters 13 & 7_, Pat Hanrahan, Greg Humphreys, Wenzel Jakob, Matt Pharr - [Robust Monte Carlo Methods for Light Transport Simulation](http://graphics.stanford.edu/papers/veach_thesis/) _Chapters 2 & 11_, Eric Veach ### Course Policies #### Assignments & Submission - Weekly short assignments, typically assigned Tuesday and due the following Tuesday. - **Written exercises** - all work must be submitted digitally (_no paper!_) - either typeset (via [LaTeX](https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes)) or scans/photos of written work - **Coding exercises** - all coding is in [Python 🐍](https://www.python.org/) - Python is **not** a prerequisite, but you should have _some_ coding experience (in any language) - Submit via [Gradescope](https://www.gradescope.com/courses/592187), `21387` in the *Math* department. - If you joined late, add yourself to Gradescope using the code [here](https://www.math.cmu.edu/~mcm-cmu/auth/) #### Late Days & Dropped Assignments - Assignments due at 8:29 am Eastern time on due date (one hour before class starts) - **8:29 am is not midnight!** 🤪 - Two assignments can be dropped without penalty - if you don’t drop any, we’ll just take best N-2 scores - Can use five late days throughout semester - _if no more late days remain, late work gets a zero!_ - Late days & drops _already_ account for sick days, late adds, job interviews, conference travel, etc. - Cannot be used for midterm & final - Please don’t bug TAs/instructors about extra late days and drops! 🥵 #### Waitlist & Late Add - Don't be fooled by the waitlist: we have _never once_ had a situation where an eligible student has not ultimately been able to get a spot in the class. The room is big, and people inevitably drop. Please just hang in there. - If you're on the waitlist and hope to join the class, **please still show up to lecture, and complete / hand in the assignments!** Doing so will only make life easier once you are officially enrolled in the class. - If there are free spots in the class but you're still stuck on the waitlist, there is likely an administrative block (e.g., you don't officially meet the prereqs, or are signed up for too many hours). Good to check with your advisor. - Note that _instructors do not have the ability to move students off the waitlist directly_—we have to coordinate with the course administrators. We do periodically clear the waitlist, so again, please just hang tight if things aren't getting updated immediately. - If you are adding the course late for any other reason, please make sure to: - Review the slides/notes from the lectures you missed, which are linked from the [schedule](#schedule). If you have trouble understanding the material from the slides alone, the [Monte Carlo book by Owen](https://artowen.su.domains/mc/) provides all the essentials (and much more!). - Complete the [assignments](#assignments) you missed. Like any other assignments, these are covered by the policy on [late days and dropped assignments](#latedays). - Chat with your peers, the TAs, and the instructors in [office hours](#officehours), on [Discord, and on Discourse](#infrastructure) to help fill in the gaps in your understanding. - Note that **instructors will not do one-on-one makeup sessions on missed material** (sorry!). But again, please take full advantage of the resources above, which should be enough to get you up to speed. #### Collaboration Policy - _Encouraged_ to work with anyone/everyone! - Must write up final solutions _100% on your own_ (including code) - e.g., erase the board, walk home, write up solutions - **Copying any part of someone else’s solutions is considered cheating** - any instance of cheating will result in an immediate “R” for the class - both/all parties will be considered cheating, no questions asked #### Grades - **Weekly assignments** — 70% - each assignment worth the same amount - _can_ collaborate - _can_ use late days & drops - **Take-home midterm & final** — 15% each - cumulative - _not_ collaborative - _cannot_ use late days & drops #### Accommodations for Students with Disabilities If you have a disability and have an accommodations letter from the Disability Resources office, I encourage you to discuss your accommodations and needs with me as early in the semester as possible. I will work with you to ensure that accommodations are provided as appropriate. If you suspect that you may have a disability and would benefit from accommodations but are not yet registered with the Office of Disability Resources, I encourage you to contact them at [access@andrew.cmu.edu](mailto:access@andrew.cmu.edu). #### Student Wellness As a student, you may experience a range of challenges that can interfere with learning, such as strained relationships, increased anxiety, substance use, feeling down, difficulty concentrating and/or lack of motivation. These mental health concerns or stressful events may diminish your academic performance and/or reduce your ability to participate in daily activities. CMU services are available, and treatment does work. You can learn more about confidential mental health services available on campus [here](http://www.cmu.edu/counseling). Support is always available (24/7) from Counseling and Psychological Services: 412-268-2922.

This page rendered with showdownjs.