cdensityestbase.h

00001 //==========================================================================
00002 //  CDENSITYESTBASE.H - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //
00007 //  Declaration of the following classes:
00008 //    cDensityEstBase : common base class for density estimation classes
00009 //
00010 //==========================================================================
00011 
00012 /*--------------------------------------------------------------*
00013   Copyright (C) 1992-2008 Andras Varga
00014   Copyright (C) 2006-2008 OpenSim Ltd.
00015 
00016   This file is distributed WITHOUT ANY WARRANTY. See the file
00017   `license' for details on this and other legal matters.
00018 *--------------------------------------------------------------*/
00019 
00020 #ifndef __CDENSITYESTBASE_H
00021 #define __CDENSITYESTBASE_H
00022 
00023 #include "cstddev.h"
00024 
00025 NAMESPACE_BEGIN
00026 
00070 class SIM_API cDensityEstBase : public cStdDev
00071 {
00072   public:
00076     enum RangeMode {
00077         RANGE_AUTO,      // automatic range setup, using precollected values and range extension (the default)
00078         RANGE_AUTOLOWER, // like RANGE_AUTO, but upper limit is fixed
00079         RANGE_AUTOUPPER, // like RANGE_AUTO, but lower limit is fixed
00080         RANGE_FIXED,     // fixed range (lower, upper)
00081         RANGE_NOTSET     // not set, but it is OK (cVarHistogram only)
00082     };
00083 
00089     struct Cell
00090     {
00091         double lower;  // lower cell bound (inclusive)
00092         double upper;  // lower cell bound (exclusive)
00093         double value;  // counter (or its estimate)
00094         double relativeFreq;  // value / total
00095         Cell() {lower=upper=value=relativeFreq=0;}
00096     };
00097 
00098   protected:
00099     double rangemin, rangemax;   // range for distribution density collection
00100     int num_firstvals;         // number of "pre-collected" observations
00101                                 // before transform() is performed.
00102     unsigned long cell_under;
00103     unsigned long cell_over;    // for counting observations that fall out of range
00104 
00105     double range_ext_factor;    // the range of histogram is: [min_vals, max_vals] made
00106                                 // range_ext_factor times larger
00107     RangeMode range_mode;       // one of RANGE_xxx constants
00108 
00109     bool transfd;
00110     double *firstvals;         // pointer to array of "pre-collected" observations
00111 
00112   private:
00113     void copy(const cDensityEstBase& other);
00114 
00115   protected:
00116     static void plotline (std::ostream& os, const char *pref, double xval, double count, double a);
00117 
00118     // part of merge(); to be implemented in subclasses
00119     virtual void doMergeCellValues(const cDensityEstBase *other) = 0;
00120   public:
00121     // internal, for use in sim_std.msg; note: each call overwrites the previous value!
00122     const Cell& internalGetCellInfo(int k) const;
00123 
00124   public:
00127 
00131     cDensityEstBase(const cDensityEstBase& other) : cStdDev(other) {firstvals=NULL;copy(other);}
00132 
00136     explicit cDensityEstBase(const char *name=NULL);
00137 
00141     virtual ~cDensityEstBase();
00142 
00146     cDensityEstBase& operator=(const cDensityEstBase& res);
00148 
00151 
00152     /* No dup() because this is an abstract class. */
00153 
00157     virtual std::string detailedInfo() const;
00158 
00164     virtual void parsimPack(cCommBuffer *buffer);
00165 
00171     virtual void parsimUnpack(cCommBuffer *buffer);
00173 
00176 
00184     virtual void collect(double value);
00185 
00189     virtual void collect(SimTime value) {collect(value.dbl());}
00190 
00197     virtual void merge(const cStatistic *other);
00198 
00202     virtual void clearResult();
00203 
00207     virtual void saveToFile(FILE *) const;
00208 
00212     virtual void loadFromFile(FILE *);
00214 
00217 
00222     virtual void setRange(double lower, double upper);
00223 
00235     virtual void setRangeAuto(int num_firstvals=100, double range_ext_fact=2.0);
00236 
00244     virtual void setRangeAutoLower(double upper, int num_firstvals=100, double range_ext_fact=2.0);
00245 
00253     virtual void setRangeAutoUpper(double lower, int num_firstvals=100, double range_ext_fact=2.0);
00254 
00259     virtual void setNumFirstVals(int num_firstvals);
00260 
00265     virtual int getNumFirstVals() const {return num_firstvals;}
00266 
00271     virtual double getRangeExtensionFactor() const {return range_ext_factor;}
00273 
00274   protected:
00281     virtual void setupRange();
00282 
00289     virtual void collectTransformed(double value) = 0;
00290 
00291   public:
00292 
00295 
00299     virtual bool isTransformed() const   {return transfd;}
00300 
00307     virtual void transform() = 0;
00309 
00312 
00317     virtual int getNumCells() const = 0;
00318 
00326     virtual double getBasepoint(int k) const = 0;
00327 
00333     virtual double getCellValue(int k) const = 0;
00334 
00342     virtual double getCellPDF(int k) const;
00343 
00348     virtual unsigned long getUnderflowCell() const {return cell_under;}
00349 
00354     virtual unsigned long getOverflowCell() const {return cell_over;}
00355 
00360     virtual Cell getCellInfo(int k) const;
00362 
00365 
00371     virtual double getPDF(double x) const = 0;
00372 
00378     virtual double getCDF(double x) const = 0;
00380 };
00381 
00382 NAMESPACE_END
00383 
00384 
00385 #endif
00386 
00387 
00388 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3