Implements an equidistant histogram that can operate in two modes. More...
#include <chistogram.h>
Public Member Functions | |
Constructors, destructor, assignment. | |
cHistogram (const cHistogram &r) | |
cHistogram (const char *name=NULL, int numcells=-1, Mode mode=MODE_AUTO) | |
cHistogram & | operator= (const cHistogram &res) |
Redefined cObject member functions. | |
virtual void | parsimPack (cCommBuffer *buffer) |
virtual void | parsimUnpack (cCommBuffer *buffer) |
Redefined member functions from cStatistic and its subclasses. | |
virtual double | getBasepoint (int k) const |
virtual double | getCellValue (int k) const |
virtual double | getPDF (double x) const |
virtual double | getCDF (double x) const |
virtual double | random () const |
virtual void | saveToFile (FILE *) const |
virtual void | loadFromFile (FILE *) |
Misc. | |
virtual void | setMode (Mode mode) |
virtual Mode | getMode () const |
virtual void | setCellSize (double d) |
virtual double | getCellSize () const |
Protected Member Functions | |
virtual void | collectTransformed (double value) |
virtual void | setupRange () |
Implements an equidistant histogram that can operate in two modes.
In INTEGERS mode, cell boundaries are whole numbers; in DOUBLES mode, they can be real numbers. The operating mode can be chosen with a constructor argument or with the setMode() method; the default behavior is to choose the mode automatically, by inspecting precollected observations.
By default, the number of cells is chosen automatically, and the histogram range is determined by precollecting a number of observations and extending their range by a range extension factor.
It is possible to explicitly set any of the following values (and the rest will be chosen or computed automatically): number of cells; cell size; number of observations to precollect; range extension factor; range lower bound; range upper bound. See the setNumCells(), setCellSize(), setNumFirstVals(), setRangeAuto(), setRangeAutoUpper(), and setRangeAutoLower() methods (many of them are inherited from cDensityEstBase and cHistogramBase).
Especially in INTEGERS mode, if the cells cannot be set up to satisfy all explicitly given constraints (for example, if the explicitly specified range is not an integer multiple of the explicitly specified cell size), an error will be thrown.
Informational defaults for the various configuration values (subject to change without notice in any release): number of values to precollect: 100; range extension factor: 2.0; number of cells: 200 in INTEGERS mode and 30 in DOUBLES mode.
Examples:
Automatic mode:
cHistogram h("histogram");
Setting up a 50-cell histogram on the range [0.0, 5.0) (cell size = 0.1):
cHistogram h("histogram", 50, cHistogram::MODE_DOUBLES); h.setRange(0,5);
If you only know that the numbers will be nonnegative but the exact range is unknown:
cHistogram h("histogram"); h.setRangeAutoUpper(0); // sets zero as lower bound
virtual double cHistogram::getCellSize | ( | ) | const [inline, virtual] |
Returns the cell size, or 0 when unknow (i.e.
the cells have not been set up yet, and setCellSize() has not been called).
cHistogram& cHistogram::operator= | ( | const cHistogram & | res | ) |
Assignment operator.
The name member is not copied; see cNamedObject's operator=() for more details.
virtual void cHistogram::parsimPack | ( | cCommBuffer * | buffer | ) | [virtual] |
Serializes the object into an MPI send buffer.
Used by the simulation kernel for parallel execution. See cObject for more details.
Reimplemented from cHistogramBase.
virtual void cHistogram::parsimUnpack | ( | cCommBuffer * | buffer | ) | [virtual] |
Deserializes the object from an MPI receive buffer Used by the simulation kernel for parallel execution.
See cObject for more details.
Reimplemented from cHistogramBase.
virtual double cHistogram::random | ( | ) | const [virtual] |
Returns a random number based on the distribution collected.
If no values have been collected, it returns 0; when in initial collection phase, it returns one of the stored observations; after the histogram has been set up, a random integer or double is returned, depending on mode.
Reimplemented from cStdDev.
virtual void cHistogram::setCellSize | ( | double | d | ) | [virtual] |
Sets the cell size.
Cannot be called when the cells have been set up already.
virtual void cHistogram::setMode | ( | Mode | mode | ) | [virtual] |
Sets the histogram mode: MODE_AUTO, MODE_INTEGERS or MODE_DOUBLES.
Cannot be called when the cells have been set up already.
virtual void cHistogram::setupRange | ( | ) | [protected, virtual] |
Called internally by transform(), this method should determine and set up the histogram range.
It also calculates the cell size.
Reimplemented from cDensityEstBase.