caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] entropy etc. in OCaml
@ 2004-08-11  9:41 Viktor Tron
  2004-08-11 10:22 ` Markus Mottl
  0 siblings, 1 reply; 2+ messages in thread
From: Viktor Tron @ 2004-08-11  9:41 UTC (permalink / raw)
  To: caml-list

Dear caml-listers,

Does anyone know of an OCaml library implementing or binding
Information Theoretical concepts like data entropy?
(e.g. gsl does not provide these).

I posted this query on the ocaml-beginners list but got no reply.

Thank you
Viktor Tron

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] entropy etc. in OCaml
  2004-08-11  9:41 [Caml-list] entropy etc. in OCaml Viktor Tron
@ 2004-08-11 10:22 ` Markus Mottl
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Mottl @ 2004-08-11 10:22 UTC (permalink / raw)
  To: Viktor Tron; +Cc: caml-list

On Wed, 11 Aug 2004, Viktor Tron wrote:
> Does anyone know of an OCaml library implementing or binding
> Information Theoretical concepts like data entropy?
> (e.g. gsl does not provide these).

I don't have a separate library for that, but you might want to take a
look at AIFAD:

  http://www.oefai.at/~markus/aifad

It implements several functions for computing the entropy of discrete
data including structured values.  Its purpose is decision tree learning
on structured data (represented by algebraic datatypes).

One function for computing entropy from histograms is the following
(taken from src/entropy_utils.ml in the distribution):

---------------------------------------------------------------------------
let calc_entropy histo n =
  if n = 0 then 0.0
  else
    let rec loop sum ix =
      if ix < 0 then sum
      else
        let freq = histo.(ix) in
        if freq = 0 then loop sum (ix - 1)
        else
          let ffreq = float freq in
          loop (sum +. ffreq *. log ffreq) (ix - 1) in
    let sum = loop 0.0 (Array.length histo - 1) in
    let f_n = float n in
    log2 f_n -. sum /. f_n /. log_2
---------------------------------------------------------------------------

If you pass it an array of integers (histogram) that counts the frequency
of class values in variable "histo" and the number of observations in "n"
(must be the sum of frequencies in the histogram), then this function
will return you the entropy in bits.

Regards,
Markus

-- 
Markus Mottl          http://www.oefai.at/~markus          markus@oefai.at

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-08-11 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-11  9:41 [Caml-list] entropy etc. in OCaml Viktor Tron
2004-08-11 10:22 ` Markus Mottl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).