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

Generated by: LCOV version 1.16