queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-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 <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 (),
40  m_preComputingPositions(),
41  m_rvs (),
42  m_stageId (0)
43 {
44 }
45 // Constructor with values---------------------------
46 template<class V, class M>
48  const char* prefix,
49  const VectorSpace<V,M>& vectorSpace,
50  const std::vector<double>& scales)
51  :
52  m_emptyEnv (NULL),
53  m_env (vectorSpace.env()),
54  m_prefix (prefix),
55  m_vectorSpace (&vectorSpace),
56  m_scales (scales.size(),1.),
57  m_preComputingPositions(scales.size()+1,NULL), // Yes, +1
58  m_rvs (scales.size(),NULL), // IMPORTANT: it stays like this for scaledTK, but it will be overwritten to '+1' by hessianTK constructor
59  m_stageId (0)
60 {
61  for (unsigned int i = 0; i < m_scales.size(); ++i) {
62  m_scales[i] = scales[i];
63  }
64 }
65 // Destructor ---------------------------------------
66 template<class V, class M>
68 {
69  for (unsigned int i = 0; i < m_rvs.size(); ++i) {
70  if (m_rvs[i]) delete m_rvs[i];
71  }
72  for (unsigned int i = 0; i < m_preComputingPositions.size(); ++i) {
73  if (m_preComputingPositions[i]) delete m_preComputingPositions[i];
74  }
75  if (m_emptyEnv) delete m_emptyEnv;
76 }
77 // Misc methods--------------------------------------
78 template<class V, class M>
79 const BaseEnvironment&
81 {
82  return m_env;
83 }
84 //---------------------------------------------------
85 template<class V, class M>
86 const V&
87 BaseTKGroup<V,M>::preComputingPosition(unsigned int stageId) const
88 {
89  queso_require_greater_msg(m_preComputingPositions.size(), stageId, "m_preComputingPositions.size() <= stageId");
90 
91  queso_require_msg(m_preComputingPositions[stageId], "m_preComputingPositions[stageId] == NULL");
92 
93  return *m_preComputingPositions[stageId];
94 }
95 //---------------------------------------------------
96 template<class V, class M>
97 bool
98 BaseTKGroup<V,M>::setPreComputingPosition(const V& position, unsigned int stageId)
99 {
100  queso_require_greater_msg(m_preComputingPositions.size(), stageId, "m_preComputingPositions.size() <= stageId");
101 
102  queso_require_msg(!(m_preComputingPositions[stageId]), "m_preComputingPositions[stageId] != NULL");
103 
104  m_preComputingPositions[stageId] = new V(position);
105 
106  return true;
107 }
108 //---------------------------------------------------
109 template<class V, class M>
110 void
112 {
113  for (unsigned int i = 0; i < m_preComputingPositions.size(); ++i) {
114  if (m_preComputingPositions[i]) {
115  delete m_preComputingPositions[i];
116  m_preComputingPositions[i] = NULL;
117  }
118  }
119 
120  return;
121 }
122 
123 template <class V, class M>
124 unsigned int
125 BaseTKGroup<V, M>::set_dr_stage(unsigned int stageId)
126 {
127  return this->m_stageId;
128 }
129 
130 // I/O methods---------------------------------------
131 template<class V, class M>
132 void
133 BaseTKGroup<V,M>::print(std::ostream& os) const
134 {
135  os << "In BaseTKGroup<V,M>::print()"
136  << ": nothing to be printed" << std::endl;
137  return;
138 }
139 
140 } // End namespace QUESO
141 
const BaseEnvironment & env() const
QUESO&#39;s environment.
Definition: TKGroup.C:80
A class representing a vector space.
Definition: VectorSet.h:49
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:198
virtual void print(std::ostream &os) const
TODO: Prints the transition kernel.
Definition: TKGroup.C:133
virtual void clearPreComputingPositions()
Clears the pre-computing positions m_preComputingPositions[stageId].
Definition: TKGroup.C:111
This class sets up the environment underlying the use of the QUESO library by an executable.
Definition: Environment.h:484
virtual ~BaseTKGroup()
Destructor.
Definition: TKGroup.C:67
const V & preComputingPosition(unsigned int stageId) const
Pre-computing position; access to protected attribute *m_preComputingPositions[stageId].
Definition: TKGroup.C:87
BaseTKGroup()
Default constructor.
Definition: TKGroup.C:33
std::vector< double > m_scales
Definition: TKGroup.h:131
virtual unsigned int set_dr_stage(unsigned int stageId)
Does nothing. Subclasses may re-implement. Returns the current stage id.
Definition: TKGroup.C:125
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:98

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