Action: OPT_AVERAGED_SGD
Module | ves |
---|---|
Description | Usage |
Averaged stochastic gradient decent with fixed step size. | |
output value | type |
a scalar | scalar |
Details and examples
Averaged stochastic gradient decent with fixed step size.
Algorithm
This optimizer updates the coefficients according to the averaged stochastic gradient decent algorithm described here. This algorithm considers two sets of coefficients, the so-called instantaneous coefficients that are updated according to the recursion formula given by
where is a fixed step size and the gradient and the Hessian depend on the averaged coefficients defined as
This means that the bias acting on the system depends on the averaged coefficients which leads to a smooth convergence of the bias and the estimated free energy surface. Furthermore, this allows for a rather short sampling time for each iteration, for classical MD simulations typical sampling times are on the order of few ps (around 1000-4000 MD steps).
Currently it is only supported to employ the diagonal part of the Hessian which is generally sufficient. Support for employing the full Hessian will be added later on.
The VES bias that is to be optimized should be specified using the BIAS keyword. The fixed step size is given using the STEPSIZE keyword. The frequency of updating the coefficients is given using the STRIDE keyword where the value is given in the number of MD steps. For example, if the MD time step is 0.02 ps and STRIDE=2000 will the coefficients be updated every 4 ps. The coefficients will be outputted to the file given by the COEFFS_FILE keyword. How often the coefficients are written to this file is controlled by the COEFFS_OUTPUT keyword.
If the VES bias employs a dynamic target distribution that needs to be iteratively updated (e.g. TD_WELLTEMPERED) the second paper cited below, you will need to specify the stride for updating the target distribution by using the TARGETDIST_STRIDE keyword where the stride is given in terms coefficient iterations. For example if the MD time step is 0.02 ps and STRIDE=1000, such that the coefficients are updated every 2 ps, will TARGETDIST_STRIDE=500 mean that the target distribution will be updated every 1000 ps.
The output of the free energy surfaces and biases is controlled by the FES_OUTPUT and the BIAS_OUTPUT keywords. It is also possible to output one-dimensional projections of the free energy surfaces by using the FES_PROJ_OUTPUT keyword but for that to work you will need to select for which argument to do the projections by using the numbered PROJ_ARG keyword in the VES bias that is optimized. You can also output dynamic target distributions by using the TARGETDIST_OUTPUT and TARGETDIST_PROJ_OUTPUT keywords.
It is possible to start the optimization from some initial set of coefficients that have been previously obtained by using the INITIAL_COEFFS keyword.
When restarting simulations it should be sufficient to put the RESTART action in the beginning of the input files (or some MD codes the PLUMED should automatically detect if it is a restart run) and keep the same input as before The restarting of the optimization should be automatic as the optimizer will then read in the coefficients from the file given in COEFFS_FILE. For dynamic target distribution the code will also read in the final target distribution from the previous run (which is always outputted even if the TARGETDIST_OUTPUT keyword is not used).
This optimizer supports the usage of multiple walkers where different copies of the system share the same bias potential (i.e. coefficients) and cooperatively sample the averages needed for the gradient and Hessian. This can significantly help with convergence in difficult cases. It is of course best to start the different copies from different positions in CV space. To activate this option you just need to add the MULTIPLE_WALKERS flag. Note that this is only supported if the MD code support running multiple replicas connected via MPI.
The optimizer supports the usage of a so-called mask file that can be used to employ different step sizes for different coefficients and/or deactivate the optimization of certain coefficients (by putting values of 0.0). The mask file is read in by using the MASK_FILE keyword and should be in the same format as the coefficient file. It is possible to generate a template mask file by using the OUTPUT_MASK_FILE keyword.
Examples
In the following input we employ an averaged stochastic gradient decent with a fixed step size of 1.0 and update the coefficient every 1000 MD steps (e.g. every 2 ps if the MD time step is 0.02 ps). The coefficient are outputted to the coefficients.data every 50 iterations while the FES and bias is outputted to files every 500 iterations (e.g. every 1000 ps).
phiTORSIONCalculate one or multiple torsional angles. More details ATOMSthe four atoms involved in the torsional angle=5,7,9,15 bf1: BF_FOURIERFourier basis functions. More details ORDERThe order of the basis function expansion=5 MINIMUMThe minimum of the interval on which the basis functions are defined=-pi MAXIMUMThe maximum of the interval on which the basis functions are defined=pi VES_LINEAR_EXPANSIONLinear basis set expansion bias. This action has hidden defaults. More details ... ARGthe labels of the scalars on which the bias will act=phi BASIS_FUNCTIONSthe label of the one dimensional basis functions that should be used=bf1 LABELa label for the action so that its output can be referenced in the input to other actions=ves1 TEMPthe system temperature - this is needed if the MD code does not pass the temperature to PLUMED=300.0 GRID_BINSthe number of bins used for the grid=100 ... VES_LINEAR_EXPANSION:
OPT_AVERAGED_SGDAveraged stochastic gradient decent with fixed step size. More details ... BIASthe label of the VES bias to be optimized=ves1 STRIDEthe frequency of updating the coefficients given in the number of MD steps=1000 LABELa label for the action so that its output can be referenced in the input to other actions=o1 STEPSIZEthe step size used for the optimization=1.0 COEFFS_FILE the name of output file for the coefficients=coefficients.data COEFFS_OUTPUT how often the coefficients should be written to file=50 FES_OUTPUThow often the FES(s) should be written out to file=500 BIAS_OUTPUThow often the bias(es) should be written out to file=500 ... OPT_AVERAGED_SGD
In the following example we employ a well-tempered target distribution that is updated every 500 iterations (e.g. every 1000 ps). The target distribution is also output to a file every 2000 iterations (the TARGETDIST_OUTPUT keyword). Here we also employ MULTIPLE_WALKERS flag to enable the usage of multiple walkers.
#SETTINGS NREPLICAS=2 phi : TORSIONCalculate one or multiple torsional angles. More details ATOMSthe four atoms involved in the torsional angle=5,7,9,15 psi : TORSIONCalculate one or multiple torsional angles. More details ATOMSthe four atoms involved in the torsional angle=7,9,15,17 bf1: BF_FOURIERFourier basis functions. More details ORDERThe order of the basis function expansion=5 MINIMUMThe minimum of the interval on which the basis functions are defined=-pi MAXIMUMThe maximum of the interval on which the basis functions are defined=pi bf2: BF_FOURIERFourier basis functions. More details ORDERThe order of the basis function expansion=4 MINIMUMThe minimum of the interval on which the basis functions are defined=-pi MAXIMUMThe maximum of the interval on which the basis functions are defined=pi td1: TD_WELLTEMPEREDWell-tempered target distribution (dynamic). More details BIASFACTORThe bias factor used for the well-tempered distribution=10 VES_LINEAR_EXPANSIONLinear basis set expansion bias. This action has hidden defaults. More details ... ARGthe labels of the scalars on which the bias will act=phi,psi BASIS_FUNCTIONSthe label of the one dimensional basis functions that should be used=bf1,bf2 LABELa label for the action so that its output can be referenced in the input to other actions=ves1 TEMPthe system temperature - this is needed if the MD code does not pass the temperature to PLUMED=300.0 GRID_BINSthe number of bins used for the grid=100,100 TARGET_DISTRIBUTIONthe label of the target distribution to be used=td1 PROJ_ARG1arguments for doing projections of the FES or the target distribution=phi PROJ_ARG2arguments for doing projections of the FES or the target distribution=psi ... VES_LINEAR_EXPANSION
OPT_AVERAGED_SGDAveraged stochastic gradient decent with fixed step size. More details ... BIASthe label of the VES bias to be optimized=ves1 STRIDEthe frequency of updating the coefficients given in the number of MD steps=1000 LABELa label for the action so that its output can be referenced in the input to other actions=o1 STEPSIZEthe step size used for the optimization=1.0 MULTIPLE_WALKERS if optimization is to be performed using multiple walkers connected via MPI COEFFS_FILE the name of output file for the coefficients=coefficients.data COEFFS_OUTPUT how often the coefficients should be written to file=50 FES_OUTPUThow often the FES(s) should be written out to file=500 FES_PROJ_OUTPUThow often the projections of the FES(s) should be written out to file=500 BIAS_OUTPUThow often the bias(es) should be written out to file=500 TARGETDIST_STRIDEstride for updating a target distribution that is iteratively updated during the optimization=500 TARGETDIST_OUTPUThow often the dynamic target distribution(s) should be written out to file=2000 ... OPT_AVERAGED_SGD
Output components
This action can calculate the values in the following table when the associated keyword is included in the input for the action. These values can be referenced elsewhere in the input by using this Action's label followed by a dot and the name of the value required from the list below.
Name | Type | Keyword | Description |
---|---|---|---|
gradrms | scalar | MONITOR_INSTANTANEOUS_GRADIENT | the root mean square value of the coefficient gradient |
gradmax | scalar | MONITOR_INSTANTANEOUS_GRADIENT | the largest absolute value of the coefficient gradient |
avergradrms | scalar | MONITOR_AVERAGE_GRADIENT | the root mean square value of the averaged coefficient gradient |
avergradmax | scalar | MONITOR_AVERAGE_GRADIENT | the largest absolute value of the averaged coefficient gradient |
Full list of keywords
The following table describes the keywords and options that can be used with this action
Keyword | Type | Default | Description |
---|---|---|---|
BIAS | compulsory | none | the label of the VES bias to be optimized |
STRIDE | compulsory | none | the frequency of updating the coefficients given in the number of MD steps |
COEFFS_FILE | compulsory | coeffs.data | the name of output file for the coefficients |
COEFFS_OUTPUT | compulsory | 100 | how often the coefficients should be written to file |
STEPSIZE | compulsory | none | the step size used for the optimization |
COEFFS_FMT | optional | not used | specify format for coefficient file(s) (useful for decrease the number of digits in regtests) |
COEFFS_SET_ID_PREFIX | optional | not used | suffix to add to the filename given in FILE to identify the bias, should only be given if a single filename is given in FILE when optimizing multiple biases |
INITIAL_COEFFS | optional | not used | the name(s) of file(s) with the initial coefficients |
MONITOR_INSTANTANEOUS_GRADIENT | optional | false | if quantities related to the instantaneous gradient should be outputted |
TARGETDIST_AVERAGES_FILE | optional | not used | the name of output file for the target distribution averages |
TARGETDIST_AVERAGES_OUTPUT | optional | not used | how often the target distribution averages should be written out to file |
BIAS_OUTPUT | optional | not used | how often the bias(es) should be written out to file |
FES_OUTPUT | optional | not used | how often the FES(s) should be written out to file |
FES_PROJ_OUTPUT | optional | not used | how often the projections of the FES(s) should be written out to file |
RESTART | optional | not used | allows per-action setting of restart (YES/NO/AUTO) |
UPDATE_FROM | optional | not used | Only update this action from this time |
UPDATE_UNTIL | optional | not used | Only update this action until this time |
MULTIPLE_WALKERS | optional | false | if optimization is to be performed using multiple walkers connected via MPI |
MASK_FILE | optional | not used | read in a mask file which allows one to employ different step sizes for different coefficients and/or deactivate the optimization of certain coefficients (by putting values of 0 |
OUTPUT_MASK_FILE | optional | not used | Name of the file to write out the mask resulting from using the MASK_FILE keyword |
START_OPTIMIZATION_AFRESH | optional | false | if the iterations should be started afresh when a restart has been triggered by the RESTART keyword or the MD code |
MONITOR_AVERAGE_GRADIENT | optional | false | if the averaged gradient should be monitored and quantities related to it should be outputted |
MONITOR_AVERAGES_GRADIENT_EXP_DECAY | optional | not used | use an exponentially decaying averaging with a given time constant when monitoring the averaged gradient |
TARGETDIST_STRIDE | optional | not used | stride for updating a target distribution that is iteratively updated during the optimization |
TARGETDIST_OUTPUT | optional | not used | how often the dynamic target distribution(s) should be written out to file |
TARGETDIST_PROJ_OUTPUT | optional | not used | how often the projections of the dynamic target distribution(s) should be written out to file |
EXP_DECAYING_AVER | optional | not used | calculate the averaged coefficients using exponentially decaying averaging using the decaying constant given here in the number of iterations |
References
More information about how this action can be used is available in the following articles: