QMCPACK
SizeLimitedDataQueue< T, NUM_FIELDS > Class Template Reference

collect data with a history limit. More...

+ Inheritance diagram for SizeLimitedDataQueue< T, NUM_FIELDS >:
+ Collaboration diagram for SizeLimitedDataQueue< T, NUM_FIELDS >:

Classes

struct  HistoryElement
 

Public Types

using value_type = HistoryElement
 

Public Member Functions

 SizeLimitedDataQueue (size_t size_limit)
 
void push (const value_type &val)
 add a new record More...
 
void push (value_type &&val)
 add a new record More...
 
auto weighted_avg () const
 return weighted average More...
 
auto size () const
 return the number of records More...
 

Private Attributes

std::deque< value_typedata
 
const size_t size_limit_
 

Detailed Description

template<typename T, size_t NUM_FIELDS>
class qmcplusplus::SizeLimitedDataQueue< T, NUM_FIELDS >

collect data with a history limit.

data stored in std::deque<std::array<T, NUM_FIELDS>>

Definition at line 26 of file SizeLimitedDataQueue.hpp.


Class Documentation

◆ qmcplusplus::SizeLimitedDataQueue::HistoryElement

struct qmcplusplus::SizeLimitedDataQueue::HistoryElement

template<typename T, size_t NUM_FIELDS>
struct qmcplusplus::SizeLimitedDataQueue< T, NUM_FIELDS >::HistoryElement

Definition at line 29 of file SizeLimitedDataQueue.hpp.

+ Collaboration diagram for SizeLimitedDataQueue< T, NUM_FIELDS >::HistoryElement:
Class Members
array< T, NUM_FIELDS > properties
T weight

Member Typedef Documentation

◆ value_type

Definition at line 35 of file SizeLimitedDataQueue.hpp.

Constructor & Destructor Documentation

◆ SizeLimitedDataQueue()

SizeLimitedDataQueue ( size_t  size_limit)
inline

Definition at line 37 of file SizeLimitedDataQueue.hpp.

37 : size_limit_(size_limit) {}

Member Function Documentation

◆ push() [1/2]

void push ( const value_type val)
inline

add a new record

Definition at line 40 of file SizeLimitedDataQueue.hpp.

Referenced by DMCRefEnergy::pushWeightEnergyVariance(), and qmcplusplus::TEST_CASE().

41  {
42  if (data.size() == size_limit_)
43  data.pop_front();
44  assert(data.size() < size_limit_);
45  data.push_back(val);
46  }

◆ push() [2/2]

void push ( value_type &&  val)
inline

add a new record

Definition at line 49 of file SizeLimitedDataQueue.hpp.

50  {
51  if (data.size() == size_limit_)
52  data.pop_front();
53  assert(data.size() < size_limit_);
54  data.push_back(val);
55  }

◆ size()

auto size ( void  ) const
inline

return the number of records

Definition at line 75 of file SizeLimitedDataQueue.hpp.

Referenced by DMCRefEnergy::count(), and qmcplusplus::TEST_CASE().

75 { return data.size(); }

◆ weighted_avg()

auto weighted_avg ( ) const
inline

return weighted average

Definition at line 58 of file SizeLimitedDataQueue.hpp.

Referenced by DMCRefEnergy::getEnergyVariance(), and qmcplusplus::TEST_CASE().

59  {
60  std::array<T, NUM_FIELDS> avg;
61  std::fill(avg.begin(), avg.end(), T(0));
62  T weight_sum = 0;
63  for (auto& element : data)
64  {
65  weight_sum += element.weight;
66  for (size_t i = 0; i < NUM_FIELDS; i++)
67  avg[i] += element.properties[i] * element.weight;
68  }
69  for (size_t i = 0; i < NUM_FIELDS; i++)
70  avg[i] /= weight_sum;
71  return avg;
72  }

Member Data Documentation

◆ data

◆ size_limit_

const size_t size_limit_
private

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