Entropy: Difference between revisions

102 bytes added ,  10 years ago
→‎{{header|Racket}}: need hash-entropy for "Fibonacci Words"
(→‎{{header|Racket}}: exports functions for "Fibonacci Words", uses frequencies not characters for calculation)
(→‎{{header|Racket}}: need hash-entropy for "Fibonacci Words")
Line 717:
<lang racket>#lang racket
(require math)
(provide entropy hash-entropy list-entropy digital-entropy)
 
(define (listhash-entropy xh)
(define (log2 x) (/ (log x) (log 2)))
(define n (lengthfor/sum x[(c (in-hash-values h))] c))
(- (for/sum ([c (in-hash-values h)] #:unless (samples->hashzero? xc))])
(* (/ c n) (log2 (/ c n))))))
 
(define (list-entropy x) (hash-entropy (samples->hash x)))
 
(define entropy (compose list-entropy string->list))
569

edits