queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
SampledVectorCdf.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/SampledVectorCdf.h>
26 
27 namespace QUESO {
28 
29 // Default constructor -----------------------------
30 template<class V,class M>
32  const char* prefix,
33  const ArrayOfOneDGrids <V,M>& oneDGrids,
34  const ArrayOfOneDTables<V,M>& cdfValues)
35  :
36  BaseVectorCdf<V,M>(prefix,oneDGrids.rowSpace()),
37  m_cdfs(m_pdfSupport.vectorSpace().map(),1)
38 {
39  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
40  *m_env.subDisplayFile() << "Entering SampledVectorCdf<V,M>::constructor()"
41  << ": prefix = " << m_prefix
42  << std::endl;
43  }
44 
45  char strI[65];
46  for (unsigned int i = 0; i < (unsigned int) m_cdfs.MyLength(); ++i) {
47  sprintf(strI,"%u_",i);
49  ((std::string)(m_prefix)+strI).c_str(),
50  oneDGrids.grid(i),
51  cdfValues.oneDTable(i));
52  }
53 
54  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
55  *m_env.subDisplayFile() << "Leaving SampledVectorCdf<V,M>::constructor()"
56  << ": prefix = " << m_prefix
57  << std::endl;
58  }
59 }
60 // Destructor ---------------------------------------
61 template<class V,class M>
63 {
64  for (unsigned int i = 0; i < (unsigned int) m_cdfs.MyLength(); ++i) {
65  if (m_cdfs(i,0)) delete m_cdfs(i,0);
66  }
67 }
68 // Math methods--------------------------------------
69 template<class V, class M>
70 void
72  const V& paramValues,
73  V& cdfVec) const
74 {
75  queso_error_msg("incomplete code");
76  return;
77 }
78 // --------------------------------------------------
79 template<class V, class M>
81 SampledVectorCdf<V,M>::cdf(unsigned int rowId) const
82 {
83  queso_require_less_msg(rowId, m_pdfSupport.vectorSpace().dimLocal(), "rowId is out of range");
84 
85  SampledVectorCdf<V,M>* tmp = const_cast<SampledVectorCdf<V,M>*>(this);
86  return *(tmp->m_cdfs(rowId,0));
87 
88 }
89 // I/O methods---------------------------------------
90 template <class V, class M>
91 void
92 SampledVectorCdf<V,M>::print(std::ostream& os) const
93 {
94  SampledVectorCdf<V,M>* tmp = const_cast<SampledVectorCdf<V,M>*>(this);
95  for (unsigned int i = 0; i < (unsigned int) m_cdfs.MyLength(); ++i) {
96  os << (*tmp->m_cdfs(i,0))
97  << std::endl;
98  }
99 
100  return;
101 }
102 //---------------------------------------------------
103 template<class V, class M>
104 void
106  const std::string& varNamePrefix,
107  const std::string& fileName,
108  const std::string& fileType,
109  const std::set<unsigned int>& allowedSubEnvIds) const
110 {
111  queso_require_greater_equal_msg(m_env.subRank(), 0, "unexpected subRank");
112 
113  SampledVectorCdf<V,M>* tmp = const_cast<SampledVectorCdf<V,M>*>(this);
114  char compId[16+1];
115  for (unsigned int i = 0; i < (unsigned int) m_cdfs.MyLength(); ++i) {
116  sprintf(compId,"%d",i);
117  tmp->m_cdfs(i,0)->subWriteContents(varNamePrefix+"comp"+compId,fileName,fileType,allowedSubEnvIds);
118  }
119 
120  return;
121 }
122 
123 } // End namespace QUESO
Class to accommodate arrays of one-dimensional grid.
const BaseOneDGrid< double > & grid(unsigned int rowId) const
Returns the grid stored in the rowId-th position of the array of grids.
A class for handling sampled vector CDFs.
std::string m_prefix
Definition: VectorCdf.h:99
SampledVectorCdf(const char *prefix, const ArrayOfOneDGrids< V, M > &oneDGrids, const ArrayOfOneDTables< V, M > &cdfValues)
Default constructor.
Class to accommodate arrays of one-dimensional tables.
const BaseScalarCdf< double > & cdf(unsigned int rowId) const
Returns a scalar CDF stored at row rowId of the vector CDF.
DistArray< SampledScalarCdf< double > * > m_cdfs
A templated (base) class for handling CDFs of vector functions.
Definition: VectorCdf.h:53
void print(std::ostream &os) const
Prints the vector CDF (values of the grid points and of the CDF at such grid points).
A class for handling sampled CDFs.
const std::vector< double > & oneDTable(unsigned int rowId) const
Returns the array located at position rowId of the one-dimensional table.
const BaseEnvironment & m_env
Definition: VectorCdf.h:98
A templated (base) class for handling CDFs.
Definition: ScalarCdf.h:49
void values(const V &paramValues, V &cdfVec) const
TODO: Returns the values of the vector CDF at each element of paramValues.
void subWriteContents(const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
Writes the CDF of an allowed sub-environment to a file.
unsigned int displayVerbosity() const
Definition: Environment.C:450
~SampledVectorCdf()
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:56 for queso-0.57.1 by  doxygen 1.8.5