queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
ConcatenatedVectorRealizer.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/ConcatenatedVectorRealizer.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 // Constructor -------------------------------------
32 template<class V, class M>
34  const char* prefix,
35  const BaseVectorRealizer<V,M>& realizer1,
36  const BaseVectorRealizer<V,M>& realizer2,
37  const VectorSet<V,M>& unifiedImageSet)
38  :
39  BaseVectorRealizer<V,M>( ((std::string)(prefix)+"gen").c_str(),unifiedImageSet,std::min(realizer1.subPeriod(),realizer2.subPeriod()) ), // 2011/Oct/02
40  m_realizers(2,(const BaseVectorRealizer<V,M>*) NULL)
41 {
42  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
43  *m_env.subDisplayFile() << "Entering ConcatenatedVectorRealizer<V,M>::constructor()"
44  << ": prefix = " << m_prefix
45  << std::endl;
46  }
47 
48  m_realizers[0] = &realizer1;
49  m_realizers[1] = &realizer2;
50 
51  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
52  *m_env.subDisplayFile() << "Leaving ConcatenatedVectorRealizer<V,M>::constructor()"
53  << ": prefix = " << m_prefix
54  << std::endl;
55  }
56 }
57 // Constructor -------------------------------------
58 template<class V, class M>
60  const char* prefix,
61  const std::vector<const BaseVectorRealizer<V,M>* >& realizers,
62  unsigned int minPeriod,
63  const VectorSet<V,M>& unifiedImageSet)
64  :
65  BaseVectorRealizer<V,M>( ((std::string)(prefix)+"gen").c_str(),unifiedImageSet,minPeriod),
66  m_realizers(realizers.size(),(const BaseVectorRealizer<V,M>*) NULL)
67 {
68  for (unsigned int i = 0; i < m_realizers.size(); ++i) {
69  m_realizers[i] = realizers[i];
70  }
71 }
72 // Destructor --------------------------------------
73 template<class V, class M>
75 {
76 }
77 // Realization-related methods----------------------
78 template<class V, class M>
79 void
81 {
82  std::vector<V*> vecs(m_realizers.size(),(V*)NULL);
83  for (unsigned int i = 0; i < vecs.size(); ++i) {
84  vecs[i] = new V(m_realizers[i]->unifiedImageSet().vectorSpace().zeroVector());
85  //std::cout << "In ConcatenatedVectorRealizer<V,M>::realization: v[i]->sizeLocal() = " << v[i]->sizeLocal() << std::endl;
86  m_realizers[i]->realization(*(vecs[i]));
87  }
88 
89  //std::cout << "In ConcatenatedVectorRealizer<V,M>::realization: nextValues.sizeLocal() = " << nextValues.sizeLocal() << std::endl;
90  std::vector<const V*> constVecs(m_realizers.size(),(V*)NULL);
91  for (unsigned int i = 0; i < vecs.size(); ++i) {
92  constVecs[i] = vecs[i];
93  }
94  nextValues.cwSetConcatenated(constVecs);
95  //std::cout << "In ConcatenatedVectorRealizer<V,M>::realization: succeeded" << std::endl;
96 
97  for (unsigned int i = 0; i < vecs.size(); ++i) {
98  delete vecs[i];
99  }
100 
101  return;
102 }
103 
104 } // End namespace QUESO
105 
A templated (base) class for handling sampling from vector RVs.
const BaseEnvironment & m_env
A templated class for handling sets.
Definition: VectorSet.h:52
std::vector< const BaseVectorRealizer< V, M > * > m_realizers
void realization(V &nextValues) const
Performs a realization (sample) from a probability density function. See template specialization...
ConcatenatedVectorRealizer(const char *prefix, const BaseVectorRealizer< V, M > &realizer1, const BaseVectorRealizer< V, M > &realizer2, const VectorSet< V, M > &unifiedImageSet)
Constructor.
A class for handling sampling from concatenated probability density distributions.
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320

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