QMCPACK
FSUtilities.cpp
Go to the documentation of this file.
1 #include "FSUtilities.h"
2 #include <algorithm>
3 
4 namespace qmcplusplus
5 {
6 void get_gridinfo_from_posgrid(const std::vector<PosType>& posgridlist,
7  const IndexType& axis,
8  RealType& lx,
9  RealType& rx,
10  RealType& dx,
11  IndexType& Nx)
12 {
13  std::vector<RealType> kx;
14  kx.resize(posgridlist.size());
15 
16  for (IndexType i = 0; i < posgridlist.size(); i++)
17  kx[i] = posgridlist[i][axis];
18 
19  std::vector<RealType>::iterator it;
20 
21  std::sort(kx.begin(), kx.end());
22 
23  it = std::unique(kx.begin(), kx.end());
24 
25  lx = *(kx.begin());
26  rx = *(it - 1);
27  Nx = it - kx.begin();
28  dx = (rx - lx) / RealType(Nx - 1);
29 }
30 
31 void getStats(const std::vector<RealType>& vals, RealType& avg, RealType& err, int start)
32 {
33  avg = 0.0;
34  int n = 0;
35  for (int i = start; i < vals.size(); i++)
36  {
37  avg += vals[i];
38  n++;
39  }
40  avg /= n;
41  err = 0.0;
42  for (int i = start; i < vals.size(); i++)
43  {
44  err += (vals[i] - avg) * (vals[i] - avg);
45  }
46  err /= n;
47  err = std::sqrt(err);
48 }
49 
50 int estimateEquilibration(const std::vector<RealType>& vals, RealType frac)
51 {
52  int idx = int(frac * vals.size());
53  RealType avg, err;
54  getStats(vals, avg, err, idx);
55  int c3, c2, c1;
56  c3 = vals.size();
57  c2 = vals.size();
58  c1 = vals.size();
59  for (int i = vals.size() - 2; i >= 0; i--)
60  {
61  if ((vals[i] - avg) * (vals[i + 1] - avg) < 0.0)
62  {
63  c3 = c2;
64  c2 = c1;
65  c1 = i;
66  }
67  }
68  if (c3 > frac * vals.size())
69  c3 = int(frac * vals.size());
70  return c3;
71 }
72 
73 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QMCTraits::IndexType IndexType
Definition: FSUtilities.h:11
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
void getStats(const std::vector< RealType > &vals, RealType &avg, RealType &err, int start)
Simpleaverage and error estimate.
Definition: FSUtilities.cpp:31
int estimateEquilibration(const std::vector< RealType > &vals, RealType frac)
estimate equilibration of block data
Definition: FSUtilities.cpp:50
void get_gridinfo_from_posgrid(const std::vector< PosType > &posgridlist, const IndexType &axis, RealType &lx, RealType &rx, RealType &dx, IndexType &Nx)
Definition: FSUtilities.cpp:6