Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-2021 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 "TargetDistribution.h" 24 : 25 : #include "core/ActionRegister.h" 26 : 27 : 28 : namespace PLMD { 29 : namespace ves { 30 : 31 : //+PLUMEDOC VES_TARGETDIST TD_EXPONENTIAL 32 : /* 33 : Exponential distribution (static). 34 : 35 : Employ a target distribution given by an 36 : [exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution) 37 : that is defined as 38 : 39 : $$ 40 : p(s) = 41 : \lambda e^{-\lambda(s-a)} 42 : $$ 43 : 44 : where $a$ is the minimum of the distribution that is defined on the interval $[a,\infty)$, 45 : and $\lambda>0$ is the so-called rate parameter. 46 : 47 : The minimum $a$ is given using the MINIMUM keyword, and the rate parameter $\lambda$ is given 48 : using the LAMBDA keyword. 49 : 50 : This target distribution action is only defined for one dimension, for multiple dimensions 51 : it should be used in combination with [TD_PRODUCT_DISTRIBUTION](TD_PRODUCT_DISTRIBUTION.md) action. 52 : 53 : ## Examples 54 : 55 : Exponential distribution with $a=10.0$ and $\lambda=0.5$ 56 : 57 : ```plumed 58 : td: TD_EXPONENTIAL MINIMUM=-10.0 LAMBDA=0.5 59 : ``` 60 : 61 : The exponential distribution is only defined for one dimension so for multiple 62 : dimensions we have to use it in combination with the [TD_PRODUCT_DISTRIBUTION](TD_PRODUCT_DISTRIBUTION.md) action as shown in 63 : the following example where we have a uniform distribution for argument 1 and 64 : and an exponential distribution for argument 2 65 : 66 : ```plumed 67 : td_uni: TD_UNIFORM 68 : 69 : td_exp: TD_EXPONENTIAL MINIMUM=-10.0 LAMBDA=0.5 70 : 71 : td_pd: TD_PRODUCT_DISTRIBUTION DISTRIBUTIONS=td_uni,td_exp 72 : ``` 73 : 74 : 75 : */ 76 : //+ENDPLUMEDOC 77 : 78 : class TD_Exponential: public TargetDistribution { 79 : std::vector<double> minima_; 80 : std::vector<double> lambda_; 81 : public: 82 : static void registerKeywords(Keywords&); 83 : explicit TD_Exponential(const ActionOptions& ao); 84 : double getValue(const std::vector<double>&) const override; 85 : }; 86 : 87 : 88 : PLUMED_REGISTER_ACTION(TD_Exponential,"TD_EXPONENTIAL") 89 : 90 : 91 10 : void TD_Exponential::registerKeywords(Keywords& keys) { 92 10 : TargetDistribution::registerKeywords(keys); 93 10 : keys.add("compulsory","MINIMUM","The minimum of the exponential distribution."); 94 10 : keys.add("compulsory","LAMBDA","The lambda parameter of the exponential distribution given as positive number."); 95 10 : keys.use("WELLTEMPERED_FACTOR"); 96 10 : keys.use("SHIFT_TO_ZERO"); 97 10 : keys.use("NORMALIZE"); 98 10 : } 99 : 100 : 101 8 : TD_Exponential::TD_Exponential(const ActionOptions& ao): 102 : PLUMED_VES_TARGETDISTRIBUTION_INIT(ao), 103 16 : minima_(0), 104 8 : lambda_(0) { 105 8 : parseVector("MINIMUM",minima_); 106 8 : parseVector("LAMBDA",lambda_); 107 16 : for(unsigned int k=0; k<lambda_.size(); k++) { 108 8 : if(lambda_[k] < 0.0) { 109 0 : plumed_merror(getName()+": the value given in LAMBDA should be positive."); 110 : } 111 : } 112 : 113 : 114 8 : setDimension(minima_.size()); 115 8 : if(getDimension()>1) { 116 0 : plumed_merror(getName()+": only defined for one dimension, for multiple dimensions it should be used in combination with the TD_PRODUCT_DISTRIBUTION action."); 117 : } 118 8 : if(lambda_.size()!=getDimension()) { 119 0 : plumed_merror(getName()+": the LAMBDA keyword does not match the given dimension in MINIMUM"); 120 : } 121 8 : checkRead(); 122 8 : } 123 : 124 : 125 1308 : double TD_Exponential::getValue(const std::vector<double>& argument) const { 126 : double value = 1.0; 127 2616 : for(unsigned int k=0; k<argument.size(); k++) { 128 1308 : double arg = (argument[k]-minima_[k])*lambda_[k]; 129 1308 : if(arg<0.0) { 130 0 : plumed_merror(getName()+": the exponential distribution is not defined for values less that ones given in MINIMUM"); 131 : } 132 1308 : value *= lambda_[k]*exp(-arg); 133 : } 134 1308 : return value; 135 : } 136 : 137 : 138 : 139 : } 140 : }