Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2018-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/ActionShortcut.h" 23 : #include "core/ActionRegister.h" 24 : 25 : namespace PLMD { 26 : namespace dimred { 27 : 28 : //+PLUMEDOC DIMRED SKETCH_MAP 29 : /* 30 : This can be used to output the data that has been stored in an Analysis object. 31 : 32 : \par Examples 33 : 34 : */ 35 : //+ENDPLUMEDOC 36 : 37 : class SketchMap : public ActionShortcut { 38 : public: 39 : static void registerKeywords( Keywords& keys ); 40 : explicit SketchMap( const ActionOptions& ); 41 : }; 42 : 43 10419 : PLUMED_REGISTER_ACTION(SketchMap,"SKETCH_MAP") 44 : 45 1 : void SketchMap::registerKeywords( Keywords& keys ) { 46 1 : ActionShortcut::registerKeywords( keys ); 47 2 : keys.add("compulsory","NLOW_DIM","the dimension of the low dimensional space in which the projections will be constructed"); 48 2 : keys.add("compulsory","MATRIX","the matrix of distances between points that you want to reproduce in your sketch-map projection"); 49 3 : keys.add("compulsory","HIGH_DIM_FUNCTION","the parameters of the switching function in the high dimensional space"); 50 3 : keys.add("compulsory","LOW_DIM_FUNCTION","the parameters of the switching function in the low dimensional space"); 51 2 : keys.add("compulsory","ANNEAL_RATE","0.5","the rate at which to do the annealing"); 52 2 : keys.add("compulsory","ANNEAL_STEPS","10","the number of steps of annealing to do"); 53 2 : keys.add("compulsory","CGTOL","1E-6","the tolerance for the conjugate gradient minimization"); 54 : // Smap pointwise input 55 2 : keys.add("compulsory","NCYCLES","5","the number of cycles of global optimization to attempt"); 56 2 : keys.add("compulsory","BUFFER","1.1","grid extent for search is (max projection - minimum projection) multiplied by this value"); 57 2 : keys.add("compulsory","CGRID_SIZE","10","number of points to use in each grid direction"); 58 2 : keys.add("compulsory","FGRID_SIZE","0","interpolate the grid onto this number of points -- only works in 2D"); 59 1 : } 60 : 61 0 : SketchMap::SketchMap( const ActionOptions& ao ) : 62 : Action(ao), 63 0 : ActionShortcut(ao) 64 : { 65 : // Input for MDS 66 0 : std::string mds_line = getShortcutLabel() + "_mds: CLASSICAL_MDS"; 67 0 : std::string nlow; parse("NLOW_DIM",nlow); mds_line += " NLOW_DIM=" + nlow; 68 0 : std::string mat; parse("MATRIX",mat); mds_line += " USE_OUTPUT_DATA_FROM=" + mat; 69 0 : readInputLine( mds_line ); 70 : // Create generic input for all conjgrad cycles 71 0 : std::string cgtol; parse("CGTOL",cgtol); std::string ncyc; parse("NCYCLES",ncyc); std::string buf; parse("BUFFER",buf); 72 0 : std::string cg_grid; parse("CGRID_SIZE",cg_grid); std::string fg_grid; parse("FGRID_SIZE",fg_grid); 73 0 : std::string cg_step_input = " CGTOL=" + cgtol; unsigned nlow_dim; Tools::convert( nlow, nlow_dim ); 74 0 : std::string pw_step_input = cg_step_input + " NCYCLES=" + ncyc + " BUFFER=" + buf; 75 0 : pw_step_input += " CGRID_SIZE=" + cg_grid; for(unsigned i=1; i<nlow_dim; ++i) pw_step_input += "," + cg_grid; 76 0 : pw_step_input += " FGRID_SIZE=" + fg_grid; for(unsigned i=1; i<nlow_dim; ++i) pw_step_input += "," + fg_grid; 77 : // Input for iterative distance matching 78 0 : std::string imds_line_cg = getShortcutLabel() + "_smap1_cg: SKETCHMAP_CONJGRAD USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_mds"; 79 0 : std::string hd_func; parse("HIGH_DIM_FUNCTION",hd_func); imds_line_cg += " HIGH_DIM_FUNCTION={" + hd_func + "}"; 80 0 : std::string ld_func; parse("LOW_DIM_FUNCTION",ld_func); imds_line_cg += " LOW_DIM_FUNCTION={" + ld_func + "}"; 81 0 : imds_line_cg += cg_step_input + " MIXPARAM=1.0"; readInputLine( imds_line_cg ); 82 0 : std::string imds_line_pw = getShortcutLabel() + "_smap1_pw: SKETCHMAP_POINTWISE USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_smap1_cg"; 83 0 : imds_line_pw += pw_step_input + " MIXPARAM=1.0"; readInputLine( imds_line_pw ); 84 : // Now sketch-map 85 0 : unsigned asteps; parse("ANNEAL_STEPS",asteps); std::string psmap = getShortcutLabel() + "_smap1_pw"; 86 0 : if( asteps>1 ) { 87 0 : double smear; parse("ANNEAL_RATE", smear); double old_mix = 1.0; double new_mix = old_mix*smear; 88 0 : for(unsigned i=0; i<asteps; ++i) { 89 0 : std::string omix; Tools::convert( old_mix, omix ); std::string nmix; Tools::convert( new_mix, nmix ); 90 0 : imds_line_cg = getShortcutLabel() + "_smap" + nmix + "_cg: SKETCHMAP_CONJGRAD USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_smap" + omix + "_pw"; 91 0 : imds_line_cg += cg_step_input + " MIXPARAM=" + nmix; readInputLine( imds_line_cg ); 92 0 : imds_line_pw = getShortcutLabel() + "_smap" + nmix + "_pw: SKETCHMAP_POINTWISE USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_smap" + omix + "_cg"; 93 0 : imds_line_pw += pw_step_input + " MIXPARAM=" + nmix; readInputLine( imds_line_pw ); 94 0 : old_mix = new_mix; new_mix = old_mix*smear; psmap = getShortcutLabel() + "_smap" + nmix + "_pw"; 95 : } 96 : } 97 : // Final sketch-map with no mixing of distance matching 98 0 : imds_line_cg = getShortcutLabel() + "_smap_cg: SKETCHMAP_CONJGRAD USE_OUTPUT_DATA_FROM=" + psmap + cg_step_input; 99 0 : readInputLine( imds_line_cg ); 100 0 : imds_line_pw = getShortcutLabel() + ": SKETCHMAP_POINTWISE USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_smap_cg" + pw_step_input; 101 0 : readInputLine( imds_line_pw ); 102 0 : } 103 : 104 : } 105 : }