Skip to content

Lecture 11 — Classes and object-oriented design for simulation code

Fri 30 Oct 2026 · Boris Bolliet

TL;DR — A class bundles data with the functions that act on it. Attribute lookup, special methods and copying follow fixed rules.

Slides Notes Self-test

Demonstration files

File View Download Colab
lecture11-mine.ipynb Open in Colab
lecture11.ipynb Open in Colab

data/lynx_hare.csv: annual lynx and snowshoe hare pelts traded by the Hudson's Bay Company, 1900–1920, in thousands. Copied on 24 October 2026 from knitr/lotka-volterra/hudson-bay-lynx-hare.csv of github.com/stan-dev/example-models (raw URL https://raw.githubusercontent.com/stan-dev/example-models/master/knitr/lotka-volterra/hudson-bay-lynx-hare.csv), the data file of B. Carpenter, Predator-Prey Population Dynamics: the Lotka-Volterra model in Stan (2018), https://mc-stan.org/learn-stan/case-studies/lotka-volterra-predator-prey.html, which takes the table from P. Howard's lecture notes (2009) and gives no archival source (the case study cites Hewitt's 1921 book only for its plots of 1821–1914). The repository's README (https://github.com/stan-dev/example-models, accessed 24 October 2026) states: "All of the example models are copyrighted by their author(s) or assignees under the new BSD license unless another open-source license is explicitly stipulated in the directory containing the model"; the directory stipulates none. The case study's text is CC-BY-NC 4.0 and is not copied. The two header lines of the original file are kept (the Howard PDF URL in the first one returned 404 on 24 October 2026); the table is a widely reproduced textbook digest of the Company's records, not an archival extract.

The chemostat runs data/C1.csv to C10.csv are those of Blasius, Rudolf, Weithoff, Gaedke and Fussmann, Long-term cyclic persistence in an experimental predator-prey system, Nature 577, 226–230 (2020), figshare doi:10.6084/m9.figshare.10045976 (CC BY 4.0). The Goodwin run is synthetic.

Content

  1. Objects, classes and attribute lookup
  2. Special methods
  3. Copies of objects holding arrays
  4. Interfaces, dataclasses and composition

Exercises with solutions