Skip to content

Commit d461b86

Browse files
committed
abs->fabs fixes and other improvements
1 parent 2a15c29 commit d461b86

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

examples/ex3/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int main(){
102102

103103
cout << endl << " - - - WAVE FUNCTION OPTIMIZATION - - - " << endl << endl;
104104

105-
const long NMC = 2000l; // MC samplings to use for computing the energy
105+
const long NMC = 20000l; // MC samplings to use for computing the energy
106106
double * energy = new double[4]; // energy
107107
double * d_energy = new double[4]; // energy error bar
108108
double * vp = new double[psi->getNVP()];

src/ConjugateGradientTargetFunction.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ConjugateGradientTargetFunction: public NoisyFunctionWithGradient
8686
// compute direction (or gradient) to follow
8787
for (int i=0; i<_wf->getNVP(); ++i){
8888
grad_E[i] = 2.*( HOi[i] - H[0]*Oi[i] );
89-
dgrad_E[i] = 2.*( dHOi[i] + abs(H[0]*Oi[i])*(dH[0]/H[0]+dOi[i]/Oi[i]) );
89+
dgrad_E[i] = 2.*( dHOi[i] + fabs(H[0]*Oi[i])*(dH[0]/H[0]+dOi[i]/Oi[i]) );
9090
}
9191

9292
if (_lambda_reg > 0.) { // compute the regularization derivative

src/NoisyStochasticReconfigurationOptimization.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class NoisyStochasticReconfigurationOptimization: public WFOptimization{
2323
// optimization
2424
void optimizeWF(){
2525
// create targetfunction
26-
NoisyStochasticReconfigurationTargetFunction * targetf = new NoisyStochasticReconfigurationTargetFunction(_wf, _H, getMCI(), _Nmc);
26+
NoisyStochasticReconfigurationTargetFunction * targetf = new NoisyStochasticReconfigurationTargetFunction(_wf, _H, getMCI(), _Nmc, 0., true);
2727
// declare the Dynamic Descent object
2828
DynamicDescent * ddesc = new DynamicDescent(targetf);
2929
// allocate an array that will contain the wave function variational parameters

src/StochasticReconfigurationOptimization.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace sropt_details {
4040
}
4141

4242
// perform the integral and store the values
43-
MPIVMC::Integrate(w.mci, w.Nmc, obs, dobs, true, true);
43+
MPIVMC::Integrate(w.mci, w.Nmc, obs, dobs, true, false);
4444

4545
// clear
4646
w.mci->clearObservables();
@@ -81,7 +81,7 @@ namespace sropt_details {
8181
for (int j=0; j<nvp; ++j){
8282
gsl_matrix_set(sij, i, j, OiOj[i*nvp + j] - Oi[i] * Oi[j]);
8383
if (flag_dgrad) gsl_matrix_set(rdsij, i, j,
84-
(dOiOj[i*nvp + j] + abs(Oi[i]*Oi[j])*( (dOi[i]/Oi[i]) + (dOi[j]/Oi[j]) ))
84+
(dOiOj[i*nvp + j] + fabs(Oi[i]*Oi[j])*( (dOi[i]/Oi[i]) + (dOi[j]/Oi[j]) ))
8585
/ gsl_matrix_get(sij, i, j) );
8686
}
8787
}
@@ -90,7 +90,7 @@ namespace sropt_details {
9090
for (int i=0; i<nvp; ++i){
9191
gsl_vector_set(fi, i, H[0]*Oi[i] - HOi[i]);
9292
if (flag_dgrad) gsl_vector_set(rdfi, i,
93-
(abs(H[0]*Oi[i])*( (dH[0]/H[0]) + (dOi[i]/Oi[i]) ) + dHOi[i])
93+
(fabs(H[0]*Oi[i])*( (dH[0]/H[0]) + (dOi[i]/Oi[i]) ) + dHOi[i])
9494
/ gsl_vector_get(fi, i) );
9595
}
9696
// invert matrix using SVD
@@ -127,7 +127,7 @@ namespace sropt_details {
127127
for (int k=0; k<nvp; ++k){
128128
foo = gsl_vector_get(fi, k)*gsl_matrix_get(Isij, k, i);
129129
grad_E[i] -= foo;
130-
if (flag_dgrad) dgrad_E[i] += abs(foo) * ( gsl_vector_get(rdfi, k) + gsl_matrix_get(rdsij, k, i) ); // not correct, just a rough estimation
130+
if (flag_dgrad) dgrad_E[i] += fabs(foo) * ( gsl_vector_get(rdfi, k) + gsl_matrix_get(rdsij, k, i) ); // not correct, just a rough estimation
131131
}
132132
}
133133

0 commit comments

Comments
 (0)