tsam ยท duration representation

A typical day that still makes sense

When a year of hourly data is squeezed into a handful of “typical days,” the new medoid method keeps each signal’s range of values and the way the signals move together — by borrowing the timing of a real day.

1Two things a typical day must get right

A typical day is a stand-in for many real days. To be useful it has to be faithful in two different ways, and these pull in different directions:

Distribution

The bag of numbers for each signal on its own. Across the day, how often is solar high, medium, low? The set of values should match reality — even if you ignore the clock.

Concurrency

What happens at the same time. When the sun is up, how much wind and demand usually come with it? Signals rise and fall together in patterns that should survive.

The duration representation is built to nail distribution: it collects every value each signal takes inside a cluster and keeps that exact bag. The open question is how to lay those values out across the 24 hours — and that ordering is what decides concurrency.

2The old default sorts each signal alone

The original approach orders every signal by its own average shape. Each signal ends up looking sensible by itself — but nothing ties solar’s clock to demand’s clock. A halfway fix, the reference trick, picks one signal as a master clock and forces all the others to follow it. That locks everything into step, so suddenly everything peaks together — a new kind of wrong. The picture below shows what each choice does to the real “what-moves-with-what” pattern.

Which signals move together — real vs. reconstructed

−1 (move oppositely)+1 (move together) number = distance from reality (lower is better)
Each grid is the correlation between the four signals (GHI solar, temperature, wind, demand). Medoid keeps the true structure — even the negative links, like temperature vs. wind (−0.21 vs. a real −0.20). The reference master-clock paints almost everything warm: wind–demand balloons to 0.73 when the truth is 0.16.

3The new idea: borrow a real day’s timing

Every cluster already contains real days that actually happened. The medoid is simply the most typical one of them. The new method keeps each signal’s bag of numbers exactly as before, but lays them out in the order that real day had them. Because that day is real, its “what happens together” pattern is real too — for every pair of signals at once. No master signal, no lockstep.

One typical day — the medoid borrows a real day’s shape

Cluster of days. Faint lines are the real member days; the bold lines are the medoid typical day for solar and demand. Same bag of values as every other method — arranged on a timeline that genuinely occurred.

4Same distribution, better concurrency

The trade is the whole point: every method keeps the distribution identically (duration-curve error is the same to six decimals), so the only thing that changes is how well concurrency survives.

Concurrency error by method — lower is better

Distance between the real correlation structure and the reconstructed one. Medoid cuts it roughly below the old default; the single-clock methods (reference, consensus, assignment) land identically and worse than doing nothing, because forcing one shared order makes every signal move together. Distribution error for all five: 0.006806.

How to use it

from tsam import aggregate, ClusterConfig, Distribution

aggregate(df, n_clusters=8, cluster=ClusterConfig(
    method="hierarchical",
    representation=Distribution(concurrency="medoid"),
))

Add preserve_minmax=True to also pin each signal’s peak value; the medoid places that peak at the hour the real day peaked.