cstddev.h Source File

API: cstddev.h Source File
API
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#include "statsum_t.h"
22
23namespace omnetpp {
24
30class SIM_API cStdDev : public cStatistic
31{
32 protected:
33 bool weighted;
34 double minValue;
35 double maxValue;
36 int64_t numValues; // the actual count of observations, independent of their weights
37 statsum_t sumWeights; // equals count in the unweighted case
38 statsum_t sumWeightedValues; // equals sum in the unweighted case
39 statsum_t sumSquaredWeights; // equals count in the unweighted case
40 statsum_t sumWeightedSquaredValues; // sum of squared values in the unweighted case
41
42 private:
43 void copy(const cStdDev& other);
44
45 protected:
46 void assertUnweighted() const;
47
48 public:
51
55 cStdDev(const cStdDev& r) : cStatistic(r) {copy(r);}
56
60 explicit cStdDev(const char *name=nullptr, bool weighted=false);
61
65 virtual ~cStdDev() {}
66
72
75
80 virtual cStdDev *dup() const override {return new cStdDev(*this);}
81
86 virtual std::string str() const override;
87
93 virtual void parsimPack(cCommBuffer *buffer) const override;
94
100 virtual void parsimUnpack(cCommBuffer *buffer) override;
102
105
109 virtual bool isWeighted() const override {return weighted;}
110
114 virtual void collect(double value) override;
116
122 virtual void collectWeighted(double value, double weight) override;
124
128 virtual void merge(const cStatistic *other) override;
129
133 virtual int64_t getCount() const override {return numValues;}
134
140 virtual double getSum() const override {assertUnweighted(); return sumWeightedValues;}
141
147 virtual double getSqrSum() const override {assertUnweighted(); return sumWeightedSquaredValues;}
148
153 virtual double getMin() const override;
154
159 virtual double getMax() const override;
160
165 virtual double getMean() const override;
166
171 virtual double getStddev() const override;
172
177 virtual double getVariance() const override;
178
183 virtual double getSumWeights() const override {return sumWeights;}
184
189 virtual double getWeightedSum() const override {return sumWeightedValues;}
190
195 virtual double getSqrSumWeights() const override {return sumSquaredWeights;}
196
201 virtual double getWeightedSqrSum() const override {return sumWeightedSquaredValues;}
202
207 virtual double draw() const override;
208
212 virtual void clear() override;
213
217 virtual void saveToFile(FILE *) const override;
218
223 virtual void loadFromFile(FILE *) override;
225};
226
227} // namespace omnetpp
228
229#endif
230
Buffer for the communications layer of parallel simulation.
Definition ccommbuffer.h:42
virtual void collectWeighted(double value, double weight)
virtual void collect(double value)=0
cStatistic(const cStatistic &r)
virtual void saveToFile(FILE *) const override
virtual ~cStdDev()
Definition cstddev.h:65
virtual void collectWeighted(double value, double weight) override
cStdDev(const cStdDev &r)
Definition cstddev.h:55
virtual bool isWeighted() const override
Definition cstddev.h:109
virtual void loadFromFile(FILE *) override
virtual double getSum() const override
Definition cstddev.h:140
virtual void collect(double value) override
cStdDev(const char *name=nullptr, bool weighted=false)
virtual double getSqrSumWeights() const override
Definition cstddev.h:195
virtual cStdDev * dup() const override
Definition cstddev.h:80
virtual void parsimPack(cCommBuffer *buffer) const override
virtual double draw() const override
virtual void parsimUnpack(cCommBuffer *buffer) override
virtual void clear() override
virtual double getSumWeights() const override
Definition cstddev.h:183
virtual int64_t getCount() const override
Definition cstddev.h:133
virtual double getMax() const override
virtual double getMin() const override
virtual void merge(const cStatistic *other) override
virtual std::string str() const override
virtual double getVariance() const override
virtual double getMean() const override
virtual double getStddev() const override
virtual double getWeightedSqrSum() const override
Definition cstddev.h:201
cStdDev & operator=(const cStdDev &res)
virtual double getSqrSum() const override
Definition cstddev.h:147
virtual double getWeightedSum() const override
Definition cstddev.h:189