# cdensity.h

    00001 //==========================================================================
    00002 //  CDENSITY.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-2005 Andras Varga
    00014
    00015   This file is distributed WITHOUT ANY WARRANTY. See the file
    00016   `license' for details on this and other legal matters.
    00017 *--------------------------------------------------------------*/
    00018
    00019 #ifndef __CDENSITY_H
    00020 #define __CDENSITY_H
    00021
    00022 #include "cstat.h"
    00023
    00024 //==========================================================================
    00025
    00069 class SIM_API cDensityEstBase : public cStdDev
    00070 {
    00071   public:
    00072     // to range_mode:
    00073     enum { RANGE_INVALID,   // --> needs to be set
    00074            RANGE_FIXED,     // --> fixed range (lower,upper)
    00075            RANGE_AUTO,
    00076            RANGE_AUTOLOWER, // --> will be determined from firstvals[],
    00077            RANGE_AUTOUPPER, //        using min and/or max and range_ext_fact
    00078            RANGE_NOTSET     // --> not set, but it's OK (cVarHistogram only)
    00079          };
    00080
    00081   protected:
    00082     double rangemin,rangemax;   // range for distribution density collection
    00083     long num_firstvals;         // number of "pre-collected" samples
    00084                                 // before transform() is performed.
    00085     unsigned long cell_under;
    00086     unsigned long cell_over;    // for counting observations that fall out of range
    00087
    00088     double range_ext_factor;    // the range of histogram is: [min_samples,max_samples] made
    00089                                 // range_ext_factor times larger
    00090     int range_mode;             // one of RANGE_xxx constants
    00091
    00092     bool transfd;
    00093     double *firstvals;         // pointer to array of "pre-collected" samples
    00094
    00095   protected:
    00096     static void plotline (std::ostream& os, char* pref, double xval,
    00097                           double count, double a);
    00098
    00099   public:
    00102
    00106     cDensityEstBase(const cDensityEstBase& r) : cStdDev()
    00107             {setName(r.name());firstvals=NULL;operator=(r);}
    00108
    00112     explicit cDensityEstBase(const char *name=NULL);
    00113
    00117     virtual ~cDensityEstBase();
    00118
    00122     cDensityEstBase& operator=(const cDensityEstBase& res);
    00124
    00127
    00128     /* No dup() because this is an abstract class. */
    00129
    00134     virtual void writeContents(std::ostream& os);
    00135
    00141     virtual void netPack(cCommBuffer *buffer);
    00142
    00148     virtual void netUnpack(cCommBuffer *buffer);
    00150
    00153
    00161     virtual void collect(double val);
    00162
    00166     virtual void clearResult();
    00167
    00171     virtual void saveToFile(FILE *) const;
    00172
    00176     virtual void loadFromFile(FILE *);
    00178
    00181
    00186     virtual void setRange(double lower, double upper);
    00187
    00199     virtual void setRangeAuto(int num_firstvals=100, double range_ext_fact=2.0);
    00200
    00208     virtual void setRangeAutoLower(double upper, int num_firstvals=100, double range_ext_fact=2.0);
    00209
    00217     virtual void setRangeAutoUpper(double lower, int num_firstvals=100, double range_ext_fact=2.0);
    00218
    00223     virtual void setNumFirstVals(int num_firstvals);
    00225
    00226   protected:
    00233     virtual void setupRange();
    00234
    00241     virtual void collectTransformed(double val) = 0;
    00242
    00243   public:
    00244
    00247
    00251     virtual bool transformed() const   {return transfd;}
    00252
    00259     virtual void transform() = 0;
    00261
    00264
    00269     virtual int cells() const = 0;
    00270
    00278     virtual double basepoint(int k) const = 0;
    00279
    00285     virtual double cell(int k) const = 0;
    00286
    00294     virtual double cellPDF(int k) const;
    00295
    00300     virtual unsigned long underflowCell() const {return cell_under;}
    00301
    00306     virtual unsigned long overflowCell() const {return cell_over;}
    00308
    00311
    00317     virtual double pdf(double x) const = 0;
    00318
    00324     virtual double cdf(double x) const = 0;
    00326 };
    00327
    00328 #endif
    00329
    00330
    00331