OMNeT++ Simulation Library  5.6.1
cstddev.h
1 //==========================================================================
2 // CSTDDEV.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_CSTDDEV_H
17 #define __OMNETPP_CSTDDEV_H
18 
19 #include <cstdio>
20 #include "cstatistic.h"
21 
22 namespace omnetpp {
23 
29 class SIM_API cStdDev : public cStatistic
30 {
31  protected:
32  bool weighted;
33  double minValue;
34  double maxValue;
35  int64_t numValues; // the actual count of observations, independent of their weights
36  double sumWeights; // equals count in the unweighted case
37  double sumWeightedValues; // equals sum in the unweighted case
38  double sumSquaredWeights; // equals count in the unweighted case
39  double sumWeightedSquaredValues; // sum of squared values in the unweighted case
40 
41  private:
42  void copy(const cStdDev& other);
43 
44  protected:
45  void assertUnweighted() const;
46 
47  public:
50 
54  cStdDev(const cStdDev& r) : cStatistic(r) {copy(r);}
55 
59  explicit cStdDev(const char *name=nullptr, bool weighted=false);
60 
64  virtual ~cStdDev() {}
65 
69  cStdDev& operator=(const cStdDev& res);
71 
74 
79  virtual cStdDev *dup() const override {return new cStdDev(*this);}
80 
85  virtual std::string str() const override;
86 
92  virtual void parsimPack(cCommBuffer *buffer) const override;
93 
99  virtual void parsimUnpack(cCommBuffer *buffer) override;
101 
108  virtual bool isWeighted() const override {return weighted;}
109 
113  virtual void collect(double value) override;
114  using cStatistic::collect;
115 
121  virtual void collectWeighted(double value, double weight) override;
123 
127  virtual void merge(const cStatistic *other) override;
128 
132  virtual int64_t getCount() const override {return numValues;}
133 
139  virtual double getSum() const override {assertUnweighted(); return sumWeightedValues;}
140 
146  virtual double getSqrSum() const override {assertUnweighted(); return sumWeightedSquaredValues;}
147 
152  virtual double getMin() const override;
153 
158  virtual double getMax() const override;
159 
164  virtual double getMean() const override;
165 
170  virtual double getStddev() const override;
171 
176  virtual double getVariance() const override;
177 
182  virtual double getSumWeights() const override {return sumWeights;}
183 
188  virtual double getWeightedSum() const override {return sumWeightedValues;}
189 
194  virtual double getSqrSumWeights() const override {return sumSquaredWeights;}
195 
200  virtual double getWeightedSqrSum() const override {return sumWeightedSquaredValues;}
201 
206  virtual double draw() const override;
207 
211  virtual void clear() override;
212 
216  virtual void saveToFile(FILE *) const override;
217 
222  virtual void loadFromFile(FILE *) override;
224 };
225 
226 #if defined(__clang__) || defined(__GNUC__)
227 #pragma GCC diagnostic push
228 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
229 #endif
230 
239 class _OPPDEPRECATED SIM_API cWeightedStdDev : public cStdDev
240 {
241  public:
247  explicit cWeightedStdDev(const char *name=nullptr) : cStdDev(name, true) {}
248 
253 
257  cWeightedStdDev& operator=(const cWeightedStdDev& res) {cStdDev::operator=(res); return *this;}
258 
263  virtual cWeightedStdDev *dup() const override {return new cWeightedStdDev(*this);}
265 };
266 
267 #if defined(__clang__) || defined(__GNUC__)
268 #pragma GCC diagnostic pop
269 #endif
270 
271 } // namespace omnetpp
272 
273 #endif
274 
virtual void collect(double value)=0
cWeightedStdDev(const cWeightedStdDev &r)
Definition: cstddev.h:252
virtual double getWeightedSum() const override
Definition: cstddev.h:188
cStdDev & operator=(const cStdDev &res)
cStdDev(const cStdDev &r)
Definition: cstddev.h:54
virtual double getSum() const override
Definition: cstddev.h:139
virtual cStdDev * dup() const override
Definition: cstddev.h:79
cWeightedStdDev & operator=(const cWeightedStdDev &res)
Definition: cstddev.h:257
virtual void collectWeighted(double value, double weight)
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
cWeightedStdDev(const char *name=nullptr)
Definition: cstddev.h:247
virtual double getSqrSumWeights() const override
Definition: cstddev.h:194
Statistics class to collect doubles and calculate weighted statistics from them. One application is t...
Definition: cstddev.h:239
virtual double getWeightedSqrSum() const override
Definition: cstddev.h:200
virtual double getSumWeights() const override
Definition: cstddev.h:182
virtual cWeightedStdDev * dup() const override
Definition: cstddev.h:263
Definition: cabstracthistogram.h:21
virtual int64_t getCount() const override
Definition: cstddev.h:132
virtual ~cStdDev()
Definition: cstddev.h:64
Statistics class to collect min, max, mean, and standard deviation.
Definition: cstddev.h:29
virtual bool isWeighted() const override
Definition: cstddev.h:108
virtual double getSqrSum() const override
Definition: cstddev.h:146
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34