queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
GenericScalarFunction.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2017 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <cmath>
26 
27 #include <queso/Defines.h>
28 #include <queso/VectorSet.h>
29 #include <queso/VectorSubset.h>
30 #include <queso/Environment.h>
31 #include <queso/GenericScalarFunction.h>
32 #include <queso/GslVector.h>
33 #include <queso/GslMatrix.h>
34 
35 namespace QUESO {
36 
37 // Default constructor
38 template<class V,class M>
40  const VectorSet<V,M>& domainSet,
41  double (*valueRoutinePtr)(const V& domainVector, const V* domainDirection, const void* routinesDataPtr, V* gradVector, M* hessianMatrix, V* hessianEffect),
42  const void* routinesDataPtr,
43  bool routineIsForLn)
44  : BaseScalarFunction<V,M>(((std::string)(prefix)+"gen").c_str(), domainSet),
45  m_valueRoutinePtr (valueRoutinePtr),
46  m_routinesDataPtr (routinesDataPtr),
47  m_routineIsForLn (routineIsForLn)
48 {
49 }
50 
51 // Destructor
52 template<class V,class M>
54 {
55 }
56 
57 // Math methods
58 template<class V,class M>
59 double GenericScalarFunction<V,M>::actualValue(const V& domainVector,
60  const V* domainDirection,
61  V* gradVector,
62  M* hessianMatrix,
63  V* hessianEffect) const
64 {
65  queso_require_msg(m_valueRoutinePtr, "m_valueRoutinePtr = NULL");
66 
67  double value = m_valueRoutinePtr(domainVector, domainDirection, m_routinesDataPtr, gradVector, hessianMatrix, hessianEffect);
68  if (m_routineIsForLn) {
69  value = std::exp(value);
70 
71  if ((domainDirection != NULL) ||
72  (gradVector != NULL) ||
73  (hessianMatrix != NULL) ||
74  (hessianEffect != NULL))
75  queso_not_implemented();
76  }
77  return value;
78 }
79 
80 
81 template<class V,class M>
82 double GenericScalarFunction<V,M>::lnValue(const V& domainVector,
83  const V* domainDirection,
84  V* gradVector,
85  M* hessianMatrix,
86  V* hessianEffect) const
87 {
88  queso_require_msg(m_valueRoutinePtr, "m_valueRoutinePtr = NULL");
89 
90  double value = m_valueRoutinePtr(domainVector, domainDirection, m_routinesDataPtr, gradVector, hessianMatrix, hessianEffect);
91  if (m_routineIsForLn == false) {
92  value = log(value);
93 
94  if ((domainDirection != NULL) ||
95  (gradVector != NULL) ||
96  (hessianMatrix != NULL) ||
97  (hessianEffect != NULL))
98  queso_not_implemented();
99  }
100  return value;
101 }
102 
103 } // End namespace QUESO
104 
virtual ~GenericScalarFunction()
Virtual destructor.
A templated (base) class for handling scalar functions.
double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Calculates the logarithm of value of this scalar function.
A templated class for handling sets.
Definition: VectorSet.h:52
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Calculates the actual value of this scalar function.
GenericScalarFunction(const char *prefix, const VectorSet< V, M > &domainSet, double(*valueRoutinePtr)(const V &domainVector, const V *domainDirection, const void *routinesDataPtr, V *gradVector, M *hessianMatrix, V *hessianEffect), const void *routinesDataPtr, bool routineIsForLn)
Default constructor.
A class for handling generic scalar functions.

Generated on Tue Jun 5 2018 19:48:54 for queso-0.57.1 by  doxygen 1.8.5