OMNeT++ API 6.1
Discrete Event Simulation Library
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 } // namespace omnetpp
227 
228 #endif
229 
omnetpp::cStdDev::~cStdDev
virtual ~cStdDev()
Definition: cstddev.h:64
omnetpp::cStdDev::getSqrSum
virtual double getSqrSum() const override
Definition: cstddev.h:146
omnetpp::cStdDev::getSumWeights
virtual double getSumWeights() const override
Definition: cstddev.h:182
omnetpp::cStatistic::collectWeighted
virtual void collectWeighted(double value, double weight)
omnetpp::cStdDev::getCount
virtual int64_t getCount() const override
Definition: cstddev.h:132
omnetpp::cStdDev::isWeighted
virtual bool isWeighted() const override
Definition: cstddev.h:108
omnetpp::cStatistic::collect
virtual void collect(double value)=0
omnetpp::cStdDev::cStdDev
cStdDev(const cStdDev &r)
Definition: cstddev.h:54
omnetpp::cStdDev::getWeightedSum
virtual double getWeightedSum() const override
Definition: cstddev.h:188
omnetpp::cStdDev::getSqrSumWeights
virtual double getSqrSumWeights() const override
Definition: cstddev.h:194
omnetpp::cStdDev::getWeightedSqrSum
virtual double getWeightedSqrSum() const override
Definition: cstddev.h:200
omnetpp::cStatistic
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
omnetpp::cStdDev
Statistics class to collect min, max, mean, and standard deviation.
Definition: cstddev.h:29
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
omnetpp::cStdDev::getSum
virtual double getSum() const override
Definition: cstddev.h:139
omnetpp::cStdDev::dup
virtual cStdDev * dup() const override
Definition: cstddev.h:79