queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
ConcatenatedVectorRV.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/ConcatenatedVectorRV.h>
26 #include <queso/ConcatenatedVectorRealizer.h>
27 #include <queso/ConcatenatedJointPdf.h>
28 #include <queso/GslVector.h>
29 #include <queso/GslMatrix.h>
30 
31 #include <limits>
32 
33 namespace QUESO {
34 
35 // Constructor -------------------------------------
36 template<class V, class M>
38  const char* prefix,
39  const BaseVectorRV<V,M>& rv1,
40  const BaseVectorRV<V,M>& rv2,
41  const VectorSet<V,M>& imageSet)
42  :
43  BaseVectorRV<V,M>(((std::string)(prefix)+"concat").c_str(),imageSet),
44  m_rvs (2,(const BaseVectorRV <V,M>*) NULL),
45  m_pdfs (2,(const BaseJointPdf <V,M>*) NULL),
46  m_realizers (2,(const BaseVectorRealizer<V,M>*) NULL)
47 {
48  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
49  *m_env.subDisplayFile() << "Entering ConcatenatedVectorRV<V,M>::constructor(1)"
50  << ": prefix = " << m_prefix
51  << std::endl;
52  }
53 
54  m_rvs[0] = &rv1;
55  m_rvs[1] = &rv2;
56  m_pdfs[0] = &(m_rvs[0]->pdf());
57  m_pdfs[1] = &(m_rvs[1]->pdf());
58  m_realizers[0] = m_rvs[0]->has_realizer() ?
59  &(m_rvs[0]->realizer()) : NULL;
60  m_realizers[1] = m_rvs[1]->has_realizer() ?
61  &(m_rvs[1]->realizer()) : NULL;
62 
64  *(m_pdfs[0]),
65  *(m_pdfs[1]),
66  m_imageSet);
67 
68  // Iff we have all sub-realizers, we can make our own realizer
69  m_realizer = (m_rvs[0]->has_realizer() &&
70  m_rvs[1]->has_realizer()) ?
72  *(m_realizers[0]),
73  *(m_realizers[1]),
74  m_imageSet) :
75  NULL;
76 
77  m_subCdf = NULL; // FIX ME: complete code
78  m_unifiedCdf = NULL; // FIX ME: complete code
79  m_mdf = NULL; // FIX ME: complete code
80 
81  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
82  *m_env.subDisplayFile() << "Leaving ConcatenatedVectorRV<V,M>::constructor(1)"
83  << ": prefix = " << m_prefix
84  << std::endl;
85  }
86 }
87 // Constructor -------------------------------------
88 template<class V, class M>
90  const char* prefix,
91  const std::vector<const BaseVectorRV<V,M>* >& rvs,
92  const VectorSet<V,M>& imageSet)
93  :
94  BaseVectorRV<V,M>(((std::string)(prefix)+"concat").c_str(),imageSet),
95  m_rvs (rvs.size(),(const BaseVectorRV <V,M>*) NULL),
96  m_pdfs (rvs.size(),(const BaseJointPdf <V,M>*) NULL),
97  m_realizers (rvs.size(),(const BaseVectorRealizer<V,M>*) NULL)
98 {
99  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
100  *m_env.subDisplayFile() << "Entering ConcatenatedVectorRV<V,M>::constructor(2)"
101  << ": prefix = " << m_prefix
102  << std::endl;
103  }
104 
105  bool have_all_subrealizers = true; // maybe
106  for (unsigned int i = 0; i < m_rvs.size(); ++i) {
107  m_rvs [i] = rvs[i];
108  m_pdfs[i] = &(m_rvs[i]->pdf());
109 
110  // If our sub-RV has no realizer, we leave our pointer to it set
111  // to NULL
112  if (m_rvs[i]->has_realizer())
113  m_realizers[i] = &(m_rvs[i]->realizer());
114  else
115  have_all_subrealizers = false;
116  }
117 
119  m_pdfs,
120  m_imageSet);
121 
122  unsigned int minPeriod = std::numeric_limits<unsigned int>::max();
123  for (unsigned int i = 0; i < m_realizers.size(); ++i) {
124  if (m_realizers[i] && minPeriod > m_realizers[i]->subPeriod()) {
125  minPeriod = m_realizers[i]->subPeriod();
126  }
127  }
128 
129  m_realizer = have_all_subrealizers ?
131  m_realizers,
132  minPeriod,
133  m_imageSet) :
134  NULL;
135  m_subCdf = NULL; // FIX ME: complete code
136  m_unifiedCdf = NULL; // FIX ME: complete code
137  m_mdf = NULL; // FIX ME: complete code
138 
139  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
140  *m_env.subDisplayFile() << "Leaving ConcatenatedVectorRV<V,M>::constructor(2)"
141  << ": prefix = " << m_prefix
142  << std::endl;
143  }
144 }
145 // Destructor --------------------------------------
146 template<class V, class M>
148 {
149  delete m_mdf;
150  delete m_unifiedCdf;
151  delete m_subCdf;
152  delete m_realizer;
153  delete m_pdf;
154 }
155 //--------------------------------------------------
156 template <class V, class M>
157 void
158 ConcatenatedVectorRV<V,M>::print(std::ostream& os) const
159 {
160  os << "ConcatenatedVectorRV<V,M>::print() says, 'Please implement me.'" << std::endl;
161  return;
162 }
163 
164 } // End namespace QUESO
165 
ConcatenatedVectorRV(const char *prefix, const BaseVectorRV< V, M > &rv1, const BaseVectorRV< V, M > &rv2, const VectorSet< V, M > &imageSet)
Constructor.
std::string m_prefix
Definition: VectorRV.h:118
A templated (base) class for handling sampling from vector RVs.
const BaseVectorCdf< V, M > * m_unifiedCdf
Definition: VectorRV.h:123
A class for handling concatenated PDFs.
std::vector< const BaseJointPdf< V, M > * > m_pdfs
const BaseEnvironment & m_env
Definition: VectorRV.h:117
A templated class for handling sets.
Definition: VectorSet.h:52
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:121
A class representing concatenated vector RVs.
std::vector< const BaseVectorRV< V, M > * > m_rvs
A templated (base) class for handling joint PDFs.
Definition: JointPdf.h:55
void print(std::ostream &os) const
TODO: Prints the vector RV.
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:120
std::vector< const BaseVectorRealizer< V, M > * > m_realizers
A templated base class for handling vector RV.
Definition: VectorRV.h:53
const BaseVectorCdf< V, M > * m_subCdf
Definition: VectorRV.h:122
A class for handling sampling from concatenated probability density distributions.
unsigned int displayVerbosity() const
Definition: Environment.C:450
bool has_realizer() const
Returns true iff this RV has the ability to produce realizations (samples)
Definition: VectorRV.C:99
const BaseVectorRealizer< V, M > & realizer() const
Finds a realization (sample) of the PDF of this vector RV; access to private attribute m_realizer...
Definition: VectorRV.C:106
const VectorSet< V, M > & m_imageSet
Definition: VectorRV.h:119
const BaseVectorMdf< V, M > * m_mdf
Definition: VectorRV.h:124
virtual ~ConcatenatedVectorRV()
Virtual destructor.
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