statistics/commit

First version of the statistics library

authorJan Wielemaker
Fri Dec 10 14:21:22 2010 +0100
committerJan Wielemaker
Fri Dec 10 14:21:22 2010 +0100
commitcd6b8bea7989f3459d3d6f4998d038c2789405dd
tree373123a16f785c67172f0a0da7eaf7cd6d5f97d5
parent4b9bf0739b3ad5fa9a7f5da1f0a9bd9cc3fa8ebe
Diff style: patch stat
diff --git a/config-available/DEFAULTS b/config-available/DEFAULTS
deleted file mode 100644
index cc086a7..0000000
--- a/config-available/DEFAULTS
+++ /dev/null
@@ -1 +0,0 @@
-config(statistics, link).
diff --git a/config-available/statistics.pl b/config-available/statistics.pl
deleted file mode 100644
index cd7d604..0000000
--- a/config-available/statistics.pl
+++ /dev/null
@@ -1,5 +0,0 @@
-:- module(conf_statistics, []).
-
-/** <module> Gather statistical information
-*/
-
diff --git a/lib/stat_lists.pl b/lib/stat_lists.pl
new file mode 100644
index 0000000..683a232
--- /dev/null
+++ b/lib/stat_lists.pl
@@ -0,0 +1,72 @@
+/*  Part of ClioPatria SeRQL and SPARQL server
+
+    Author:        Jan Wielemaker
+    E-mail:        J.Wielemaker@cs.vu.nl
+    WWW:           http://www.swi-prolog.org
+    Copyright (C): 2010, University of Amsterdam,
+		   VU University Amsterdam
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    As a special exception, if you link this library with other files,
+    compiled with a Free Software compiler, to produce an executable, this
+    library does not by itself cause the resulting executable to be covered
+    by the GNU General Public License. This exception does not however
+    invalidate any other reasons why the executable file might be covered by
+    the GNU General Public License.
+*/
+
+:- module(stat_lists,
+	  [ list_mean/2,		% +List, -Mean
+	    list_variance/2		% +List, -Variance
+	  ]).
+:- use_module(library(lists)).
+:- use_module(library(error)).
+
+/** <module> Compute statistical properies of lists
+
+This library computes statistical properties of lists of numbers.
+
+@tbd	Fill it in ...
+*/
+
+%%	list_mean(+List, -Mean:float) is det.
+%
+%	True when Mean is the average value of amm numbers in List.
+%
+%	@error domain_error(non_empty_list, List) if List is [].
+
+list_mean(List, Mean) :-
+	length(List, Len),
+	(   Len == 0
+	->  domain_error(non_empty_list, List)
+	;   sumlist(List, Sum),
+	    Mean is Sum/Len
+	).
+
+%%	list_variance(+List, -Variance:float) is det.
+%
+%	True when Variance is the variance of List.
+%
+%	@error domain_error(non_empty_list, List) if List is [].
+
+list_variance(List, Variance) :-
+	list_mean(List, Mean),
+	variance(List, Mean, 0, Variance).
+
+variance([], _, V, V).
+variance([H|T], Mean, V0, V) :-
+	V1 is V0+(H-Mean)**2,
+	variance(T, Mean, V1, V).
diff --git a/rdf/cpack/statistics.ttl b/rdf/cpack/statistics.ttl
index 6e6c9b1..3f3a6d6 100644
--- a/rdf/cpack/statistics.ttl
+++ b/rdf/cpack/statistics.ttl
@@ -11,12 +11,12 @@
 # this.  Otherwise you can specify the information inline as done below.
 # See http://xmlns.com/foaf/spec/ for defines fields.
 
-<> a cpack:Package ;
+<> a cpack:Library ;
 	cpack:packageName "statistics" ;
 	dcterms:title "Gather statistical information" ;
 	cpack:author [ a foaf:Person ;
 		       foaf:name "Jan Wielemaker" ;
-		       foaf:mbox "@FOAFMBOX@" ;
+		       foaf:mbox <mailto:J.Wielemaker@cs.vu.nl> ;
 		     ] ;
 	cpack:primaryRepository
 	    [ a cpack:GitRepository ;
@@ -24,7 +24,8 @@
 	    ] ;
 	cpack:description
 
-"""The package description goes here.  You can use PlDoc Wiki markup.
+"""This package is intended to collect libraries compute statistics
+   over various datasets.  It is currently almost empty.
 """ .