31 engine_target_excited_(false),
55 std::string excited(
"no");
56 std::string ramp_eta_str(
"no");
59 m_param.
add(excited,
"targetExcited");
71 m_param.
add(ramp_eta_str,
"Ramp_eta");
89 app_log() <<
"On descent finalization, have collect_count as true" << std::endl;
152 for (
int i = 0; i < num_replicas; i++)
173 for (
int i = 0; i < num_replicas; i++)
215 const std::vector<FullPrecValueType>& der_rat_samp,
216 const std::vector<FullPrecValueType>& le_der_samp,
217 const std::vector<FullPrecValueType>& ls_der_samp,
222 const size_t num_optimizables = der_rat_samp.size() - 1;
244 for (
int i = 0; i < num_optimizables; i++)
256 n = (
omega_ - etmp) * vgs_samp;
269 for (
int i = 0; i < num_optimizables; i++)
274 (static_cast<FullPrecValueType>(
omega_) * der_rat_samp.at(i + 1) - le_der_samp.at(i + 1)) *
275 static_cast<FullPrecValueType>(vgs_samp);
280 ((static_cast<FullPrecValueType>(
omega_) * der_rat_samp.at(i + 1) - le_der_samp.at(i + 1)) *
281 (static_cast<FullPrecValueType>(
omega_) * der_rat_samp.at(0) - le_der_samp.at(0))) *
297 for(
int i =0; i< num_threads; i++)
323 for(
int i =0; i< num_threads; i++)
352 app_log() <<
"Energy Average: " << std::setprecision(9) <<
e_avg_ << std::endl;
353 app_log() <<
"Energy Variance: " << std::setprecision(9) <<
e_var_ << std::endl;
354 app_log() <<
"Weight Total: " << std::setprecision(9) <<
w_sum_ << std::endl;
356 app_log() <<
"Energy Standard Deviation: " << std::setprecision(9) <<
e_sd_ << std::endl;
357 app_log() <<
"Energy Standard Error: " << std::setprecision(9) <<
e_err_ << std::endl;
370 for (
int j = 0; j <
lderivs_.size(); j++)
391 app_log() <<
"Target Function Average: " << std::setprecision(9) <<
target_avg_ << std::endl;
392 app_log() <<
"Target Function Variance: " << std::setprecision(9) <<
target_var_ << std::endl;
393 app_log() <<
"Target Function Error: " << std::setprecision(9) <<
target_err_ << std::endl;
402 for (
int j = 0; j <
lderivs_.size(); j++)
413 int num_optimizables =
lderivs_.size();
416 std::vector<ValueType> numer_term1(num_optimizables, 0.0);
417 std::vector<ValueType> numer_term2(num_optimizables, 0.0);
418 std::vector<ValueType> denom(num_optimizables, 0.0);
423 for (
int i = 0; i < num_optimizables; i++)
437 app_log() <<
"Derivative for param # " << i <<
" : " <<
lderivs_.at(i) << std::endl;
458 lderivs_.at(i) = (numer_term1.at(i) - numer_term2.at(i)) / denom.at(i);
465 app_log() <<
"Norm of gradient vector is: " << gradNorm << std::endl;
482 std::vector<ValueType>& weights,
483 std::vector<ValueType>& numerSamples,
484 std::vector<ValueType>& denomSamples,
489 std::vector<ValueType> y(7);
498 for (
int i = 0; i < numSamples; i++)
507 y[3] += weight *
n *
n;
508 y[4] += weight * d * d;
509 y[5] += weight *
n * d;
521 ValueType vf = (sf - mf * mf) *
ns / (
ns - static_cast<ValueType>(1.0));
522 ValueType vg = (sg - mg * mg) *
ns / (
ns - static_cast<ValueType>(1.0));
523 ValueType cv = (
mp - mf * mg) *
ns / (
ns - static_cast<ValueType>(1.0));
526 mean = (mf / mg) / (static_cast<ValueType>(1.0) + (vg / mg / mg - cv / mf / mg) /
ns);
527 variance = (mf * mf / mg / mg) * (vf / mf / mf + vg / mg / mg - static_cast<ValueType>(2.0) * cv / mf / mg);
544 app_log() <<
"Parameter Type step sizes: " 550 std::vector<ValueType> prev_deriv_set;
570 if (
flavor_.compare(
"RMSprop") == 0)
572 app_log() <<
"Using RMSprop" << std::endl;
581 std::sqrt(static_cast<ValueType>(1.0) + static_cast<ValueType>(4.0) * cur_lambda * cur_lambda);
589 gamma = gamma * decay_factor;
615 tau = type_eta / denom;
622 tau = tau / step_decay_denom;
631 gamma * (
params_copy_[i] - old_tau * prev_deriv_set[i]);
643 taus_.push_back(tau);
661 else if (
flavor_.compare(
"Random") == 0)
663 app_log() <<
"Using Random" << std::endl;
672 app_log() <<
"Got a nan, choosing sign randomly with 50-50 probability" << std::endl;
684 app_log() <<
"This is random alpha: " << alpha <<
" with sign: " <<
sign << std::endl;
693 if (
flavor_.compare(
"ADAM") == 0)
695 app_log() <<
"Using ADAM" << std::endl;
716 tau = type_eta / denom;
723 taus_.push_back(tau);
743 else if (
flavor_.compare(
"AMSGrad") == 0)
745 app_log() <<
"Using AMSGrad" << std::endl;
764 tau = type_eta / denom;
771 taus_.push_back(tau);
801 app_log() <<
"Computing average energy and its variance over stored " 802 "steps and its standard error" 808 ValueType final_e_avg = final_e_sum / collected_steps;
812 ValueType final_var_avg = final_var_sum / collected_steps;
814 app_log() <<
"Final average energy: " << final_e_avg << std::endl;
815 app_log() <<
"Final varaince: " << final_var_avg << std::endl;
822 app_log() <<
"Computing average target function over stored steps and " 829 ValueType final_tar_avg = final_tar_sum / collected_steps;
833 ValueType final_tar_var_avg = final_tar_var_sum / collected_steps;
835 app_log() <<
"Final average target function: " << final_tar_avg << std::endl;
836 app_log() <<
"Final target function varaince: " << final_tar_var_avg << std::endl;
856 if ((name.find(
"uu") != std::string::npos) || (name.find(
"ud") != std::string::npos))
866 else if (name.find(
"F_") != std::string::npos)
870 else if (name.find(
"CIcoeff_") != std::string::npos || name.find(
"CSFcoeff_") != std::string::npos)
874 else if (name.find(
"orb_rot_") != std::string::npos)
878 else if (name.find(
"g") != std::string::npos)
911 if (my_vars.
where(i) != -1)
926 std::vector<ValueType> row_vec(current_params.size(), 0.0);
933 for (
int i = 0; i < current_params.size(); i++)
950 #if !defined(QMC_COMPLEX) 953 std::string entry =
"";
958 app_log() <<
"Stored Vector: " << entry << std::endl;
967 std::vector<ValueType>& numerSamples,
968 std::vector<ValueType>& denomSamples)
971 std::vector<ValueType> wtv(weights);
972 std::vector<ValueType> nmv(numerSamples);
973 std::vector<ValueType> dnv(denomSamples);
978 int section_len =
n / 100;
980 std::vector<ValueType> bbvars(blocks);
984 for (
int i = 0; i < blocks; i++)
986 std::vector<ValueType> sub_wtv(section_len);
987 std::vector<ValueType> sub_nmv(section_len);
988 std::vector<ValueType> sub_dnv(section_len);
991 std::copy(wtv.begin() + i * section_len, wtv.begin() + (i + 1) * section_len, sub_wtv.begin());
992 std::copy(nmv.begin() + i * section_len, nmv.begin() + (i + 1) * section_len, sub_nmv.begin());
993 std::copy(dnv.begin() + i * section_len, dnv.begin() + (i + 1) * section_len, sub_dnv.begin());
1001 bbvars[i] = blockVar;
1003 bbv += bbvars.at(i) /
static_cast<ValueType>(blocks);
1004 bbv2 += bbvars.at(i) * bbvars.at(i) /
static_cast<ValueType>(blocks);
1010 const ValueType bbvov = bbv2 - bbv * bbv;
1017 app_log() <<
"Uncertainty in variance of averaged quantity: " << var_uncertainty << std::endl;
1029 app_log() <<
"Blocking analysis error for per process length " <<
n <<
" is: " << currentErr << std::endl;
1031 std::vector<ValueType> tmp1, tmp2, tmp3;
1033 for (
int i = 0; i <
n; i += 2)
1035 ValueType avgW = (wtv[i] + wtv[i + 1]) / static_cast<ValueType>(2.0);
1036 ValueType avgNumer = (nmv[i] + nmv[i + 1]) / static_cast<ValueType>(2.0);
1037 ValueType avgDenom = (dnv[i] + dnv[i + 1]) / static_cast<ValueType>(2.0);
1039 tmp1.push_back(avgW);
1040 tmp2.push_back(avgNumer);
1041 tmp3.push_back(avgDenom);
int num_params_
Number of optimizable parameters.
std::vector< std::vector< ValueType > > deriv_records_
Vector for storing Lagrangian derivatives from previous optimization steps.
DescentEngine(Communicate *comm, const xmlNodePtr cur)
Constructor for engine.
Communicate * my_comm_
Communicator handles MPI reduction.
std::vector< std::vector< ValueType > > replica_final_tnv_history_
std::vector< ValueType > final_tar_var_history_
a vector to store the variances of the target function during the descent finalization phase ...
std::vector< ValueType > final_tdv_history_
a history of target function denomerator times the |value/guiding|^2 ratios during the descent finali...
int store_count_
Counter of how many vectors have been stored so far.
std::vector< ValueType > final_vg_history_
history of sampled |value/guiding|^2 ratios during the descent finalization phase ...
helper functions for EinsplineSetBuilder
ValueType numer_err_
Standard error of the target function numerator.
int final_descent_num_
Counter for the number of descent steps taken in the finalization phase.
std::vector< ValueType > tnv_history_
a history of target function numerator times the |value/guiding|^2 ratios for one iteration ...
int ramp_num_
Number of steps over which to ramp up step size.
std::vector< ValueType > denom_records_
Vector for storing step size denominator values from previous optimization step.
void sample_finish()
Function that reduces all vector information from all processors to the root processor.
qmcplusplus::QMCTraits::RealType RealType
std::vector< ValueType > taus_
Vector for storing step sizes from previous optimization step.
ValueType tjf_2body_eta_
Step sizes for different types of parameters.
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
std::vector< std::vector< FullPrecValueType > > replica_denom_der_samp_
Vector for target function denominator parameter derivatives on one thread.
std::vector< ValueType > vg_history_
history of sampled |value/guiding|^2 ratios for one iteration
int store_num_
Number of parameter difference vectors stored when descent is used in a hybrid optimization.
ValueType target_avg_
Average target function value on a descent step.
std::vector< std::vector< ValueType > > replica_final_w_history_
ValueType denom_avg_
Average target function denominator on a descent step.
void setupUpdate(const optimize::VariableSet &my_vars)
helper method for transferring information on parameter names and types to the engine ...
std::vector< ValueType > final_le_avg_history_
a vector to store the averages of the energy during the descent finalization phase ...
std::vector< std::vector< FullPrecValueType > > replica_numer_der_samp_
Vector for target function numerator parameter derivatives on one thread.
int collection_step_
Iteration to start collecting samples for final average and error blocking analysis.
ValueType denom_err_
Standard error of the target function denominator.
std::vector< ValueType > tdv_history_
a history of target function denominator times the |value/guiding|^2 ratios for one iteration ...
std::vector< int > engine_param_types_
void updateParameters()
helper method for updating parameter values with descent
std::vector< FullPrecValueType > avg_le_der_samp_
Vector for local energy parameter derivatives.
std::vector< std::vector< ValueType > > hybrid_blm_input_
Vector for storing the input vectors to the BLM steps of hybrid method.
void prepareStorage(const int num_replicas, const int num_optimizables)
Prepare for taking samples.
ValueType e_err_
Standard error of the energy.
std::vector< FullPrecValueType > avg_denom_der_samp_
Vector for target function denominator parameter derivatives.
bool put(std::istream &is) override
read from std::istream
std::vector< FullPrecValueType > avg_numer_der_samp_
Vector for target function numerator parameter derivatives.
std::vector< FullPrecValueType > avg_der_rat_samp_
Vector for WF parameter derivatives.
bool engine_target_excited_
Whether to target excited state.
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
std::vector< std::vector< ValueType > > replica_final_lev_history_
Wrapping information on parallelism.
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
ValueType denom_var_
Variance of the target function denominator.
std::vector< std::vector< ValueType > > replica_tnv_history_
std::vector< ValueType > lderivs_
Vector that stores the final averaged derivatives of the cost function.
int compute_step_
Iteration to start computing averages and errors from the stored values during the finalization phase...
std::vector< ValueType > w_history_
history of sampled configuration weights for one iteration
std::vector< std::vector< ValueType > > replica_lev_history_
class to handle a set of parameters
std::vector< std::string > engine_param_names_
Vectors of parameter names and types, used in the assignment of step sizes.
std::vector< ValueType > final_w_history_
history of sampled configuration weights during descent finalization phase
std::vector< std::vector< ValueType > > replica_tdv_history_
ValueType setStepSize(int i)
helper method for seting step sizes for different parameter types in descent optimization ...
ValueType e_sd_
Standard deviation of the energy.
std::vector< ValueType > params_copy_
Vector for storing parameter values from previous optimization step.
std::vector< ValueType > current_params_
Vector for storing parameter values for current optimization step.
class to handle a set of variables that can be modified during optimizations
ValueType target_var_
Variance of the target function.
void computeFinalizationUncertainties(std::vector< ValueType > &weights, std::vector< ValueType > &numerSamples, std::vector< ValueType > &denomSamples)
Compute uncertainties for energy/target function and variance over a history of samples from a set of...
std::vector< ValueType > final_var_avg_history_
a vector to store the variances of the energy during the descent finalization phase ...
int where(int i) const
return the locator of the i-th Index
int getType(int i) const
get the i-th parameter's type
std::vector< ValueType > final_tar_avg_history_
a vector to store the averages of the target function during the descent finalization phase ...
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
ValueType w_sum_
Total sum of weights.
size_type size() const
return the size
bool processXML(const xmlNodePtr cur)
process xml node
ValueType numer_avg_
Average target function numerator on a descent step.
ValueType e_avg_
Average energy on a descent step.
void add(PDT &aparam, const std::string &aname_in, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new parameter corresponding to an xmlNode <parameter>
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
qmcplusplus::QMCTraits::ValueType ValueType
std::vector< ValueType > final_lev_history_
history of sampled local energies times the |value/guiding|^2 raitos during the descent finalization ...
ValueType omega_
Value of omega in excited state functional.
bool ramp_eta_
Whether to gradually ramp up step sizes in descent.
std::vector< std::vector< FullPrecValueType > > replica_le_der_samp_
Vector for local energy parameter derivatives on one thread.
const std::string & name(int i) const
return the name of i-th variable
std::vector< ValueType > derivs_squared_
Vector for storing running average of squares of the derivatives.
std::vector< ValueType > params_for_diff_
Vector for storing parameter values for calculating differences to be given to hybrid method...
int descent_num_
Integer for keeping track of only number of descent steps taken.
bool collect_count_
Whether to start collecting samples for the histories in the finalization phase.
void mpi_unbiased_ratio_of_means(int numSamples, std::vector< ValueType > &weights, std::vector< ValueType > &numerSamples, std::vector< ValueType > &denomSamples, ValueType &mean, ValueType &variance, ValueType &stdErr)
Function for computing ratios of the form <f>/<g> as well as the associated variance and standard err...
ValueType lambda_
Parameter for accelerated descent recursion relation.
std::vector< std::vector< FullPrecValueType > > replica_der_rat_samp_
Vector for WF parameter derivatives on one thread.
void storeVectors(std::vector< ValueType > ¤t_params)
Store a vector of parameter differences to be used by the BLM in a hybrid optimization.
std::vector< std::vector< ValueType > > replica_final_vg_history_
std::vector< std::vector< ValueType > > replica_final_tdv_history_
qmcplusplus::QMCTraits::FullPrecValueType FullPrecValueType
std::string flavor_
What variety of gradient descent will be used.
std::vector< ValueType > lev_history_
a history of sampled local energies times the |value/guiding|^2 raitos for one iteration ...
ValueType e_var_
Variance of the energy.
void takeSample(const int replica_id, const std::vector< FullPrecValueType > &der_rat_samp, const std::vector< FullPrecValueType > &le_der_samp, const std::vector< FullPrecValueType > &ls_der_samp, ValueType vgs_samp, ValueType weight_samp)
Function that Take Sample Data from the Host Code.
std::string print_deriv_
Whether to print out derivative terms for each parameter.
ACC::value_type mean(const ACC &ac)
std::vector< ValueType > numer_records_
Vector for storing step size numerator values from previous optimization step.
std::vector< std::vector< ValueType > > replica_w_history_
ValueType target_err_
Standard error of the target function.
std::vector< std::vector< ValueType > > replica_vg_history_
ValueType numer_var_
Variance of the target function numerator.
bool isnan(float a)
return true if the value is NaN.
std::vector< ValueType > final_tnv_history_
a history of target function numerator times the |value/guiding|^2 ratios during the descent finaliza...