cdensityestbase.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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,
00078 RANGE_AUTOLOWER,
00079 RANGE_AUTOUPPER,
00080 RANGE_FIXED,
00081 RANGE_NOTSET
00082 };
00083
00089 struct Cell
00090 {
00091 double lower;
00092 double upper;
00093 double value;
00094 double relativeFreq;
00095 Cell() {lower=upper=value=relativeFreq=0;}
00096 };
00097
00098 protected:
00099 double rangemin, rangemax;
00100 int num_firstvals;
00101
00102 unsigned long cell_under;
00103 unsigned long cell_over;
00104
00105 double range_ext_factor;
00106
00107 RangeMode range_mode;
00108
00109 bool transfd;
00110 double *firstvals;
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
00119 virtual void doMergeCellValues(const cDensityEstBase *other) = 0;
00120 public:
00121
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
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