Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2012-2019 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 : #ifndef __PLUMED_tools_KernelFunctions_h
23 : #define __PLUMED_tools_KernelFunctions_h
24 :
25 : #include "Tools.h"
26 : #include "Matrix.h"
27 : #include "core/Value.h"
28 : #include <vector>
29 :
30 : namespace PLMD {
31 :
32 234504 : class KernelFunctions {
33 : private:
34 : /// Is the metric matrix diagonal
35 : bool diagonal;
36 : /// What type of kernel are we using
37 : enum {gaussian,uniform,triangular} ktype;
38 : /// The center of the kernel function
39 : std::vector<double> center;
40 : /// The width of the kernel
41 : std::vector<double> width;
42 : /// The height of the kernel
43 : double height;
44 : /// Used to set all the data in the kernel during construction - avoids double coding as this has two constructors
45 : void setData( const std::vector<double>& at, const std::vector<double>& sig, const std::string& type, const bool multivariate,const double& w, const bool norm );
46 : /// Convert the width into matrix form
47 : Matrix<double> getMatrix() const;
48 : public:
49 : KernelFunctions( const std::string& input, const bool& normed );
50 : KernelFunctions( const std::vector<double>& at, const std::vector<double>& sig, const std::string& type, const bool multivariate,const double& w, const bool norm );
51 : /// Get the dimensionality of the kernel
52 : unsigned ndim() const;
53 : /// Get the cutoff for a kernel
54 : double getCutoff( const double& width ) const ;
55 : /// Get the position of the center
56 : std::vector<double> getCenter() const;
57 : /// Get the support
58 : std::vector<unsigned> getSupport( const std::vector<double>& dx ) const;
59 : /// get it in continuous form
60 : std::vector<double> getContinuousSupport( ) const;
61 : /// Evaluate the kernel function with constant intervals
62 : double evaluate( const std::vector<Value*>& pos, std::vector<double>& derivatives, bool usederiv=true, bool doInt=false, double lowI_=-1, double uppI_=-1 ) const;
63 : /// Read a kernel function from a file
64 : static KernelFunctions* read( IFile* ifile, const std::vector<std::string>& valnames );
65 : };
66 :
67 : inline
68 974872 : Matrix<double> KernelFunctions::getMatrix() const {
69 : unsigned k=0, ncv=ndim(); Matrix<double> mymatrix(ncv,ncv);
70 4874360 : for(unsigned i=0; i<ncv; i++) {
71 7798976 : for(unsigned j=i; j<ncv; j++) {
72 8773848 : mymatrix(i,j)=mymatrix(j,i)=width[k]; // recompose the full inverse matrix
73 2924616 : k++;
74 : }
75 : }
76 974872 : return mymatrix;
77 : }
78 :
79 : inline
80 : unsigned KernelFunctions::ndim() const {
81 107315382 : return center.size();
82 : }
83 :
84 : inline
85 : std::vector<double> KernelFunctions::getCenter() const {
86 26967 : return center;
87 : }
88 :
89 : }
90 : #endif
|