Standard deviation

Description

Example how to count standard deviation of list elements

Source: PROLOG str. 190 Wydawnictwo PLJ Warszawa 1991 ISBN 83-85190-63-5

Download

Program source code: standard_deviation.pl

Listing

sred(L, Sr) :- suma(L, S, 0, I, 0), Sr is S/I.
 
suma([], Sum, Sum, Ilosc, Ilosc).
suma([H|T], Sum, Sum1, Ilosc, Ilosc1) :- Nilosc is Ilosc + 1,
Nsuma is Sum1 + H, suma(T, Sum, Nsuma, Ilosc, Nilosc).
 
wari(L, W) :- sred(L, Sr), rozn2(L, H, Sr), suma(H, Suma, 0, Ilosc, 0),
W is Suma/Ilosc.
rozn2([], [], _).
rozn2([H|T], [R|T1], Sr) :- R is (H - Sr)*(H - Sr), rozn2(T, T1, Sr).
 
odch(L, O) :- wari(L, War), O is sqrt(War).
 
test :- odch([1, 2, 3, 4, 5], O).

Comments

pl/prolog/pllib/standard_deviation.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0