queso-0.51.1
ExponentialMatrixCovarianceFunction.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,2009,2010,2011,2012,2013 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/ExponentialMatrixCovarianceFunction.h>
26 
27 namespace QUESO {
28 
29 // Default constructor -----------------------------
30 template<class P_V, class P_M, class Q_V, class Q_M>
32  const char* prefix,
33  const VectorSet<P_V,P_M>& basicDomainSet,
34  const VectorSet<Q_V,Q_M>& imageSet,
35  const Q_M& sigmas,
36  const Q_M& as)
37  :
38  BaseMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>(prefix,basicDomainSet,imageSet),
39  m_sigmas(NULL),
40  m_as (NULL)
41 {
42  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
43  *m_env.subDisplayFile() << "Entering ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::constructor()"
44  << ": prefix = " << m_prefix
45  << std::endl;
46  }
47 
48  m_sigmas = new Q_M(sigmas);
49  m_as = new Q_M(as);
50 
51  unsigned int matrixOrder = m_imageSet.vectorSpace().dimLocal();
52 
53  UQ_FATAL_TEST_MACRO(m_sigmas->numRowsLocal() != matrixOrder,
54  m_env.worldRank(),
55  "ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::Constructor()",
56  "m_sigmas has invalid number of rows");
57 
58  UQ_FATAL_TEST_MACRO(m_sigmas->numCols() != matrixOrder,
59  m_env.worldRank(),
60  "ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::Constructor()",
61  "m_sigmas has invalid number of columns");
62 
63  UQ_FATAL_TEST_MACRO(m_as->numRowsLocal() != matrixOrder,
64  m_env.worldRank(),
65  "ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::Constructor()",
66  "m_as has invalid number of rows");
67 
68  UQ_FATAL_TEST_MACRO(m_as->numCols() != matrixOrder,
69  m_env.worldRank(),
70  "ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::Constructor()",
71  "m_as has invalid number of columns");
72 
73  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
74  *m_env.subDisplayFile() << "Leaving ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::constructor()"
75  << ": prefix = " << m_prefix
76  << std::endl;
77  }
78 }
79 // Destructor ---------------------------------------
80 template<class P_V, class P_M, class Q_V, class Q_M>
82 {
83  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
84  *m_env.subDisplayFile() << "Entering ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::destructor()"
85  << ": prefix = " << m_prefix
86  << std::endl;
87  }
88 
89  delete m_as;
90  delete m_sigmas;
91 
92  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
93  *m_env.subDisplayFile() << "Leaving ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::destructor()"
94  << ": prefix = " << m_prefix
95  << std::endl;
96  }
97 }
98 // Math methods -------------------------------------
99 template<class P_V, class P_M, class Q_V, class Q_M>
100 void
101 ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::covMatrix(const P_V& domainVector1, const P_V& domainVector2, Q_M& imageMatrix) const
102 {
103  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
104  *m_env.subDisplayFile() << "Entering ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::covMatrix()"
105  << std::endl;
106  }
107 
108  unsigned int matrixOrder = m_imageSet.vectorSpace().dimLocal();
109 
110  UQ_FATAL_TEST_MACRO(imageMatrix.numRowsLocal() != matrixOrder,
111  m_env.worldRank(),
112  "ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::covMatrix()",
113  "imageMatrix has invalid number of rows");
114 
115  UQ_FATAL_TEST_MACRO(imageMatrix.numCols() != matrixOrder,
116  m_env.worldRank(),
117  "ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::covMatrix()",
118  "imageMatrix has invalid number of columns");
119 
120  double tmpSq = -(domainVector1 - domainVector2).norm2Sq();
121 
122  for (unsigned int i = 0; i < matrixOrder; ++i) {
123  for (unsigned int j = 0; j < matrixOrder; ++j) {
124  double tmp = tmpSq/( (*m_sigmas)(i,j) * (*m_sigmas)(i,j) );
125  imageMatrix(i,j) = (*m_as)(i,j) * std::exp(tmp);
126  }
127  }
128 
129  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
130  *m_env.subDisplayFile() << "Leaving ExponentialMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>::covMatrix()"
131  << std::endl;
132  }
133 
134  return;
135 }
136 
137 } // End namespace QUESO
unsigned int dimLocal() const
Definition: VectorSpace.C:199
const VectorSet< Q_V, Q_M > & m_imageSet
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
A templated (base) class to accommodate covariance matrix of (random) vector functions.
ExponentialMatrixCovarianceFunction(const char *prefix, const VectorSet< P_V, P_M > &basicDomainSet, const VectorSet< Q_V, Q_M > &imageSet, const Q_M &sigmas, const Q_M &as)
Default constructor.
unsigned int displayVerbosity() const
Definition: Environment.C:436
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
void covMatrix(const P_V &domainVector1, const P_V &domainVector2, Q_M &imageMatrix) const
Calculates the covariance matrix, given two parameter domains.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223

Generated on Thu Apr 23 2015 19:26:15 for queso-0.51.1 by  doxygen 1.8.5