Skip to content

Commit

Permalink
abs->fabs fixes and other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ithanil committed Jan 22, 2019
1 parent 2a15c29 commit d461b86
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/ex3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int main(){

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

const long NMC = 2000l; // MC samplings to use for computing the energy
const long NMC = 20000l; // MC samplings to use for computing the energy
double * energy = new double[4]; // energy
double * d_energy = new double[4]; // energy error bar
double * vp = new double[psi->getNVP()];
Expand Down
2 changes: 1 addition & 1 deletion src/ConjugateGradientTargetFunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ConjugateGradientTargetFunction: public NoisyFunctionWithGradient
// compute direction (or gradient) to follow
for (int i=0; i<_wf->getNVP(); ++i){
grad_E[i] = 2.*( HOi[i] - H[0]*Oi[i] );
dgrad_E[i] = 2.*( dHOi[i] + abs(H[0]*Oi[i])*(dH[0]/H[0]+dOi[i]/Oi[i]) );
dgrad_E[i] = 2.*( dHOi[i] + fabs(H[0]*Oi[i])*(dH[0]/H[0]+dOi[i]/Oi[i]) );
}

if (_lambda_reg > 0.) { // compute the regularization derivative
Expand Down
2 changes: 1 addition & 1 deletion src/NoisyStochasticReconfigurationOptimization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NoisyStochasticReconfigurationOptimization: public WFOptimization{
// optimization
void optimizeWF(){
// create targetfunction
NoisyStochasticReconfigurationTargetFunction * targetf = new NoisyStochasticReconfigurationTargetFunction(_wf, _H, getMCI(), _Nmc);
NoisyStochasticReconfigurationTargetFunction * targetf = new NoisyStochasticReconfigurationTargetFunction(_wf, _H, getMCI(), _Nmc, 0., true);
// declare the Dynamic Descent object
DynamicDescent * ddesc = new DynamicDescent(targetf);
// allocate an array that will contain the wave function variational parameters
Expand Down
8 changes: 4 additions & 4 deletions src/StochasticReconfigurationOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace sropt_details {
}

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

// clear
w.mci->clearObservables();
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace sropt_details {
for (int j=0; j<nvp; ++j){
gsl_matrix_set(sij, i, j, OiOj[i*nvp + j] - Oi[i] * Oi[j]);
if (flag_dgrad) gsl_matrix_set(rdsij, i, j,
(dOiOj[i*nvp + j] + abs(Oi[i]*Oi[j])*( (dOi[i]/Oi[i]) + (dOi[j]/Oi[j]) ))
(dOiOj[i*nvp + j] + fabs(Oi[i]*Oi[j])*( (dOi[i]/Oi[i]) + (dOi[j]/Oi[j]) ))
/ gsl_matrix_get(sij, i, j) );
}
}
Expand All @@ -90,7 +90,7 @@ namespace sropt_details {
for (int i=0; i<nvp; ++i){
gsl_vector_set(fi, i, H[0]*Oi[i] - HOi[i]);
if (flag_dgrad) gsl_vector_set(rdfi, i,
(abs(H[0]*Oi[i])*( (dH[0]/H[0]) + (dOi[i]/Oi[i]) ) + dHOi[i])
(fabs(H[0]*Oi[i])*( (dH[0]/H[0]) + (dOi[i]/Oi[i]) ) + dHOi[i])
/ gsl_vector_get(fi, i) );
}
// invert matrix using SVD
Expand Down Expand Up @@ -127,7 +127,7 @@ namespace sropt_details {
for (int k=0; k<nvp; ++k){
foo = gsl_vector_get(fi, k)*gsl_matrix_get(Isij, k, i);
grad_E[i] -= foo;
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
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
}
}

Expand Down

0 comments on commit d461b86

Please sign in to comment.