INTERFACE PZHistogram; (* Tools for generating histograms *) (* Last edited on 1999-11-12 23:17:28 by hcgl *) IMPORT Wr; FROM PZTypes IMPORT LONG, NAT, LONGS; TYPE T = RECORD lo, hi: LONG; (* Values beyond this range are clipped. *) m: NAT; (* Number of bins. *) c: REF LONGS; (* The bins. *) wxSum: LONG; wSum: LONG; wxxSum: LONG; END; (* A histogram with "m" equal-width bins. The entry "c[k]", for "k" in "[0..m-1]", is centered at "lo + k*(hi-lo)/(m-1)". *) PROCEDURE New(lo, hi: LONG; m: NAT): REF T; (* A new histgram with "m" bins covering the range "[lo..hi]". *) PROCEDURE Add(VAR h: T; x: LONG; w: LONG := 1.0d0); (* Adds observation "x" with weight "w" to the histogram "h". *) PROCEDURE Output(wr: Wr.T; READONLY h: T); (* Prints the histogram "h" to "wr", in four columns: lower limit of bin, center of bin, higher limit of bin, and bin count. Note that the two end bins actually extend to infinity, but their printed ranges have the same width at the other bins. *) PROCEDURE Avg(READONLY h: T): LONG; PROCEDURE Var(READONLY h: T): LONG; PROCEDURE Dev(READONLY h: T): LONG; (* Average, variance, and standard deviation of the observations added to "h". *) END PZHistogram. (* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP). Authors: Helena C. G. Leitão and Jorge Stolfi. This file can be freely distributed, used, and modified, provided that this copyright and authorship notice is preserved, and that any modified versions are clearly marked as such. This software has NO WARRANTY of correctness or applicability for any purpose. Neither the authors nor their employers chall be held responsible for any losses or damages that may result from its use. *)