PSCF v1.1
Public Member Functions | List of all members
Util::AutoCorrStage< Data, Product > Class Template Reference

Hierarchical auto-correlation function algorithm. More...

#include <AutoCorrStage.h>

Inheritance diagram for Util::AutoCorrStage< Data, Product >:
Util::AutoCorrelation< Data, Product >

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...
 
AutoCorrStagechild ()
 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...
 

Detailed Description

template<typename Data, typename Product>
class Util::AutoCorrStage< Data, Product >

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.

Constructor & Destructor Documentation

◆ AutoCorrStage()

template<typename Data , typename Product >
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().

◆ ~AutoCorrStage()

template<typename Data , typename Product >
Util::AutoCorrStage< Data, Product >::~AutoCorrStage
virtual

Destructor.

Recursively destroy all descendant stages.

Definition at line 79 of file AutoCorrStage.tpp.

Member Function Documentation

◆ setParam()

template<typename Data , typename Product >
void Util::AutoCorrStage< Data, Product >::setParam ( int  bufferCapacity = 64,
int  maxStageId = 0,
int  blockFactor = 2 
)

Set all parameters and allocate to initialize state.

Parameters
bufferCapacitymax. number of values stored in buffer
maxStageIdmaximum stage index (0=primary)
blockFactorratio of block sizes of subsequent stages

Definition at line 90 of file AutoCorrStage.tpp.

◆ sample()

template<typename Data , typename Product >
void Util::AutoCorrStage< Data, Product >::sample ( Data  value)
virtual

Sample a value.

Parameters
valuecurrent Data value

Definition at line 121 of file AutoCorrStage.tpp.

References Util::product(), and Util::setToZero().

◆ clear()

template<typename Data , typename Product >
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().

◆ serialize()

template<typename Data , typename Product >
template<class Archive >
void Util::AutoCorrStage< Data, Product >::serialize ( Archive &  ar,
const unsigned int  version 
)

Serialize to/from an archive.

Parameters
ararchive
versionarchive version id

Definition at line 168 of file AutoCorrStage.tpp.

◆ output() [1/2]

template<typename Data , typename Product >
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.

Parameters
outoutput stream.

Definition at line 259 of file AutoCorrStage.tpp.

References Util::setToZero().

◆ output() [2/2]

template<typename Data , typename Product >
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)).

Parameters
outoutput stream
aveSqsquare of ave(x)

Definition at line 270 of file AutoCorrStage.tpp.

◆ bufferCapacity()

template<typename Data , typename Product >
int Util::AutoCorrStage< Data, Product >::bufferCapacity

Return capacity of history buffer.

Definition at line 231 of file AutoCorrStage.tpp.

◆ bufferSize()

template<typename Data , typename Product >
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().

◆ nSample()

template<typename Data , typename Product >
long Util::AutoCorrStage< Data, Product >::nSample

Return the number of sampled values.

Definition at line 245 of file AutoCorrStage.tpp.

◆ stageInterval()

template<typename Data , typename Product >
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().

◆ autoCorrelation() [1/2]

template<typename Data , typename Product >
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.

Parameters
tthe lag time, in Data samples

Definition at line 296 of file AutoCorrStage.tpp.

References Util::setToZero().

◆ autoCorrelation() [2/2]

template<typename Data , typename Product >
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.

Parameters
tthe lag time, in Data samples
aveSqsquare ave(x(t))

Definition at line 307 of file AutoCorrStage.tpp.

◆ corrTime() [1/2]

template<typename Data , typename Product >
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().

◆ corrTime() [2/2]

template<typename Data , typename Product >
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.

Parameters
aveSqsquare ave(x(t))

Definition at line 330 of file AutoCorrStage.tpp.

References Util::setToZero().

◆ allocate()

template<typename Data , typename Product >
void Util::AutoCorrStage< Data, Product >::allocate
protected

Allocate memory and initialize to empty state.

Definition at line 357 of file AutoCorrStage.tpp.

References Util::AutoCorrStage< Data, Product >::clear().

◆ hasChild()

template<typename Data , typename Product >
bool Util::AutoCorrStage< Data, Product >::hasChild
inlineprotected

Does this have a child AutoCorrStage?

Definition at line 305 of file AutoCorrStage.h.

◆ child()

template<typename Data , typename Product >
AutoCorrStage< Data, Product > & Util::AutoCorrStage< Data, Product >::child
inlineprotected

Return the child AutoCorrStage by reference.

Definition at line 312 of file AutoCorrStage.h.

◆ registerDescendant()

template<typename Data , typename Product >
void Util::AutoCorrStage< Data, Product >::registerDescendant ( AutoCorrStage< Data, Product > *  ptr)
protectedvirtual

Register the creation of a descendant stage.

This should be called only by a root stage.

Parameters
ptrpointer to a descendant AutoCorrStage.

Reimplemented in Util::AutoCorrelation< Data, Product >.

Definition at line 385 of file AutoCorrStage.tpp.

◆ serializePrivate()

template<typename Data , typename Product >
template<class Archive >
void Util::AutoCorrStage< Data, Product >::serializePrivate ( Archive &  ar,
const unsigned int  version 
)
protected

Serialize private data members, and descendants.

Parameters
ararchive
versionarchive version id

Definition at line 186 of file AutoCorrStage.tpp.

Member Data Documentation

◆ bufferCapacity_

template<typename Data , typename Product >
int Util::AutoCorrStage< Data, Product >::bufferCapacity_
protected

Physical capacity (# of elements) of buffer, corr, and nCorr.

Definition at line 193 of file AutoCorrStage.h.

◆ maxStageId_

template<typename Data , typename Product >
int Util::AutoCorrStage< Data, Product >::maxStageId_
protected

Maximum allowed stage index (controls maximum degree of blocking).

Definition at line 196 of file AutoCorrStage.h.

◆ blockFactor_

template<typename Data , typename Product >
int Util::AutoCorrStage< Data, Product >::blockFactor_
protected

Number of values per block (ratio of intervals for successive stages).

Definition at line 199 of file AutoCorrStage.h.


The documentation for this class was generated from the following files: