cprecolldensityest.h Source File

API: cprecolldensityest.h Source File
API
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#include "statsum_t.h"
21
22namespace omnetpp {
23
57{
58 public:
62 enum RangeMode {
63 RANGE_AUTO, // automatic range setup, using precollected values and range extension (the default)
64 RANGE_AUTOLOWER, // like RANGE_AUTO, but upper limit is fixed
65 RANGE_AUTOUPPER, // like RANGE_AUTO, but lower limit is fixed
66 RANGE_FIXED, // fixed range (lower, upper)
67 RANGE_NOTSET // not set, but it is OK (not used)
68 };
69
70 protected:
71 // we can precollect observations to automatically determine the range before histogram bins are set up
72 bool transformed = false; // whether precollected values have been transformed into a histogram
73 double *precollectedValues = nullptr;
74 double *precollectedWeights = nullptr; // nullptr for unweighted
75 int numPrecollected = 100;
76
77 // range for distribution density collection
78 RangeMode rangeMode = RANGE_AUTO;
79 double rangeExtFactor = 2.0; // we extend the range of precollected values by rangeExtFactor
80 double rangeMin = 0, rangeMax = 0;
81 double finiteMinValue = NAN, finiteMaxValue = NAN;
82
83 // variables for counting out-of-range observations
84 int64_t numFiniteUnderflows = 0;
85 int64_t numFiniteOverflows = 0;
86 int64_t numNegInfs = 0;
87 int64_t numPosInfs = 0;
88 statsum_t finiteUnderflowSumWeights = 0;
89 statsum_t finiteOverflowSumWeights = 0;
90 statsum_t negInfSumWeights = 0;
91 statsum_t posInfSumWeights = 0;
92
93 private:
94 void copy(const cPrecollectionBasedDensityEst& other);
95
96 protected:
97 // part of merge(); to be implemented in subclasses
98 virtual void doMergeBinValues(const cPrecollectionBasedDensityEst *other) = 0;
99
100 public:
103
108
112 explicit cPrecollectionBasedDensityEst(const char *name=nullptr, bool weighted=false);
113
118
124
127
128 /* No dup() because this is an abstract class. */
129
135 virtual void parsimPack(cCommBuffer *buffer) const override;
136
142 virtual void parsimUnpack(cCommBuffer *buffer) override;
144
147
155 virtual void collect(double value) override;
157
163 virtual void collectWeighted(double value, double weight) override;
165
172 virtual void merge(const cStatistic *other) override;
173
177 virtual void clear() override;
178
182 virtual void saveToFile(FILE *) const override;
183
187 virtual void loadFromFile(FILE *) override;
189
192
197 virtual void setRange(double lower, double upper);
198
210 virtual void setRangeAuto(int numPrecollect=100, double rangeExtensionFactor=2.0);
211
219 virtual void setRangeAutoLower(double upper, int numPrecollect=100, double rangeExtensionFactor=2.0);
220
228 virtual void setRangeAutoUpper(double lower, int numPrecollect=100, double rangeExtensionFactor=2.0);
229
234 virtual void setNumPrecollectedValues(int numPrecollect);
235
240 virtual int getNumPrecollectedValues() const {return numPrecollected;}
241
246 virtual double getRangeExtensionFactor() const {return rangeExtFactor;}
248
249 protected:
256 virtual void setupRange();
257
264 virtual void collectIntoHistogram(double value) = 0;
265
272 virtual void collectWeightedIntoHistogram(double value, double weight) = 0;
273
274 public:
277
280 virtual bool binsAlreadySetUp() const override {return transformed;}
281
286 virtual int64_t getNumUnderflows() const override {return numFiniteUnderflows + numNegInfs;}
287
292 virtual int64_t getNumOverflows() const override {return numFiniteOverflows + numPosInfs;}
293
297 virtual double getUnderflowSumWeights() const override {return finiteUnderflowSumWeights + negInfSumWeights;}
298
302 virtual double getOverflowSumWeights() const override {return finiteOverflowSumWeights + posInfSumWeights;}
303
307 virtual int64_t getNumNegInfs() const override {return numNegInfs;}
308
312 virtual int64_t getNumPosInfs() const override {return numPosInfs;}
313
317 virtual double getNegInfSumWeights() const override {return negInfSumWeights;}
318
322 virtual double getPosInfSumWeights() const override {return posInfSumWeights;}
324};
325
326} // namespace omnetpp
327
328
329#endif
330
331
cAbstractHistogram(const cAbstractHistogram &other)=default
Buffer for the communications layer of parallel simulation.
Definition ccommbuffer.h:42
Base class for histogram-like density estimation classes.
Definition cprecolldensityest.h:57
virtual void saveToFile(FILE *) const override
virtual void setRange(double lower, double upper)
virtual double getRangeExtensionFactor() const
Definition cprecolldensityest.h:246
virtual double getUnderflowSumWeights() const override
Definition cprecolldensityest.h:297
virtual bool binsAlreadySetUp() const override
Definition cprecolldensityest.h:280
virtual double getNegInfSumWeights() const override
Definition cprecolldensityest.h:317
virtual int64_t getNumOverflows() const override
Definition cprecolldensityest.h:292
virtual void collectWeighted(double value, double weight) override
virtual double getOverflowSumWeights() const override
Definition cprecolldensityest.h:302
virtual void setNumPrecollectedValues(int numPrecollect)
virtual void loadFromFile(FILE *) override
virtual void collect(double value) override
cPrecollectionBasedDensityEst(const char *name=nullptr, bool weighted=false)
cPrecollectionBasedDensityEst & operator=(const cPrecollectionBasedDensityEst &res)
virtual void parsimPack(cCommBuffer *buffer) const override
virtual void collectWeightedIntoHistogram(double value, double weight)=0
virtual int64_t getNumNegInfs() const override
Definition cprecolldensityest.h:307
RangeMode
Constants for histogram range_mode.
Definition cprecolldensityest.h:62
virtual void setRangeAutoUpper(double lower, int numPrecollect=100, double rangeExtensionFactor=2.0)
virtual void parsimUnpack(cCommBuffer *buffer) override
virtual void setRangeAuto(int numPrecollect=100, double rangeExtensionFactor=2.0)
virtual void setRangeAutoLower(double upper, int numPrecollect=100, double rangeExtensionFactor=2.0)
virtual int64_t getNumPosInfs() const override
Definition cprecolldensityest.h:312
virtual void collectIntoHistogram(double value)=0
virtual void merge(const cStatistic *other) override
virtual int getNumPrecollectedValues() const
Definition cprecolldensityest.h:240
virtual int64_t getNumUnderflows() const override
Definition cprecolldensityest.h:286
cPrecollectionBasedDensityEst(const cPrecollectionBasedDensityEst &other)
Definition cprecolldensityest.h:107
virtual double getPosInfSumWeights() const override
Definition cprecolldensityest.h:322
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition cstatistic.h:35
virtual void collectWeighted(double value, double weight)
virtual void collect(double value)=0