Inputs, Outputs, and Checks

Before running an experiment, name its inputs and outputs.

For a noisy line experiment:

PartExample
input settingpoints = 8
input settingtrue_slope = 2.0
input settingnoise = 0.2
outputfitted slope
outputmean squared error
outputplot 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

Runs locally with Python in your browser.

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.