Data Analytics / Chapter 04

Change and structure

One table can describe a steady addition, a repeated multiplication, or a change of measurement. Make the mathematical choice visible before drawing the curve.

Local developmental companion · constructed teaching numbers · no account, tracking or network execution.

In this chapter
  1. Addition or multiplication?
  2. Energy is a weighted sum
  3. Return to the vessel
  4. Reproduce and challenge the calculations
  5. Code and captured output
Investigation 01 · paths through time

Addition or multiplication?

Start at 100. Choose an additive step and a percentage growth rate. Both paths may share their first change, yet compound growth separates later. The display is a scenario, not a forecast.

After 3 steps: 130 vs 133.1

Additive: 100 + 3×10 = 130. Multiplicative: 100×1.1³ = 133.1.

Original reference figure comparing a fixed addition with a fixed percentage increase from the same start; it uses fixed textbook values and does not update with the controls.

Reference figure shows the book's fixed 100, +10 and +10% case. The numbers above change with your choices; the figure intentionally remains the printed reference.

Investigation 02 · aligned intervals

Energy is a weighted sum

Power and duration must refer to the same interval. Change a duration and compare the correct energy with the equal-time shortcut.

16 kWh

2×3 + 5×2 = 16 kWh; average power 3.2 kW.

Fixed textbook reference figure showing three hours at 2 kilowatts and two hours at 5 kilowatts.

The graphic is the fixed reference case. It does not update when the hours change.

Investigation 03 · an early pattern fails

Return to the vessel

The constructed optical-density readings are 0.10, 0.20, 0.40 and 0.62 at 0, 2, 4 and 6 hours. An early doubling rule predicts 0.80 at six hours. The observed final reading is 0.18 lower.

Four fixed constructed culture readings on ordinary and logarithmic vertical axes; the final reading lies below a doubling scenario.

Last observed factor: 0.62 / 0.40 = 1.55; early factor: 2.

The difference suggests checking the vessel, protocol and instrument before claiming a biological cause. A straight line on log paper is a mathematical description over a range, not proof of indefinite growth.

Run · explain · break

Reproduce and challenge the calculations

Download the standard-library Python investigation. It prints the interval rates, energy, projection and exact small least-squares solution. Then try duplicate time points, a zero value before taking a logarithm, swapped pump durations, and a zero projection direction. The program rejects invalid cases instead of returning a plausible-looking number.

python3 change_lab.py
Aligned pump energy: 16.0 kWh; duration-weighted power: 3.2 kW
Projection onto east: (3.0, 0.0)
Least-squares intercept/slope: 7/6, 1/2
Why is the derivative not an observation?

It is the local slope of a proposed continuous function. Sparse measurements give average interval changes. A derivative does not recover an unseen spike between readings.

What changes when a feature's unit changes?

Raw Euclidean distances may change. A fixed multiplicative conversion of a positive series shifts its log intercept, but its log differences remain the same. Every transformation needs a declared purpose and units.

What does the eastward projection discard?

Projecting (3,4) metres onto east returns (3,0) metres; the four-metre north component remains real, but it lies outside this one-direction representation.

Original vector diagram showing a three-metre eastward projection of a displacement that also contains four metres north.

Chapter 4 · private developmental edition. Public chapter route and printed QR are pending final release approval.

The reproducible notebook

Inspect the work.

Read the programs, run them in your own environment, and compare the results. The captured output records the chapter’s checked practical run; changing an input may change its answer.

Python change_lab.py
"""Chapter 4: constructed change, energy and projection investigations.

Run with Python 3.11+. Standard library only; no data or network access.
"""

from fractions import Fraction
from math import log, sqrt


def interval_report(times: list[float], values: list[float]) -> list[tuple[float, float, float]]:
    if len(times) != len(values) or len(times) < 2:
        raise ValueError("aligned time and value arrays need at least two points")
    if any(b <= a for a, b in zip(times, times[1:])):
        raise ValueError("times must strictly increase")
    if any(v <= 0 for v in values):
        raise ValueError("log changes require positive readings")
    return [((b-a)/(tb-ta), b/a, log(b/a)/(tb-ta))
            for ta, tb, a, b in zip(times, times[1:], values, values[1:])]


def energy(power_kw: list[float], duration_h: list[float]) -> tuple[float, float]:
    if not power_kw or len(power_kw) != len(duration_h):
        raise ValueError("power and duration arrays must align")
    if any(p < 0 for p in power_kw) or any(h < 0 for h in duration_h):
        raise ValueError("negative power/duration outside this case")
    hours = sum(duration_h)
    if not hours:
        raise ValueError("no operating duration")
    total = sum(p*h for p, h in zip(power_kw, duration_h))
    return total, total/hours


def project(x: tuple[float, float], v: tuple[float, float]) -> tuple[float, float]:
    denominator = sum(z*z for z in v)
    if not denominator:
        raise ValueError("cannot project onto a zero vector")
    scalar = sum(a*b for a, b in zip(x, v))/denominator
    return scalar*v[0], scalar*v[1]


def small_least_squares() -> tuple[Fraction, Fraction, list[Fraction], list[Fraction]]:
    """Exact intercept and slope for (0,1), (1,2), (2,2)."""
    xs = [Fraction(0), Fraction(1), Fraction(2)]
    ys = [Fraction(1), Fraction(2), Fraction(2)]
    xbar = sum(xs)/len(xs)
    ybar = sum(ys)/len(ys)
    numerator = sum((x-xbar)*(y-ybar) for x,y in zip(xs,ys))
    denominator = sum((x-xbar)**2 for x in xs)
    if not denominator:
        raise ValueError("input has no variation")
    slope = numerator/denominator
    intercept = ybar-slope*xbar
    fitted = [intercept+slope*x for x in xs]
    residuals = [y-p for y,p in zip(ys,fitted)]
    return intercept, slope, fitted, residuals


def main() -> None:
    changes = interval_report([0,2,4,6],[.10,.20,.40,.62])
    print("Constructed culture: interval, absolute rate per hour, ratio, log rate per hour")
    for i,(rate,ratio,log_rate) in enumerate(changes,1):
        print(f"  {i}: {rate:.3f}, {ratio:.2f}, {log_rate:.3f}")
    assert [round(x[1],2) for x in changes] == [2.0,2.0,1.55]
    total,mean = energy([2,5],[3,2])
    assert (total,mean)==(16,3.2)
    print(f"Aligned pump energy: {total:.1f} kWh; duration-weighted power: {mean:.1f} kW")
    print(f"Equal-time shortcut: {sum([2,5])/2*5:.1f} kWh (incorrect for these durations)")
    projection=project((3,4),(2,0))
    assert projection==(3,0) and project((3,4),(10,0))==(3,0)
    print(f"Projection onto east: {projection}")
    intercept,slope,fitted,residuals=small_least_squares()
    assert (intercept,slope)==(Fraction(7,6),Fraction(1,2))
    assert sum(residuals)==0 and sum(x*r for x,r in enumerate(residuals))==0
    assert sum(r*r for r in residuals)==Fraction(1,6)
    print(f"Least-squares intercept/slope: {intercept}, {slope}")
    print(f"Fitted values: {', '.join(map(str,fitted))}")
    print(f"Residuals: {', '.join(map(str,residuals))}; squared sum: {sum(r*r for r in residuals)}")
    pooled_speed=Fraction(7*60,22)
    assert 19 < float(pooled_speed) < 19.1
    print(f"Pooled journey speed: {float(pooled_speed):.2f} km/h")


if __name__ == "__main__":
    main()
Output Checked chapter run
Constructed culture: interval, absolute rate per hour, ratio, log rate per hour
  1: 0.050, 2.00, 0.347
  2: 0.100, 2.00, 0.347
  3: 0.110, 1.55, 0.219
Aligned pump energy: 16.0 kWh; duration-weighted power: 3.2 kW
Equal-time shortcut: 17.5 kWh (incorrect for these durations)
Projection onto east: (3.0, 0.0)
Least-squares intercept/slope: 7/6, 1/2
Fitted values: 7/6, 5/3, 13/6
Residuals: -1/6, 1/3, -1/6; squared sum: 1/6
Pooled journey speed: 19.09 km/h