Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-2017 The VES code team 3 : (see the PEOPLE-VES file at the root of this folder for a list of names) 4 : 5 : See http://www.ves-code.org for more information. 6 : 7 : This file is part of VES code module. 8 : 9 : The VES code module is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : The VES code module is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with the VES code module. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : 23 : #include "Optimizer.h" 24 : #include "CoeffsVector.h" 25 : 26 : #include "core/ActionRegister.h" 27 : 28 : 29 : namespace PLMD { 30 : namespace ves { 31 : 32 : //+PLUMEDOC VES_OPTIMIZER OPT_STEEPEST_DECENT 33 : /* 34 : Steepest decent optimizer. 35 : 36 : \par Examples 37 : 38 : */ 39 : //+ENDPLUMEDOC 40 : 41 4 : class Opt_SteepestDecent : public Optimizer { 42 : 43 : public: 44 : static void registerKeywords(Keywords&); 45 : explicit Opt_SteepestDecent(const ActionOptions&); 46 : void coeffsUpdate(const unsigned int c_id = 0); 47 : }; 48 : 49 : 50 7836 : PLUMED_REGISTER_ACTION(Opt_SteepestDecent,"OPT_STEEPEST_DECENT") 51 : 52 : 53 3 : void Opt_SteepestDecent::registerKeywords(Keywords& keys) { 54 3 : Optimizer::registerKeywords(keys); 55 3 : Optimizer::useFixedStepSizeKeywords(keys); 56 3 : Optimizer::useMultipleWalkersKeywords(keys); 57 3 : Optimizer::useMaskKeywords(keys); 58 3 : } 59 : 60 : 61 2 : Opt_SteepestDecent::Opt_SteepestDecent(const ActionOptions&ao): 62 2 : PLUMED_VES_OPTIMIZER_INIT(ao) 63 : { 64 2 : checkRead(); 65 2 : } 66 : 67 : 68 20 : void Opt_SteepestDecent::coeffsUpdate(const unsigned int c_id) { 69 40 : Coeffs(c_id) += - StepSize(c_id) * CoeffsMask(c_id) * Gradient(c_id); 70 : // 71 20 : double aver_decay = 1.0 / ( getIterationCounterDbl() + 1.0 ); 72 40 : AuxCoeffs(c_id) += aver_decay * ( Coeffs(c_id)-AuxCoeffs(c_id) ); 73 : 74 20 : } 75 : 76 : 77 : } 78 5874 : }