Go to the documentation of this file.
30 #include <boost/numeric/ublas/vector.hpp>
31 #include <boost/numeric/ublas/vector_proxy.hpp>
32 #include <boost/numeric/ublas/matrix.hpp>
33 #include <boost/numeric/ublas/matrix_proxy.hpp>
35 #include <o2scl/vec_stats.h>
36 #include <o2scl/tensor.h>
56 #ifndef DOXYGEN_NO_O2NS
104 expval_base(
size_t n_blocks=1,
size_t n_per_block=1);
127 virtual void set_blocks(
size_t n_blocks,
size_t n_per_block);
132 virtual void get_blocks(
size_t &n_blocks,
size_t &n_per_block)
const;
142 size_t &i_curr_block)
const;
166 O2SCL_ERR2(
"Either 'nblocks' or 'n_per_block' is zero in ",
216 virtual void set_blocks(
size_t n_blocks,
size_t n_per_block);
224 virtual void add(
double val);
232 double &avg_err,
size_t &m_block,
233 size_t &m_per_block)
const;
238 virtual void current_avg(
double &avg,
double &std_dev,
239 double &avg_err)
const;
248 double &std_dev,
double &avg_err,
249 size_t &m_per_block)
const;
254 virtual void reblock_avg(
size_t new_blocks,
double &avg,
255 double &std_dev,
double &avg_err)
const;
264 const double &
operator[](
size_t i_block)
const;
271 for(
size_t ib=0;ib<
nblocks;ib++) {
333 expval_vector(
size_t n,
size_t n_blocks=1,
size_t n_per_block=1);
351 virtual void set_blocks_vec(
size_t n,
size_t n_blocks,
size_t n_per_block);
359 template<
class vec_t>
void add(vec_t &val) {
364 for(
size_t iv=0;iv<
nvec;iv++) {
366 O2SCL_ERR2(
"Current or 'i' nonzero with full blocks in ",
372 for(
size_t iv=0;iv<
nvec;iv++) {
373 for(
size_t j=0;j<
nblocks/2;j++) {
384 for(
size_t iv=0;iv<
nvec;iv++) {
390 for(
size_t iv=0;iv<
nvec;iv++) {
401 for(
size_t iv=0;iv<
nvec;iv++) {
410 for(
size_t iv=0;iv<
nvec;iv++) {
430 template<
class vec_t,
class vec2_t,
class vec3_t>
432 size_t &m_block,
size_t &m_per_block) {
434 for(
size_t k=0;k<
nvec;k++) {
440 O2SCL_ERR(
"No data in expval_scalar::current_avg_stats().",
464 typedef boost::numeric::ublas::matrix_row<ubmatrix> ubmatrix_row;
465 ubmatrix_row row(
vals,k);
468 avg_err[k]=std_dev[k]/sqrt(((
double)
iblock));
483 template<
class vec_t,
class vec2_t,
class vec3_t>
485 size_t m_per_block, m_block;
492 template<
class vec_t,
class vec2_t,
class vec3_t>
494 vec3_t &avg_err,
size_t &m_per_block)
const {
498 "expval_vector::reblock_avg_stats().",
exc_einval);
502 for(
size_t ii=0;ii<
nvec;ii++) {
503 for(
size_t j=0;j<new_blocks;j++) {
509 size_t fact=
iblock/new_blocks;
512 "in expval_vector::reblock_avg_stats().",
exc_einval);
514 for(
size_t ik=0;ik<
nvec;ik++) {
517 for(
size_t k=0;k<new_blocks;k++) {
518 for(
size_t j=0;j<fact;j++) {
519 dat(ik,k)+=
vals(ik,iblock2);
523 dat(ik,k)/=((double)fact);
526 for(
size_t ik=0;ik<
nvec;ik++) {
527 typedef boost::numeric::ublas::matrix_row<ubmatrix> ubmatrix_row;
528 ubmatrix_row row(dat,ik);
534 avg_err[ik]=std_dev[ik]/sqrt(((
double)new_blocks));
549 template<
class vec_t,
class vec2_t,
class vec3_t>
551 vec2_t &std_dev, vec3_t &avg_err)
const {
562 friend void o2scl_hdf::hdf_output
590 typedef boost::numeric::ublas::vector_slice<ubvector> ubvector_slice;
591 typedef boost::numeric::ublas::slice slice;
616 size_t n_per_block=1);
635 size_t n_blocks,
size_t n_per_block);
643 template<
class mat_t>
void add(mat_t &val) {
648 for(
size_t iv=0;iv<
nr;iv++) {
649 for(
size_t jv=0;jv<
nc;jv++) {
651 O2SCL_ERR2(
"Current or 'i' nonzero with full blocks in ",
658 for(
size_t iv=0;iv<
nr;iv++) {
659 for(
size_t jv=0;jv<
nc;jv++) {
660 for(
size_t j=0;j<
nblocks/2;j++) {
673 for(
size_t iv=0;iv<
nr;iv++) {
674 for(
size_t jv=0;jv<
nc;jv++) {
681 for(
size_t iv=0;iv<
nr;iv++) {
682 for(
size_t jv=0;jv<
nc;jv++) {
694 for(
size_t iv=0;iv<
nr;iv++) {
695 for(
size_t jv=0;jv<
nc;jv++) {
705 for(
size_t iv=0;iv<
nr;iv++) {
706 for(
size_t jv=0;jv<
nc;jv++) {
727 template<
class mat_t,
class mat2_t,
class mat3_t>
729 mat3_t &avg_err,
size_t &m_block,
730 size_t &m_per_block) {
732 for(
size_t j=0;j<
nr;j++) {
733 for(
size_t k=0;k<
nc;k++) {
739 O2SCL_ERR(
"No data in expval_scalar::current_avg_stats().",
775 std::vector<double> col(
iblock);
776 for (
size_t ik=0;ik<
iblock;ik++) {
783 avg_err(j,k)=std_dev(j,k)/sqrt(((
double)
iblock));
798 template<
class mat_t,
class mat2_t,
class mat3_t>
800 size_t m_per_block, m_block;
807 template<
class mat_t,
class mat2_t,
class mat3_t>
809 mat2_t &std_dev, mat3_t &avg_err,
810 size_t &m_per_block)
const {
814 "expval_vector::reblock_avg_stats().",
exc_einval);
821 size_t fact=
iblock/new_blocks;
824 "in expval_vector::reblock_avg_stats().",
exc_einval);
826 for(
size_t ik=0;ik<
nr;ik++) {
827 for(
size_t jk=0;jk<
nc;jk++) {
830 for(
size_t k=0;k<new_blocks;k++) {
831 for(
size_t j=0;j<fact;j++) {
836 dat.
get(ik,jk,k)/=((double)fact);
840 for(
size_t ik=0;ik<
nr;ik++) {
841 for(
size_t jk=0;jk<
nc;jk++) {
846 std::vector<double> vec(new_blocks);
847 for (
size_t ii=0;ii<new_blocks;ii++) {
848 vec[ii]=dat.
get(ik,jk,ii);
856 avg_err(ik,jk)=std_dev(ik,jk)/sqrt(((
double)new_blocks));
872 template<
class mat_t,
class mat2_t,
class mat3_t>
874 mat2_t &std_dev, mat3_t &avg_err)
const {
884 friend void o2scl_hdf::hdf_output
ubvector vals
The average for each block.
virtual void set_blocks_mat(size_t rows, size_t cols, size_t n_blocks, size_t n_per_block)
Set for a matrix with n_blocks blocks and n_per_block points block.
virtual void set_blocks_vec(size_t n, size_t n_blocks, size_t n_per_block)
Set for a vector of size n with n_blocks blocks and n_per_block points block.
void current_avg_stats(mat_t &avg, mat2_t &std_dev, mat3_t &avg_err, size_t &m_block, size_t &m_per_block)
Report current average, standard deviation, and the error in the average and include block informatio...
virtual void set_blocks(size_t n_blocks, size_t n_per_block)
Reset for n_blocks blocks and n_per_block points block.
const tensor3< double > & get_data() const
Return the current data for all blocks.
size_t nc
The number of columns (zero for an empty expval_matrix object)
ubmatrix current
The current rolling average.
size_t i
Index for the number of values in the current block.
@ exc_efailed
generic failure
void set_data(vec_t &v)
Set the data for all blocks.
size_t nr
The number of rows (zero for an empty expval_matrix object)
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
std::string name
The name of the expectation value.
Expectation value base class.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
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.
ubmatrix vals
The average for each block.
virtual void free()
Free allocated data (but do not change the current values of n_blocks or n_per_block)
double vector_mean(size_t n, const vec_t &data)
Compute the mean of the first n elements of a vector.
const double & operator[](size_t i_block) const
Return the current data for block with index i_block.
void reblock_avg_stats(size_t new_blocks, mat_t &avg, mat2_t &std_dev, mat3_t &avg_err, size_t &m_per_block) const
Report average, standard deviation, and the error in the average assuming a new block size.
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
void reblock_avg_stats(size_t new_blocks, vec_t &avg, vec2_t &std_dev, vec3_t &avg_err, size_t &m_per_block) const
Report average, standard deviation, and the error in the average assuming a new block size.
Scalar expectation value.
double current
The current rolling average.
void current_avg_stats(vec_t &avg, vec2_t &std_dev, vec3_t &avg_err, size_t &m_block, size_t &m_per_block)
Report current average, standard deviation, and the error in the average and include block informatio...
void is_valid() const
Internal consistency check.
virtual void free()
Free allocated data (but do not change the current values of n_blocks or n_per_block)
void current_avg(mat_t &avg, mat2_t &std_dev, mat3_t &avg_err)
Report current average, standard deviation, and the error in the average.
virtual void free()
Free allocated data (but do not change the current values of n_blocks or n_per_block)
double vector_stddev(size_t n, const vec_t &data)
Standard deviation with specified mean.
virtual void current_avg(double &avg, double &std_dev, double &avg_err) const
Report current average, standard deviation, and the error in the average.
size_t nblocks
Total number of blocks (default 1)
virtual double progress() const
Report progress as a fraction between zero to one (inclusive)
expval_matrix & operator=(const expval_matrix &ev)
Copy constructor.
void reblock_avg(size_t new_blocks, mat_t &avg, mat2_t &std_dev, mat3_t &avg_err) const
Report average, standard deviation, and the error in the average assuming a new block size.
virtual void current_avg_stats(double &avg, double &std_dev, double &avg_err, size_t &m_block, size_t &m_per_block) const
Report current average, standard deviation, and the error in the average and include block informatio...
@ exc_einval
invalid argument supplied by user
void is_valid() const
Internal consistency check.
data_t & get(size_t ix1, size_t ix2, size_t ix3)
Get the element indexed by (ix1,ix2,ix3)
const ubvector & get_data() const
Return the current data for all blocks.
void add(mat_t &val)
Add measurement of value val.
expval_base(size_t n_blocks=1, size_t n_per_block=1)
Create with n_blocks blocks and n_per_block points per block.
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.
expval_vector & operator=(const expval_vector &ev)
Copy constructor.
Vector expectation value.
Matrix expectation value.
void reblock_avg(size_t new_blocks, vec_t &avg, vec2_t &std_dev, vec3_t &avg_err) const
Report average, standard deviation, and the error in the average assuming a new block size.
The O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl namespace ...
size_t iblock
Index denoting the current block number.
expval_scalar & operator=(const expval_scalar &ev)
Copy constructor.
virtual void reblock_avg(size_t new_blocks, double &avg, double &std_dev, double &avg_err) const
Report average, standard deviation, and the error in the average assuming a new block size.
size_t nperblock
Number of measurements per block (default 1)
std::string short_name
The shortened name.
virtual void add(double val)
Add measurement of value val.
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
expval_base & operator=(const expval_base &ev)
Copy constructor with operator=()
@ exc_esanity
sanity check failed - shouldn't happen
void add(vec_t &val)
Add measurement of value val.
virtual void reblock_avg_stats(size_t new_blocks, double &avg, double &std_dev, double &avg_err, size_t &m_per_block) const
Report average, standard deviation, and the error in the average assuming a new block size.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
const ubmatrix & get_data() const
Return the current data for all blocks.
size_t nvec
The size of the vector.
tensor3 vals
The average for each 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.
expval_scalar(size_t n_blocks=1, size_t n_per_block=1)
Create with n_blocks blocks and n_per_block points block.
ubvector current
The current rolling average.
virtual bool finished() const
Returns true if all blocks have been stored.
void current_avg(vec_t &avg, vec2_t &std_dev, vec3_t &avg_err)
Report current average, standard deviation, and the error in the average.
virtual void free()
Free allocated data (but do not change the current values of n_blocks or n_per_block)
void set_all(double x)
Set all elements in a tensor to some fixed value.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).