OMNeT++ Simulation Library  5.4.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 
81  // variables for counting out-of-range observations
82  int64_t numUnderflows;
83  int64_t numOverflows;
84  double underflowSumWeights;
85  double overflowSumWeights;
86 
87  private:
88  void copy(const cPrecollectionBasedDensityEst& other);
89 
90  protected:
91  static void plotline (std::ostream& os, const char *pref, double xval, double count, double a);
92 
93  // part of merge(); to be implemented in subclasses
94  virtual void doMergeBinValues(const cPrecollectionBasedDensityEst *other) = 0;
95 
96  public:
99 
103  cPrecollectionBasedDensityEst(const cPrecollectionBasedDensityEst& other) : cAbstractHistogram(other) {precollectedValues=nullptr; precollectedWeights=nullptr; copy(other);}
104 
108  explicit cPrecollectionBasedDensityEst(const char *name=nullptr, bool weighted=false);
109 
114 
120 
123 
124  /* No dup() because this is an abstract class. */
125 
131  virtual void parsimPack(cCommBuffer *buffer) const override;
132 
138  virtual void parsimUnpack(cCommBuffer *buffer) override;
140 
143 
151  virtual void collect(double value) override;
152  using cStatistic::collect;
153 
159  virtual void collectWeighted(double value, double weight) override;
161 
168  virtual void merge(const cStatistic *other) override;
169 
173  virtual void clear() override;
174 
178  virtual void saveToFile(FILE *) const override;
179 
183  virtual void loadFromFile(FILE *) override;
185 
188 
193  virtual void setRange(double lower, double upper);
194 
206  virtual void setRangeAuto(int numPrecollect=100, double rangeExtensionFactor=2.0);
207 
215  virtual void setRangeAutoLower(double upper, int numPrecollect=100, double rangeExtensionFactor=2.0);
216 
224  virtual void setRangeAutoUpper(double lower, int numPrecollect=100, double rangeExtensionFactor=2.0);
225 
230  virtual void setNumPrecollectedValues(int numPrecollect);
231 
236  virtual int getNumPrecollectedValues() const {return numPrecollected;}
237 
242  virtual double getRangeExtensionFactor() const {return rangeExtFactor;}
244 
245  protected:
252  virtual void setupRange();
253 
260  virtual void collectIntoHistogram(double value) = 0;
261 
268  virtual void collectWeightedIntoHistogram(double value, double weight) = 0;
269 
270  public:
276  virtual bool binsAlreadySetUp() const override {return transformed;}
277 
282  virtual int64_t getNumUnderflows() const override {return numUnderflows;}
283 
288  virtual int64_t getNumOverflows() const override {return numOverflows;}
289 
293  virtual double getUnderflowSumWeights() const override {return underflowSumWeights;}
294 
298  virtual double getOverflowSumWeights() const override {return overflowSumWeights;}
300 };
301 
302 } // namespace omnetpp
303 
304 
305 #endif
306 
307 
virtual void collect(double value)=0
Interface and base class for histogram-like density estimation classes.
Definition: cabstracthistogram.h:26
virtual int64_t getNumOverflows() const override
Definition: cprecolldensityest.h:288
cPrecollectionBasedDensityEst(const cPrecollectionBasedDensityEst &other)
Definition: cprecolldensityest.h:103
virtual double getRangeExtensionFactor() const
Definition: cprecolldensityest.h:242
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:298
Definition: cabstracthistogram.h:21
virtual double getUnderflowSumWeights() const override
Definition: cprecolldensityest.h:293
virtual bool binsAlreadySetUp() const override
Definition: cprecolldensityest.h:276
Base class for histogram-like density estimation classes.
Definition: cprecolldensityest.h:55
virtual int getNumPrecollectedValues() const
Definition: cprecolldensityest.h:236
virtual int64_t getNumUnderflows() const override
Definition: cprecolldensityest.h:282
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34