Gromacs
2024.1

#include <gromacs/analysisdata/modules/frameaverager.h>
Helper class for modules that average values over frames.
This class implements common functionality for analysis data modules that need to average a set of values over frames. Currently, it is designed for computing averages for each input column independently, but should be relatively easy to make more general if required.
This class takes care of accumulating the values and computing their variance. It allows different number of samples for each input column. Accumulation is always in double precision and uses a formula that is relatively stable numerically. For now, does nothing fancy, but provides ground for other implementation (e.g., related to parallelization) that would benefit all such modules.
Methods in this class do not throw unless otherwise indicated.
Public Member Functions  
int  columnCount () const 
Returns the number of columns in this averager.  
void  setColumnCount (int columnCount) 
Sets the number of columns in the input data. More...  
void  addValue (int index, real value) 
Adds a single value to the average for a given column. More...  
void  addPoints (const AnalysisDataPointSetRef &points) 
Accumulates data from a given point set into the average. More...  
void  finish () 
Finalizes the calculation of the averages and variances. More...  
real  average (int index) const 
Returns the computed average for a given column. More...  
real  variance (int index) const 
Returns the computed (sample) variance for a given column. More...  
int  sampleCount (int index) const 
Returns the number of samples for a given column. More...  
void gmx::AnalysisDataFrameAverager::addPoints  (  const AnalysisDataPointSetRef &  points  ) 
Accumulates data from a given point set into the average.
Typically called from IAnalysisDataModule::pointsAdded().
Each call accumulates the values for those columns that are present in the point set. Can be called multiple times for a frame, and does not need to be called for every frame.
void gmx::AnalysisDataFrameAverager::addValue  (  int  index, 
real  value  
) 
Adds a single value to the average for a given column.
[in]  index  Index of the column to add the value to. 
[in]  value  Value to add to the sample. 

inline 
Returns the computed average for a given column.
If called before finish(), the results are undefined.
void gmx::AnalysisDataFrameAverager::finish  (  ) 
Finalizes the calculation of the averages and variances.
Does any computation that is not done during the accumulation in addPoints(). Currently, does nothing, but provided as a placeholder for more complex implementation.
Typically called from IAnalysisDataModule::dataFinished().

inline 
Returns the number of samples for a given column.
If called before finish(), the results are undefined.
void gmx::AnalysisDataFrameAverager::setColumnCount  (  int  columnCount  ) 
Sets the number of columns in the input data.
std::bad_alloc  if out of memory. 
Typically called from IAnalysisDataModule::dataStarted().
Must be called exactly once, before setting calling any other method in the class.

inline 
Returns the computed (sample) variance for a given column.
If called before finish(), the results are undefined.