HistogramsOut.Mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last tweaked by Mike Spreitzer on June 28, 1988 3:36:10 pm PDT
An interface for getting information out of Histograms.
DIRECTORY IO, Histograms, LinearSystem;
HistogramsOut: CEDAR DEFINITIONS = {OPEN Histograms;
Stats1D: PROC [h: Histogram] RETURNS [sum0: INT, sum1, sum2, avg, stdDev: REAL, range: RealRange1];
Consider the histogram a set of <x, n> pairs, each saying that there are n counts in the bin centered on x.
sum0 = S n
sum1 = S n*x
sum2 = S n*x2
avg = sum1/sum0
stdDev = SqRt[( S n*(x - avg)2 ) / ((Sn) - 1)]
range.min = least x with non-zero n
range.max = greatest x with non-zero n
range.min>range.max { sum0=0
Stats2D: PROC [h: Histogram, degree: NATURAL, log: BoolPair] RETURNS [sums: Sums2D, range: RealRange2];
Returns the sums necessary to compute a least-squares fit of the given degree. The log argument tells whether to sum the <x,y> or their natural logarithms.
Sums2D: TYPE ~ RECORD [
degree: NATURAL ← 0,
exception: BOOLFALSE,
Sy2: REAL ← 0.0,
Sxky: ColumnN ← NIL,
Sxkl: MatrixN ← NIL
];
If exception, there's been a floating-point exception, and the other fields are worthless.
RowN: TYPE ~ LinearSystem.RowN;
ColumnN: TYPE ~ LinearSystem.ColumnN;
MatrixN: TYPE ~ LinearSystem.MatrixN;
Analyze: PROC [sums: Sums2D] RETURNS [ak: ColumnN ← NIL, s, r: REAL ← 0.0];
Do a least-squares fit of the sums. The coefficients are in ak, error is s, and linear correlation is r. If there's a floating-point exception, ak will be NIL. s non-zero only if the number of samples exceeds the degree. In certain degenerate cases, r will not be evaluated, and left 0.
EvalError: PROC [sums: Sums2D, ak: ColumnN] RETURNS [s, r: REAL ← 0.0];
WriteTo: PROC [h: Histogram, to: IO.STREAM, create, data: BOOL];
Writes descriptions of the create and/or the data.
}.