25 #include <queso/ScalarGaussianRandomField.h>
26 #include <queso/GaussianVectorRV.h>
31 template <
class V,
class M>
38 m_env (indexSet.env()),
39 m_prefix ((std::string)(prefix)+
"grf_"),
40 m_indexSet (indexSet),
41 m_meanFunction (meanFunction),
42 m_covarianceFunction (covarianceFunction),
43 m_savedRvImageSpace (NULL),
44 m_savedRvLawExpVector(NULL),
45 m_savedRvLawCovMatrix(NULL),
51 template <
class V,
class M>
56 template <
class V,
class M>
63 template <
class V,
class M>
67 return m_meanFunction;
70 template <
class V,
class M>
74 return m_covarianceFunction;
77 template <
class V,
class M>
81 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
82 *m_env.subDisplayFile() <<
"Entering ScalarGaussianRandomField<V,M>::sampleFunction()"
88 if ((m_savedPositions.size() == 0 ) &&
89 (m_savedRvImageSpace == NULL) &&
90 (m_savedRvLawExpVector == NULL) &&
91 (m_savedRvLawCovMatrix == NULL) &&
92 (m_savedRv == NULL)) {
95 else if ((m_savedPositions.size() != 0 ) &&
96 (m_savedRvImageSpace != NULL) &&
97 (m_savedRvLawExpVector != NULL) &&
98 (m_savedRvLawCovMatrix != NULL) &&
99 (m_savedRv != NULL)) {
103 queso_error_msg(
"invalid combination of pointer values");
106 unsigned int numberOfPositions = fieldPositions.size();
107 bool instantiate =
true;
108 if (m_savedPositions.size() == numberOfPositions) {
109 bool allPositionsAreEqual =
true;
110 for (
unsigned int i = 0; i < numberOfPositions; ++i) {
111 queso_require_msg(m_savedPositions[i],
"m_savedPositions[i] should not be NULL");
112 if ((m_savedPositions[i]->sizeLocal() == fieldPositions[i]->sizeLocal()) &&
113 (*(m_savedPositions[i]) == *(fieldPositions[i]) )) {
117 allPositionsAreEqual =
false;
121 instantiate = !allPositionsAreEqual;
126 delete m_savedRvLawCovMatrix;
127 delete m_savedRvLawExpVector;
128 delete m_savedRvImageSpace;
129 for (
unsigned int i = 0; i < m_savedPositions.size(); ++i) {
130 delete m_savedPositions[i];
132 m_savedPositions.clear();
135 m_savedPositions.resize(numberOfPositions,NULL);
136 for (
unsigned int i = 0; i < m_savedPositions.size(); ++i) {
137 m_savedPositions[i] =
new V(*(fieldPositions[i]));
141 m_savedRvImageSpace =
new VectorSpace<V,M>(m_env,
"grf_", numberOfPositions, NULL);
144 m_savedRvLawExpVector =
new V(m_savedRvImageSpace->zeroVector());
145 for (
unsigned int i = 0; i < numberOfPositions; ++i) {
146 (*m_savedRvLawExpVector)[i] = m_meanFunction.actualValue(*(fieldPositions[i]),NULL,NULL,NULL,NULL);
150 m_savedRvLawCovMatrix =
new M(m_savedRvImageSpace->zeroVector());
151 for (
unsigned int i = 0; i < numberOfPositions; ++i) {
152 for (
unsigned int j = 0; j < numberOfPositions; ++j) {
153 (*m_savedRvLawCovMatrix)(i,j) = m_covarianceFunction.value(*(fieldPositions[i]),*(fieldPositions[j]));
154 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
155 *m_env.subDisplayFile() <<
"In ScalarGaussianRandomField<V,M>::sampleFunction()"
158 <<
", *(fieldPositions[i]) = " << *(fieldPositions[i])
159 <<
", *(fieldPositions[j]) = " << *(fieldPositions[j])
160 <<
", (*m_savedRvLawCovMatrix)(i,j) = " << (*m_savedRvLawCovMatrix)(i,j)
168 *m_savedRvImageSpace,
169 *m_savedRvLawExpVector,
170 *m_savedRvLawCovMatrix);
172 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
173 *m_env.subDisplayFile() <<
"In ScalarGaussianRandomField<V,M>::sampleFunction()"
174 <<
": just instantiated Gaussian RV"
175 <<
"\n *m_savedRvLawExpVector = " << *m_savedRvLawExpVector
176 <<
"\n *m_savedRvLawCovMatrix = " << *m_savedRvLawCovMatrix
178 for (
unsigned int i = 0; i < numberOfPositions; ++i) {
179 *m_env.subDisplayFile() <<
" *(m_savedPositions[" << i
180 <<
"]) = " << *(m_savedPositions[i])
187 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
188 *m_env.subDisplayFile() <<
"In ScalarGaussianRandomField<V,M>::sampleFunction()"
189 <<
": about to realize sample values"
192 m_savedRv->realizer().realization(sampleValues);
193 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
194 *m_env.subDisplayFile() <<
"In ScalarGaussianRandomField<V,M>::sampleFunction()"
195 <<
": just realized sample values"
199 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
200 *m_env.subDisplayFile() <<
"Leaving ScalarGaussianRandomField<V,M>::sampleFunction()"
A templated (base) class for handling scalar functions.
~ScalarGaussianRandomField()
Destructor.
A class representing a vector space.
ScalarGaussianRandomField(const char *prefix, const VectorSet< V, M > &indexSet, const BaseScalarFunction< V, M > &meanFunction, const BaseScalarCovarianceFunction< V, M > &covarianceFunction)
Constructor.
A class representing a Gaussian vector RV.
A templated class for handling sets.
A templated (base) class to accommodate scalar covariance functions (of random variables).
const BaseScalarCovarianceFunction< V, M > & covarianceFunction() const
Covariance function; access to protected attribute m_covarianceFunction.
const BaseScalarFunction< V, M > & meanFunction() const
Mean function; access to protected attribute m_meanFunction.
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"))
std::vector< V * > m_savedPositions
Saved positions.
const VectorSet< V, M > & indexSet() const
Index set; access to protected attribute m_indexSet.
void sampleFunction(const std::vector< V * > &fieldPositions, V &sampleValues)
Function that samples from a Gaussian PDF.