24 #include "Grids/Grid.h"
25 #include "nnet/nnet.h"
64 std::vector<Grid<double>*>
F_;
152 const MPI_Comm& world,
153 const MPI_Comm& comm,
154 const Eigen::VectorXi& topol,
160 const std::vector<double>& lowerb,
161 const std::vector<double>& upperb,
162 const std::vector<double>& lowerk,
163 const std::vector<double>& upperk,
175 upperb_(upperb),
lowerk_(lowerk), upperk_(upperk),
outfile_(
"CFF.out"),
185 auto coord = it.coordinates();
186 auto n = coord.size();
187 for(decltype(n) j = 0; j < n; ++j)
188 hist_(i, j) = coord[j];
196 bias_.array() =
net_.get_activation().col(0).array();
235 auto params =
net_.get_train_params();
236 params.max_iter = iters;
237 net_.set_train_params(params);
239 auto params2 =
net2_.get_train_params();
240 params2.max_iter = iters;
241 net2_.set_train_params(params2);
247 auto params =
net_.get_train_params();
248 params.min_loss = loss;
249 net_.set_train_params(params);
251 auto params2 =
net2_.get_train_params();
252 params2.min_loss = loss;
253 net2_.set_train_params(params2);
259 auto params =
net_.get_train_params();
260 params.ratio = trainratio;
261 net_.set_train_params(params);
263 auto params2 =
net2_.get_train_params();
264 params2.ratio = trainratio;
265 net2_.set_train_params(params2);
270 const Json::Value& json,
271 const MPI_Comm& world,
272 const MPI_Comm& comm,
273 const std::string& path
Combined Force Frequency (CFF) Algorithm.
unsigned int citers_
Number of iterations after which we turn on full weight.
void SetRatio(double trainratio)
Set training ratio for gradient vs value.
bool overwrite_
Overwrite outputs.
nnet::neural_net net_
Neural network trained using visit frequency.
unsigned int sweep_
Number of iterations per sweep.
Grid< unsigned int > * hgrid_
Histogram grid.
void SetConvergeIters(unsigned int citers)
Set number of iterations after which we turn on full weight.
double temp_
System temperature and energy units.
double timestep_
Timestep.
Eigen::VectorXi topol_
Neural network topology.
double ratio_
Hold parameters to adjust ratio of 1st and 2nd neural networks (freq vs force-based).
void SetMinLoss(double loss)
Set minimum loss function value (should be zero for production).
nnet::neural_net net2_
Neural network trained on both visit frequency and force.
std::string outfile_
Output filename.
Eigen::ArrayXi Nworld_
Histogram grid for that sotres the number of global hits.
void SetPrevWeight(double h)
Set previous history weight.
static CFF * Build(const Json::Value &json, const MPI_Comm &world, const MPI_Comm &comm, const std::string &path)
Build a derived method from JSON node.
Eigen::VectorXd Fold_
To hold the last iterations F_ value for removing bias.
std::vector< Grid< double > * > Fworld_
Generalized force grid that stors the global total.
Eigen::VectorXd wdotp2_
To hold second to last iteration wdotp value for numerical derivative.
void SetMaxIters(unsigned int iters)
Set maximum number of training iterations per sweep.
std::vector< double > lowerb_
Bounds.
CFF(const MPI_Comm &world, const MPI_Comm &comm, const Eigen::VectorXi &topol, Grid< Eigen::VectorXd > *fgrid, Grid< unsigned int > *hgrid, Grid< double > *ugrid, std::vector< Grid< double > * > F, std::vector< Grid< double > * > Fworld, const std::vector< double > &lowerb, const std::vector< double > &upperb, const std::vector< double > &lowerk, const std::vector< double > &upperk, double temperature, double unitconv, double timestep, double weight, unsigned int nsweep, int min)
Constructor.
double pweight_
Previous and current histogram weight.
Grid< double > * ugrid_
Unbiased histogram grid.
void PostIntegration(Snapshot *snapshot, const class CVManager &cvmanager) override
Method call post integration.
void WriteBias()
Writes out the bias and CFF output files.
Grid< Eigen::VectorXd > * fgrid_
Force grid.
std::vector< double > lowerk_
Bound restraints.
Eigen::MatrixXd force_to_val_ratio_
To hold booleans for training neural network only in specific region for net2_.
void PreSimulation(Snapshot *snapshot, const class CVManager &cvmanager) override
Method call prior to simulation initiation.
Eigen::MatrixXd hist_
Eigen matrices of grids.
std::vector< Grid< double > * > F_
Generalized force grid that stores total of the local walker.
void PostSimulation(Snapshot *snapshot, const class CVManager &cvmanager) override
Method call post simulation.
void TrainNetwork()
Trains the neural network.
int dim_
Number of CVs in system.
double unitconv_
Unit conversion from mass*velocity/time to force.
void SetOutputOverwrite(bool overwrite)
Set overwrite flag on output file.
Eigen::VectorXd wdotp1_
To hold last iteration wdotp value for numerical derivative.
void SetOutput(const std::string &outfile)
Set name of output file.
Collective variable manager.
size_t size() const
Get the size of the internal storage vector.
size_t GetDimension() const
Get the dimension.
iterator begin()
Return iterator at first grid point.
iterator end()
Return iterator after last valid grid point.
Interface for Method implementations.
Class containing a snapshot of the current simulation in time.