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);
346 virtual void set_blocks(
size_t n,
size_t n_blocks,
size_t n_per_block);
354 template<
class vec_t>
void add(vec_t &val) {
359 for(
size_t iv=0;iv<
nvec;iv++) {
361 O2SCL_ERR2(
"Current or 'i' nonzero with full blocks in ",
367 for(
size_t iv=0;iv<
nvec;iv++) {
368 for(
size_t j=0;j<
nblocks/2;j++) {
379 for(
size_t iv=0;iv<
nvec;iv++) {
385 for(
size_t iv=0;iv<
nvec;iv++) {
396 for(
size_t iv=0;iv<
nvec;iv++) {
405 for(
size_t iv=0;iv<
nvec;iv++) {
425 template<
class vec_t,
class vec2_t,
class vec3_t>
427 size_t &m_block,
size_t &m_per_block) {
429 for(
size_t k=0;k<
nvec;k++) {
435 O2SCL_ERR(
"No data in expval_scalar::current_avg_stats().",
459 typedef boost::numeric::ublas::matrix_row<ubmatrix> ubmatrix_row;
460 ubmatrix_row row(
vals,k);
463 avg_err[k]=std_dev[k]/sqrt(((
double)
iblock));
478 template<
class vec_t,
class vec2_t,
class vec3_t>
480 size_t m_per_block, m_block;
487 template<
class vec_t,
class vec2_t,
class vec3_t>
489 vec3_t &avg_err,
size_t &m_per_block)
const {
493 "expval_vector::reblock_avg_stats().",
exc_einval);
497 for(
size_t ii=0;ii<
nvec;ii++) {
498 for(
size_t j=0;j<new_blocks;j++) {
504 size_t fact=
iblock/new_blocks;
507 "in expval_vector::reblock_avg_stats().",
exc_einval);
509 for(
size_t ik=0;ik<
nvec;ik++) {
512 for(
size_t k=0;k<new_blocks;k++) {
513 for(
size_t j=0;j<fact;j++) {
514 dat(ik,k)+=
vals(ik,iblock2);
518 dat(ik,k)/=((double)fact);
521 for(
size_t ik=0;ik<
nvec;ik++) {
522 typedef boost::numeric::ublas::matrix_row<ubmatrix> ubmatrix_row;
523 ubmatrix_row row(dat,ik);
529 avg_err[ik]=std_dev[ik]/sqrt(((
double)new_blocks));
544 template<
class vec_t,
class vec2_t,
class vec3_t>
546 vec2_t &std_dev, vec3_t &avg_err)
const {
557 friend void o2scl_hdf::hdf_output
585 typedef boost::numeric::ublas::vector_slice<ubvector> ubvector_slice;
586 typedef boost::numeric::ublas::slice slice;
611 size_t n_per_block=1);
624 virtual void set_blocks(
size_t rows,
size_t cols,
625 size_t n_blocks,
size_t n_per_block);
633 template<
class mat_t>
void add(mat_t &val) {
638 for(
size_t iv=0;iv<
nr;iv++) {
639 for(
size_t jv=0;jv<
nc;jv++) {
641 O2SCL_ERR2(
"Current or 'i' nonzero with full blocks in ",
648 for(
size_t iv=0;iv<
nr;iv++) {
649 for(
size_t jv=0;jv<
nc;jv++) {
650 for(
size_t j=0;j<
nblocks/2;j++) {
663 for(
size_t iv=0;iv<
nr;iv++) {
664 for(
size_t jv=0;jv<
nc;jv++) {
671 for(
size_t iv=0;iv<
nr;iv++) {
672 for(
size_t jv=0;jv<
nc;jv++) {
684 for(
size_t iv=0;iv<
nr;iv++) {
685 for(
size_t jv=0;jv<
nc;jv++) {
695 for(
size_t iv=0;iv<
nr;iv++) {
696 for(
size_t jv=0;jv<
nc;jv++) {
717 template<
class mat_t,
class mat2_t,
class mat3_t>
719 mat3_t &avg_err,
size_t &m_block,
720 size_t &m_per_block) {
722 for(
size_t j=0;j<
nr;j++) {
723 for(
size_t k=0;k<
nc;k++) {
729 O2SCL_ERR(
"No data in expval_scalar::current_avg_stats().",
765 std::vector<double> col(
iblock);
766 for (
size_t ik=0;ik<
iblock;ik++) {
773 avg_err(j,k)=std_dev(j,k)/sqrt(((
double)iblock));
788 template<
class mat_t,
class mat2_t,
class mat3_t>
790 size_t m_per_block, m_block;
797 template<
class mat_t,
class mat2_t,
class mat3_t>
799 mat2_t &std_dev, mat3_t &avg_err,
800 size_t &m_per_block)
const {
804 "expval_vector::reblock_avg_stats().",
exc_einval);
811 size_t fact=
iblock/new_blocks;
814 "in expval_vector::reblock_avg_stats().",
exc_einval);
816 for(
size_t ik=0;ik<
nr;ik++) {
817 for(
size_t jk=0;jk<
nc;jk++) {
820 for(
size_t k=0;k<new_blocks;k++) {
821 for(
size_t j=0;j<fact;j++) {
826 dat.
get(ik,jk,k)/=((double)fact);
830 for(
size_t ik=0;ik<
nr;ik++) {
831 for(
size_t jk=0;jk<
nc;jk++) {
836 std::vector<double> vec(new_blocks);
837 for (
size_t ii=0;ii<new_blocks;ii++) {
838 vec[ii]=dat.
get(ik,jk,ii);
846 avg_err(ik,jk)=std_dev(ik,jk)/sqrt(((
double)new_blocks));
862 template<
class mat_t,
class mat2_t,
class mat3_t>
864 mat2_t &std_dev, mat3_t &avg_err)
const {
874 friend void o2scl_hdf::hdf_output
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.
virtual void set_blocks(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 free()
Free allocated data (but do not change the current values of n_blocks or n_per_block) ...
virtual void add(double val)
Add measurement of value val.
virtual void current_avg(double &avg, double &std_dev, double &avg_err) const
Report current average, standard deviation, and the error in the average.
Matrix expectation value.
ubvector vals
The average for each block.
std::string name
The name of the expectation value.
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.
size_t nvec
The size of the vector.
void is_valid() const
Internal consistency check.
virtual void set_blocks(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 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...
double & get(size_t ix1, size_t ix2, size_t ix3)
Get the element indexed by (ix1,ix2,ix3)
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...
sanity check failed - shouldn't happen
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)
invalid argument supplied by user
const ubmatrix & get_data() const
Return the current data for all blocks.
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...
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...
Expectation value base class.
size_t i
Index for the number of values in the current block.
void is_valid() const
Internal consistency check.
tensor3 vals
The average for each 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.
ubmatrix vals
The average for each 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 current_avg(mat_t &avg, mat2_t &std_dev, mat3_t &avg_err)
Report current average, standard deviation, and the error in the average.
double vector_stddev(size_t n, const vec_t &data)
Standard deviation with specified mean.
const tensor3 & get_data() const
Return the current data for all blocks.
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.
Vector expectation value.
ubmatrix current
The current rolling average.
void set_all(double x)
Set all elements in a tensor to some fixed value.
size_t nc
The number of columns (zero for an empty expval_matrix object)
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
const ubvector & get_data() const
Return the current data for all blocks.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
expval_vector & operator=(const expval_vector &ev)
Copy constructor.
size_t iblock
Index denoting the current block number.
Scalar expectation value.
size_t nr
The number of rows (zero for an empty expval_matrix object)
const double & operator[](size_t i_block) const
Return the current data for block with index i_block.
virtual void free()
Free allocated data (but do not change the current values of n_blocks or n_per_block) ...
expval_matrix & operator=(const expval_matrix &ev)
Copy constructor.
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 free()
Free allocated data (but do not change the current values of n_blocks or n_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.
size_t nperblock
Number of measurements per block (default 1)
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...
void set_data(vec_t &v)
Set the data for all blocks.
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl...
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...
std::string short_name
The shortened name.
expval_base & operator=(const expval_base &ev)
Copy constructor with operator=()
ubvector current
The current rolling average.
void add(vec_t &val)
Add measurement of value val.
expval_scalar & operator=(const expval_scalar &ev)
Copy constructor.
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...
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...
void add(mat_t &val)
Add measurement of value val.
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
virtual void set_blocks(size_t n_blocks, size_t n_per_block)
Reset for n_blocks blocks and n_per_block points block.
size_t nblocks
Total number of blocks (default 1)
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.
double current
The current rolling average.