Project

General

Profile

Statistics
| Branch: | Revision:

root / include / cpsquare.h @ b781545c

History | View | Annotate | Download (5.7 KB)

1
//==========================================================================
2
//  CPSQUARE.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//
7
//  Declaration of the following classes:
8
//    cPSquare : calculates quantile values without storing the observations
9
//
10
//  Author: Babak Fakhamzadeh, TU Delft, Dec 1996
11
//
12
//==========================================================================
13

    
14
/*--------------------------------------------------------------*
15
  Copyright (C) 1992-2008 Andras Varga
16
  Copyright (C) 2006-2008 OpenSim Ltd.
17

18
  This file is distributed WITHOUT ANY WARRANTY. See the file
19
  `license' for details on this and other legal matters.
20
*--------------------------------------------------------------*/
21

    
22
#ifndef __CPSQUARE_H
23
#define __CPSQUARE_H
24

    
25
#include "cdensityestbase.h"
26

    
27
NAMESPACE_BEGIN
28

    
29

    
30
/**
31
 * Implements the P<SUP>2</SUP> algorithm, which calculates quantile values
32
 * without storing the observations.
33
 *
34
 * @ingroup Statistics
35
 */
36
class SIM_API cPSquare : public cDensityEstBase
37
{
38
  protected:
39
    int numcells;      // number of observations
40
    long numobs;       // number of cells,
41
    int *n;            // array of positions
42
    double *q;         // array of heights
43

    
44
  protected:
45
    // abstract method in cDensityEstBase
46
    virtual void doMergeCellValues(const cDensityEstBase *other);
47

    
48
  public:
49
    /** @name Constructors, destructor, assignment. */
50
    //@{
51

    
52
    /**
53
     * Copy constructor.
54
     */
55
    cPSquare(const cPSquare& r);
56

    
57
    /**
58
     * Constructor.
59
     */
60
    explicit cPSquare(const char *name=NULL, int cells=10);
61

    
62
    /**
63
     * Destructor.
64
     */
65
    virtual ~cPSquare();
66

    
67
    /**
68
     * Assignment operator. The name member is not copied; see cNamedObject's operator=() for more details.
69
     */
70
    cPSquare& operator=(const cPSquare& res);
71
    //@}
72

    
73
    /** @name Redefined cObject member functions. */
74
    //@{
75

    
76
    /**
77
     * Creates and returns an exact copy of this object.
78
     * See cObject for more details.
79
     */
80
    virtual cPSquare *dup() const  {return new cPSquare(*this);}
81

    
82
    /**
83
     * Produces a multi-line description of the object's contents.
84
     * See cObject for more details.
85
     */
86
    virtual std::string detailedInfo() const;
87

    
88
    /**
89
     * Serializes the object into an MPI send buffer.
90
     * Used by the simulation kernel for parallel execution.
91
     * See cObject for more details.
92
     */
93
    virtual void parsimPack(cCommBuffer *buffer);
94

    
95
    /**
96
     * Deserializes the object from an MPI receive buffer
97
     * Used by the simulation kernel for parallel execution.
98
     * See cObject for more details.
99
     */
100
    virtual void parsimUnpack(cCommBuffer *buffer);
101
    //@}
102

    
103
  private:
104
    // internal: issues error message
105
    void giveError();
106

    
107
  protected:
108
    /**
109
     * Called internally by collect(), this method updates the P2 data structure
110
     * with the new value.
111
     */
112
    virtual void collectTransformed(double val);
113

    
114
  public:
115
    /** @name Redefined member functions from cStatistic and its subclasses. */
116
    //@{
117

    
118
    /**
119
     * This method is not used with cPSquare, but it could not remain pure virtual.
120
     */
121
    virtual void transform() {}
122

    
123
    /**
124
     * setRange() and setNumFirstVals() methods are not used with cPSquare
125
     * (the algorithm does not require them), but they could not remain pure virtual.
126
     */
127
    virtual void setRange(double,double) {giveError();}
128

    
129
    /**
130
     * setRange() and setNumFirstVals() methods are not used with cPSquare
131
     * (the algorithm does not require them), but they could not remain pure virtual.
132
     */
133
    virtual void setRangeAuto(int,double) {giveError();}
134

    
135
    /**
136
     * setRange() and setNumFirstVals() methods are not used with cPSquare
137
     * (the algorithm does not require them), but they could not remain pure virtual.
138
     */
139
    virtual void setRangeAutoLower(double,int,double) {giveError();}
140

    
141
    /**
142
     * setRange() and setNumFirstVals() methods are not used with cPSquare
143
     * (the algorithm does not require them), but they could not remain pure virtual.
144
     */
145
    virtual void setRangeAutoUpper(double,int,double) {giveError();}
146

    
147
    /**
148
     * setRange() and setNumFirstVals() methods are not used with cPSquare
149
     * (the algorithm does not require them), but they could not remain pure virtual.
150
     */
151
    virtual void setNumFirstVals(int) {giveError();}
152

    
153
    /**
154
     * Returns the number of cells used.
155
     */
156
    virtual int getNumCells() const;
157

    
158
    /**
159
     * Returns the kth cell boundary. Note that because of the P2 algorithm,
160
     * cell boundaries are shifting during data collection, thus getCellValue() and
161
     * other methods based on getCellValue() and getBasepoint() return approximate values.
162
     */
163
    virtual double getBasepoint(int k) const;
164

    
165
    /**
166
     * Returns the number of observations that fell into the kth histogram cell.
167
     */
168
    virtual double getCellValue(int k) const;
169

    
170
    /**
171
     * Returns the value of the Cumulated Density Function at a given x.
172
     */
173
    virtual double getCDF(double x) const;
174

    
175
    /**
176
     * Returns the value of the Probability Density Function at a given x.
177
     */
178
    virtual double getPDF(double x) const;
179

    
180
    /**
181
     * Generates a random number based on the collected data. Uses the random number generator set by setGenK().
182
     */
183
    virtual double random() const;
184

    
185
    /**
186
     * Merging is not supported by this class. This method throws an error.
187
     */
188
    virtual void merge(const cStatistic *other);
189

    
190
    /**
191
     * Writes the contents of the object into a text file.
192
     */
193
    virtual void saveToFile(FILE *) const;
194

    
195
    /**
196
     * Reads the object data from a file, in the format written out by saveToFile().
197
     */
198
    virtual void loadFromFile(FILE *);
199
    //@}
200
};
201

    
202
NAMESPACE_END
203

    
204

    
205
#endif
206