Created
August 21, 2011 09:29
-
-
Save pingles/1160386 to your computer and use it in GitHub Desktop.
Exponential smooth for incanter
This file contains 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; 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