Last active
September 7, 2016 16:06
-
-
Save cgrand/59b8d4ad5b31611435aa821ac0286c63 to your computer and use it in GitHub Desktop.
window-by-time transducer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=> (require '[net.cgrand.xforms :as x]) ; https://github.com/cgrand/xforms | |
=> (into [] | |
(x/window-by-time | |
:ts ; normalized time function -- window length is always 1.0 | |
4 ; number of steps to slide the window | |
(fn ; initializing/snapshooting/reducing function | |
([] clojure.lang.PersistentQueue/EMPTY) | |
([q] (vec q)) | |
([q x] (conj q x))) | |
(fn [q _] (pop q))) ; inverse reducing function | |
(map (fn [x] {:ts x}) (concat (range 0 2 0.5) (range 3 5 0.25)))) ; input with "holes" | |
[[{:ts 0}] ; t = 0 | |
[{:ts 0}] ; t = 0.25 | |
[{:ts 0} {:ts 0.5}] ; t = 0.5 | |
[{:ts 0} {:ts 0.5}] ; t = 0.75 | |
[{:ts 0.5} {:ts 1.0}] ; t = 1.0 | |
[{:ts 0.5} {:ts 1.0}] ; t = 1.25 | |
[{:ts 1.0} {:ts 1.5}] ; t = 1.5 | |
[{:ts 1.0} {:ts 1.5}] ; t = 1.75 | |
[{:ts 1.5}] ; t = 2.0 | |
[{:ts 1.5}] ; t = 2.25 | |
[] ; t = 2.5 | |
[] ; t = 2.75 | |
[{:ts 3}] ; t = 3.0 | |
[{:ts 3} {:ts 3.25}] ; t = 3.25 | |
[{:ts 3} {:ts 3.25} {:ts 3.5}] ; t = 3.5 | |
[{:ts 3} {:ts 3.25} {:ts 3.5} {:ts 3.75}] ; t = 3.75 | |
[{:ts 3.25} {:ts 3.5} {:ts 3.75} {:ts 4.0}] ; t = 4.0 | |
[{:ts 3.5} {:ts 3.75} {:ts 4.0} {:ts 4.25}] ; t = 4.25 | |
[{:ts 3.75} {:ts 4.0} {:ts 4.25} {:ts 4.5}] ; t = 4.5 | |
[{:ts 4.0} {:ts 4.25} {:ts 4.5} {:ts 4.75}]] ; t = 4.75 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment