Skip to content

Commit

Permalink
First version of the statistics library
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wielemaker authored and Jan Wielemaker committed Dec 10, 2010
1 parent 4b9bf07 commit cd6b8be
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 9 deletions.
1 change: 0 additions & 1 deletion config-available/DEFAULTS

This file was deleted.

5 changes: 0 additions & 5 deletions config-available/statistics.pl

This file was deleted.

72 changes: 72 additions & 0 deletions lib/stat_lists.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* Part of ClioPatria SeRQL and SPARQL server
Author: Jan Wielemaker
E-mail: [email protected]
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).
7 changes: 4 additions & 3 deletions rdf/cpack/statistics.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
# 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:[email protected]> ;
] ;
cpack:primaryRepository
[ a cpack:GitRepository ;
cpack:gitURL <git://eculture.cs.vu.nl/home/janw/git/ClioPatria/statistics.git>
] ;
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.
""" .


0 comments on commit cd6b8be

Please sign in to comment.