public class StatisticsHelper.Library
extends java.lang.Object
PatternEngine
worker library.Constructor and Description |
---|
Library() |
Modifier and Type | Method and Description |
---|---|
private java.lang.Number |
getValueAtRank(java.util.SortedMap rankMap,
long rank)
Given a sorted map of cumulative numbers of occurrences (ranks) to
numeric data values, return the number associated with a specific rank.
|
java.util.Map |
loadDistributions(java.lang.String filename,
java.lang.String type)
Given an XML filename and a distribution type, load statistics from
an XML document and produce a map of all distributions of that type.
|
java.lang.Object |
maximum(java.util.Map distrib)
Locate the maximum value of a distribution, where the map's keys are
the data values and the map's values are the corresponding numbers of
occurrences of these data values in the distribution.
|
double |
mean(java.util.Map distrib)
Calculate the weighted average value of the
Number s
represented by the keys of the specified map. |
double |
median(java.util.Map distrib)
Calculate the median value of a distribution, where the map's keys are
the data values and the map's values are the corresponding numbers of
occurrences of these data values in the distribution.
|
java.lang.Object |
minimum(java.util.Map distrib)
Locate the minimum value of a distribution, where the map's keys are
the data values and the map's values are the corresponding numbers of
occurrences of these data values in the distribution.
|
long |
population(java.util.Map distrib)
Calculate the total population size of a distribution.
|
double |
standardDeviation(java.util.Map distrib)
Calculate the standard deviation of the given distribution using the
"sum of the squares" algorithm.
|
public java.lang.Object maximum(java.util.Map distrib)
Comparable
.distrib
- Map of data values to numbers of occurrences. For purposes of
this algorithm, the map's values are ignored; only the keys
are of interest.public java.lang.Object minimum(java.util.Map distrib)
Comparable
.distrib
- Map of data values to numbers of occurrences. For purposes of
this algorithm, the map's values are ignored; only the keys
are of interest.public long population(java.util.Map distrib)
distrib
- Map of data values to numbers of occurrences (i.e., population
for each data value). For purposes of this algorithm, the
map's keys are ignored; only the values are of interest.public double median(java.util.Map distrib)
Number
, since a numeric result is
generated.
To locate the median, we sort the values in the distribution in ascending order, then determine which bucket in the distribution contains the middle-ranked value. For distributions with an odd total population, this number represents the median. For an even total population, the two middle-ranked values are averaged to produce the median.
distrib
- Map of data values to numbers of occurrences.java.lang.ClassCastException
- if a non-numeric key is encountered in distrib
.public double mean(java.util.Map distrib)
Number
s
represented by the keys of the specified map. The average is weighted
by the number of occurrences contained in the value of each bucket of
the distribution.distrib
- Distribution buckets; mapping of numeric values to the number
of occurrences for each. The keys of this map must each be an
instance of Number
distrib
's numeric keys.java.lang.ClassCastException
- if a non-numeric key is encountered in distrib
.public double standardDeviation(java.util.Map distrib)
distrib
- Distribution buckets; mapping of numeric values to the number
of occurrences for each. The keys of this map must each be an
instance of Number
java.lang.ClassCastException
- if a non-numeric key is encountered in distrib
.public java.util.Map loadDistributions(java.lang.String filename, java.lang.String type)
Each distribution is represented as a SortedMap
, where
each map key represents a "bucket" value, and each map value
represents the the number of occurrences of that value in the
distribution.
filename
- Name of the file containing the XML document to be read.type
- Type of distribution to collect; this corresponds with the
"type" attribute of the "distribution" element within the
XML document.java.lang.RuntimeException
- if any error occurs loading the distribution data from the
specified XML file.private java.lang.Number getValueAtRank(java.util.SortedMap rankMap, long rank)
rankMap
- A sorted map whose keys represent the highest rank for a given
data value, when a distribution is sorted in ascending order
by data value. The map's values represent the data values at
each rank.rank
- Target rank.