queso-0.52.0
TKGroup.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 <queso/TKGroup.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 // Default constructor ------------------------------
32 template<class V, class M>
34  :
35  m_emptyEnv (new EmptyEnvironment()),
36  m_env (*m_emptyEnv),
37  m_prefix (""),
38  m_vectorSpace (NULL),
39  m_scales (0),
40  m_preComputingPositions(NULL),
41  m_rvs (0)
42 {
43 }
44 // Constructor with values---------------------------
45 template<class V, class M>
47  const char* prefix,
48  const VectorSpace<V,M>& vectorSpace,
49  const std::vector<double>& scales)
50  :
51  m_emptyEnv (NULL),
52  m_env (vectorSpace.env()),
53  m_prefix (prefix),
54  m_vectorSpace (&vectorSpace),
55  m_scales (scales.size(),1.),
56  m_preComputingPositions(scales.size()+1,NULL), // Yes, +1
57  m_rvs (scales.size(),NULL) // IMPORTANT: it stays like this for scaledTK, but it will be overwritten to '+1' by hessianTK constructor
58 {
59  for (unsigned int i = 0; i < m_scales.size(); ++i) {
60  m_scales[i] = scales[i];
61  }
62 }
63 // Destructor ---------------------------------------
64 template<class V, class M>
66 {
67  for (unsigned int i = 0; i < m_rvs.size(); ++i) {
68  if (m_rvs[i]) delete m_rvs[i];
69  }
70  for (unsigned int i = 0; i < m_preComputingPositions.size(); ++i) {
71  if (m_preComputingPositions[i]) delete m_preComputingPositions[i];
72  }
73  if (m_emptyEnv) delete m_emptyEnv;
74 }
75 // Misc methods--------------------------------------
76 template<class V, class M>
77 const BaseEnvironment&
79 {
80  return m_env;
81 }
82 //---------------------------------------------------
83 template<class V, class M>
84 const V&
85 BaseTKGroup<V,M>::preComputingPosition(unsigned int stageId) const
86 {
87  UQ_FATAL_TEST_MACRO(m_preComputingPositions.size() <= stageId,
88  m_env.worldRank(),
89  "BaseTKGroup<V,M>::preComputingPosition()",
90  "m_preComputingPositions.size() <= stageId");
91 
92  UQ_FATAL_TEST_MACRO(m_preComputingPositions[stageId] == NULL,
93  m_env.worldRank(),
94  "BaseTKGroup<V,M>::preComputingPosition()",
95  "m_preComputingPositions[stageId] == NULL");
96 
97  return *m_preComputingPositions[stageId];
98 }
99 //---------------------------------------------------
100 template<class V, class M>
101 bool
102 BaseTKGroup<V,M>::setPreComputingPosition(const V& position, unsigned int stageId)
103 {
104  UQ_FATAL_TEST_MACRO(m_preComputingPositions.size() <= stageId,
105  m_env.worldRank(),
106  "BaseTKGroup<V,M>::setPreComputingPosition()",
107  "m_preComputingPositions.size() <= stageId");
108 
109  UQ_FATAL_TEST_MACRO(m_preComputingPositions[stageId] != NULL,
110  m_env.worldRank(),
111  "BaseTKGroup<V,M>::setPreComputingPosition()",
112  "m_preComputingPositions[stageId] != NULL");
113 
114  m_preComputingPositions[stageId] = new V(position);
115 
116  return true;
117 }
118 //---------------------------------------------------
119 template<class V, class M>
120 void
122 {
123  for (unsigned int i = 0; i < m_preComputingPositions.size(); ++i) {
124  if (m_preComputingPositions[i]) {
125  delete m_preComputingPositions[i];
126  m_preComputingPositions[i] = NULL;
127  }
128  }
129 
130  return;
131 }
132 // I/O methods---------------------------------------
133 template<class V, class M>
134 void
135 BaseTKGroup<V,M>::print(std::ostream& os) const
136 {
137  os << "In BaseTKGroup<V,M>::print()"
138  << ": nothing to be printed" << std::endl;
139  return;
140 }
141 
142 } // End namespace QUESO
143 
std::vector< double > m_scales
Definition: TKGroup.h:102
This base class allows the representation of a transition kernel.
Definition: TKGroup.h:49
virtual void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
Definition: TKGroup.C:121
virtual void print(std::ostream &os) const
TODO: Prints the transition kernel.
Definition: TKGroup.C:135
const BaseEnvironment & env() const
QUESO&#39;s environment.
Definition: TKGroup.C:78
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:187
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
const V & preComputingPosition(unsigned int stageId) const
Pre-computing position; access to protected attribute *m_preComputingPositions[stageId].
Definition: TKGroup.C:85
BaseTKGroup()
Default constructor.
Definition: TKGroup.C:33
A class representing a vector space.
Definition: VectorSet.h:46
This class sets up the environment underlying the use of the QUESO library by an executable.
Definition: Environment.h:396
virtual bool setPreComputingPosition(const V &position, unsigned int stageId)
Sets the pre-computing positions m_preComputingPositions[stageId] with a new vector of size position...
Definition: TKGroup.C:102
virtual ~BaseTKGroup()
Destructor.
Definition: TKGroup.C:65

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