OMNeT++ Simulation Library  5.6.1
cprecolldensityest.h
1 //==========================================================================
2 // CPRECOLLDENSITYEST.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CPRECOLLDENSITYEST_H
17 #define __OMNETPP_CPRECOLLDENSITYEST_H
18 
19 #include "cabstracthistogram.h"
20 
21 namespace omnetpp {
22 
56 {
57  public:
61  enum RangeMode {
62  RANGE_AUTO, // automatic range setup, using precollected values and range extension (the default)
63  RANGE_AUTOLOWER, // like RANGE_AUTO, but upper limit is fixed
64  RANGE_AUTOUPPER, // like RANGE_AUTO, but lower limit is fixed
65  RANGE_FIXED, // fixed range (lower, upper)
66  RANGE_NOTSET // not set, but it is OK (cVarHistogram only)
67  };
68 
69  protected:
70  // we can precollect observations to automatically determine the range before histogram bins are set up
71  bool transformed; // whether precollected values have been transformed into a histogram
72  double *precollectedValues;
73  double *precollectedWeights; // nullptr for unweighted
74  int numPrecollected;
75 
76  // range for distribution density collection
77  RangeMode rangeMode;
78  double rangeExtFactor; // we extend the range of precollected values by rangeExtFactor
79  double rangeMin, rangeMax;
80  double finiteMinValue = NAN, finiteMaxValue = NAN;
81 
82  // variables for counting out-of-range observations
83  int64_t numFiniteUnderflows;
84  int64_t numFiniteOverflows;
85  int64_t numNegInfs;
86  int64_t numPosInfs;
87  double finiteUnderflowSumWeights;
88  double finiteOverflowSumWeights;
89  double negInfSumWeights;
90  double posInfSumWeights;
91 
92  private:
93  void copy(const cPrecollectionBasedDensityEst& other);
94 
95  protected:
96  // part of merge(); to be implemented in subclasses
97  virtual void doMergeBinValues(const cPrecollectionBasedDensityEst *other) = 0;
98 
99  public:
102 
106  cPrecollectionBasedDensityEst(const cPrecollectionBasedDensityEst& other) : cAbstractHistogram(other) {precollectedValues=nullptr; precollectedWeights=nullptr; copy(other);}
107 
111  explicit cPrecollectionBasedDensityEst(const char *name=nullptr, bool weighted=false);
112 
117 
123 
126 
127  /* No dup() because this is an abstract class. */
128 
134  virtual void parsimPack(cCommBuffer *buffer) const override;
135 
141  virtual void parsimUnpack(cCommBuffer *buffer) override;
143 
146 
154  virtual void collect(double value) override;
155  using cStatistic::collect;
156 
162  virtual void collectWeighted(double value, double weight) override;
164 
171  virtual void merge(const cStatistic *other) override;
172 
176  virtual void clear() override;
177 
181  virtual void saveToFile(FILE *) const override;
182 
186  virtual void loadFromFile(FILE *) override;
188 
191 
196  virtual void setRange(double lower, double upper);
197 
209  virtual void setRangeAuto(int numPrecollect=100, double rangeExtensionFactor=2.0);
210 
218  virtual void setRangeAutoLower(double upper, int numPrecollect=100, double rangeExtensionFactor=2.0);
219 
227  virtual void setRangeAutoUpper(double lower, int numPrecollect=100, double rangeExtensionFactor=2.0);
228 
233  virtual void setNumPrecollectedValues(int numPrecollect);
234 
239  virtual int getNumPrecollectedValues() const {return numPrecollected;}
240 
245  virtual double getRangeExtensionFactor() const {return rangeExtFactor;}
247 
248  protected:
255  virtual void setupRange();
256 
263  virtual void collectIntoHistogram(double value) = 0;
264 
271  virtual void collectWeightedIntoHistogram(double value, double weight) = 0;
272 
273  public:
279  virtual bool binsAlreadySetUp() const override {return transformed;}
280 
285  virtual int64_t getNumUnderflows() const override {return numFiniteUnderflows + numNegInfs;}
286 
291  virtual int64_t getNumOverflows() const override {return numFiniteOverflows + numPosInfs;}
292 
296  virtual double getUnderflowSumWeights() const override {return finiteUnderflowSumWeights + negInfSumWeights;}
297 
301  virtual double getOverflowSumWeights() const override {return finiteOverflowSumWeights + posInfSumWeights;}
302 
306  virtual int64_t getNumNegInfs() const override {return numNegInfs;}
307 
311  virtual int64_t getNumPosInfs() const override {return numPosInfs;}
312 
316  virtual double getNegInfSumWeights() const override {return negInfSumWeights;}
317 
321  virtual double getPosInfSumWeights() const override {return posInfSumWeights;}
323 };
324 
325 } // namespace omnetpp
326 
327 
328 #endif
329 
330 
virtual void collect(double value)=0
Interface and base class for histogram-like density estimation classes.
Definition: cabstracthistogram.h:26
virtual double getNegInfSumWeights() const override
Definition: cprecolldensityest.h:316
virtual int64_t getNumOverflows() const override
Definition: cprecolldensityest.h:291
cPrecollectionBasedDensityEst(const cPrecollectionBasedDensityEst &other)
Definition: cprecolldensityest.h:106
virtual double getRangeExtensionFactor() const
Definition: cprecolldensityest.h:245
virtual int64_t getNumPosInfs() const override
Definition: cprecolldensityest.h:311
RangeMode
Constants for histogram range_mode.
Definition: cprecolldensityest.h:61
virtual void collectWeighted(double value, double weight)
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
virtual double getOverflowSumWeights() const override
Definition: cprecolldensityest.h:301
virtual int getNumPrecollectedValues() const
Definition: cprecolldensityest.h:239
virtual int64_t getNumNegInfs() const override
Definition: cprecolldensityest.h:306
Definition: cabstracthistogram.h:21
virtual double getUnderflowSumWeights() const override
Definition: cprecolldensityest.h:296
virtual bool binsAlreadySetUp() const override
Definition: cprecolldensityest.h:279
Base class for histogram-like density estimation classes.
Definition: cprecolldensityest.h:55
virtual double getPosInfSumWeights() const override
Definition: cprecolldensityest.h:321
virtual int64_t getNumUnderflows() const override
Definition: cprecolldensityest.h:285
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34