Entropy: Difference between revisions
→{{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 (
(define (log2 x) (/ (log x) (log 2)))
(define n (
(- (for/sum ([c (in-hash-values h)] #:unless (
(* (/ c n) (log2 (/ c n))))))
(define (list-entropy x) (hash-entropy (samples->hash x)))
(define entropy (compose list-entropy string->list))
|