AII 600. Lab 1
Due before class, 2 September 2026
The Canvas submission is one Jupyter notebook, lab1.ipynb. Not this page. Credit is on-time submission. Part A is how you set up; Cell 1 is where you record it, including the tutor. Part B is the probability we reached tonight: random variables, the basic rules, independence, and the complement. The posted slides continue past that. Joint tables are Lab 2. Bayes and expectation come later.
Part A is a cold start if the tools are new. Begin it before Sunday, not the hour before class.
These are not the in-class stops. In class we work different problems with a neighbor.
Part A: toolchain
Install these once. The notebook is how you show they work. You can do A1 and A2 by hand, or ask an agent to do them. If you do not already know the language or git, ask the agent to teach you enough to run a cell, read an error, and say what a commit is. Do not wait for a lecture on the tools. Seed the tutor in A3 first if you want that agent to be the course one; any assistant is allowed. Installer failures are syntax questions: it should answer directly.
A1. R or Python
Install one language you will actually defend in, yourself or by asking the agent. The notes are mostly R; Python is allowed. Module 6 has some Python. The notebook kernel should be that language. If the language is new, tell the agent that and have it install, then explain what you just installed and how you will run a cell.
A2. Git, notes, and finalproject
Install git if it is not already there (git --version). Same rule: do the steps below yourself, or paste them to the agent and have it run them. If you are new to git, ask agents to explain what is init, add, commit, status, and .gitignore are for before you treat the output as done.
Create a course folder, then two folders inside it, then start tracking. Git does not see empty folders: put a file in each, write a .gitignore, then commit. If git commit refuses, set user.name and user.email (Mason email) first. On Windows, Git Bash is the easy way to run the same commands; change ~/aii600 if you put the folder somewhere else.
bash
mkdir -p ~/aii600/notes ~/aii600/finalproject
cd ~/aii600
git init
printf '%s\n' '.DS_Store' '.venv/' '__pycache__/' '.Rhistory' '.RData' > .gitignore
printf 'personal notes and code from class\n' > notes/README.md
printf 'project work, including before teams lock in week 9\n' > finalproject/README.md
git add -A
git commit -m "week 1 setup"
git status
git log --oneline
git ls-filesnotes is for personal notes and code chunks from class. finalproject is for the project, including work you do before teams lock in week 9. You do not have to push anywhere. A local repository is enough; GitHub is optional backup. Cell 1 asks what else you will track, and what else belongs in .gitignore.
A3. Course tutor
Seed your assistant with the two course files. You do not have to download them. Point the agent at the URLs:
- https://vsokolov.org/courses/files/600/tutor-instructions.md
- https://vsokolov.org/courses/files/600/course-context.md
Cursor, Claude Code, or similar: @ those URLs, or save the files into ~/aii600 and set tutor-instructions.md as the instructions file. Claude or ChatGPT with Projects: paste tutor-instructions.md into the project instructions and add course-context.md as a project file. A chat with no Projects: paste both into the first message.
Ask it one factual question (syntax) and one conceptual question from tonight.
Part B: the notebook, submitted on Canvas
Create lab1.ipynb and upload that file. JupyterLab, VS Code / Cursor, or Positron all count. Python kernel or R kernel, matching A1. Colab is fine for Part B. Cells 2 and 3 have to come from your own machine. Run every code cell and leave the output in. Copy R or Python, not both. The checks only run once you replace every NA / None. Change ~/aii600 if your folder is elsewhere.
Cell 1: markdown text
Paste this into a markdown cell. Edit the list so it matches what you installed, and write the answers.
# AII 600, Lab 1
What I installed:
- language and version:
- git
- Jupyter
Course page: [AII 600](https://vsokolov.org/courses/600.html)
Write one sentence of your own that uses $P(\text{not }A)=1-P(A)$ and one `code` span.
YOUR SENTENCE
Git. Look at the `.gitignore` you committed. What else belongs in the repo that is not there yet, and what else belongs in `.gitignore`? Name one of each, and one reason for each.
YOUR ANSWER
Tutor. Did it answer the syntax question directly, and did it ask you one question back before explaining the concept?
YOUR ANSWER
Disclose. What did you use (tutor, Cursor, ChatGPT, a classmate, nothing) and for which parts?
YOUR ANSWERCell 2: language version
R
R.version.stringPython
import sys
print(sys.version)Cell 3: git
R
repo <- path.expand("~/aii600")
for (cmd in list(c("status"), c("log", "--oneline"), c("ls-files"))) {
cat("$ git", cmd, "\n")
cat(system2("git", c("-C", repo, cmd), stdout = TRUE), sep = "\n")
cat("\n")
}Python
import os, subprocess
course = os.path.expanduser("~/aii600")
for args in (["git", "status"], ["git", "log", "--oneline"], ["git", "ls-files"]):
print("$", *args)
print(subprocess.check_output(args, cwd=course, text=True))Cell 4: a random variable is a function
A loan officer is about to open one of four applicant files, equally likely: \(A\), \(B\), \(C\), \(D\). Let \(X\) be the number of late payments on the file.
\[ \begin{array}{c|c} \text{file} & X \\ \hline A & 0 \\ B & 0 \\ C & 1 \\ D & 3 \end{array} \]
\(X\) is not the file. \(X\) is a function from those four outcomes to a number.
- Write the distribution of \(X\): \(P(X=0)\), \(P(X=1)\), \(P(X=3)\).
- What is \(P(X \ge 1)\)? Use the complement.
Copy one of the chunks, fill in the four numbers, run it.
R
p_x0 <- NA
p_x1 <- NA
p_x3 <- NA
p_at_least_one <- NA
if (!anyNA(c(p_x0, p_x1, p_x3, p_at_least_one))) {
stopifnot(
abs(p_x0 - 1/2) < 1e-12,
abs(p_x1 - 1/4) < 1e-12,
abs(p_x3 - 1/4) < 1e-12,
abs(p_at_least_one - 1/2) < 1e-12,
abs(p_x0 + p_x1 + p_x3 - 1) < 1e-12
)
}
c(p_x0 = p_x0, p_x1 = p_x1, p_x3 = p_x3, p_at_least_one = p_at_least_one)Python
p_x0 = None
p_x1 = None
p_x3 = None
p_at_least_one = None
vals = [p_x0, p_x1, p_x3, p_at_least_one]
if all(v is not None for v in vals):
assert abs(p_x0 - 1/2) < 1e-12
assert abs(p_x1 - 1/4) < 1e-12
assert abs(p_x3 - 1/4) < 1e-12
assert abs(p_at_least_one - 1/2) < 1e-12
assert abs(p_x0 + p_x1 + p_x3 - 1) < 1e-12
p_x0, p_x1, p_x3, p_at_least_oneCell 5: at least one, and overlap
A barcode scanner fails to read 8% of packages, independently. Two packages come down the belt.
- What is \(P(\text{at least one failure})\)? Use independence and the complement. Do not add \(0.08+0.08\).
- Estimate it with a simulation of at least 10,000 trials.
A second, smaller question, using the overlap rule from the slides. Tonight’s email goes to people who opened last week (\(P(A)=0.12\)) or who clicked last week (\(P(B)=0.05\)). Both: \(P(A\text{ and }B)=0.03\). These are not independent: \(P(A)P(B)=0.006\), not \(0.03\). What is \(P(A\text{ or }B)\)?
R
p_fail <- 0.08
p_at_least <- NA
set.seed(1)
p_sim <- NA
p_open_or_click <- NA
if (!anyNA(c(p_at_least, p_open_or_click))) {
stopifnot(
abs(p_at_least - 0.1536) < 1e-12,
abs(p_open_or_click - 0.14) < 1e-12
)
}
if (!anyNA(c(p_sim, p_at_least))) {
stopifnot(length(p_sim) == 1, abs(p_sim - p_at_least) < 0.05)
}
c(p_at_least = p_at_least, p_sim = p_sim, p_open_or_click = p_open_or_click)Python
import random
p_fail = 0.08
p_at_least = None
random.seed(1)
p_sim = None
p_open_or_click = None
if p_at_least is not None:
assert abs(p_at_least - 0.1536) < 1e-12
if p_open_or_click is not None:
assert abs(p_open_or_click - 0.14) < 1e-12
if p_sim is not None and p_at_least is not None:
assert isinstance(p_sim, (int, float))
assert abs(p_sim - p_at_least) < 0.05
p_at_least, p_sim, p_open_or_clickCell 6: independence twice
A fraud filter scores three independent transactions a night. Each is flagged with probability \(0.2\). A night is noisy if at least one transaction is flagged.
- What is \(P(\text{a noisy night})\)? Complement, then independence within the night.
- What is \(P(\text{five noisy nights in a row})\)? Independence across nights.
This is the hitting-streak move from class: a probability built inside one block, then raised to the number of blocks. Do not use Rose’s batting average or 44 games.
R
p_noisy <- NA
p_five <- NA
if (!anyNA(c(p_noisy, p_five))) {
stopifnot(
abs(p_noisy - (1 - 0.8^3)) < 1e-12,
abs(p_five - (1 - 0.8^3)^5) < 1e-12
)
}
c(p_noisy = p_noisy, p_five = p_five)Python
p_noisy = None
p_five = None
if p_noisy is not None and p_five is not None:
assert abs(p_noisy - (1 - 0.8**3)) < 1e-12
assert abs(p_five - (1 - 0.8**3)**5) < 1e-12
p_noisy, p_five