LCOV - code coverage report
Current view: top level - tools - KernelFunctions.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 9 9 100.0 %
Date: 2024-10-18 13:59:31 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.16