My favorites | Sign in
Project Home Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/********************************************\
*
* Sire - Molecular Simulation Framework
*
* Copyright (C) 2008 Christopher Woods
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For full details of the license please see the COPYING file
* that should have come with this distribution.
*
* You can contact the authors via the developer's mailing list
* at http://siremol.org
*
\*********************************************/

#ifndef SIREMATHS_ACCUMULATOR_H
#define SIREMATHS_ACCUMULATOR_H

#include <QVector>

#include "Siren/object.h"
#include "Siren/objptr.hpp"
#include "Siren/mutable.h"

#include "sireglobal.h"

SIRE_BEGIN_HEADER

namespace SireMaths
{

/** This is the base class of all Accumulators - these are objects
that can accumulate values and calculate properties of that
collection of values - e.g. they could accumulate the values
so that the mean average could be collected, or so that the
maximum and minimum values could be determined etc.

@author Christopher Woods
*/
class SIREMATHS_EXPORT Accumulator
: public Siren::Extends<Accumulator,Siren::Object>,
public Siren::Interfaces<Accumulator,Siren::Mutable>
{
public:
Accumulator();

Accumulator(const Accumulator &other);

virtual ~Accumulator();

///////////////////////////
// Extends Siren::Object //
///////////////////////////
static QString typeName();
uint hashCode() const;
void stream(Siren::Stream &s);

///////////////////////////////
// Interfaces Siren::Mutable //
///////////////////////////////
Siren::ObjRef saveState() const;
void restoreState(const Siren::Object &object);

////////////////////////////
// SireMaths::Accumulator //
////////////////////////////

virtual int nSamples() const;

virtual void accumulate(double value);

virtual void accumulate(const QVector<double> &values);
virtual void accumulate(const QList<double> &values);

virtual void clear();

virtual operator double() const=0;

virtual double value() const;

protected:
Accumulator& operator=(const Accumulator &other);

bool operator==(const Accumulator &other) const;
bool operator!=(const Accumulator &other) const;

friend class Siren::Extends<Accumulator,Object>;
static QStringList listInterfaces()
{
return Siren::Interfaces<Accumulator,Siren::Mutable>::listInterfaces();
}

private:
/** The number of values that have been accumulated */
quint32 nvalues;
};

/** This class is used to accumulate the mean average of a collection
of values

@author Christopher Woods
*/
class SIREMATHS_EXPORT Average : public Siren::Implements<Average,Accumulator>
{

public:
Average();
Average(const Average &other);

~Average();

Average& operator=(const Average &other);

bool operator==(const Average &other) const;
bool operator!=(const Average &other) const;

//////////////////////////////
// Implements Siren::Object //
//////////////////////////////
QString toString() const;
void stream(Siren::Stream &s);

////////////////////////////
// Implements Accumulator //
////////////////////////////

void clear();

void accumulate(double value);

double average() const;

operator double() const;

private:
/** The current average value */
double avgval;
};

/** This class is used to accumulate the mean average
and standard deviation of a collection of values

@author Christopher Woods
*/
class SIREMATHS_EXPORT AverageAndStddev
: public Siren::Implements<AverageAndStddev,Average>
{
public:
AverageAndStddev();

AverageAndStddev(const AverageAndStddev &other);

~AverageAndStddev();

AverageAndStddev& operator=(const AverageAndStddev &other);

bool operator==(const AverageAndStddev &other) const;
bool operator!=(const AverageAndStddev &other) const;

//////////////////////////////
// Implements Siren::Object //
//////////////////////////////
QString toString() const;
void stream(Siren::Stream &s);

////////////////////////////
// Implements Accumulator //
////////////////////////////

void clear();

void accumulate(double value);

double stddev() const;
double standardDeviation() const;

double meanOfSquares() const;

private:
/** The current average of the squares */
double avgval2;
};

/** This class is used to accumulate the exponential average
of a collection of values - this is the average formed
as;

avg = scale * ln( Mean of e^(value/scale) )

It is used to weight the average, e.g. if scale = -kT
then this Boltzmann weights the average

@author Christopher Woods
*/
class SIREMATHS_EXPORT ExpAverage : public Siren::Implements<ExpAverage,Accumulator>
{
public:
ExpAverage(double scale=1);

ExpAverage(const ExpAverage &other);

~ExpAverage();

ExpAverage& operator=(const ExpAverage &other);

bool operator==(const ExpAverage &other) const;
bool operator!=(const ExpAverage &other) const;

//////////////////////////////
// Implements Siren::Object //
//////////////////////////////
QString toString() const;
void stream(Siren::Stream &s);

////////////////////////////
// Implements Accumulator //
////////////////////////////

void clear();

void accumulate(double value);

double average() const;

operator double() const;

protected:
double scaleFactor() const;

private:
/** The intermediate in the average calculation */
double avgval;

/** The scaling factor */
double sclfac;
};

/** This class is used to calculate the maximum, minimum and median
of a collection of values

@author Christopher Woods
*/
class SIREMATHS_EXPORT Median : public Siren::Implements<Median,Accumulator>
{
public:
Median();

Median(const Median &other);

~Median();

Median& operator=(const Median &other);

bool operator==(const Median &other) const;
bool operator!=(const Median &other) const;

//////////////////////////////
// Implements Siren::Object //
//////////////////////////////
QString toString() const;
void stream(Siren::Stream &s);

////////////////////////////
// Implements Accumulator //
////////////////////////////

void clear();

void accumulate(double value);

double max() const;
double maximum() const;

double median() const;

double min() const;
double minimum() const;

operator double() const;

private:
/** The current minimum value */
double minval;

/** The current maximum value */
double maxval;
};

/** This class is used to collect a record of all of the values.
This allows you to extract the values and calculate whatever
statistical property you wish in post-production

@author Christopher Woods
*/
class SIREMATHS_EXPORT RecordValues : public Siren::Implements<RecordValues,Accumulator>
{
public:
RecordValues();

RecordValues(const RecordValues &other);

~RecordValues();

RecordValues& operator=(const RecordValues &other);

bool operator==(const RecordValues &other) const;
bool operator!=(const RecordValues &other) const;

//////////////////////////////
// Implements Siren::Object //
//////////////////////////////
QString toString() const;
void stream(Siren::Stream &s);

////////////////////////////
// Implements Accumulator //
////////////////////////////

void clear();

void accumulate(double value);

double max() const;
double maximum() const;

double median() const;
double mean() const;

double min() const;
double minimum() const;

double sum() const;
double sum2() const;

double meanOfSquares() const;

double standardDeviation() const;
double stddev() const;

int count() const;
int size() const;
int nValues() const;

operator double() const;

QVector<double> values() const;

private:
/** The record of all values */
QVector<double> vals;
};

typedef Siren::ObjPtr<Accumulator> AccumulatorPtr;

}

Q_DECLARE_METATYPE( SireMaths::Average )
Q_DECLARE_METATYPE( SireMaths::AverageAndStddev )
Q_DECLARE_METATYPE( SireMaths::ExpAverage )
Q_DECLARE_METATYPE( SireMaths::Median )
Q_DECLARE_METATYPE( SireMaths::RecordValues )

SIRE_EXPOSE_CLASS( SireMaths::Accumulator )
SIRE_EXPOSE_CLASS( SireMaths::Average )
SIRE_EXPOSE_CLASS( SireMaths::AverageAndStddev )
SIRE_EXPOSE_CLASS( SireMaths::ExpAverage )
SIRE_EXPOSE_CLASS( SireMaths::Median )
SIRE_EXPOSE_CLASS( SireMaths::RecordValues )

SIRE_EXPOSE_OBJECT_PTR( SireMaths::AccumulatorPtr, SireMaths::Accumulator )

SIRE_END_HEADER

#endif

Change log

r1117 by chryswoods on Dec 1, 2009   Diff
I've ported SireMaths/accumulator.h/.cpp
across to Siren. This file contains a
hierarchy of
classes that really demonstrate how Siren
is to be used in Sire, e.g.

class Accumulator : public
Extends<Accumulator,Object>,
                    public
Interfaces<Accumulator,Mutable>


...
Go to: 
Sign in to write a code review

Older revisions

r1111 by chryswoods on Nov 27, 2009   Diff
OK  - this is the start of a very
broken set of versions of Sire. I am
now starting the
migration of the code over to Siren. I
assumed I could do this piecemeal, but
...
r1014 by chryswoods on Jul 2, 2009   Diff
Compilation problems of the python
wrappers on AIX have meant that I have
had to
 move all .clone() functions out-of-
line...
...
r946 by chryswoods on Jun 2, 2009   Diff
I've updated SireMaths to make it
compatible with xlC

All revisions of this file

File info

Size: 9713 bytes, 387 lines
Powered by Google Project Hosting