queso-0.51.1
Protected Member Functions | Protected Attributes | List of all members
QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M > Class Template Reference

A class for handling vector Gaussian random fields (GRF). More...

#include <VectorGaussianRandomField.h>

Collaboration diagram for QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 VectorGaussianRandomField (const char *prefix, const VectorSet< P_V, P_M > &indexSet, const VectorSet< Q_V, Q_M > &imageSetPerIndex, const BaseVectorFunction< P_V, P_M, Q_V, Q_M > &meanFunction, const BaseMatrixCovarianceFunction< P_V, P_M, Q_V, Q_M > &covarianceFunction)
 Constructor. More...
 
 VectorGaussianRandomField (const VectorGaussianRandomField &obj)
 TODO: Copy constructor. More...
 
 ~VectorGaussianRandomField ()
 Destructor. More...
 
Set methods
VectorGaussianRandomFieldoperator= (const VectorGaussianRandomField &rhs)
 TODO: Assignment operator; it copies rhs to this. More...
 
Math methods
const VectorSet< P_V, P_M > & indexSet () const
 Index set; access to protected attribute m_indexSet. More...
 
const BaseVectorFunction< P_V,
P_M, Q_V, Q_M > & 
meanFunction () const
 Mean function; access to protected attribute m_meanFunction. More...
 
const
BaseMatrixCovarianceFunction
< P_V, P_M, Q_V, Q_M > & 
covarianceFunction () const
 Covariance function; access to protected attribute m_covarianceFunction. More...
 
void sampleFunction (const std::vector< P_V * > &fieldPositions, Q_V &sampleValues)
 Function that samples from a Gaussian PDF. More...
 

Protected Member Functions

void copy (const VectorGaussianRandomField &src)
 Copy method. More...
 

Protected Attributes

const BaseEnvironmentm_env
 Environment. More...
 
std::string m_prefix
 Prefix. More...
 
const VectorSet< P_V, P_M > & m_indexSet
 Index set. More...
 
const VectorSet< Q_V, Q_M > & m_imageSetPerIndex
 Image set of the RV, per index. More...
 
const BaseVectorFunction< P_V,
P_M, Q_V, Q_M > & 
m_meanFunction
 Mean function. More...
 
const
BaseMatrixCovarianceFunction
< P_V, P_M, Q_V, Q_M > & 
m_covarianceFunction
 Covariance function. More...
 
std::vector< P_V * > m_savedPositions
 Saved positions. More...
 
VectorSpace< Q_V, Q_M > * m_savedRvImageSpace
 Image set of the RV. More...
 
Q_V * m_savedRvLawExpVector
 Vector of the mean value of the RV. More...
 
Q_M * m_savedRvLawCovMatrix
 Covariance matrix of the RV. More...
 
GaussianVectorRV< Q_V, Q_M > * m_savedRv
 My RV. More...
 

Detailed Description

template<class P_V, class P_M, class Q_V, class Q_M>
class QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >

A class for handling vector Gaussian random fields (GRF).

This class implements a vector Gaussian random field (GRF); i.e. a random field involving vector Gaussian probability density functions (PDFs) of the variables.

Definition at line 45 of file VectorGaussianRandomField.h.

Constructor & Destructor Documentation

template<class P_V , class P_M , class Q_V , class Q_M >
QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::VectorGaussianRandomField ( const char *  prefix,
const VectorSet< P_V, P_M > &  indexSet,
const VectorSet< Q_V, Q_M > &  imageSetPerIndex,
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > &  meanFunction,
const BaseMatrixCovarianceFunction< P_V, P_M, Q_V, Q_M > &  covarianceFunction 
)

Constructor.

Constructs a new object, given a prefix, an index set, and both a mean and a covariance function. This method deletes the previous saved positions.

Definition at line 31 of file VectorGaussianRandomField.C.

References QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_savedPositions.

37  :
38  m_env (indexSet.env()),
39  m_prefix ((std::string)(prefix)+"grf_"),
40  m_indexSet (indexSet),
41  m_imageSetPerIndex (imageSetPerIndex),
44  m_savedRvImageSpace (NULL),
47  m_savedRv (NULL)
48 {
49  m_savedPositions.clear();
50 }
const VectorSet< Q_V, Q_M > & m_imageSetPerIndex
Image set of the RV, per index.
Q_V * m_savedRvLawExpVector
Vector of the mean value of the RV.
Q_M * m_savedRvLawCovMatrix
Covariance matrix of the RV.
const BaseMatrixCovarianceFunction< P_V, P_M, Q_V, Q_M > & covarianceFunction() const
Covariance function; access to protected attribute m_covarianceFunction.
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > & m_meanFunction
Mean function.
std::vector< P_V * > m_savedPositions
Saved positions.
const BaseEnvironment & env() const
Environment. Access to private attribute m_env.
Definition: VectorSet.C:82
GaussianVectorRV< Q_V, Q_M > * m_savedRv
My RV.
const BaseEnvironment & m_env
Environment.
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > & meanFunction() const
Mean function; access to protected attribute m_meanFunction.
const BaseMatrixCovarianceFunction< P_V, P_M, Q_V, Q_M > & m_covarianceFunction
Covariance function.
const VectorSet< P_V, P_M > & m_indexSet
Index set.
VectorSpace< Q_V, Q_M > * m_savedRvImageSpace
Image set of the RV.
template<class P_V , class P_M , class Q_V , class Q_M >
QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::VectorGaussianRandomField ( const VectorGaussianRandomField< P_V, P_M, Q_V, Q_M > &  obj)

TODO: Copy constructor.

Todo:
: implement me!
template<class P_V , class P_M , class Q_V , class Q_M >
QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::~VectorGaussianRandomField ( )

Destructor.

Definition at line 53 of file VectorGaussianRandomField.C.

54 {
55 }

Member Function Documentation

template<class P_V , class P_M , class Q_V , class Q_M >
void QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::copy ( const VectorGaussianRandomField< P_V, P_M, Q_V, Q_M > &  src)
protected

Copy method.

template<class P_V , class P_M , class Q_V , class Q_M >
const BaseMatrixCovarianceFunction< P_V, P_M, Q_V, Q_M > & QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::covarianceFunction ( ) const

Covariance function; access to protected attribute m_covarianceFunction.

Definition at line 73 of file VectorGaussianRandomField.C.

74 {
75  return m_covarianceFunction;
76 }
const BaseMatrixCovarianceFunction< P_V, P_M, Q_V, Q_M > & m_covarianceFunction
Covariance function.
template<class P_V , class P_M , class Q_V , class Q_M >
const VectorSet< P_V, P_M > & QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::indexSet ( ) const

Index set; access to protected attribute m_indexSet.

Definition at line 59 of file VectorGaussianRandomField.C.

60 {
61  return m_indexSet;
62 }
const VectorSet< P_V, P_M > & m_indexSet
Index set.
template<class P_V , class P_M , class Q_V , class Q_M >
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > & QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::meanFunction ( ) const

Mean function; access to protected attribute m_meanFunction.

Definition at line 66 of file VectorGaussianRandomField.C.

67 {
68  return m_meanFunction;
69 }
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > & m_meanFunction
Mean function.
template<class P_V , class P_M , class Q_V , class Q_M >
VectorGaussianRandomField& QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::operator= ( const VectorGaussianRandomField< P_V, P_M, Q_V, Q_M > &  rhs)

TODO: Assignment operator; it copies rhs to this.

Todo:
: implement me!
template<class P_V , class P_M , class Q_V , class Q_M >
void QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::sampleFunction ( const std::vector< P_V * > &  fieldPositions,
Q_V &  sampleValues 
)

Function that samples from a Gaussian PDF.

Given the field positions, this method performs a number of tests, calculates the mean vector, the covariance matrix and then it samples from a Gaussian random vector as many positions as required.

Definition at line 80 of file VectorGaussianRandomField.C.

References UQ_FATAL_TEST_MACRO.

81 {
82  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
83  *m_env.subDisplayFile() << "Entering VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()"
84  << std::endl;
85  }
86 
87  UQ_FATAL_TEST_MACRO(( sampleValues.sizeLocal() % fieldPositions.size() ) != 0,
88  m_env.fullRank(),
89  "VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()",
90  "input data is not multiple of each other");
91 
92  unsigned int numberOfImageValuesPerIndex = sampleValues.sizeLocal()/fieldPositions.size();
93 
94  UQ_FATAL_TEST_MACRO(numberOfImageValuesPerIndex != m_imageSetPerIndex.vectorSpace().dimLocal(),
95  m_env.fullRank(),
96  "VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()",
97  "invalid input data dimension");
98 
99  if ((m_savedPositions.size() == 0 ) &&
100  (m_savedRvImageSpace == NULL) &&
101  (m_savedRvLawExpVector == NULL) &&
102  (m_savedRvLawCovMatrix == NULL) &&
103  (m_savedRv == NULL)) {
104  // Ok
105  }
106  else if ((m_savedPositions.size() != 0 ) &&
107  (m_savedRvImageSpace != NULL) &&
108  (m_savedRvLawExpVector != NULL) &&
109  (m_savedRvLawCovMatrix != NULL) &&
110  (m_savedRv != NULL)) {
111  // Ok
112  }
113  else {
114  UQ_FATAL_TEST_MACRO(true,
115  m_env.fullRank(),
116  "VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()",
117  "invalid combination of pointer values");
118  }
119 
120  unsigned int numberOfPositions = fieldPositions.size();
121  bool instantiate = true;
122  if (m_savedPositions.size() == numberOfPositions) {
123  bool allPositionsAreEqual = true;
124  for (unsigned int i = 0; i < numberOfPositions; ++i) {
126  m_env.fullRank(),
127  "VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()",
128  "m_savedPositions[i] should not be NULL");
129  if ((m_savedPositions[i]->sizeLocal() == fieldPositions[i]->sizeLocal()) &&
130  (*(m_savedPositions[i]) == *(fieldPositions[i]) )) {
131  // Ok
132  }
133  else {
134  allPositionsAreEqual = false;
135  break;
136  }
137  } // for i
138  instantiate = !allPositionsAreEqual;
139  }
140 
141  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
142  *m_env.subDisplayFile() << "In VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()"
143  << ": numberOfPositions = " << numberOfPositions
144  << ", instantiate = " << instantiate
145  << std::endl;
146  }
147 
148  if (instantiate) {
149  delete m_savedRv;
150  delete m_savedRvLawCovMatrix;
151  delete m_savedRvLawExpVector;
152  delete m_savedRvImageSpace;
153  for (unsigned int i = 0; i < m_savedPositions.size(); ++i) {
154  delete m_savedPositions[i];
155  }
156  m_savedPositions.clear();
157 
158  // Set m_savedPositions
159  m_savedPositions.resize(numberOfPositions,NULL);
160  for (unsigned int i = 0; i < m_savedPositions.size(); ++i) {
161  m_savedPositions[i] = new P_V(*(fieldPositions[i]));
162  }
163 
164  // Set m_savedRvImageSpace
165  m_savedRvImageSpace = new VectorSpace<Q_V,Q_M>(m_env, "grf_", numberOfPositions*numberOfImageValuesPerIndex, NULL);
166 
167  // Set m_savedRvLawExpVector
168  Q_V tmpVec(m_imageSetPerIndex.vectorSpace().zeroVector());
170  for (unsigned int i = 0; i < numberOfPositions; ++i) {
171  m_meanFunction.compute(*(fieldPositions[i]),NULL,tmpVec,NULL,NULL,NULL);
172  for (unsigned int j = 0; j < numberOfImageValuesPerIndex; ++j) {
173  (*m_savedRvLawExpVector)[i*numberOfImageValuesPerIndex + j] = tmpVec[j];
174  }
175  }
176 
177  // Set m_savedRvLawCovMatrix
178  Q_M tmpMat(m_imageSetPerIndex.vectorSpace().zeroVector());
180  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
181  *m_env.subDisplayFile() << "In VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()"
182  << ": m_savedRvLawCovMatrix order = " << m_savedRvLawCovMatrix->numCols()
183  << ", numberOfPositions = " << numberOfPositions
184  << ", tmpMat order = " << tmpMat.numCols()
185  << ", numberOfImageValuesPerIndex = " << numberOfImageValuesPerIndex
186  << std::endl;
187  }
188  for (unsigned int i = 0; i < numberOfPositions; ++i) {
189  for (unsigned int j = 0; j < numberOfPositions; ++j) {
190  m_covarianceFunction.covMatrix(*(fieldPositions[i]),*(fieldPositions[j]),tmpMat);
191 #if 1
192  Q_M testMat(tmpMat);
193  if (testMat.chol() != 0) {
194  *m_env.subDisplayFile() << "In VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()"
195  << ": i = " << i
196  << ", j = " << j
197  << ", *(fieldPositions[i]) = " << *(fieldPositions[i])
198  << ", *(fieldPositions[j]) = " << *(fieldPositions[j])
199  << ", tmpMat = " << tmpMat
200  << ", testMat = " << testMat
201  << ", tmpMat is not positive definite"
202  << std::endl;
203  UQ_FATAL_TEST_MACRO(true,
204  m_env.fullRank(),
205  "VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()",
206  "tmpMat is not positive definite");
207  }
208 #endif
209  for (unsigned int k1 = 0; k1 < numberOfImageValuesPerIndex; ++k1) {
210  for (unsigned int k2 = 0; k2 < numberOfImageValuesPerIndex; ++k2) {
211  unsigned int tmpI = i*numberOfImageValuesPerIndex + k1;
212  unsigned int tmpJ = j*numberOfImageValuesPerIndex + k2;
213  (*m_savedRvLawCovMatrix)(tmpI,tmpJ) = tmpMat(k1,k2);
214  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
215  *m_env.subDisplayFile() << "In VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()"
216  << ": i = " << i
217  << ", j = " << j
218  << ", k1 = " << k1
219  << ", k2 = " << k2
220  << ", tmpI = " << tmpI
221  << ", tmpJ = " << tmpJ
222  << ", *(fieldPositions[i]) = " << *(fieldPositions[i])
223  << ", *(fieldPositions[j]) = " << *(fieldPositions[j])
224  << ", (*m_savedRvLawCovMatrix)(tmpI,tmpJ) = " << (*m_savedRvLawCovMatrix)(tmpI,tmpJ)
225  << std::endl;
226  }
227  }
228  }
229  }
230  }
231 
232  // Set m_savedRv
233  m_savedRv = new GaussianVectorRV<Q_V,Q_M>("grf_",
237 
238  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
239  *m_env.subDisplayFile() << "In VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()"
240  << ": just instantiated Gaussian RV"
241  << "\n *m_savedRvLawExpVector = " << *m_savedRvLawExpVector
242  << "\n *m_savedRvLawCovMatrix = " << *m_savedRvLawCovMatrix
243  << std::endl;
244  for (unsigned int i = 0; i < numberOfPositions; ++i) {
245  *m_env.subDisplayFile() << " *(m_savedPositions[" << i
246  << "]) = " << *(m_savedPositions[i])
247  << std::endl;
248  }
249  }
250  } // if (instantiate)
251 
252  // Generate sample function
253  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
254  *m_env.subDisplayFile() << "In VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()"
255  << ": about to realize sample values"
256  << std::endl;
257  }
258  m_savedRv->realizer().realization(sampleValues);
259  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
260  *m_env.subDisplayFile() << "In VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()"
261  << ": just realized sample values"
262  << std::endl;
263  }
264 
265  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
266  *m_env.subDisplayFile() << "Leaving VectorGaussianRandomField<P_V,P_M,Q_V,Q_M>::sampleFunction()"
267  << std::endl;
268  }
269 
270  return;
271 }
unsigned int dimLocal() const
Definition: VectorSpace.C:199
const VectorSet< Q_V, Q_M > & m_imageSetPerIndex
Image set of the RV, per index.
Q_V * m_savedRvLawExpVector
Vector of the mean value of the RV.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
Q_M * m_savedRvLawCovMatrix
Covariance matrix of the RV.
const BaseVectorFunction< P_V, P_M, Q_V, Q_M > & m_meanFunction
Mean function.
std::vector< P_V * > m_savedPositions
Saved positions.
int fullRank() const
Returns the process full rank.
Definition: Environment.C:241
GaussianVectorRV< Q_V, Q_M > * m_savedRv
My RV.
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:98
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:218
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.
const BaseEnvironment & m_env
Environment.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
const BaseMatrixCovarianceFunction< P_V, P_M, Q_V, Q_M > & m_covarianceFunction
Covariance function.
VectorSpace< Q_V, Q_M > * m_savedRvImageSpace
Image set of the RV.

Member Data Documentation

template<class P_V , class P_M , class Q_V , class Q_M >
const BaseMatrixCovarianceFunction<P_V,P_M,Q_V,Q_M>& QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_covarianceFunction
protected

Covariance function.

Definition at line 111 of file VectorGaussianRandomField.h.

template<class P_V , class P_M , class Q_V , class Q_M >
const BaseEnvironment& QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_env
protected

Environment.

Definition at line 96 of file VectorGaussianRandomField.h.

template<class P_V , class P_M , class Q_V , class Q_M >
const VectorSet<Q_V,Q_M>& QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_imageSetPerIndex
protected

Image set of the RV, per index.

Definition at line 105 of file VectorGaussianRandomField.h.

template<class P_V , class P_M , class Q_V , class Q_M >
const VectorSet<P_V,P_M>& QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_indexSet
protected

Index set.

Definition at line 102 of file VectorGaussianRandomField.h.

template<class P_V , class P_M , class Q_V , class Q_M >
const BaseVectorFunction<P_V,P_M,Q_V,Q_M>& QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_meanFunction
protected

Mean function.

Definition at line 108 of file VectorGaussianRandomField.h.

template<class P_V , class P_M , class Q_V , class Q_M >
std::string QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_prefix
protected

Prefix.

Definition at line 99 of file VectorGaussianRandomField.h.

template<class P_V , class P_M , class Q_V , class Q_M >
std::vector<P_V*> QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_savedPositions
protected
template<class P_V , class P_M , class Q_V , class Q_M >
GaussianVectorRV<Q_V,Q_M>* QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_savedRv
protected

My RV.

Definition at line 126 of file VectorGaussianRandomField.h.

template<class P_V , class P_M , class Q_V , class Q_M >
VectorSpace<Q_V,Q_M>* QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_savedRvImageSpace
protected

Image set of the RV.

Definition at line 117 of file VectorGaussianRandomField.h.

template<class P_V , class P_M , class Q_V , class Q_M >
Q_M* QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_savedRvLawCovMatrix
protected

Covariance matrix of the RV.

Definition at line 123 of file VectorGaussianRandomField.h.

template<class P_V , class P_M , class Q_V , class Q_M >
Q_V* QUESO::VectorGaussianRandomField< P_V, P_M, Q_V, Q_M >::m_savedRvLawExpVector
protected

Vector of the mean value of the RV.

Definition at line 120 of file VectorGaussianRandomField.h.


The documentation for this class was generated from the following files:

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