PSCF v1.1
|
Hierarchical auto-correlation function algorithm. More...
#include <AutoCorrStage.h>
Public Member Functions | |
AutoCorrStage () | |
Constructor. More... | |
virtual | ~AutoCorrStage () |
Destructor. More... | |
void | setParam (int bufferCapacity=64, int maxStageId=0, int blockFactor=2) |
Set all parameters and allocate to initialize state. More... | |
virtual void | sample (Data value) |
Sample a value. More... | |
void | clear () |
Clear accumulators and destroy descendants. More... | |
template<class Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
Serialize to/from an archive. More... | |
Accessors | |
int | bufferCapacity_ |
Physical capacity (# of elements) of buffer, corr, and nCorr. More... | |
int | maxStageId_ |
Maximum allowed stage index (controls maximum degree of blocking). More... | |
int | blockFactor_ |
Number of values per block (ratio of intervals for successive stages). More... | |
void | output (std::ostream &out) |
Output the autocorrelation function, assuming zero mean. More... | |
void | output (std::ostream &out, Product aveSq) |
Output the autocorrelation function. More... | |
int | bufferCapacity () const |
Return capacity of history buffer. More... | |
int | bufferSize () const |
Return current size of history buffer. More... | |
long | nSample () const |
Return the number of sampled values. More... | |
long | stageInterval () const |
Return the number of primary values per block at this stage. More... | |
Product | autoCorrelation (int t) const |
Return autocorrelation at a given time, assuming zero average. More... | |
Product | autoCorrelation (int t, Product aveSq) const |
Return autocorrelation at a given lag time. More... | |
double | corrTime () const |
Estimate of autocorrelation time, in samples. More... | |
double | corrTime (Product aveSq) const |
Numerical integration of autocorrelation function. More... | |
void | allocate () |
Allocate memory and initialize to empty state. More... | |
bool | hasChild () const |
Does this have a child AutoCorrStage? More... | |
AutoCorrStage & | child () |
Return the child AutoCorrStage by reference. More... | |
virtual void | registerDescendant (AutoCorrStage< Data, Product > *ptr) |
Register the creation of a descendant stage. More... | |
template<class Archive > | |
void | serializePrivate (Archive &ar, const unsigned int version) |
Serialize private data members, and descendants. More... | |
Hierarchical auto-correlation function algorithm.
This class calculates an autocorrelation function for a sequence x(i) of values of a variable or object of type Data. The resulting autocorrelation function is and array of values of type Product, where C(j) = <x(i-j), x(i)>. Here <A,B> denotes an inner product of type Product for objects A and B of type Data.
The meaning of the inner product is defined for various data types b the overloaded function Product product(Data, Data) that is defined for double, complex and Vector data in the product.h file.
The zero value for variables of type Data is returned by the overloaded function void setToZero(Data) method defined in the setToData.h file.
This class implements a hierarchical algorithm to calculate C(j). The algorithm is implemented by a linked list of AutoCorrStage objects. Each object in this list is assigned an integer chainId.
The "primary" AutoCorrStage object in this list, with chainId=0, calculates the autocorrelation for a primary sequence of primary Data values that are passed to the sample method of this object. For each n > 0, the object with chainId = n calculates the autocorrelation function for a sequence of values in which each value is an average of a block of blockFactor**n consecutive values of the primary sequence or, equivalently, an average of blockFactor consecutive values of the sequence maintained by the parent object with chainId = n-1. Additional stages are added to this list dynamically as needed.
Definition at line 53 of file AutoCorrStage.h.
Util::AutoCorrStage< Data, Product >::AutoCorrStage |
Constructor.
This constructor creates a primary AutoCorrStage object with stageId = 0 and stageInterval = 1. A private constructor is used to recursively create descendant stages as needed.
Definition at line 30 of file AutoCorrStage.tpp.
References Util::setToZero().
|
virtual |
Destructor.
Recursively destroy all descendant stages.
Definition at line 79 of file AutoCorrStage.tpp.
void Util::AutoCorrStage< Data, Product >::setParam | ( | int | bufferCapacity = 64 , |
int | maxStageId = 0 , |
||
int | blockFactor = 2 |
||
) |
Set all parameters and allocate to initialize state.
bufferCapacity | max. number of values stored in buffer |
maxStageId | maximum stage index (0=primary) |
blockFactor | ratio of block sizes of subsequent stages |
Definition at line 90 of file AutoCorrStage.tpp.
|
virtual |
Sample a value.
value | current Data value |
Definition at line 121 of file AutoCorrStage.tpp.
References Util::product(), and Util::setToZero().
void Util::AutoCorrStage< Data, Product >::clear |
Clear accumulators and destroy descendants.
Definition at line 103 of file AutoCorrStage.tpp.
References Util::setToZero().
Referenced by Util::AutoCorrStage< Data, Product >::allocate().
void Util::AutoCorrStage< Data, Product >::serialize | ( | Archive & | ar, |
const unsigned int | version | ||
) |
Serialize to/from an archive.
ar | archive |
version | archive version id |
Definition at line 168 of file AutoCorrStage.tpp.
void Util::AutoCorrStage< Data, Product >::output | ( | std::ostream & | out | ) |
Output the autocorrelation function, assuming zero mean.
This calls output(std::ostream out, Product aveSq) with a zero value for aveSq.
out | output stream. |
Definition at line 259 of file AutoCorrStage.tpp.
References Util::setToZero().
void Util::AutoCorrStage< Data, Product >::output | ( | std::ostream & | out, |
Product | aveSq | ||
) |
Output the autocorrelation function.
The parameter avSq = ave(x)^2 is subtracted from the correlation function ave(x(t)x(0)).
out | output stream |
aveSq | square of ave(x) |
Definition at line 270 of file AutoCorrStage.tpp.
int Util::AutoCorrStage< Data, Product >::bufferCapacity |
Return capacity of history buffer.
Definition at line 231 of file AutoCorrStage.tpp.
int Util::AutoCorrStage< Data, Product >::bufferSize |
Return current size of history buffer.
Definition at line 238 of file AutoCorrStage.tpp.
Referenced by Util::AutoCorrelation< Data, Product >::maxDelay().
long Util::AutoCorrStage< Data, Product >::nSample |
Return the number of sampled values.
Definition at line 245 of file AutoCorrStage.tpp.
long Util::AutoCorrStage< Data, Product >::stageInterval |
Return the number of primary values per block at this stage.
Definition at line 252 of file AutoCorrStage.tpp.
Referenced by Util::AutoCorrelation< Data, Product >::maxDelay().
Product Util::AutoCorrStage< Data, Product >::autoCorrelation | ( | int | t | ) | const |
Return autocorrelation at a given time, assuming zero average.
This calls autoCorrelations(t, aveSq) with a zero value for for aveSq.
t | the lag time, in Data samples |
Definition at line 296 of file AutoCorrStage.tpp.
References Util::setToZero().
Product Util::AutoCorrStage< Data, Product >::autoCorrelation | ( | int | t, |
Product | aveSq | ||
) | const |
Return autocorrelation at a given lag time.
The parameter aveSq is subtracted from ave(x(t)x(0)) in output.
t | the lag time, in Data samples |
aveSq | square ave(x(t)) |
Definition at line 307 of file AutoCorrStage.tpp.
double Util::AutoCorrStage< Data, Product >::corrTime |
Estimate of autocorrelation time, in samples.
This variant assumes a zero average.
Definition at line 319 of file AutoCorrStage.tpp.
References Util::setToZero().
double Util::AutoCorrStage< Data, Product >::corrTime | ( | Product | aveSq | ) | const |
Numerical integration of autocorrelation function.
This function returns the time integral of the autocorrelation function. The parameter aveSq is subtracted from ave(x(t)x(0)) in the integrand.
aveSq | square ave(x(t)) |
Definition at line 330 of file AutoCorrStage.tpp.
References Util::setToZero().
|
protected |
Allocate memory and initialize to empty state.
Definition at line 357 of file AutoCorrStage.tpp.
References Util::AutoCorrStage< Data, Product >::clear().
|
inlineprotected |
Does this have a child AutoCorrStage?
Definition at line 305 of file AutoCorrStage.h.
|
inlineprotected |
Return the child AutoCorrStage by reference.
Definition at line 312 of file AutoCorrStage.h.
|
protectedvirtual |
Register the creation of a descendant stage.
This should be called only by a root stage.
ptr | pointer to a descendant AutoCorrStage. |
Reimplemented in Util::AutoCorrelation< Data, Product >.
Definition at line 385 of file AutoCorrStage.tpp.
|
protected |
Serialize private data members, and descendants.
ar | archive |
version | archive version id |
Definition at line 186 of file AutoCorrStage.tpp.
|
protected |
Physical capacity (# of elements) of buffer, corr, and nCorr.
Definition at line 193 of file AutoCorrStage.h.
|
protected |
Maximum allowed stage index (controls maximum degree of blocking).
Definition at line 196 of file AutoCorrStage.h.
|
protected |
Number of values per block (ratio of intervals for successive stages).
Definition at line 199 of file AutoCorrStage.h.