QMCPACK
ExpFitClass< M > Class Template Reference
+ Collaboration diagram for ExpFitClass< M >:

Public Member Functions

void Fit (std::vector< double > &r, std::vector< double > &u)
 
void FitCusp (std::vector< double > &r, std::vector< double > &u, double cusp)
 
void eval (double r, double &u)
 
void eval (double r, double &u, double &du, double &d2u)
 

Private Attributes

TinyVector< double, M > Coefs
 
TinyVector< double, M > dCoefs
 
TinyVector< double, M > d2Coefs
 
double sign
 

Friends

class ComplexExpFitClass< M >
 

Detailed Description

template<int M>
class qmcplusplus::ExpFitClass< M >

Definition at line 31 of file ExpFitClass.h.

Member Function Documentation

◆ eval() [1/2]

void eval ( double  r,
double &  u 
)
inline

Definition at line 163 of file ExpFitClass.h.

References qmcplusplus::exp(), and sign().

164 {
165  double r2j = 1.0;
166  double poly = 0.0;
167  for (int j = 0; j < M; j++)
168  {
169  poly += Coefs[j] * r2j;
170  r2j *= r;
171  }
172  u = sign * std::exp(poly);
173 }
TinyVector< double, M > Coefs
Definition: ExpFitClass.h:34
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)

◆ eval() [2/2]

void eval ( double  r,
double &  u,
double &  du,
double &  d2u 
)
inline

Definition at line 176 of file ExpFitClass.h.

References qmcplusplus::exp(), and sign().

177 {
178  double r2j = 1.0;
179  double P = 0.0, dP = 0.0, d2P = 0.0;
180  for (int j = 0; j < M; j++)
181  {
182  P += Coefs[j] * r2j;
183  dP += dCoefs[j] * r2j;
184  d2P += d2Coefs[j] * r2j;
185  r2j *= r;
186  }
187  u = sign * std::exp(P);
188  du = dP * u;
189  d2u = (d2P + dP * dP) * u;
190 }
TinyVector< double, M > dCoefs
Definition: ExpFitClass.h:34
TinyVector< double, M > Coefs
Definition: ExpFitClass.h:34
TinyVector< double, M > d2Coefs
Definition: ExpFitClass.h:34
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)

◆ Fit()

void Fit ( std::vector< double > &  r,
std::vector< double > &  u 
)
inline

Definition at line 107 of file ExpFitClass.h.

References qmcplusplus::app_error(), qmcplusplus::det(), qmcplusplus::invert_matrix(), qmcplusplus::log(), qmcplusplus::Units::force::N, and sign().

Referenced by ComplexExpFitClass< M >::Fit().

108 {
109  int N = r.size();
110  sign = u[0] < 0.0 ? -1.0 : 1.0;
111  if (r.size() != u.size())
112  app_error() << "Different number of rows of basis functions than"
113  << " of data points in LinFit. Exitting.\n";
114  std::vector<TinyVector<double, M>> F(N);
115  std::vector<double> log_u(N);
116  for (int i = 0; i < N; i++)
117  {
118  log_u[i] = std::log(sign * u[i]);
119  double r2j = 1.0;
120  for (int j = 0; j < M; j++)
121  {
122  F[i][j] = r2j;
123  r2j *= r[i];
124  }
125  }
126  // Next, construct alpha matrix
127  Matrix<double> alpha(M, M), alphaInv(M, M);
128  alpha = 0.0;
129  for (int j = 0; j < M; j++)
130  for (int k = 0; k < M; k++)
131  {
132  alpha(k, j) = 0.0;
133  for (int i = 0; i < N; i++)
134  alpha(k, j) += F[i][j] * F[i][k];
135  }
136  // Next, construct beta vector
138  beta = 0.0;
139  for (int k = 0; k < M; k++)
140  for (int i = 0; i < N; i++)
141  beta[k] += log_u[i] * F[i][k];
142  // Now, invert alpha
143  for (int i = 0; i < M; i++)
144  for (int j = 0; j < M; j++)
145  alphaInv(i, j) = alpha(i, j);
146  double det = invert_matrix(alphaInv);
147  for (int i = 0; i < M; i++)
148  {
149  Coefs[i] = 0.0;
150  for (int j = 0; j < M; j++)
151  Coefs[i] += alphaInv(i, j) * beta[j];
152  }
153  dCoefs = 0.0;
154  d2Coefs = 0.0;
155  for (int i = 0; i < M - 1; i++)
156  dCoefs[i] = (double)(i + 1) * Coefs[i + 1];
157  for (int i = 0; i < M - 2; i++)
158  d2Coefs[i] = (double)(i + 1) * dCoefs[i + 1];
159 }
MatrixA::value_type invert_matrix(MatrixA &M, bool getdet=true)
invert a matrix
Tensor< T, D >::Type_t det(const Tensor< T, D > &a)
Definition: TensorOps.h:838
TinyVector< double, M > dCoefs
Definition: ExpFitClass.h:34
std::ostream & app_error()
Definition: OutputManager.h:67
TinyVector< double, M > Coefs
Definition: ExpFitClass.h:34
TinyVector< double, M > d2Coefs
Definition: ExpFitClass.h:34
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)

◆ FitCusp()

void FitCusp ( std::vector< double > &  r,
std::vector< double > &  u,
double  cusp 
)
inline

Definition at line 46 of file ExpFitClass.h.

References qmcplusplus::app_error(), qmcplusplus::det(), qmcplusplus::invert_matrix(), qmcplusplus::log(), qmcplusplus::Units::force::N, and sign().

Referenced by ComplexExpFitClass< M >::FitCusp().

47 {
48  int N = r.size();
49  sign = u[0] < 0.0 ? -1.0 : 1.0;
50  if (r.size() != u.size())
51  app_error() << "Different number of rows of basis functions than"
52  << " of data points in LinFit. Exitting.\n";
53  std::vector<TinyVector<double, M - 1>> F(N);
54  std::vector<double> log_u(N);
55  for (int i = 0; i < N; i++)
56  {
57  log_u[i] = std::log(sign * u[i]) - cusp * r[i];
58  double r2jp1 = r[i] * r[i];
59  F[i][0] = 1.0;
60  for (int j = 1; j < M - 1; j++)
61  {
62  F[i][j] = r2jp1;
63  r2jp1 *= r[i];
64  }
65  }
66  // Next, construct alpha matrix
67  Matrix<double> alpha(M - 1, M - 1), alphaInv(M - 1, M - 1);
68  alpha = 0.0;
69  for (int j = 0; j < M - 1; j++)
70  for (int k = 0; k < M - 1; k++)
71  {
72  alpha(k, j) = 0.0;
73  for (int i = 0; i < N; i++)
74  alpha(k, j) += F[i][j] * F[i][k];
75  }
76  // Next, construct beta vector
77  TinyVector<double, M - 1> beta;
78  beta = 0.0;
79  for (int k = 0; k < M - 1; k++)
80  for (int i = 0; i < N; i++)
81  beta[k] += log_u[i] * F[i][k];
82  // Now, invert alpha
83  for (int i = 0; i < M - 1; i++)
84  for (int j = 0; j < M - 1; j++)
85  alphaInv(i, j) = alpha(i, j);
86  double det = invert_matrix(alphaInv);
87  TinyVector<double, M - 1> c;
88  for (int i = 0; i < M - 1; i++)
89  {
90  c[i] = 0.0;
91  for (int j = 0; j < M - 1; j++)
92  c[i] += alphaInv(i, j) * beta[j];
93  }
94  Coefs[0] = c[0];
95  Coefs[1] = cusp;
96  for (int i = 2; i < M; i++)
97  Coefs[i] = c[i - 1];
98  dCoefs = 0.0;
99  d2Coefs = 0.0;
100  for (int i = 0; i < M - 1; i++)
101  dCoefs[i] = (double)(i + 1) * Coefs[i + 1];
102  for (int i = 0; i < M - 2; i++)
103  d2Coefs[i] = (double)(i + 1) * dCoefs[i + 1];
104 }
MatrixA::value_type invert_matrix(MatrixA &M, bool getdet=true)
invert a matrix
Tensor< T, D >::Type_t det(const Tensor< T, D > &a)
Definition: TensorOps.h:838
TinyVector< double, M > dCoefs
Definition: ExpFitClass.h:34
std::ostream & app_error()
Definition: OutputManager.h:67
TinyVector< double, M > Coefs
Definition: ExpFitClass.h:34
TinyVector< double, M > d2Coefs
Definition: ExpFitClass.h:34
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)

Friends And Related Function Documentation

◆ ComplexExpFitClass< M >

friend class ComplexExpFitClass< M >
friend

Definition at line 42 of file ExpFitClass.h.

Member Data Documentation

◆ Coefs

TinyVector<double, M> Coefs
private

Definition at line 34 of file ExpFitClass.h.

Referenced by ComplexExpFitClass< M >::Fit(), and ComplexExpFitClass< M >::FitCusp().

◆ d2Coefs

TinyVector<double, M> d2Coefs
private

Definition at line 34 of file ExpFitClass.h.

Referenced by ComplexExpFitClass< M >::Fit(), and ComplexExpFitClass< M >::FitCusp().

◆ dCoefs

TinyVector<double, M> dCoefs
private

Definition at line 34 of file ExpFitClass.h.

Referenced by ComplexExpFitClass< M >::Fit(), and ComplexExpFitClass< M >::FitCusp().

◆ sign

double sign
private

Definition at line 35 of file ExpFitClass.h.

Referenced by ComplexExpFitClass< M >::Fit(), and ComplexExpFitClass< M >::FitCusp().


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