math.extras: adding moving-average and exponential-moving-average words.
parent
da1747ffed
commit
3841bbb891
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2012 John Benediktsson
|
||||
! See http://factorcode.org/license.txt for BSD license
|
||||
|
||||
USING: math.extras tools.test ;
|
||||
USING: math.extras math.ranges tools.test ;
|
||||
|
||||
IN: math.extras.test
|
||||
|
||||
|
@ -9,3 +9,12 @@ IN: math.extras.test
|
|||
{ 0 } [ 3 3 jacobi ] unit-test
|
||||
{ -1 } [ 127 703 jacobi ] unit-test
|
||||
{ 1 } [ -4 197 jacobi ] unit-test
|
||||
|
||||
{ { 2 3 4 5 6 7 8 9 } } [ 10 [1,b] 3 moving-average ] unit-test
|
||||
{ { 1+1/2 2+1/2 3+1/2 4+1/2 5+1/2 6+1/2 7+1/2 8+1/2 9+1/2 } }
|
||||
[ 10 [1,b] 2 moving-average ] unit-test
|
||||
|
||||
{ { 1 1+1/2 2+1/4 3+1/8 4+1/16 5+1/32 } }
|
||||
[ 6 [1,b] 1/2 exponential-moving-average ] unit-test
|
||||
{ { 1 3 3 5 5 7 7 9 9 11 } }
|
||||
[ 10 [1,b] 2 exponential-moving-average ] unit-test
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
! Copyright (C) 2012 John Benediktsson
|
||||
! See http://factorcode.org/license.txt for BSD license
|
||||
|
||||
USING: combinators.short-circuit kernel math math.combinatorics
|
||||
math.functions math.order math.primes math.ranges
|
||||
math.statistics math.vectors memoize sequences ;
|
||||
USING: combinators.short-circuit grouping kernel math
|
||||
math.combinatorics math.functions math.order math.primes
|
||||
math.ranges math.statistics math.vectors memoize sequences ;
|
||||
|
||||
IN: math.extras
|
||||
|
||||
|
@ -85,3 +85,9 @@ PRIVATE>
|
|||
|
||||
: legendere ( a m -- n )
|
||||
check-legendere jacobi ;
|
||||
|
||||
: moving-average ( seq n -- newseq )
|
||||
clump [ mean ] map ;
|
||||
|
||||
: exponential-moving-average ( seq a -- newseq )
|
||||
[ 1 ] 2dip [ [ dupd swap - ] dip * + dup ] curry map nip ;
|
||||
|
|
Loading…
Reference in New Issue