OMNeT++ Simulation Library  6.0.3
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 (not used)
67  };
68 
69  protected:
70  // we can precollect observations to automatically determine the range before histogram bins are set up
71  bool transformed = false; // whether precollected values have been transformed into a histogram
72  double *precollectedValues = nullptr;
73  double *precollectedWeights = nullptr; // nullptr for unweighted
74  int numPrecollected = 100;
75 
76  // range for distribution density collection
77  RangeMode rangeMode = RANGE_AUTO;
78  double rangeExtFactor = 2.0; // we extend the range of precollected values by rangeExtFactor
79  double rangeMin = 0, rangeMax = 0;
80  double finiteMinValue = NAN, finiteMaxValue = NAN;
81 
82  // variables for counting out-of-range observations
83  int64_t numFiniteUnderflows = 0;
84  int64_t numFiniteOverflows = 0;
85  int64_t numNegInfs = 0;
86  int64_t numPosInfs = 0;
87  double finiteUnderflowSumWeights = 0;
88  double finiteOverflowSumWeights = 0;
89  double negInfSumWeights = 0;
90  double posInfSumWeights = 0;
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 
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 
omnetpp::cPrecollectionBasedDensityEst::getNumPrecollectedValues
virtual int getNumPrecollectedValues() const
Definition: cprecolldensityest.h:239
omnetpp::cPrecollectionBasedDensityEst::getNumNegInfs
virtual int64_t getNumNegInfs() const override
Definition: cprecolldensityest.h:306
omnetpp::cPrecollectionBasedDensityEst::cPrecollectionBasedDensityEst
cPrecollectionBasedDensityEst(const cPrecollectionBasedDensityEst &other)
Definition: cprecolldensityest.h:106
omnetpp::cStatistic::collectWeighted
virtual void collectWeighted(double value, double weight)
omnetpp::cPrecollectionBasedDensityEst::RangeMode
RangeMode
Constants for histogram range_mode.
Definition: cprecolldensityest.h:61
omnetpp::cPrecollectionBasedDensityEst::getNumUnderflows
virtual int64_t getNumUnderflows() const override
Definition: cprecolldensityest.h:285
omnetpp::cPrecollectionBasedDensityEst::getPosInfSumWeights
virtual double getPosInfSumWeights() const override
Definition: cprecolldensityest.h:321
omnetpp::cPrecollectionBasedDensityEst::getNumOverflows
virtual int64_t getNumOverflows() const override
Definition: cprecolldensityest.h:291
omnetpp::cStatistic::collect
virtual void collect(double value)=0
omnetpp::cPrecollectionBasedDensityEst
Base class for histogram-like density estimation classes.
Definition: cprecolldensityest.h:55
omnetpp::cAbstractHistogram
Interface and base class for histogram-like density estimation classes.
Definition: cabstracthistogram.h:26
omnetpp::cStatistic
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
omnetpp::cPrecollectionBasedDensityEst::getNegInfSumWeights
virtual double getNegInfSumWeights() const override
Definition: cprecolldensityest.h:316
omnetpp::cPrecollectionBasedDensityEst::getRangeExtensionFactor
virtual double getRangeExtensionFactor() const
Definition: cprecolldensityest.h:245
omnetpp::cPrecollectionBasedDensityEst::getNumPosInfs
virtual int64_t getNumPosInfs() const override
Definition: cprecolldensityest.h:311
omnetpp::cPrecollectionBasedDensityEst::binsAlreadySetUp
virtual bool binsAlreadySetUp() const override
Definition: cprecolldensityest.h:279
omnetpp::cPrecollectionBasedDensityEst::getOverflowSumWeights
virtual double getOverflowSumWeights() const override
Definition: cprecolldensityest.h:301
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
omnetpp::cPrecollectionBasedDensityEst::getUnderflowSumWeights
virtual double getUnderflowSumWeights() const override
Definition: cprecolldensityest.h:296