Path Integral Quantum Monte Carlo
Public Member Functions | Protected Member Functions | Protected Attributes
EstimatorBase Class Reference

The base class that all estimator classes will be derived from. More...

#include <estimator.h>

+ Inheritance diagram for EstimatorBase:
+ Collaboration diagram for EstimatorBase:

Public Member Functions

 EstimatorBase (const Path &_path, ActionBase *_actionPtr, const MTRand &_random, double _maxR, int _frequency=1, string _label="")
 Constructor. More...
 
virtual ~EstimatorBase ()
 Destructor.
 
virtual void sample ()
 Sample the estimator. More...
 
void reset ()
 Reset numAccumulated and the estimator to 0.
 
void restart (const uint32, const uint32)
 Restart the measurment process from a previous state.
 
virtual void output ()
 Output the estimator value to disk. More...
 
virtual void outputFlat ()
 Output a flat estimator value to disk. More...
 
virtual void outputFooter ()
 Ouptut the fooder to disk.
 
bool baseSample ()
 Determine the basic sampling condition. More...
 
uint32 getTotNumAccumulated () const
 Get the total number of accumulated measurments.
 
uint32 getNumAccumulated () const
 Get the number of accumulated measurements since the last reset.
 
uint32 getNumSampled () const
 Get the number of samples since the last reset.
 
virtual string getName () const
 Get the name of the estimator.
 
void prepare ()
 Prepare the estimator for i/o. More...
 
void addEndLine ()
 Add a carriage return to estimator files.
 
void appendLabel (string append)
 Append to default label. More...
 
string getLabel () const
 Get the estimator label.
 

Protected Member Functions

virtual void accumulate ()
 Accumulate the estimator.
 
void initialize (int)
 Initialize estimator. More...
 
void initialize (vector< string >)
 Initialize estimator. More...
 

Protected Attributes

const Pathpath
 A constant reference to the paths.
 
ActionBaseactionPtr
 A pointer to the action.
 
MTRand random
 
double maxR
 
fstream * outFilePtr
 The output fie.
 
map< string, int > estIndex
 Map estimator labels to indices.
 
Array< double, 1 > estimator
 The estimator array.
 
Array< double, 1 > norm
 The normalization factor for each estimator.
 
int numEst
 The number of individual quantities measured.
 
int frequency
 The frequency at which we accumulate.
 
int startSlice
 Where imaginary time averages begin.
 
int endSlice
 Where imaginary time averages end.
 
int endDiagSlice
 Where imaginary time averages end for diagonal estimiators.
 
vector< double > sliceFactor
 Used to properly incorporate end affects.
 
string label
 The label used for the output file.
 
uint32 numSampled
 The number of times we have sampled.
 
uint32 numAccumulated
 The number of accumulated values.
 
uint32 totNumAccumulated
 The total number of accumulated values.
 
int numBeads0
 The target number of beads for the canonical ensemble.
 
bool diagonal
 Is this a diagonal estimator?
 
bool endLine
 Should we output a carriage return?
 
bool canonical
 Are we in the canonical ensemble?
 
string header
 The data file header.
 

Detailed Description

The base class that all estimator classes will be derived from.

Contains the common elements of all estimators, including the ability to initialize, accumulate, output and reset. We assume a default measurment frequency of every time.

Definition at line 28 of file estimator.h.

Constructor & Destructor Documentation

◆ EstimatorBase()

EstimatorBase::EstimatorBase ( const Path _path,
ActionBase _actionPtr,
const MTRand &  _random,
double  _maxR,
int  _frequency = 1,
string  _label = "" 
)

Constructor.

Initialize and specify the output file.

We take in some options that might only be needed by derived classes (_actionPtr, _random, _maxR) in order to facilitate instantiation via a factory.

Definition at line 103 of file estimator.cpp.

104  :
105  path(_path),
106  actionPtr(_actionPtr),
107  random(_random),
108  maxR(_maxR),
109  frequency(_frequency),
110  label(_label),
111  numSampled(0),
112  numAccumulated(0),
114  diagonal(true),
115  endLine(true)
116 {
117  /* Two handy local constants */
120 
121  /* A normalization factor for time slices used in estimators */
122  sliceFactor.resize(constants()->numTimeSlices(),1.0);
123 
124  /* The slices over which we average quantities PIGS vs. PIMC */
125 #if PIGS
126  int midSlice = (path.numTimeSlices-1)/2;
127  startSlice = midSlice - actionPtr->period;
128  endSlice = midSlice + actionPtr->period;
130 
131  if(actionPtr->local) {
132  endDiagSlice = endSlice + 1;
133  sliceFactor[startSlice] = 0.5;
134  sliceFactor[endSlice] = 0.5;
135  }
136 #else
137  startSlice = 0;
140 #endif
141 }
const bool local
Is the action local in imaginary time?
Definition: action.h:103
int numTimeSlices()
Get number of time slices.
Definition: constants.h:99
bool canonical() const
Get ensemble.
Definition: constants.h:89
int initialNumParticles()
Get initial number of particles.
Definition: constants.h:100
int endSlice
Where imaginary time averages end.
Definition: estimator.h:96
bool diagonal
Is this a diagonal estimator?
Definition: estimator.h:106
ActionBase * actionPtr
A pointer to the action.
Definition: estimator.h:82
bool canonical
Are we in the canonical ensemble?
Definition: estimator.h:108
int endDiagSlice
Where imaginary time averages end for diagonal estimiators.
Definition: estimator.h:97
vector< double > sliceFactor
Used to properly incorporate end affects.
Definition: estimator.h:98
bool endLine
Should we output a carriage return?
Definition: estimator.h:107
int startSlice
Where imaginary time averages begin.
Definition: estimator.h:95
int frequency
The frequency at which we accumulate.
Definition: estimator.h:94
uint32 totNumAccumulated
The total number of accumulated values.
Definition: estimator.h:103
uint32 numSampled
The number of times we have sampled.
Definition: estimator.h:101
uint32 numAccumulated
The number of accumulated values.
Definition: estimator.h:102
const Path & path
A constant reference to the paths.
Definition: estimator.h:78
int numBeads0
The target number of beads for the canonical ensemble.
Definition: estimator.h:104
string label
The label used for the output file.
Definition: estimator.h:99
const int numTimeSlices
A local constant copy of the number of time slices.
Definition: path.h:37
ConstantParameters * constants()
Global public access to the constants.
Definition: constants.h:201
+ Here is the call graph for this function:

Member Function Documentation

◆ appendLabel()

void EstimatorBase::appendLabel ( string  append)

Append to default label.

AppendLabel.

Definition at line 325 of file estimator.cpp.

325  {
326  label = label + append;
327 }

◆ baseSample()

bool EstimatorBase::baseSample ( )

Determine the basic sampling condition.

We only sample when: 1) frequency > 0 2) numSampled is a even factor of frequency 3) The configuration (diagonal/off diagonal) matches the estimator type. 4) If we are canonical, then only when we match the desired number of particles

Definition at line 161 of file estimator.cpp.

161  {
162 
163  /* Increment the number of attempted samplings */
164  numSampled++;
165 
166  if (!frequency)
167  return false;
168  if ((numSampled % frequency) != 0)
169  return false;
171  return false;
172  if (!canonical)
173  return true;
174  if (path.worm.getNumBeadsOn() == numBeads0)
175  return true;
176 
177  return false;
178 }
Worm worm
Details on the worm.
Definition: path.h:44
bool isConfigDiagonal
Stores the diagonality of the configuration.
Definition: worm.h:39
int getNumBeadsOn() const
Return the number of active beads.
Definition: worm.h:88
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initialize() [1/2]

void EstimatorBase::initialize ( int  _numEst)
protected

Initialize estimator.

Initilize the estimator and normalization arrays.

Definition at line 201 of file estimator.cpp.

201  {
202 
203  numEst = _numEst;
204  estimator.resize(numEst);
205  norm.resize(numEst);
206  norm = 1.0;
207  reset();
208 }
void reset()
Reset numAccumulated and the estimator to 0.
Definition: estimator.cpp:261
Array< double, 1 > estimator
The estimator array.
Definition: estimator.h:90
Array< double, 1 > norm
The normalization factor for each estimator.
Definition: estimator.h:91
int numEst
The number of individual quantities measured.
Definition: estimator.h:93
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initialize() [2/2]

void EstimatorBase::initialize ( vector< string >  estLabel)
protected

Initialize estimator.

Initilize the estimator and normalization arrays.

Definition at line 215 of file estimator.cpp.

215  {
216 
217  /* Initialize the map linking names to indices */
218  for(size_t i = 0; i < estLabel.size(); ++i)
219  estIndex[estLabel[i]] = i;
220 
221  /* write the header string */
222  estLabel.front() = str(format("#%15s") % estLabel.front());
223  header = "";
224  for (const auto& label : estLabel)
225  header += str(format("%16s") % label);
226 
227  numEst = estLabel.size();
228  estimator.resize(numEst);
229  norm.resize(numEst);
230  norm = 1.0;
231  reset();
232 }
string header
The data file header.
Definition: estimator.h:110
map< string, int > estIndex
Map estimator labels to indices.
Definition: estimator.h:88
+ Here is the call graph for this function:

◆ output()

void EstimatorBase::output ( )
virtual

Output the estimator value to disk.


We only attempt an output if we have accumulated at least numBins measurements. This works because the final 'scalar' estimator is the diagonal estimator which gets measured for both diaagonal and off diagonal configurations.

Reimplemented in LocalPermutationEstimator, LocalSuperfluidDensityEstimator, PlaneAverageExternalPotentialEstimator, PlaneParticleAveragePositionEstimator, ParticlePositionEstimator, and TimeEstimator.

Definition at line 283 of file estimator.cpp.

283  {
284 
285  /* Average */
286  estimator *= (norm/(1.0*numAccumulated));
287 
288  /* Now write the estimator values to disk */
289  for (int n = 0; n < numEst; n++)
290  (*outFilePtr) << format("%16.8E") % estimator(n);
291 
292  if (endLine)
293  (*outFilePtr) << endl;
294 
295  /* Reset all values */
296  reset();
297 }
fstream * outFilePtr
The output fie.
Definition: estimator.h:86
+ Here is the call graph for this function:

◆ outputFlat()

void EstimatorBase::outputFlat ( )
virtual

Output a flat estimator value to disk.

Instead of keeping the individual binned averages, here we reset the output file and write the current average to disk.

Definition at line 305 of file estimator.cpp.

305  {
306 
307  /* Prepare the position file for writing over old data */
308  communicate()->file(label)->reset();
309 
310  (*outFilePtr) << header;
311  if (endLine)
312  (*outFilePtr) << endl;
313 
314  /* Now write the running average of the estimator to disk */
315  for (int n = 0; n < numEst; n++)
316  (*outFilePtr) << format("%16.8E\n") %
318 
319  communicate()->file(label)->rename();
320 }
File * file(string type)
Get method returning file object.
Definition: communicator.h:85
void reset()
Reset a file.
void rename()
Rename a file.
Communicator * communicate()
Global public access to the communcator singleton.
Definition: communicator.h:121
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepare()

void EstimatorBase::prepare ( )

Prepare the estimator for i/o.

Prepare estimator for i/o.

Assign the output file and write a header depending on whether or not we are restarting the simulation.

Definition at line 240 of file estimator.cpp.

240  {
241 
242  /* Provided that we will perform at least one measurement, open an output
243  * file and possibly write a header */
244  if (frequency > 0) {
245  /* Assign the output file pointer */
246  outFilePtr = &(communicate()->file(label)->stream());
247 
248  /* Write the header to disk if we are not restarting or if this is
249  * a new estimator. */
250  if (!constants()->restart() || (!communicate()->file(label)->exists())) {
251  (*outFilePtr) << header;
252  if (endLine)
253  (*outFilePtr) << endl;
254  }
255  }
256 }
bool restart() const
Get restart state.
Definition: constants.h:86
bool exists()
did the file exist before opening?
Definition: communicator.h:48
+ Here is the call graph for this function:

◆ sample()

void EstimatorBase::sample ( )
virtual

Sample the estimator.

Here we simply call accumulate every frequency times sample is called,
depending on whether we are measuring a diagonal or off-diagonal estimator. If frequency == 0, we don't bother to measure it.

Reimplemented in PIGSOneBodyDensityMatrixEstimator, CylinderPairCorrelationEstimator, CylinderOneBodyDensityMatrixEstimator, OneBodyDensityMatrixEstimator, DiagonalFractionEstimator, and TimeEstimator.

Definition at line 187 of file estimator.cpp.

187  {
188 
189  if (baseSample()) {
191  numAccumulated++;
192  accumulate();
193  }
194 }
virtual void accumulate()
Accumulate the estimator.
Definition: estimator.h:113
bool baseSample()
Determine the basic sampling condition.
Definition: estimator.cpp:161
+ Here is the call graph for this function:

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