-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of the statistics library
- Loading branch information
Jan Wielemaker
authored and
Jan Wielemaker
committed
Dec 10, 2010
1 parent
4b9bf07
commit cd6b8be
Showing
4 changed files
with
76 additions
and
9 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
""" . | ||
|
||
|