PSCF v1.1
AutoCorrStage.h
1#ifndef UTIL_AUTO_CORR_STAGE_H
2#define UTIL_AUTO_CORR_STAGE_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/containers/RingBuffer.h> // member
12#include <util/containers/DArray.h> // member
13#include <util/global.h>
14
15namespace Util
16{
17
52 template <typename Data, typename Product>
54 {
55
56 public:
57
66
72 virtual ~AutoCorrStage();
73
81 void setParam(int bufferCapacity=64, int maxStageId=0,
82 int blockFactor=2);
83
89 virtual void sample(Data value);
90
94 void clear();
95
102 template <class Archive>
103 void serialize(Archive& ar, const unsigned int version);
104
106
108
117 void output(std::ostream& out);
118
128 void output(std::ostream& out, Product aveSq);
129
133 int bufferCapacity() const;
134
138 int bufferSize() const;
139
143 long nSample() const;
144
148 long stageInterval() const;
149
158 Product autoCorrelation(int t) const;
159
168 Product autoCorrelation(int t, Product aveSq) const;
169
175 double corrTime() const;
176
186 double corrTime(Product aveSq) const;
187
189
190 protected:
191
194
197
200
204 void allocate();
205
209 bool hasChild() const;
210
215
224
231 template <class Archive>
232 void serializePrivate(Archive& ar, const unsigned int version);
233
234 private:
235
236 // Ring buffer containing sequence of Data values
237 RingBuffer<Data> buffer_;
238
239 // Array in which corr_[j] = sum of values of <x(i-j), x(i)>
240 DArray<Product> corr_;
241
242 // Array in which nCorr_[i] = number of products added to corr_[i]
243 DArray<int> nCorr_;
244
245 // Sum of all previous values of x(t)
246 Data sum_;
247
249 long nSample_;
250
252 Data blockSum_;
253
255 long nBlockSample_;
256
258 long stageInterval_;
259
262
265
267 int stageId_;
268
279 AutoCorrStage(long stageInterval, int stageId, int maxStageId,
280 AutoCorrStage<Data, Product>* rootPtr, int blockFactor);
281
285 AutoCorrStage(const AutoCorrStage& other);
286
290 AutoCorrStage& operator = (const AutoCorrStage& other);
291
295 bool isValid();
296
297 };
298
299 // Inline methods
300
301 /*
302 * Does this object have a child? (protected)
303 */
304 template <typename Data, typename Product>
306 { return bool(childPtr_); }
307
308 /*
309 * Return child object by reference. (protected)
310 */
311 template <typename Data, typename Product>
313 { return *childPtr_; }
314
315}
316#endif
Hierarchical auto-correlation function algorithm.
Definition: AutoCorrStage.h:54
long stageInterval() const
Return the number of primary values per block at this stage.
int bufferCapacity() const
Return capacity of history buffer.
void output(std::ostream &out)
Output the autocorrelation function, assuming zero mean.
AutoCorrStage()
Constructor.
int bufferSize() const
Return current size of history buffer.
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.
void clear()
Clear accumulators and destroy descendants.
void serializePrivate(Archive &ar, const unsigned int version)
Serialize private data members, and descendants.
AutoCorrStage & child()
Return the child AutoCorrStage by reference.
virtual void sample(Data value)
Sample a value.
Product autoCorrelation(int t) const
Return autocorrelation at a given time, assuming zero average.
virtual ~AutoCorrStage()
Destructor.
double corrTime() const
Estimate of autocorrelation time, in samples.
long nSample() const
Return the number of sampled values.
virtual void registerDescendant(AutoCorrStage< Data, Product > *ptr)
Register the creation of a descendant stage.
int bufferCapacity_
Physical capacity (# of elements) of buffer, corr, and nCorr.
int maxStageId_
Maximum allowed stage index (controls maximum degree of blocking).
int blockFactor_
Number of values per block (ratio of intervals for successive stages).
bool hasChild() const
Does this have a child AutoCorrStage?
void allocate()
Allocate memory and initialize to empty state.
void setParam(int bufferCapacity=64, int maxStageId=0, int blockFactor=2)
Set all parameters and allocate to initialize state.
Dynamically allocatable contiguous array template.
Definition: DArray.h:32
Class for storing history of previous values in an array.
Definition: RingBuffer.h:27
File containing preprocessor macros for error handling.
Utility classes for scientific computation.
Definition: accumulators.mod:1