Video and Temporal Reasoning › A worked sampling example

Michael BrenndoerferDecember 1, 20264 min read
Language AI HandbookAll chapters
Part 52 of 67Omni-Modal and Embodied Language Systems
Chapter 399Video and Temporal Reasoning › A worked sampling example
Reading section 5 of 12 · A worked sampling example · 4 minSection 5 of 12 · 4 min

Section 5 of 12 · 4 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

We'll build a toy video as a sequence of per-frame feature vectors, the way a real pipeline would after the vision encoder. Using features instead of raw pixels keeps the example cheap and makes the temporal structure visible. Imagine a 10-second clip at 30 fps with an event that flashes for 0.4 seconds at the 3.1-second mark.

PythonIn [6]
CollapseExpand
import numpy as np

rng = np.random.default_rng(0)
fps = 30
duration_s = 10
n_frames = fps * duration_s

# Each frame is a short feature vector; baseline content is slowly drifting.
t = np.arange(n_frames) / fps
feature_dim = 8
features = 0.05 * np.sin(t)[:, None] + 0.02 * rng.standard_normal(
    (n_frames, feature_dim)
)

# A short event at 3.1s lasting 0.4s: a strong, brief spike in features.
event_start = 3.1
event_dur = 0.4
event_mask = (t >= event_start) & (t < event_start + event_dur)
features[event_mask] += 1.0

n_event_frames = int(event_mask.sum())
ConsoleOut [7]
CollapseExpand
Frames: 300
Event frames: 12 (between t=3.1 and t=3.5)

Twelve of the 300 frame timestamps fall in the interval [3.1,3.5)[3.1,3.5) seconds. Sampling one frame each second retains ten frames starting at second zero.

PythonIn [8]
CollapseExpand
sample_stride = fps  # one frame per second
sampled_idx = np.arange(0, n_frames, sample_stride)
caught = bool(event_mask[sampled_idx].any())
ConsoleOut [9]
CollapseExpand
Sampled frame indices (first 10): [  0  30  60  90 120 150 180 210 240 270]
Sampled 10 of 300 frames
Event caught by uniform 1-fps sampling: False

The latest uniform sample before the event arrives at 3.0 seconds. The next arrives at 4.0 seconds. Neither is inside the interval. Shifting the event start to 3.0 seconds would include a sample under the same grid and endpoint rule.

Now compare with an adaptive strategy that keeps frames where the frame-difference signal spikes.

PythonIn [10]
CollapseExpand
# Difference i compares frame i with frame i + 1.
diffs = np.linalg.norm(np.diff(features, axis=0), axis=1)
frame_budget = len(sampled_idx)
change_order = np.argsort(-diffs, kind="stable")
adaptive_idx = np.sort(change_order[:frame_budget] + 1)
caught_adaptive = bool(event_mask[adaptive_idx].any())
ConsoleOut [11]
CollapseExpand
Adaptive kept 10 frames
Event caught by adaptive sampling: True
Event-frame indices: [93 94 95 96 97] ...

In this seeded toy clip, the adaptive sampler catches the event with the same ten-frame output budget. It keeps frame 93 as its only event frame, and it also keeps frame 105, just after the event. It computed scores using the full 300-frame feature sequence up front, so equal output budgets do not imply equal preprocessing cost. It can spend several samples on one change or choose a departure frame just outside the event. A limit on gaps between sampled timestamps can protect broad coverage while leaving sub-gap events at risk.

The chart puts both policies on the same timeline. Uniform samples appear as vertical marks. Adaptive samples are triangles in a separate row below the frame-difference signal.

PythonIn [12]
CollapseExpand
diff_time = t[1:]
VisualizationOut [13]
CollapseExpand
Uniform marks miss the event band while an adaptive triangle falls inside.
The line shows differences between consecutive features at the later frame time. The shaded interval is the 0.4-second event. The two policies each retain 10 frames. Vertical lines mark uniform samples and triangles mark adaptive samples.

Uniform samples skip the shaded interval entirely. The two largest feature changes are at frames 93 and 105, at the event onset and offset. An adaptive sample at onset falls inside the interval, while a sample exactly at the offset falls outside by the half-open convention.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy