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 13785 : PLUMED_REGISTER_ACTION(SketchMap,"SKETCH_MAP") 44 : 45 4 : void SketchMap::registerKeywords( Keywords& keys ) { 46 4 : ActionShortcut::registerKeywords( keys ); 47 8 : keys.add("compulsory","NLOW_DIM","the dimension of the low dimensional space in which the projections will be constructed"); 48 8 : keys.add("compulsory","MATRIX","the matrix of distances between points that you want to reproduce in your sketch-map projection"); 49 8 : keys.add("compulsory","HIGH_DIM_FUNCTION","the parameters of the switching function in the high dimensional space"); 50 8 : keys.add("compulsory","LOW_DIM_FUNCTION","the parameters of the switching function in the low dimensional space"); 51 8 : keys.add("compulsory","ANNEAL_RATE","0.5","the rate at which to do the annealing"); 52 8 : keys.add("compulsory","ANNEAL_STEPS","10","the number of steps of annealing to do"); 53 8 : keys.add("compulsory","CGTOL","1E-6","the tolerance for the conjugate gradient minimization"); 54 : // Smap pointwise input 55 8 : keys.add("compulsory","NCYCLES","5","the number of cycles of global optimization to attempt"); 56 8 : keys.add("compulsory","BUFFER","1.1","grid extent for search is (max projection - minimum projection) multiplied by this value"); 57 8 : keys.add("compulsory","CGRID_SIZE","10","number of points to use in each grid direction"); 58 8 : keys.add("compulsory","FGRID_SIZE","0","interpolate the grid onto this number of points -- only works in 2D"); 59 4 : } 60 : 61 0 : SketchMap::SketchMap( const ActionOptions& ao ) : 62 : Action(ao), 63 0 : ActionShortcut(ao) { 64 : // Input for MDS 65 0 : std::string mds_line = getShortcutLabel() + "_mds: CLASSICAL_MDS"; 66 : std::string nlow; 67 0 : parse("NLOW_DIM",nlow); 68 0 : mds_line += " NLOW_DIM=" + nlow; 69 : std::string mat; 70 0 : parse("MATRIX",mat); 71 0 : mds_line += " USE_OUTPUT_DATA_FROM=" + mat; 72 0 : readInputLine( mds_line ); 73 : // Create generic input for all conjgrad cycles 74 : std::string cgtol; 75 0 : parse("CGTOL",cgtol); 76 : std::string ncyc; 77 0 : parse("NCYCLES",ncyc); 78 : std::string buf; 79 0 : parse("BUFFER",buf); 80 : std::string cg_grid; 81 0 : parse("CGRID_SIZE",cg_grid); 82 : std::string fg_grid; 83 0 : parse("FGRID_SIZE",fg_grid); 84 0 : std::string cg_step_input = " CGTOL=" + cgtol; 85 : unsigned nlow_dim; 86 0 : Tools::convert( nlow, nlow_dim ); 87 0 : std::string pw_step_input = cg_step_input + " NCYCLES=" + ncyc + " BUFFER=" + buf; 88 0 : pw_step_input += " CGRID_SIZE=" + cg_grid; 89 0 : for(unsigned i=1; i<nlow_dim; ++i) { 90 0 : pw_step_input += "," + cg_grid; 91 : } 92 0 : pw_step_input += " FGRID_SIZE=" + fg_grid; 93 0 : for(unsigned i=1; i<nlow_dim; ++i) { 94 0 : pw_step_input += "," + fg_grid; 95 : } 96 : // Input for iterative distance matching 97 0 : std::string imds_line_cg = getShortcutLabel() + "_smap1_cg: SKETCHMAP_CONJGRAD USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_mds"; 98 : std::string hd_func; 99 0 : parse("HIGH_DIM_FUNCTION",hd_func); 100 0 : imds_line_cg += " HIGH_DIM_FUNCTION={" + hd_func + "}"; 101 : std::string ld_func; 102 0 : parse("LOW_DIM_FUNCTION",ld_func); 103 0 : imds_line_cg += " LOW_DIM_FUNCTION={" + ld_func + "}"; 104 0 : imds_line_cg += cg_step_input + " MIXPARAM=1.0"; 105 0 : readInputLine( imds_line_cg ); 106 0 : std::string imds_line_pw = getShortcutLabel() + "_smap1_pw: SKETCHMAP_POINTWISE USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_smap1_cg"; 107 0 : imds_line_pw += pw_step_input + " MIXPARAM=1.0"; 108 0 : readInputLine( imds_line_pw ); 109 : // Now sketch-map 110 : unsigned asteps; 111 0 : parse("ANNEAL_STEPS",asteps); 112 0 : std::string psmap = getShortcutLabel() + "_smap1_pw"; 113 0 : if( asteps>1 ) { 114 : double smear; 115 0 : parse("ANNEAL_RATE", smear); 116 0 : double old_mix = 1.0; 117 0 : double new_mix = old_mix*smear; 118 0 : for(unsigned i=0; i<asteps; ++i) { 119 : std::string omix; 120 0 : Tools::convert( old_mix, omix ); 121 : std::string nmix; 122 0 : Tools::convert( new_mix, nmix ); 123 0 : imds_line_cg = getShortcutLabel() + "_smap" + nmix + "_cg: SKETCHMAP_CONJGRAD USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_smap" + omix + "_pw"; 124 0 : imds_line_cg += cg_step_input + " MIXPARAM=" + nmix; 125 0 : readInputLine( imds_line_cg ); 126 0 : imds_line_pw = getShortcutLabel() + "_smap" + nmix + "_pw: SKETCHMAP_POINTWISE USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_smap" + omix + "_cg"; 127 0 : imds_line_pw += pw_step_input + " MIXPARAM=" + nmix; 128 0 : readInputLine( imds_line_pw ); 129 0 : old_mix = new_mix; 130 0 : new_mix = old_mix*smear; 131 0 : psmap = getShortcutLabel() + "_smap" + nmix + "_pw"; 132 : } 133 : } 134 : // Final sketch-map with no mixing of distance matching 135 0 : imds_line_cg = getShortcutLabel() + "_smap_cg: SKETCHMAP_CONJGRAD USE_OUTPUT_DATA_FROM=" + psmap + cg_step_input; 136 0 : readInputLine( imds_line_cg ); 137 0 : imds_line_pw = getShortcutLabel() + ": SKETCHMAP_POINTWISE USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_smap_cg" + pw_step_input; 138 0 : readInputLine( imds_line_pw ); 139 0 : } 140 : 141 : } 142 : }