* guile: some general improvements / cleanups in module loading, object

visibilty. turn some integers (such as message priority, log level, contact
  type) into symbols.
This commit is contained in:
djcb
2012-07-14 12:32:15 +03:00
parent fcb202d618
commit 8e3fbe380e
10 changed files with 576 additions and 671 deletions

View File

@ -24,7 +24,8 @@
:use-module (ice-9 r5rs)
:export ( mu:tabulate
mu:average
mu:stddev
mu:standard-deviation
mu:pearsons-r
mu:weekday-numbers->names
mu:month-numbers->names))
@ -45,7 +46,7 @@ get back a list like
(set! table (assoc-set! table val (1+ old-freq)))))
expr)
table))
(define (average lst)
"Calculate the average of a list LST of numbers, or #f if undefined."
(if (null? lst)
@ -67,12 +68,11 @@ undefined."
EXPR (or #t for all). Returns #f if undefined."
(average (map func (mu:message-list expr))))
(define* (mu:stddev func #:optional (expr #t))
(define* (mu:standard-deviation func #:optional (expr #t))
"Get the standard deviation for the the values of FUNC applied to
all messages matching EXPR (or #t for all). Returns #f if undefined."
(stddev (map func (mu:message-list expr))))
(define* (mu:max func #:optional (expr #t))
"Get the maximum value of FUNC applied to all messages matching
EXPR (or #t for all). Returns #f if undefined."
@ -83,6 +83,23 @@ EXPR (or #t for all). Returns #f if undefined."
EXPR (or #t for all). Returns #f if undefined."
(apply min (map func (mu:message-list expr))))
(define* (mu:pearsons-r func1 func2 #:optional (expr #t))
"Calculate Pearson's product-moment correlation coefficient between
func1 and func2. Inefficient implementation."
(let* ((msglist (mu:message-list expr))
(lst-x (map func1 msglist))
(lst-y (map func2 msglist))
(avg-x (average lst-x))
(avg-y (average lst-y))
(denominator (sqrt (* (stddev lst-x) (stddev lst-y))))
(n (length lst-x))
(cov-xy 0))
(while (not (null? lst-x))
(set! cov-xy (+ (* (- (car lst-x) avg-x) (- (car lst-y) avg-y))))
(set! lst-x (cdr lst-x))
(set! lst-y (cdr lst-y)))
(/ (/ cov-xy n) denominator)))
;; a list of abbreviated, localized day names
(define day-names