# Notation for unevenly-spaced to evenly-spaced time series conversion

I have an unevenly-spaced time series. To make it evenly-spaced, I resample the time series to a larger timespan (e.g. day) and sum up all values within this time frame.

In Python (and pandas) it is a one-liner:

ts.resample('D').sum()


But what is a precise (and ideally easily unterstandable) mathematical notation for that?

• It all depends on exactly how "resample" works! There can't be a mathematical notation for a vaguely defined operation. – whuber Jul 12 '19 at 15:51
• Thanks for your comment. resample('MS').sum() sums up all values within a calendar month. Independent from the timespan (one month), I would like to express exactly this. Probably my Python example is not helpful? – Michael Dorner Jul 12 '19 at 15:57
• It's helpful insofar as it uncovers potential complications. For instance, a monthly series is not actually evenly spaced in terms of physical time: it is only evenly spaced relative to a social construct concerning how we represent time on a human scale. This suggests that something well beyond a mathematical operator is needed to express what Python is doing--but is that really what you're after? – whuber Jul 12 '19 at 16:07
• Good point - months are a really bad example. I changed it to days. Then it should be evenly-spaced time series. I actually would prefer a mathematical notion over some Python/pseudo code. – Michael Dorner Jul 12 '19 at 16:13

Let's start with a generalization. Suppose the original data are a series of values $$\mathbf{x}=(x_1, x_2, \ldots, x_n)$$ associated with times $$\mathbf{t}=(t_1, t_2, \ldots, t_n).$$ You have in mind a new set of ordered times indexed by the integers $$\mathbf Z$$ along with a function $$f(k, \mathbf{t}, \mathbf{x})$$ that determines what new value to assign to the integer $$k$$ based on the data in $$(\mathbf{t}, \mathbf{x}).$$ The new time series is just

$$(y_k) = (f(k, \mathbf{t}, \mathbf{x})),\ k\in\mathbb{Z}.$$

In the example in the question, you have partitioned an interval of time from $$t_0$$ to $$t_\infty \gt t_0$$ into (say) $$N$$ evenly spaced intervals, each of which therefore has a length $$h= (t_\infty - t_0)/N,$$ and I am presuming (as is conventional) that you wish to index them with the integers $$0, 1, 2, \ldots, N-1.$$ The interval in which any time $$t$$ lies therefore is

$$g(t) = \lfloor \frac{t-t_0}{h} \rfloor.$$

Your resampling function sums all values within each interval and therefore can be written

$$f(k,\mathbf{t},\mathbf{x}) = \sum_{\{i\,\mid\, g(t_i)=k\}}x_i.$$

(Empty sums are, by definition, zero.)

If you like, you may combine these formulas in one grand (but less immediate) one,

$$y_k = \sum_{\{i\,\mid\, \lfloor N\frac{t_i-t_0}{t_\infty-t_0} \rfloor=k\}}x_i.$$

To demonstrate how non abstract and natural this is, here is an R implementation of the last formula:

function(times, x, t.0, t.infty, N) tapply(x, floor(N * (times - t.0)/(t.infty - t.0)), sum)


It returns an array indexed by the new times with values equal to the sums within each new interval.