CHROMA
stoch_var.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Stochastic variable construction
4  *
5  */
6 
7 #include "chromabase.h"
9 
10 namespace Chroma {
11 
12 //! Stochastic variable construction
13 /*!
14  * \ingroup hadron
15  *
16  * This routine averages timeslice sums of fermion disconnected loop
17  * operators over the number of stochastic sources.
18  * It also calculates the standard deviation on the mean of the real
19  * and imaginary parts of these operators.
20  *
21  * \param ferm_loop_sum sum over stochastice samples of timeslice
22  * disconnected fermion loop operators
23  * \param ferm_loop The timeslice operators for EACH stochastic sample
24  * \param sigma standard deviation on the mean of the real part
25  * of the operator
26  * \param im_sigma same as above for imaginary part
27  * \param t_length length of lattice in time dir
28  * \param Nsamp Number of stochastic samples.
29  */
30 
31 void
32 stoch_var(multi1d<DComplex>& ferm_loop_sum, multi2d<DComplex>& ferm_loop,
33  multi1d<Real64>& sigma, multi1d<Real64>& im_sigma,
34  int t_length, int Nsamp)
35 {
36  multi1d<Real64> mean_sq(t_length), im_mean_sq(t_length), s(t_length),
37  im_s(t_length), std_dev(t_length), im_std_dev(t_length),
38  re_loop(t_length), im_loop(t_length);
39 
40  s = im_s = zero;
41 
42  for (int t = 0; t < t_length; ++t){
43 
44  // Average over number of stochastic samples
45  re_loop[t] = real(ferm_loop_sum[t])/Nsamp;
46  im_loop[t] = imag(ferm_loop_sum[t])/Nsamp;
47  ferm_loop_sum[t] = cmplx(re_loop[t], im_loop[t]);
48 
49  // Calculate the standard deviation on the mean of the
50  // fermion loop operators.
51  // Do this for real and imaginary parts
52 
53  // Square of the mean
54  mean_sq[t] = pow(re_loop[t], 2);
55  im_mean_sq[t] = pow(im_loop[t], 2);
56 
57  // s = sum( (x_i)^2)
58  for (int i = 0; i < Nsamp; ++i){
59  s[t] += pow(real(ferm_loop[i][t]) , 2);
60  im_s[t] += pow(imag(ferm_loop[i][t]) , 2);
61  }
62 
63  // std_dev = sqrt(< (x_i)^2 > - mean^2)
64  std_dev[t] = sqrt((s[t]/Nsamp) - mean_sq[t]);
65  im_std_dev[t] = sqrt((im_s[t]/Nsamp) - im_mean_sq[t]);
66 
67  // std_dev on mean = 1/(sqrt(Nsamp-1) * std_dev
68  sigma[t] = (1/sqrt(Nsamp-1.0))*std_dev[t];
69  im_sigma[t] = (1/sqrt(Nsamp-1.0))*im_std_dev[t];
70  }
71 
72 }
73 
74 } // end namespace Chroma
Primary include file for CHROMA library code.
void stoch_var(multi1d< DComplex > &ferm_loop_sum, multi2d< DComplex > &ferm_loop, multi1d< Real64 > &sigma, multi1d< Real64 > &im_sigma, int t_length, int Nsamp)
Stochastic variable construction.
Definition: stoch_var.cc:32
int t
Definition: meslate.cc:37
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
int i
Definition: pbg5p_w.cc:55
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > s(Ncb)
Stochastic variable construction.