Skip to content

Instantly share code, notes, and snippets.

@pingles
Created August 21, 2011 09:29
Show Gist options
  • Save pingles/1160386 to your computer and use it in GitHub Desktop.
Save pingles/1160386 to your computer and use it in GitHub Desktop.
Exponential smooth for incanter
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SMOOTHING
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn exponential-smooth
"
Smooths a sequence with an exponentially decreasing weight.
Arguments:
x -- a sequence of numbers
f -- the smoothing factor (between 0 and 1). close to 0 will produce
a stronger smoothing effect less responsive to recent values. closer
to 1 will have less of an effect and give greater weight to recent
values.
Examples:
(exponential-smooth (range 1 500) 0.9)
References:
http://en.wikipedia.org/wiki/Smoothing
http://en.wikipedia.org/wiki/Exponential_smoothing
"
[x f]
(letfn [
(smooth
[alpha st xt]
(conj st
(+
(* alpha xt)
(* (- 1 alpha) (last st)))))]
(reduce (partial smooth f) [(first x)] (rest x))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment