Skip to content

Instantly share code, notes, and snippets.

@Josh-Tilles
Last active March 29, 2019 14:04
Show Gist options
  • Save Josh-Tilles/5273905 to your computer and use it in GitHub Desktop.
Save Josh-Tilles/5273905 to your computer and use it in GitHub Desktop.
implementation of an exponentially weighted moving-average function (instigated by http://grahamstratton.org/straightornamental/entries/moreclojure)
(defn ema [f values]
(reductions (fn [running v]
(let [one-minus-F (- 1 f)] ;naming intermediate results can help with the readability of non-associative operators.
(+ (* f v)
(* one-minus-F running))))
values))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment