![]() |
Object-oriented Scientific Computing Library: Version 0.910
|
Expectation value base class. More...
#include <expect_val.h>
This class is experimental.
This is a base class for a set of classes useful for recording the outputs of several iterations of a numerical simulation, and summarizing the average, standard deviation, and error in the average over all iterations. After each iteration, some measurement is performed, and that measurement is added to the class with an add()
functions (e.g. scalar_ev::add() ). Autocorrelations are common in numerical simulations, and to handle this difficulty the measurements may be demarcated into 'blocks'. These blocks may have a variable or fixed number of measurements in each block.
The constructor needs as input the number of blocks to record (at least one) and the number of measurements per block. The number of measurements per block can be zero to indicate an unspecified number of blocks to record.
If the number of measurements per block is greater than zero, then blocks are filled one by one, moving to the next block when the requested of measurements (n_per_block
) in the previous block has been provided. If the number of measurements per block is zero, then the blocks are filled evenly.
Current averages are always reported, though not all data is always used if there are incomplete blocks or the blocks have not yet been filled evenly. Two functions current_avg()
and current_avg_stats()
are provided in children. The latter provides the number of blocks and number of measurements per block used in the currently reported statistics. If only one block or one measurement is available, the standard deviation is reported as zero. If no data is available, then calls to current_avg()
will call the error handler. See, e.g. scalar_ev::current_avg() and scalar_ev::current_avg_stats().
If n_per_block
is nonzero, then children call the error handler if they get more than n_per_block
times n_blocks
measurements.
n_per_block
is nonzero and the user adds more than n_blocks
times n_per_block
data, set n_per_block
to zero, allocate the last
structure and fall back to the variable block size method. Definition at line 81 of file expect_val.h.
Public Member Functions | |
expect_val () | |
Create with one block of unspecified size. | |
expect_val (const expect_val &ev) | |
Copy constructor. | |
expect_val & | operator= (const expect_val &ev) |
Copy constructor. | |
expect_val (size_t n_blocks, size_t n_per_block) | |
Create with n_blocks blocks and n_per_block points per block. | |
virtual void | set_blocks (size_t n_blocks, size_t n_per_block) |
Reset for n_blocks blocks and n_per_block points per block. | |
virtual void | get_blocks (size_t &n_blocks, size_t &n_per_block) const |
Get the number of blocks and the number of points per block. | |
virtual void | free () |
Free allocated data. | |
virtual void | reset () |
Clear all the data. | |
virtual void | get_block_indices (size_t &i_block, size_t &i_curr_block) const |
Get the block index and the index within the current block. | |
virtual bool | finished () const |
Returns true if all blocks have been stored. | |
virtual double | progress () const |
Report progress as a fraction between zero to one (inclusive) | |
Data Fields | |
std::string | name |
The name of the expectation value. | |
std::string | short_name |
The shortened name. | |
Protected Attributes | |
size_t | iblock |
Index denoting the current block number. | |
size_t | i |
Index for the number of values in the current block (or blocks) | |
size_t | nblocks |
Total number of blocks (default 1) | |
size_t | nperblock |
Number of measurements per block (default 0) |
expect_val::expect_val | ( | size_t | n_blocks, |
size_t | n_per_block | ||
) |
If this is called with a value of zero for n_blocks
, then the error handler is called.
virtual void expect_val::set_blocks | ( | size_t | n_blocks, |
size_t | n_per_block | ||
) | [virtual] |
virtual bool expect_val::finished | ( | ) | const [virtual] |
If n_per_block
is greater than zero, then this reports true only when all n_blocks
times n_per_block
data points have been added.
Otherwise, this reports true whenever the last addition of data filled up the last block.
virtual double expect_val::progress | ( | ) | const [virtual] |
When n_per_block
is zero, this reports the progress in having filled a round of blocks (i.e. whenever the last addition of data filled up the last block). This reports zero if no data has been added.
When n_per_block
is nonzero, this reports the total progress on all blocks, reporting 1.0
only when all n_blocks
times n_per_block
data points have been added.
size_t expect_val::nblocks [protected] |
This should never be zero.
Definition at line 95 of file expect_val.h.
size_t expect_val::nperblock [protected] |
This is zero to indicate blocks of unspecified size
Definition at line 101 of file expect_val.h.
Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).