Created
July 12, 2010 23:07
-
-
Save pingles/473203 to your computer and use it in GitHub Desktop.
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
(defn exponential-smooth-recur | |
[x f] | |
(letfn [(smoothed-val [m n f] | |
(+ | |
(* m (- 1 f)) | |
(* n f)))] | |
(reverse (lazy-seq | |
(loop [observed (rest x) smoothed (list (first x))] | |
(if (empty? observed) | |
smoothed | |
(recur (rest observed) (cons (smoothed-val (first smoothed) (first observed) f) smoothed)))))))) | |
(println (exponential-smooth-recur '(1 2 3 4) 0.9)) | |
(defn exponential-smooth-partial | |
[x f] | |
(letfn [ | |
(smooth | |
[alpha st xt] | |
(conj st | |
(+ | |
(* alpha xt) | |
(* (- 1 alpha) (last st)))))] | |
(reduce (partial smooth f) [(first x)] (rest x)))) | |
(println (exponential-smooth-partial '(1 2 3 4) 0.9)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment