queso-0.52.0
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-2015 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  UQ_FATAL_TEST_MACRO(m_valueRoutinePtr == NULL,
66  m_env.worldRank(),
67  "GenericScalarFunction<V,M>::actualValue()",
68  "m_valueRoutinePtr = NULL");
69 
70  double value = m_valueRoutinePtr(domainVector, domainDirection, m_routinesDataPtr, gradVector, hessianMatrix, hessianEffect);
71  if (m_routineIsForLn) {
72  value = std::exp(value);
73  UQ_FATAL_TEST_MACRO((domainDirection != NULL) ||
74  (gradVector != NULL) ||
75  (hessianMatrix != NULL) ||
76  (hessianEffect != NULL),
77  m_env.worldRank(),
78  "GenericScalarFunction<V,M>::gradOfActual()",
79  "INCOMPLETE CODE");
80  }
81  return value;
82 }
83 
84 
85 template<class V,class M>
86 double GenericScalarFunction<V,M>::lnValue(const V& domainVector,
87  const V* domainDirection,
88  V* gradVector,
89  M* hessianMatrix,
90  V* hessianEffect) const
91 {
92  UQ_FATAL_TEST_MACRO(m_valueRoutinePtr == NULL,
93  m_env.worldRank(),
94  "GenericScalarFunction<V,M>::lnValue()",
95  "m_valueRoutinePtr = NULL");
96 
97  double value = m_valueRoutinePtr(domainVector, domainDirection, m_routinesDataPtr, gradVector, hessianMatrix, hessianEffect);
98  if (m_routineIsForLn == false) {
99  value = log(value);
100  UQ_FATAL_TEST_MACRO((domainDirection != NULL) ||
101  (gradVector != NULL) ||
102  (hessianMatrix != NULL) ||
103  (hessianEffect != NULL),
104  m_env.worldRank(),
105  "GenericScalarFunction<V,M>::gradOfLn()",
106  "INCOMPLETE CODE");
107  }
108  return value;
109 }
110 
111 } // End namespace QUESO
112 
A templated class for handling sets.
Definition: VectorSet.h:49
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
A templated (base) class for handling scalar functions.
Definition: GslOptimizer.h:48
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 class for handling generic scalar functions.
double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Calculates the actual value of this scalar function.
virtual ~GenericScalarFunction()
Virtual destructor.
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.

Generated on Thu Apr 23 2015 19:30:54 for queso-0.52.0 by  doxygen 1.8.5