queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
BoxSubset.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/VectorSpace.h>
26 #include <queso/BoxSubset.h>
27 #include <queso/GslVector.h>
28 #include <queso/GslMatrix.h>
29 
30 namespace QUESO {
31 
32 // Default, shaped constructor
33 template<class V, class M>
34 BoxSubset<V,M>::BoxSubset(const char* prefix,
35  const VectorSpace<V,M>& vectorSpace,
36  const V& minValues,
37  const V& maxValues)
38  : VectorSubset<V,M>(prefix,vectorSpace,0.),
39  m_minValues(minValues),
40  m_maxValues(maxValues)
41 {
42  queso_require_equal_to_msg(minValues.sizeLocal(), maxValues.sizeLocal(), "vectors 'minValues' and 'maxValues' should have the same size");
43  queso_require_equal_to_msg(minValues.sizeLocal(), vectorSpace.dimLocal(), "sizes of vectors 'minValues' and 'maxValues' should be equal to dimension of the vector space");
44  for (unsigned int i = 0; i < m_vectorSpace->dimLocal(); ++i) {
45  queso_require_less_equal_msg(minValues[i], maxValues[i], "it should happen minValue <= maxValue for all dimensions");
46  }
47 
48  m_volume = 1.;
49  for (unsigned int i = 0; i < m_vectorSpace->dimLocal(); ++i) {
50  m_volume *= (m_maxValues[i] - m_minValues[i]);
51  }
52 }
53 
54 // Destructor
55 template<class V, class M>
57 {
58 }
59 
60 // Math methods
61 template<class V, class M>
62 bool BoxSubset<V,M>::contains(const V& vec) const
63 {
64  // prudenci, 2012-09-26: allow boundary values because of 'beta' realizer, which can generate a sample with boundary value '1'
65  //return (!vec.atLeastOneComponentSmallerOrEqualThan(m_minValues) &&
66  // !vec.atLeastOneComponentBiggerOrEqualThan (m_maxValues));
67  return (!vec.atLeastOneComponentSmallerThan(m_minValues) &&
68  !vec.atLeastOneComponentBiggerThan (m_maxValues));
69 }
70 
71 
72 template<class V, class M>
73 void BoxSubset<V,M>::centroid(V& vec) const
74 {
75  vec = m_minValues;
76  vec += m_maxValues;
77  vec *= 0.5;
78 }
79 
80 
81 
82 template<class V, class M>
83 void BoxSubset<V,M>::moments(M& mat) const
84 {
85  mat.zeroLower();
86  mat.zeroUpper();
87  for (unsigned int i = 0; i < m_vectorSpace->dimLocal(); ++i) {
88  double length_i = (m_maxValues[i] - m_minValues[i]);
89  mat(i,i) = length_i*length_i*length_i/12;
90  }
91 }
92 
93 
94 template<class V, class M>
95 const V& BoxSubset<V,M>::minValues() const
96 {
97  return m_minValues;
98 }
99 
100 template<class V, class M>
102 {
103  return m_maxValues;
104 }
105 
106 // I/O method
107 template <class V, class M>
108 void BoxSubset<V,M>::print(std::ostream& os) const
109 {
110  os << "In BoxSubset<V,M>::print()"
111  << ": m_minValues = " << m_minValues
112  << ", m_maxValues = " << m_maxValues
113  << ", m_volume = " << m_volume
114  << std::endl;
115 
116  return;
117 }
118 
119 } // End namespace QUESO
120 
~BoxSubset()
Destructor.
Definition: BoxSubset.C:56
void centroid(V &vec) const
Returns the centroid of this box subset in the vector vec.
Definition: BoxSubset.C:73
void moments(M &mat) const
Returns the moments of inertia of this box subset in the matrix mat.
Definition: BoxSubset.C:83
A class representing a vector space.
Definition: VectorSet.h:49
A templated class for handling subsets.
Definition: VectorSubset.h:46
const VectorSpace< V, M > * m_vectorSpace
Definition: VectorSubset.h:81
const V & minValues() const
Vector of the minimum values of the box subset.
Definition: BoxSubset.C:95
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:44
void print(std::ostream &os) const
Prints the volume, the minimum and the maximum values of this.
Definition: BoxSubset.C:108
V m_minValues
Vector of templated type V to store the minimum values of the box subset class.
Definition: BoxSubset.h:92
V m_maxValues
Vector of templated type V to store the maximum values of the box subset class.
Definition: BoxSubset.h:95
unsigned int dimLocal() const
Definition: VectorSpace.C:155
BoxSubset(const char *prefix, const VectorSpace< V, M > &vectorSpace, const V &minValues, const V &maxValues)
Shaped, default constructor.
Definition: BoxSubset.C:34
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
bool contains(const V &vec) const
Checks whether this box subset contains vector vec.
Definition: BoxSubset.C:62
const V & maxValues() const
Vector of the maximum values of the box subset.
Definition: BoxSubset.C:101

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