Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5667

Re: Sliding Time Window Function

From Vince Virgilio <blueschi@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Sliding Time Window Function
Date 2011-10-16 11:09 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j7ee1f$ehu$1@smc.vnet.net> (permalink)
References <j79151$i46$1@smc.vnet.net>

Show all headers | View raw


I have something which might suit. I use it for sliding window averages over non-uniformly sampled time series.

binWin[seq_, f_, intervals_, g_:Identity] :=
Module[{sorted = SortBy[seq, f], order = Ordering@intervals[[All, 1]]},
    Function[{tLo, tHi},
        sorted = Drop[sorted, LengthWhile[sorted, f@# < tLo &] ];
        g @ TakeWhile[sorted, f@# < tHi &]
    ] @@@ intervals[[order]] // #[[Ordering@order]]&
];


'seq' is the list of (x,y) pairs, where y may be scalar or vector. 'f' picks the sort-by or key field (say, time). Usually, it is 'First'. 'intervals' is a sequence of time (key) intervals which may overlap. And 'g' is your reduction, which is applied to each window (bin). binWin will take unordered series and window specs and return the windowed results ordered according to the lower bound of the intervals.


I think it's fairly performant. But I'd appreciate any improvements.

Vince

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Sliding Time Window Function northern_flicker <max_kip@hotmail.com> - 2011-10-14 09:58 +0000
  Re: Sliding Time Window Function Vince Virgilio <blueschi@gmail.com> - 2011-10-16 11:09 +0000

csiph-web