QMCPACK
accumulator_set< T, typename > Struct Template Reference

generic accumulator of a scalar type More...

+ Inheritance diagram for accumulator_set< T, typename >:
+ Collaboration diagram for accumulator_set< T, typename >:

Public Types

enum  { VALUE = 0, VALUESQ = 1, WEIGHT = 2, CAPACITY = 4 }
 
using value_type = T
 
using return_type = T
 

Public Member Functions

 accumulator_set ()
 
void operator() (value_type x)
 add a sample More...
 
void operator() (value_type x, value_type w)
 add a sample and More...
 
void reset (value_type v, value_type vv, value_type w)
 reset properties More...
 
void reset (value_type v, value_type w)
 reset properties More...
 
void add (value_type x)
 add a value but set the weight 1 More...
 
bool good () const
 return true if Weight!= 0 More...
 
bool bad () const
 return true if Weight== 0 More...
 
return_type result () const
 return the sum More...
 
return_type result2 () const
 return the sum of value squared More...
 
return_type count () const
 return the count More...
 
std::pair< return_type, return_typemean_and_variance () const
 
return_type mean () const
 return the mean More...
 
return_type mean2 () const
 return the mean of squared values More...
 
return_type variance () const
 
void clear ()
 

Public Attributes

properties [CAPACITY]
 

Detailed Description

template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
struct accumulator_set< T, typename >

generic accumulator of a scalar type

To simplify i/o, the values are storged in contents

Definition at line 32 of file accumulators.h.

Member Typedef Documentation

◆ return_type

using return_type = T

Definition at line 35 of file accumulators.h.

◆ value_type

using value_type = T

Definition at line 34 of file accumulators.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
VALUE 
VALUESQ 
WEIGHT 
CAPACITY 

Definition at line 37 of file accumulators.h.

Constructor & Destructor Documentation

◆ accumulator_set()

accumulator_set ( )
inline

Definition at line 46 of file accumulators.h.

47  {
48  for (int i = 0; i < CAPACITY; ++i)
49  properties[i] = value_type();
50  }
T properties[CAPACITY]
Definition: accumulators.h:44

Member Function Documentation

◆ add()

void add ( value_type  x)
inline

add a value but set the weight 1

Todo:
Jeremy provides the reasonin of having this function. Suggest rename it to make the meaning clear.

Definition at line 95 of file accumulators.h.

◆ bad()

bool bad ( ) const
inline

return true if Weight== 0

Definition at line 105 of file accumulators.h.

Referenced by qmcplusplus::test_real_accumulator_basic().

◆ clear()

◆ count()

◆ good()

bool good ( ) const
inline

◆ mean()

◆ mean2()

return_type mean2 ( ) const
inline

return the mean of squared values

Definition at line 129 of file accumulators.h.

Referenced by qmcplusplus::test_real_accumulator(), qmcplusplus::test_real_accumulator_basic(), and qmcplusplus::test_real_accumulator_weights().

129 { return good() ? properties[VALUESQ] / properties[WEIGHT] : 0.0; }
bool good() const
return true if Weight!= 0
Definition: accumulators.h:103
T properties[CAPACITY]
Definition: accumulators.h:44

◆ mean_and_variance()

std::pair<return_type, return_type> mean_and_variance ( ) const
inline

Definition at line 118 of file accumulators.h.

Referenced by qmcplusplus::test_real_accumulator(), and qmcplusplus::test_real_accumulator_weights().

119  {
120  value_type norm = 1.0 / properties[WEIGHT];
121  value_type avg = properties[VALUE] * norm;
122  return std::pair<return_type, return_type>(avg, norm * properties[VALUESQ] - avg * avg);
123  }
T properties[CAPACITY]
Definition: accumulators.h:44
double norm(const zVec &c)
Definition: VectorOps.h:118

◆ operator()() [1/2]

void operator() ( value_type  x)
inline

add a sample

Definition at line 53 of file accumulators.h.

◆ operator()() [2/2]

void operator() ( value_type  x,
value_type  w 
)
inline

add a sample and

Definition at line 61 of file accumulators.h.

62  {
63  properties[VALUE] += w * x;
64  properties[VALUESQ] += w * x * x;
65  properties[WEIGHT] += w;
66  }
T properties[CAPACITY]
Definition: accumulators.h:44

◆ reset() [1/2]

void reset ( value_type  v,
value_type  vv,
value_type  w 
)
inline

reset properties

Parameters
vcummulative value
vvcummulative valuesq
wcummulative weight

Definition at line 73 of file accumulators.h.

◆ reset() [2/2]

void reset ( value_type  v,
value_type  w 
)
inline

reset properties

Parameters
vcummulative value
wcummulative weight

Definition at line 84 of file accumulators.h.

◆ result()

◆ result2()

return_type result2 ( ) const
inline

return the sum of value squared

Definition at line 111 of file accumulators.h.

Referenced by qmcplusplus::test_real_accumulator(), and qmcplusplus::test_real_accumulator_weights().

111 { return properties[VALUESQ]; }
T properties[CAPACITY]
Definition: accumulators.h:44

◆ variance()

return_type variance ( ) const
inline

Definition at line 131 of file accumulators.h.

Referenced by qmcplusplus::test_real_accumulator(), qmcplusplus::test_real_accumulator_basic(), and qmcplusplus::test_real_accumulator_weights().

132  {
134  return std::numeric_limits<T>::max();
135  value_type norm = 1.0 / properties[WEIGHT];
137  }
T properties[CAPACITY]
Definition: accumulators.h:44
bool iszero(T a)
Definition: math.hpp:77
double norm(const zVec &c)
Definition: VectorOps.h:118

Member Data Documentation

◆ properties


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