Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-2023 The plumed team 3 : (see the PEOPLE file at the root of the distribution for a list of names) 4 : 5 : See http://www.plumed.org for more information. 6 : 7 : This file is part of plumed, version 2. 8 : 9 : plumed 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 : plumed 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 plumed. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : #include "core/ActionRegister.h" 23 : #include "SketchMapBase.h" 24 : #include "tools/ConjugateGradient.h" 25 : 26 : //+PLUMEDOC DIMRED SKETCHMAP_CONJGRAD 27 : /* 28 : Optimize the sketch-map stress function using conjugate gradients. 29 : 30 : \par Examples 31 : 32 : */ 33 : //+ENDPLUMEDOC 34 : 35 : namespace PLMD { 36 : namespace dimred { 37 : 38 : class SketchMapConjGrad : public SketchMapBase { 39 : private: 40 : double cgtol; 41 : public: 42 : static void registerKeywords( Keywords& keys ); 43 : explicit SketchMapConjGrad( const ActionOptions& ao ); 44 : void minimise( Matrix<double>& ) override; 45 : }; 46 : 47 10425 : PLUMED_REGISTER_ACTION(SketchMapConjGrad,"SKETCHMAP_CONJGRAD") 48 : 49 4 : void SketchMapConjGrad::registerKeywords( Keywords& keys ) { 50 4 : SketchMapBase::registerKeywords( keys ); 51 8 : keys.add("compulsory","CGTOL","1E-6","the tolerance for the conjugate gradient minimization"); 52 4 : } 53 : 54 3 : SketchMapConjGrad::SketchMapConjGrad( const ActionOptions& ao ): 55 : Action(ao), 56 3 : SketchMapBase(ao) 57 : { 58 3 : parse("CGTOL",cgtol); 59 3 : log.printf(" tolerance for conjugate gradient algorithm equals %f \n",cgtol); 60 3 : } 61 : 62 4 : void SketchMapConjGrad::minimise( Matrix<double>& projections ) { 63 : ConjugateGradient<SketchMapConjGrad> mycgminimise( this ); 64 4 : std::vector<double> myproj( projections.getVector() ); 65 4 : mycgminimise.minimise( cgtol, myproj, &SketchMapConjGrad::calculateFullStress ); 66 4 : projections.setFromVector( myproj ); 67 4 : } 68 : 69 : } 70 : }