queso-0.53.0
ScalarCdf.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-2015 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/ScalarCdf.h>
26 
27 namespace QUESO {
28 
29 // Default constructor -----------------------------
30 template<class T>
32  const BaseEnvironment& env,
33  const char* prefix)
34  :
35  m_env (env),
36  m_prefix ((std::string)(prefix)+""),
37  m_minHorizontal(-INFINITY),
38  m_maxHorizontal( INFINITY)
39 {
40  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
41  *m_env.subDisplayFile() << "Entering BaseScalarCdf<T>::constructor()"
42  << ": prefix = " << m_prefix
43  << std::endl;
44  }
45 
46  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
47  *m_env.subDisplayFile() << "Leaving BaseScalarCdf<T>::constructor()"
48  << ": prefix = " << m_prefix
49  << std::endl;
50  }
51 }
52 // Destructor ---------------------------------------
53 template<class T>
55 {
56 }
57 // Environment methods ------------------------------
58 template <class T>
59 const BaseEnvironment&
61 {
62  return m_env;
63 }
64 // --------------------------------------------------
65 template <class T>
66 const std::string&
68 {
69  return m_prefix;
70 }
71 // I/O methods---------------------------------------
72 template<class T>
73 void
75  const std::string& varNamePrefix,
76  const std::string& fileName,
77  const std::string& fileType,
78  const std::set<unsigned int>& allowedSubEnvIds) const
79 {
80  std::cerr << "WARNING: BaseScalarCdf<T>::subWriteContents() being used..."
81  << std::endl;
82  return;
83 }
84 
85 //---------------------------------------------------
86 // Method outside either class definition------------
87 //---------------------------------------------------
88 
89 //*****************************************************
90 // Horizontal distance
91 //*****************************************************
92 
94 template <class T>
95 double
97  const BaseScalarCdf<T>& cdf2,
98  double epsilon)
99 {
100  double maxDistance = 0.;
101  double xForMaxDistance = 0.;
102 
103  double x1 = cdf1.inverse(epsilon*.5);
104  double x2 = cdf1.inverse(1.-epsilon*.5);
105  if (cdf1.env().subDisplayFile()) {
106  *cdf1.env().subDisplayFile() << "In horizontalDistance()"
107  << ", cdf1.prefix() = " << cdf1.prefix()
108  << ", cdf2.prefix() = " << cdf2.prefix()
109  << ", epsilon = " << epsilon
110  << ": x1 = " << x1
111  << ", x2 = " << x2
112  << std::endl;
113  }
114 
115  //if (cdf1.env().subDisplayFile()) {
116  // *cdf1.env().subDisplayFile() << "In horizontalDistance: x1 = " << x1
117  // << ", x2 = " << x2
118  // << std::endl;
119  //}
120 
121  double numEvaluationPoints = 1001.;
122  for (double i = 0.; i < numEvaluationPoints; ++i) {
123  double ratio = i/(numEvaluationPoints-1.); // IMPORTANT: Yes, '-1.'
124  double x = (1.-ratio)*x1 + ratio*x2;
125  double y = cdf2.inverse(cdf1.value(x));
126  double d = fabs(x-y);
127  if ((cdf1.env().subDisplayFile()) && (cdf1.env().displayVerbosity() >= 3)) {
128  *cdf1.env().subDisplayFile() << "In horizontalDistance"
129  << ": i = " << i
130  << ", x = " << x
131  << ", cdf1.value(x) = " << cdf1.value(x)
132  << ", y = " << y
133  << ", d = " << d
134  << ", currentMaxDistance = " << maxDistance
135  << std::endl;
136  }
137  if (maxDistance < d) {
138  maxDistance = d;
139  xForMaxDistance = x;
140  if ((cdf1.env().subDisplayFile()) && (cdf1.env().displayVerbosity() >= 3)) {
141  *cdf1.env().subDisplayFile() << "In horizontalDistance"
142  << ": i = " << i
143  << ", NOW maxDistance = " << maxDistance
144  << ", xForMaxDistance = " << xForMaxDistance
145  << std::endl;
146  }
147  }
148  }
149 
150  if (cdf1.env().subDisplayFile()) {
151  *cdf1.env().subDisplayFile() << "In horizontalDistance()"
152  << ", cdf1.prefix() = " << cdf1.prefix()
153  << ", cdf2.prefix() = " << cdf2.prefix()
154  << ", epsilon = " << epsilon
155  << ": maxDistance = " << maxDistance
156  << ", xForMaxDistance = " << xForMaxDistance
157  << std::endl;
158  }
159 
160  return maxDistance;
161 }
162 
163 } // End namespace QUESO
unsigned int displayVerbosity() const
Definition: Environment.C:396
A templated (base) class for handling CDFs.
Definition: ScalarCdf.h:49
const BaseEnvironment & m_env
Definition: ScalarCdf.h:99
virtual ~BaseScalarCdf()
Virtual destructor.
Definition: ScalarCdf.C:54
BaseScalarCdf(const BaseEnvironment &env, const char *prefix)
Default constructor.
Definition: ScalarCdf.C:31
double epsilon
Definition: ann_test.cpp:484
std::string m_prefix
Definition: ScalarCdf.h:100
const std::string & prefix() const
Access to private attribute m_prefix.
Definition: ScalarCdf.C:67
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
virtual T inverse(double cdfValue) const =0
Returns the position of a given value of CDF. See template specialization.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
double horizontalDistance(const BaseScalarCdf< T > &cdf1, const BaseScalarCdf< T > &cdf2, double epsilon)
It calculated the maximum horizontal distance between two CDFs.
Definition: ScalarCdf.C:96
virtual double value(T paramValue) const =0
Returns the value of the CDF at paramValue. See template specialization.
virtual 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.
Definition: ScalarCdf.C:74
const BaseEnvironment & env() const
Environment. Access to private attribute m_env.
Definition: ScalarCdf.C:60

Generated on Thu Jun 11 2015 13:52:32 for queso-0.53.0 by  doxygen 1.8.5