#412History beats a single point — next-step predictionEasy

History beats a single point — next-step prediction

Background

The lesson's motivating example: predicting a ball's next position from its current point alone is underdetermined — you can't tell which way it's moving. Give the model the trajectory and a simple constant-velocity estimate works: the next point is the last point plus the last observed step (velocity).

p^t+1=pt+(ptpt1)\hat{p}_{t+1} = p_t + (p_t - p_{t-1})

Problem statement

Implement next_position(trajectory) returning the constant-velocity prediction of the next point.

Input

  • trajectory — array-like of past points (length 2\ge 2). Each point is a scalar or a coordinate vector (e.g. [x, y]).

Output

Returns an np.ndarray (or scalar array) the shape of one point: pt+(ptpt1)p_t + (p_t - p_{t-1}).

Examples

Example 1 — 2D straight line

Input:  trajectory = [[0, 0], [1, 1], [2, 2]]
Output: [3 3]

Explanation: last step was [1,1][1,1], so the next point continues to [3,3][3,3].

Example 2 — 1D

Input:  trajectory = [1, 2, 3]
Output: 4

Explanation: velocity 11 → next is 44.

Constraints

  • Use only the last two points: last + (last - prev).
  • Return the same shape as a single point.

Notes

  • This is the simplest "temporal model" — it uses history (the previous step) rather than just the present. RNNs generalise this by learning what to remember.
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • example 2D line
  • reference 1D velocity
  • sample negative step