Inputs, Outputs, and Checks
Before running an experiment, name its inputs and outputs.
For a noisy line experiment:
| Part | Example |
|---|---|
| input setting | points = 8 |
| input setting | true_slope = 2.0 |
| input setting | noise = 0.2 |
| output | fitted slope |
| output | mean squared error |
| output | plot and summary |
This makes the program easier to inspect.
Add checks near assumptions
If the experiment needs at least two points, say so:
assert config.points >= 2
If arrays must match, check their shapes:
assert x.shape == y.shape
Check the basic assumptions
Ready to run.
Checks are not decoration. They keep a wrong run from becoming a confusing result.
Outputs should be small and named
At this stage, a good result is not a large object. It is a few named values:
slope: 1.95
loss: 0.04
Later experiments will save more, but the habit starts with clear names.
Exercise: Array shape check
Which assertion checks that x and y have the same shape?
Answer it first, then check.
Hint
Compare the .shape attribute of the two arrays with ==.
Solution
Use:
assert x.shape == y.shape
The experiment should stop early if its inputs cannot form paired points.