From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA00397; Fri, 25 Apr 2003 18:59:50 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA00547 for ; Fri, 25 Apr 2003 18:59:49 +0200 (MET DST) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h3PGxmT16173 for ; Fri, 25 Apr 2003 18:59:48 +0200 (MET DST) Received: from erle.ai.univie.ac.at (markus@erle.ai.univie.ac.at [131.130.174.154]) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.3) with ESMTP id h3PGxjwf024197; Fri, 25 Apr 2003 18:59:45 +0200 Received: (from markus@localhost) by erle.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.3) id h3PGxist007173; Fri, 25 Apr 2003 18:59:44 +0200 Date: Fri, 25 Apr 2003 18:59:44 +0200 From: Markus Mottl To: Siegfried Gonzi Cc: caml-list@inria.fr Subject: Re: [Caml-list] Easy solution in OCaml? Message-ID: <20030425165944.GC6284@erle.ai.univie.ac.at> Mail-Followup-To: Siegfried Gonzi , caml-list@inria.fr References: <3EA8D012.8040700@stud.uni-graz.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3EA8D012.8040700@stud.uni-graz.at> User-Agent: Mutt/1.4.1i Organization: Austrian Research Institute for Artificial Intelligence X-Spam: no; 0.00; caml-list:01 siegfried:01 gonzi:01 bigloo:01 matlab:01 gsl:01 oandrieu:01 lacaml:01 quarterly:99 elegantly:01 0.0:01 failwith:01 irritating:01 parentheses:01 nerim:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Siegfried Gonzi schrieb am Freitag, den 25. April 2003: > Often I am contemplating whether it would be possible to use > OCaml in combination with my beloved Bigloo to perform statistical > evaluations. I am not sure whether there are any out there who /can/ > do this evaluations with OCaml what you normally would do with Matlab. For heavy duty statistics you better use tailor-made libraries, e.g. the OCaml-interface to the GSL (Gnu Scientific Library) OCaml-GSL: http://oandrieu.nerim.net/ocaml/gsl/ possibly in combination with other linear algebra libraries, e.g. LACAML: http://www.oefai.at/~markus/home/ocaml_sources.html#LACAML This should give you top-performance on really large data. > The problem what arises: type system and working against the compiler. Mandatory rule for OCaml-beginners: NEVER try to work against the compiler. The compiler is your friend. > Rationale: given a list of 12 month. I would like to calculate the > quarterly means and skip any nan. Easy? Yes it is but only on paper and > in Scheme: Or in OCaml, if you know how to do it elegantly and reasonably efficiently: let coll (len, sum as acc) n = if n >= 0 then len + 1, sum + n else acc let qmeans = let rec loop acc = function | a :: b :: c :: t -> let len, sum = coll (coll (coll (0, 0) a) b) c in loop ((if len = 0 then 0.0 else float sum /. float len) :: acc) t | [] -> List.rev acc | _ -> failwith "qmeans: illegal list" in loop [] > In Scheme I wrote it as functional as possible, but I fail to do this in > Ocaml. I mean doing it in OCaml via loops would be straightforward, but > I didn't succeed in coming up with a solution of: > > - relies on pattern matching? Yes, you have to match the list. > - is short and and shouldn't resemble imperative style See above. > - why if-then constructs? I think this was called "guards" in Clean? I actually find it strange that there is no such thing like if-then-else in Clean. OCaml also supports guards, but they are not always best style. > - why begin-end constructs? In Scheme begin-end constructs are ordinary, > but I find it irritating to use it in OCaml. You can use parentheses instead. > - is it possible to give type information for readbility. Yes, e.g.: let qmeans : int list -> float list = ... Regards, Markus Mottl -- 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