Project 4

A Complete Numerical Experiment

Generate a small repeatable dataset, search a supplied grid of lines, and preserve enough numerical and visual evidence to explain which candidate the program selected.

  • 8 milestones
  • Optional
  • Browser workspace

Project question: Can you generate a small repeatable dataset, search a supplied grid of candidate lines, and preserve enough evidence to explain which candidate the program selected?

What makes this a project

This project joins several small numerical tasks into one complete investigation. You will define a configuration, generate observed values with controlled variation, calculate a supplied prediction and score, search every candidate in an ordered grid, inspect the selected candidate, and save a report that another run can check.

The project assesses the investigation and its evidence. It does not ask you to implement a general method for estimating a line, and it does not claim that the selected candidate is a true or universally useful line. The supplied rules keep the numerical work visible so that you can hand-check the important steps.

You will produce:

  • a validated configuration and generated data record;
  • one score for every slope/intercept pair in the supplied candidate grid;
  • a selected result with predictions and signed differences;
  • numerical and visual checks of the selected candidate;
  • saved artifacts and a separate replay record; and
  • a short report whose claims point to those artifacts.

What you should know first

The project follows the Python path through Chapter 13. You should be able to organize several files, use configuration and result records, construct and transform arrays, calculate reductions, make plots, control randomness, save artifacts, and replay a run. DATA-03 is useful preparation but optional. The project supplies the local numerical rules; you do not need a course in statistical estimation to begin.

The supplied numerical contract

For an input value x, a candidate line produces:

prediction = slope * x + intercept

For observed and predicted arrays of equal, non-zero length, the score is the mean of the squared differences:

mean((prediction - observed) ** 2)

The project calls this value mean_squared_difference. First expand and check one three-value example by hand. Then use the compact NumPy expression while keeping the expanded meaning available in the report.

The generated data

Create nine evenly spaced input values from -2.0 through 2.0. Calculate a configured source line and add bounded uniform variation from [-noise_bound, noise_bound). Save the input, variation, and observed value for every row. The configuration records the source slope and intercept, noise bound, seed, and input construction. Those source parameters help verify the fixture; finding them again from the observations is not the success criterion.

The candidate grid

The search receives ordered one-dimensional arrays of candidate slopes and intercepts. Evaluate every Cartesian pair exactly once and store one score per pair at its documented position in a (slopes, intercepts) grid. If exact scores tie, keep the first pair in row-major candidate order. Do not use random search, a library fitting function, gradients, or an unrecorded tolerance to change the selected candidate.

The selected result records the candidate parameters, its score, candidate-grid identity and shape, predictions, signed differences defined as observed - predicted, and a check that no stored score is smaller. Describe the candidate as the best one in this supplied grid, not as the true line.

The project workspace

project/
  README.md
  src/config.py                    # reader implementation
  src/data.py                      # reader implementation
  src/line.py                      # reader implementation
  src/search.py                    # reader implementation
  src/report.py                    # reader implementation
  src/main.py                      # reader implementation
  plans/baseline.json              # supplied starting configuration
  output/                          # generated artifacts
  tests/public_cases.py            # supplied, read only

Keep the responsibilities separate and keep one continuous workspace through all milestones. Implementation review may combine files when the numerical and evidence boundaries remain clear and separately testable.

Project milestones

Work through these in order. Each milestone produces evidence used by the next one, while project completion remains separate from lesson progress.

  1. 1Define the investigation and configuration

    State the generated data, candidate grid, score, outputs, seed, and checks, then reject invalid settings before data generation.

  2. 2Implement and hand-check line prediction and score

    Keep prediction and mean squared difference independent, validate their arrays, and reproduce one small calculation by hand.

  3. 3Generate the repeatable observed data

    Generate nine identified inputs with one local random generator, save exact variation and observations, and verify bounded same-seed replay.

  4. 4Evaluate the complete candidate grid

    Evaluate every ordered slope and intercept pair exactly once and store each score at its documented grid position.

  5. 5Select and verify the winning candidate

    Apply the exact row-major tie rule, reconstruct predictions and signed differences, and prove no stored score is smaller.

  6. 6Inspect the result numerically and visually

    Inspect observed points, generation evidence, the selected line, and signed differences without hiding them behind one score.

  7. 7Save and replay the investigation

    Write configuration, data, full search evidence, selection, figure, runtime, and manifest artifacts, then replay them separately.

  8. 8Write and audit the report

    Explain the question, implementation, checks, selected grid candidate, visible evidence, replay, and limits against saved artifacts.

Required evidence

The completed project contains:

  • experiment_config.json;
  • generated_data.csv, including input, bounded variation, and observed value;
  • search_scores.csv or an equally explicit full-grid representation;
  • selected_result.json with prediction and difference values;
  • fit_and_differences.png;
  • run_manifest.json with source, configuration, runtime, and artifact identity;
  • a separate replay agreement or mismatch record; and
  • a concise report.md.

Checks should include hand-computed prediction and score cases, invalid/empty/mismatched arrays, exact input and bounded-noise reconstruction, same-seed replay, complete grid evaluation, known ties, winner reconstruction, artifact read-back, and figure-data checks. Automated checks cannot decide whether an explanation is justified; the final review must do that.

Limits

This project does not teach regression estimation, probability distributions beyond the supplied bounded generator, expected error, confidence intervals, generalization, train/test evaluation, statistical claims, derivatives, gradients, continuous optimization, performance competition, or claims that the selected grid candidate is the true line. Mathematics will establish the meaning and limits of those ideas later.

Review

The final review asks whether the configuration is explicit, generated values can be replayed, every candidate was evaluated once, ties use the stated rule, the selected result can be reconstructed, and the plots and report agree with saved artifacts. State what the evidence supports and what it cannot establish.