LCOV - code coverage report
Current view: top level - ves - CoeffsVector.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 2 4 50.0 %
Date: 2024-10-18 13:59:31 Functions: 0 0 -

          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             : #ifndef __PLUMED_ves_CoeffsVector_h
      23             : #define __PLUMED_ves_CoeffsVector_h
      24             : 
      25             : #include "CoeffsBase.h"
      26             : 
      27             : #include <vector>
      28             : #include <string>
      29             : #include <cmath>
      30             : #include <memory>
      31             : 
      32             : 
      33             : namespace PLMD {
      34             : 
      35             : class Action;
      36             : class Value;
      37             : class IFile;
      38             : class OFile;
      39             : class Communicator;
      40             : 
      41             : namespace ves {
      42             : 
      43             : class BasisFunctions;
      44             : class CoeffsMatrix;
      45             : 
      46             : 
      47             : class CoeffsVector:
      48             :   public CoeffsBase
      49             : {
      50             : public:
      51             : private:
      52             :   std::vector<double> data;
      53             :   //
      54             :   unsigned int averaging_counter;
      55             :   unsigned int averaging_exp_decay_;
      56             :   //
      57             :   Communicator& mycomm;
      58             :   //
      59             :   CoeffsVector& operator=(const CoeffsVector&);
      60             : public:
      61             :   explicit CoeffsVector(
      62             :     const std::string&,
      63             :     const std::vector<std::string>&,
      64             :     const std::vector<unsigned int>&,
      65             :     Communicator&,
      66             :     const bool use_counter=false);
      67             :   //
      68             :   explicit CoeffsVector(
      69             :     const std::string&,
      70             :     const std::vector<Value*>&,
      71             :     std::vector<BasisFunctions*>&,
      72             :     Communicator&,
      73             :     const bool use_counter=false);
      74             :   //
      75             :   explicit CoeffsVector(
      76             :     const std::string&,
      77             :     std::vector<std::vector<Value*> >&,
      78             :     std::vector<std::vector<BasisFunctions*> >&,
      79             :     Communicator&,
      80             :     const bool use_counter=false,
      81             :     const std::string& multicoeffs_label="bias");
      82             :   //
      83             :   explicit CoeffsVector(
      84             :     const std::string&,
      85             :     CoeffsMatrix*,
      86             :     Communicator&);
      87             :   //
      88             :   ~CoeffsVector();
      89             :   //
      90             :   size_t getSize() const {return numberOfCoeffs();}
      91             :   // clear coeffs
      92             :   void clear();
      93             :   void setAllValuesToZero();
      94             :   //
      95             :   std::vector<double> getDataAsVector() const {return data;}
      96             :   //
      97             :   bool sameShape(CoeffsVector&) const;
      98             :   bool sameShape(CoeffsMatrix&) const;
      99             :   static bool sameShape(CoeffsVector&, CoeffsVector&);
     100             :   //
     101             :   void resizeCoeffs(const std::vector<unsigned int>&);
     102             :   void resizeCoeffs(std::vector<BasisFunctions*>&);
     103             :   //
     104             :   void sumCommMPI();
     105             :   void sumCommMPI(Communicator& cc);
     106             :   //
     107             :   void sumMultiSimCommMPI(Communicator&);
     108             :   // get value
     109             :   double getValue(const size_t) const;
     110             :   double getValue(const std::vector<unsigned int>&) const;
     111             :   double& operator[](const size_t index);
     112             :   const double& operator[](const size_t index) const;
     113             :   double& operator[](const std::vector<unsigned int>&);
     114             :   const double& operator[](const std::vector<unsigned int>&) const;
     115             :   double& operator()(const size_t index);
     116             :   const double& operator()(const size_t index) const;
     117             :   double& operator()(const std::vector<unsigned int>&);
     118             :   const double& operator()(const std::vector<unsigned int>&) const;
     119             :   // set value
     120             :   void setValue(const size_t, const double);
     121             :   void setValue(const std::vector<unsigned int>&, const double);
     122             :   // add to value
     123             :   void addToValue(const size_t, const double);
     124             :   void addToValue(const std::vector<unsigned int>&, const double);
     125             :   // scale all values
     126             :   void scaleAllValues(const double);
     127             :   void multiplyWithValues(const std::vector<double>&);
     128             :   CoeffsVector& operator*=(const double);
     129             :   friend CoeffsVector operator*(const double, const CoeffsVector&);
     130             :   friend CoeffsVector operator*(const CoeffsVector&, const double);
     131             :   CoeffsVector& operator*=(const std::vector<double>&);
     132             :   friend CoeffsVector operator*(const std::vector<double>&, const CoeffsVector&);
     133             :   friend CoeffsVector operator*(const CoeffsVector&, const std::vector<double>&);
     134             :   CoeffsVector& operator*=(const CoeffsVector&);
     135             :   CoeffsVector operator*(const CoeffsVector&) const;
     136             :   // set all values
     137             :   void setValues(const double);
     138             :   void setValues(const std::vector<double>&);
     139             :   void setValues(const CoeffsVector&);
     140             :   CoeffsVector& operator=(const double);
     141             :   CoeffsVector& operator=(const std::vector<double>&);
     142             :   // CoeffsVector& operator=(const CoeffsVector&);
     143             :   // add to all values
     144             :   CoeffsVector operator+() const;
     145             :   CoeffsVector operator-() const;
     146             :   void addToValues(const double);
     147             :   void addToValues(const std::vector<double>&);
     148             :   void addToValues(const CoeffsVector&);
     149             :   void subtractFromValues(const double);
     150             :   void subtractFromValues(const std::vector<double>&);
     151             :   void subtractFromValues(const CoeffsVector&);
     152             :   CoeffsVector& operator+=(const double);
     153             :   friend CoeffsVector operator+(const double, const CoeffsVector&);
     154             :   friend CoeffsVector operator+(const CoeffsVector&, const double);
     155             :   CoeffsVector& operator+=(const std::vector<double>&);
     156             :   friend CoeffsVector operator+(const std::vector<double>&, const CoeffsVector&);
     157             :   friend CoeffsVector operator+(const CoeffsVector&, const std::vector<double>&);
     158             :   CoeffsVector& operator-=(const double);
     159             :   friend CoeffsVector operator-(const double, const CoeffsVector&);
     160             :   friend CoeffsVector operator-(const CoeffsVector&, const double);
     161             :   CoeffsVector& operator-=(const std::vector<double>&);
     162             :   friend CoeffsVector operator-(const std::vector<double>&, const CoeffsVector&);
     163             :   friend CoeffsVector operator-(const CoeffsVector&, const std::vector<double>&);
     164             :   CoeffsVector& operator+=(const CoeffsVector&);
     165             :   CoeffsVector operator+(const CoeffsVector&) const;
     166             :   CoeffsVector& operator-=(const CoeffsVector&);
     167             :   CoeffsVector operator-(const CoeffsVector&) const;
     168             :   //
     169             :   void setValuesFromDifferentShape(const CoeffsVector&);
     170             :   //
     171             :   static void averageVectors(CoeffsVector&, CoeffsVector&);
     172             :   static void averageVectors(const std::vector<CoeffsVector*>&);
     173             :   //
     174             :   double getMinValue() const;
     175             :   double getMinValue(size_t&) const;
     176             :   double getMinAbsValue() const;
     177             :   double getMinAbsValue(size_t&) const;
     178             :   //
     179             :   double getMaxValue() const;
     180             :   double getMaxValue(size_t&) const;
     181             :   double getMaxAbsValue() const;
     182             :   double getMaxAbsValue(size_t&) const;
     183             :   //
     184             :   double getNorm() const;
     185             :   double getL1Norm() const;
     186             :   double getL2Norm() const;
     187             :   double getLpNorm(const double) const;
     188             :   double getRMS() const;
     189             :   //
     190             :   void normalizeCoeffs();
     191             :   // Random values
     192             :   void randomizeValuesGaussian(int);
     193             :   //
     194           0 :   void resetAveragingCounter() {averaging_counter=0;}
     195           1 :   void setupExponentiallyDecayingAveraging(const unsigned int averaging_exp_decay_in) {averaging_exp_decay_=averaging_exp_decay_in;}
     196             :   void turnOffExponentiallyDecayingAveraging() {averaging_exp_decay_=0;}
     197             :   void resetAveraging();
     198             :   void addToAverage(const CoeffsVector&);
     199             :   //
     200             :   size_t countValues(const double) const;
     201             : 
     202             :   // file input/output stuff
     203             :   void writeToFile(const std::string&, const bool print_description=false, const bool append_file=false, Action* action_pntr=NULL);
     204             :   void writeToFile(OFile&, const bool print_description=false);
     205             :   void writeToFile(OFile& ofile, CoeffsVector*, const bool print_coeffs_descriptions=false);
     206             :   static void writeToFile(const std::string&, const std::vector<CoeffsVector*>&, const bool print_description=false, const bool append_file=false, Action* action_pntr=NULL);
     207             :   static void writeToFile(OFile&, const std::vector<CoeffsVector*>&, const bool print_description=false);
     208             : private:
     209             :   void writeHeaderToFile(OFile&) const;
     210             :   static void writeDataToFile(OFile&, const std::vector<CoeffsVector*>&, const bool print_description=false);
     211             : public:
     212             :   size_t readFromFile(IFile&, const bool ignore_missing_coeffs=false, const bool ignore_header=false);
     213             :   size_t readFromFile(const std::string&, const bool ignore_missing_coeffs=false, const bool ignore_header=false);
     214             :   size_t readOneSetFromFile(IFile& ifile, const bool ignore_header=false);
     215             : private:
     216             :   void readHeaderFromFile(IFile&, const bool ignore_coeffs_info=false);
     217             :   size_t readDataFromFile(IFile&, const bool ignore_missing_coeffs=false);
     218             : public:
     219           0 :   Communicator& getCommunicator() const {return mycomm;}
     220             : };
     221             : 
     222             : 
     223             : inline
     224             : double CoeffsVector::getValue(const size_t index) const {
     225   142877390 :   return data[index];
     226             : }
     227             : 
     228             : 
     229             : inline
     230             : double CoeffsVector::getValue(const std::vector<unsigned int>& indices) const {
     231             :   return data[getIndex(indices)];
     232             : }
     233             : 
     234             : 
     235             : }
     236             : 
     237             : }
     238             : 
     239             : 
     240             : #endif

Generated by: LCOV version 1.16