queso-0.53.0
GPMSA.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/GPMSA.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 template <class V, class M>
33  const VectorSet<V, M> & domain,
34  const VectorSpace<V, M> & m_scenarioSpace,
35  const VectorSpace<V, M> & m_parameterSpace,
36  const VectorSpace<V, M> & m_simulationOutputSpace,
37  const VectorSpace<V, M> & m_experimentOutputSpace,
38  const unsigned int m_numSimulations,
39  const unsigned int m_numExperiments,
40  const std::vector<V *> & m_simulationScenarios,
41  const std::vector<V *> & m_simulationParameters,
42  const std::vector<V *> & m_simulationOutputs,
43  const std::vector<V *> & m_experimentScenarios,
44  const std::vector<V *> & m_experimentOutputs,
45  const M & m_experimentErrors,
46  const ConcatenatedVectorRV<V, M> & m_totalPrior)
47  :
48  BaseScalarFunction<V, M>("", m_totalPrior.imageSet()),
49  m_scenarioSpace(m_scenarioSpace),
50  m_parameterSpace(m_parameterSpace),
51  m_simulationOutputSpace(m_simulationOutputSpace),
52  m_experimentOutputSpace(m_experimentOutputSpace),
53  m_numSimulations(m_numSimulations),
54  m_numExperiments(m_numExperiments),
55  m_simulationScenarios(m_simulationScenarios),
56  m_simulationParameters(m_simulationParameters),
57  m_simulationOutputs(m_simulationOutputs),
58  m_experimentScenarios(m_experimentScenarios),
59  m_experimentOutputs(m_experimentOutputs),
60  m_experimentErrors(m_experimentErrors),
61  m_totalPrior(m_totalPrior)
62 {
63 }
64 
65 template <class V, class M>
67 {
68  // Do nothing?
69 }
70 
71 template <class V, class M>
72 double
73 GPMSAEmulator<V, M>::lnValue(const V & domainVector,
74  const V * domainDirection,
75  V * gradVector,
76  M * hessianMatrix,
77  V * hessianEffect) const
78 {
79  // Components of domainVector:
80  // theta(1)
81  // theta(2)
82  // ...
83  // theta(dimParameterSpace)
84  // emulator_mean
85  // emulator_precision
86  // emulator_corr_strength(1)
87  // ...
88  // emulator_corr_strength(dimScenario + dimParameter)
89  // discrepancy_precision
90  // discrepancy_corr_strength(1)
91  // ...
92  // discrepancy_corr_strength(dimScenario)
93  // emulator_data_precision(1)
94 
95  // Construct covariance matrix
96  unsigned int totalDim = this->m_numExperiments + this->m_numSimulations;
97  double prodScenario = 1.0;
98  double prodParameter = 1.0;
99  double prodDiscrepancy = 1.0;
100  unsigned int dimScenario = (this->m_scenarioSpace).dimLocal();
101  unsigned int dimParameter = (this->m_parameterSpace).dimLocal();
102 
103  // This is cumbersome. All I want is a matrix.
104  VectorSpace<V, M> gpSpace(this->m_scenarioSpace.env(), "", totalDim, NULL);
105  V residual(gpSpace.zeroVector());
106  M covMatrix(residual);
107 
108  V *scenario1;
109  V *scenario2;
110  V *parameter1;
111  V *parameter2;
112 
113  // This for loop is a disaster and could do with a *lot* of optimisation
114  for (unsigned int i = 0; i < totalDim; i++) {
115  for (unsigned int j = 0; j < totalDim; j++) {
116  // Decide whether to do experiment part of the covariance matrix
117  // Get i-th simulation-parameter pair
118  if (i < this->m_numExperiments) {
119  // Experiment scenario (known)
120  scenario1 = new V(*((this->m_experimentScenarios)[i]));
121 
122  // Experiment parameter (unknown)
123  parameter1 = new V(*((this->m_simulationParameters)[0]));
124  for (unsigned int k = 0; k < dimParameter; k++) {
125  (*parameter1)[k] = domainVector[k];
126  }
127  }
128  else {
129  scenario1 =
130  new V(*((this->m_simulationScenarios)[i-this->m_numExperiments]));
131  parameter1 =
132  new V(*((this->m_simulationParameters)[i-this->m_numExperiments]));
133  }
134 
135  if (j < this->m_numExperiments) {
136  scenario2 = new V(*((this->m_experimentScenarios)[j]));
137  parameter2 = new V(*((this->m_simulationParameters)[0]));
138  for (unsigned int k = 0; k < dimParameter; k++) {
139  (*parameter2)[k] = domainVector[k];
140  }
141  }
142  else {
143  scenario2 =
144  new V(*((this->m_simulationScenarios)[j-this->m_numExperiments]));
145  parameter2 =
146  new V(*((this->m_simulationParameters)[j-this->m_numExperiments]));
147  }
148 
149  // Emulator component
150  prodScenario = 1.0;
151  prodParameter = 1.0;
152  unsigned int emulatorCorrStrStart = dimParameter + 2;
153  for (unsigned int k = 0; k < dimScenario; k++) {
154  prodScenario *= std::pow(domainVector[emulatorCorrStrStart+k],
155  4.0 * ((*scenario1)[k] - (*scenario2)[k]) *
156  ((*scenario1)[k] - (*scenario2)[k]));
157  }
158 
159  for (unsigned int k = 0; k < dimParameter; k++) {
160  prodParameter *= std::pow(
161  domainVector[emulatorCorrStrStart+dimScenario+k],
162  4.0 * ((*parameter1)[k] - (*parameter2)[k]) *
163  ((*parameter1)[k] - (*parameter2)[k]));
164  }
165 
166  double emPrecision = domainVector[dimParameter+1];
167  covMatrix(i, j) = prodScenario * prodParameter /
168  emPrecision; // emulator precision
169 
170  delete scenario1;
171  delete scenario2;
172  delete parameter1;
173  delete parameter2;
174 
175  // If we're in the experiment cross correlation part, need extra foo
176  if (i < this->m_numExperiments && j < this->m_numExperiments) {
177  scenario1 = new V(*((this->m_simulationScenarios)[i]));
178  scenario2 = new V(*((this->m_simulationScenarios)[j]));
179  prodDiscrepancy = 1.0;
180  unsigned int discrepancyCorrStrStart = dimParameter +
181  dimParameter +
182  dimScenario + 3;
183  for (unsigned int k = 0; k < dimScenario; k++) {
184  prodDiscrepancy *= std::pow(domainVector[discrepancyCorrStrStart+k],
185  4.0 * ((*scenario1)[k] - (*scenario2)[k]) *
186  ((*scenario1)[k] - (*scenario2)[k]));
187  }
188 
189  covMatrix(i, j) += prodDiscrepancy /
190  domainVector[discrepancyCorrStrStart-1];
191  covMatrix(i, j) += (this->m_experimentErrors)(i, j);
192 
193  delete scenario1;
194  delete scenario2;
195  }
196  }
197 
198  // Add small white noise component to diagonal to make stuff +ve def
199  unsigned int dimSum = 4 +
200  dimParameter +
201  dimParameter +
202  dimScenario +
203  dimScenario; // yum
204  double nugget = 1.0 / domainVector[dimSum-1];
205  covMatrix(i, i) += nugget;
206  }
207 
208  // Form residual = D - mean
209  for (unsigned int i = 0; i < this->m_numExperiments; i++) {
210  // Scalar so ok -- will need updating for nonscalar case
211  residual[i] = (*((this->m_experimentOutputs)[i]))[0];
212  }
213  for (unsigned int i = 0; i < this->m_numSimulations; i++) {
214  // Scalar so ok -- will need updating for nonscalar case
215  residual[i+this->m_numExperiments] = (*((this->m_simulationOutputs)[i]))[0];
216  }
217 
218  // Solve covMatrix * sol = residual
219  V sol(covMatrix.invertMultiply(residual));
220 
221  // There's no dot product function in GslVector.
222  double minus_2_log_lhd = 0.0;
223  for (unsigned int i = 0; i < totalDim; i++) {
224  minus_2_log_lhd += sol[i] * residual[i];
225  }
226 
227  return -0.5 * minus_2_log_lhd;
228 }
229 
230 template <class V, class M>
231 double
232 GPMSAEmulator<V, M>::actualValue(const V & domainVector,
233  const V * domainDirection,
234  V * gradVector,
235  M * hessianMatrix,
236  V * hessianEffect) const
237 {
238  // Do nothing?
239  return 1.0;
240 }
241 
242 template <class V, class M>
244  const BaseEnvironment & env,
245  GPMSAOptions * opts,
246  const BaseVectorRV<V, M> & parameterPrior,
247  const VectorSpace<V, M> & scenarioSpace,
248  const VectorSpace<V, M> & parameterSpace,
249  const VectorSpace<V, M> & simulationOutputSpace,
250  const VectorSpace<V, M> & experimentOutputSpace,
251  unsigned int numSimulations,
252  unsigned int numExperiments)
253  :
254  m_env(env),
255  m_parameterPrior(parameterPrior),
256  m_scenarioSpace(scenarioSpace),
257  m_parameterSpace(parameterSpace),
258  m_simulationOutputSpace(simulationOutputSpace),
259  m_experimentOutputSpace(experimentOutputSpace),
260  m_numSimulations(numSimulations),
261  m_numExperiments(numExperiments),
262  m_simulationScenarios(numSimulations, (V *)NULL),
263  m_simulationParameters(numSimulations, (V *)NULL),
264  m_simulationOutputs(numSimulations, (V *)NULL),
265  m_experimentScenarios(numExperiments, (V *)NULL),
266  m_experimentOutputs(numExperiments, (V *)NULL),
267  m_numSimulationAdds(0),
268  m_numExperimentAdds(0),
269  priors(7, (const BaseVectorRV<V, M> *)NULL) // Needed for gcc 4.3.2
270 {
271  // DM: Not sure if the logic in these 3 if-blocks is correct
272  if ((opts == NULL) && (this->m_env.optionsInputFileName() == "")) {
273  queso_error_msg("Must options object or an input file");
274  }
275 
276  if (opts != NULL) {
277  this->m_opts = opts;
278  }
279  else {
280  // Create a default one
281  this->m_opts = new GPMSAOptions(this->m_env, "");
282  }
283 
284  this->setUpHyperpriors();
285  this->m_constructedGP = false;
286 }
287 
288 template <class V, class M>
290 {
291  // Do nothing
292 }
293 
294 template <class V, class M>
295 unsigned int
297 {
298  return this->m_numSimulations;
299 }
300 
301 template <class V, class M>
302 unsigned int
304 {
305  return this->m_numExperiments;
306 }
307 
308 template <class V, class M>
309 const VectorSpace<V, M> &
311 {
312  return this->m_scenarioSpace;
313 }
314 
315 template <class V, class M>
316 const VectorSpace<V, M> &
318 {
319  return this->m_parameterSpace;
320 }
321 
322 template <class V, class M>
323 const VectorSpace<V, M> &
325 {
326  return this->m_simulationOutputSpace;
327 }
328 
329 template <class V, class M>
330 const VectorSpace<V, M> &
332 {
333  return this->m_experimentOutputSpace;
334 }
335 
336 template <class V, class M>
337 const V &
339  unsigned int simulationId) const
340 {
341  queso_require_less_msg(simulationId, m_simulationScenarios.size(), "simulationId is too large");
342 
343  queso_require_msg(m_simulationScenarios[simulationId], "vector is NULL");
344 
345  return *(this->m_simulationScenarios[simulationId]);
346 }
347 
348 template <class V, class M>
349 const std::vector<V *> &
351 {
352  return this->m_simulationScenarios;
353 }
354 
355 template <class V, class M>
356 const V &
358  unsigned int simulationId) const
359 {
360  queso_require_less_msg(simulationId, m_simulationParameters.size(), "simulationId is too large");
361 
362  queso_require_msg(m_simulationParameters[simulationId], "vector is NULL");
363 
364  return *(this->m_simulationParameters[simulationId]);
365 }
366 
367 template <class V, class M>
368 const std::vector<V *> &
370 {
371  return this->m_simulationParameters;
372 }
373 
374 template <class V, class M>
375 const V &
377  unsigned int simulationId) const
378 {
379  queso_require_less_msg(simulationId, m_simulationOutputs.size(), "simulationId is too large");
380 
381  queso_require_msg(m_simulationOutputs[simulationId], "vector is NULL");
382 
383  return *(this->m_simulationOutputs[simulationId]);
384 }
385 
386 template <class V, class M>
387 const std::vector<V *> &
389 {
390  return this->m_simulationOutputs;
391 }
392 
393 template <class V, class M>
394 const V &
396  unsigned int experimentId) const
397 {
398  queso_require_less_msg(experimentId, (this->m_experimentScenarios).size(), "experimentId is too large");
399 
400  queso_require_msg(this->m_experimentScenarios[experimentId], "vector is NULL");
401 
402  return *(this->m_experimentScenarios[experimentId]);
403 }
404 
405 template <class V, class M>
406 const std::vector<V *> &
408 {
409  return this->m_experimentScenarios;
410 }
411 
412 template <class V, class M>
413 const V &
415  unsigned int experimentId) const
416 {
417  queso_require_less_msg(experimentId, (this->m_experimentOutputs).size(), "experimentId is too large");
418 
419  queso_require_msg(this->m_experimentOutputs[experimentId], "vector is NULL");
420 
421  return *(this->m_experimentOutputs[experimentId]);
422 }
423 
424 template <class V, class M>
425 const std::vector<V *> &
427 {
428  return this->m_experimentOutputs;
429 }
430 
431 template <class V, class M>
432 const M &
434 {
435  return *(this->m_experimentErrors);
436 }
437 
438 template <class V, class M>
439 const BaseEnvironment &
441 {
442  return this->m_env;
443 }
444 
445 template <class V, class M>
446 const GPMSAEmulator<V, M> &
448 {
449  return *(this->gpmsaEmulator);
450 }
451 
452 template <class V, class M>
453 void
454 GPMSAFactory<V, M>::addSimulation(V & simulationScenario,
455  V & simulationParameter,
456  V & simulationOutput)
457 {
458  queso_require_less_msg(this->m_numSimulationAdds, this->m_numSimulations, "too many simulation adds...");
459 
460  this->m_simulationScenarios[this->m_numSimulationAdds] = &simulationScenario;
461  this->m_simulationParameters[this->m_numSimulationAdds] = &simulationParameter;
462  this->m_simulationOutputs[this->m_numSimulationAdds] = &simulationOutput;
463  this->m_numSimulationAdds++;
464 
465  if ((this->m_numSimulationAdds == this->m_numSimulations) &&
466  (this->m_numExperimentAdds == this->m_numExperiments) &&
467  (this->m_constructedGP == false)) {
468  this->m_constructedGP = true;
469  this->gpmsaEmulator = new GPMSAEmulator<V, M>(
470  this->prior().imageSet(),
471  this->m_scenarioSpace,
472  this->m_parameterSpace,
473  this->m_simulationOutputSpace,
474  this->m_experimentOutputSpace,
475  this->m_numSimulations,
476  this->m_numExperiments,
477  this->m_simulationScenarios,
478  this->m_simulationParameters,
479  this->m_simulationOutputs,
480  this->m_experimentScenarios,
481  this->m_experimentOutputs,
482  *(this->m_experimentErrors),
483  *(this->m_totalPrior));
484  }
485 }
486 
487 template <class V, class M>
488 void
490  const std::vector<V *> & simulationScenarios,
491  const std::vector<V *> & simulationParameters,
492  const std::vector<V *> & simulationOutputs)
493 {
494  for (unsigned int i = 0; i < this->m_numSimulations; i++) {
495  this->addSimulation(*(simulationScenarios[i]), *(simulationParameters[i]),
496  *(simulationOutputs[i]));
497  }
498 }
499 
500 template <class V, class M>
501 void
503  const std::vector<V *> & experimentScenarios,
504  const std::vector<V *> & experimentOutputs,
505  const M * experimentErrors)
506 {
507  queso_require_less_equal_msg(experimentScenarios.size(), this->m_numExperiments, "too many experiments...");
508 
509  for (unsigned int i = 0; i < this->m_experimentScenarios.size(); i++) {
510  this->m_experimentScenarios[i] = experimentScenarios[i];
511  this->m_experimentOutputs[i] = experimentOutputs[i];
512  }
513  this->m_experimentErrors = experimentErrors;
514  this->m_numExperimentAdds += experimentScenarios.size();
515 
516  if ((this->m_numSimulationAdds == this->m_numSimulations) &&
517  (this->m_numExperimentAdds == this->m_numExperiments) &&
518  (this->m_constructedGP == false)) {
519  this->m_constructedGP = true;
520  this->gpmsaEmulator = new GPMSAEmulator<V, M>(
521  this->prior().imageSet(),
522  this->m_scenarioSpace,
523  this->m_parameterSpace,
524  this->m_simulationOutputSpace,
525  this->m_experimentOutputSpace,
526  this->m_numSimulations,
527  this->m_numExperiments,
528  this->m_simulationScenarios,
529  this->m_simulationParameters,
530  this->m_simulationOutputs,
531  this->m_experimentScenarios,
532  this->m_experimentOutputs,
533  *(this->m_experimentErrors),
534  *(this->m_totalPrior));
535  }
536 }
537 
538 template <class V, class M>
541 {
542  return *(this->m_totalPrior);
543 }
544 
545 template <class V, class M>
546 void
547 GPMSAFactory<V, M>::print(std::ostream& os) const
548 {
549  // Do nothing
550 }
551 
552 // Private methods follow
553 template <class V, class M>
554 void
556 {
557  double emulatorPrecisionShape = this->m_opts->m_emulatorPrecisionShape;
558  double emulatorPrecisionScale = this->m_opts->m_emulatorPrecisionScale;
559  double emulatorCorrelationStrengthAlpha = this->m_opts->m_emulatorCorrelationStrengthAlpha;
560  double emulatorCorrelationStrengthBeta = this->m_opts->m_emulatorCorrelationStrengthBeta;
561  double discrepancyPrecisionShape = this->m_opts->m_discrepancyPrecisionShape;
562  double discrepancyPrecisionScale = this->m_opts->m_discrepancyPrecisionScale;
563  double discrepancyCorrelationStrengthAlpha = this->m_opts->m_discrepancyCorrelationStrengthAlpha;
564  double discrepancyCorrelationStrengthBeta = this->m_opts->m_discrepancyCorrelationStrengthBeta;
565  double emulatorDataPrecisionShape = this->m_opts->m_emulatorDataPrecisionShape;
566  double emulatorDataPrecisionScale = this->m_opts->m_emulatorDataPrecisionScale;
567 
568  this->oneDSpace = new VectorSpace<V, M>(this->m_env, "", 1, NULL);
569 
570  // Emulator mean
571  this->emulatorMeanMin = new V(this->oneDSpace->zeroVector());
572  this->emulatorMeanMax = new V(this->oneDSpace->zeroVector());
573  this->emulatorMeanMin->cwSet(-INFINITY);
574  this->emulatorMeanMax->cwSet(INFINITY);
575 
576  this->emulatorMeanDomain = new BoxSubset<V, M>(
577  "",
578  *(this->oneDSpace),
579  *(this->emulatorMeanMin),
580  *(this->emulatorMeanMax));
581 
582  this->m_emulatorMean = new UniformVectorRV<V, M>(
583  "",
584  *(this->emulatorMeanDomain));
585 
586  // Emulator precision
587  this->emulatorPrecisionMin = new V(this->oneDSpace->zeroVector());
588  this->emulatorPrecisionMax = new V(this->oneDSpace->zeroVector());
589  this->m_emulatorPrecisionShapeVec = new V(this->oneDSpace->zeroVector());
590  this->m_emulatorPrecisionScaleVec = new V(this->oneDSpace->zeroVector());
591  this->emulatorPrecisionMin->cwSet(0.3);
592  this->emulatorPrecisionMax->cwSet(INFINITY);
593  this->m_emulatorPrecisionShapeVec->cwSet(emulatorPrecisionShape);
594  this->m_emulatorPrecisionScaleVec->cwSet(emulatorPrecisionScale);
595 
596  this->emulatorPrecisionDomain = new BoxSubset<V, M>(
597  "",
598  *(this->oneDSpace),
599  *(this->emulatorPrecisionMin),
600  *(this->emulatorPrecisionMax));
601 
602  this->m_emulatorPrecision = new GammaVectorRV<V, M>("",
603  *(this->emulatorPrecisionDomain),
604  *(this->m_emulatorPrecisionShapeVec),
605  *(this->m_emulatorPrecisionScaleVec));
606 
607  // Emulator correlation strength
608  unsigned int dimScenario = (this->scenarioSpace()).dimLocal();
609  unsigned int dimParameter = (this->parameterSpace()).dimLocal();
610  this->emulatorCorrelationSpace = new VectorSpace<V, M>(
611  this->m_env,
612  "",
613  dimScenario + dimParameter,
614  NULL);
615 
616  this->emulatorCorrelationMin = new V(
617  this->emulatorCorrelationSpace->zeroVector());
618  this->emulatorCorrelationMax = new V(
619  this->emulatorCorrelationSpace->zeroVector());
620  this->m_emulatorCorrelationStrengthAlphaVec = new V(
621  this->emulatorCorrelationSpace->zeroVector());
622  this->m_emulatorCorrelationStrengthBetaVec = new V(
623  this->emulatorCorrelationSpace->zeroVector());
624  this->emulatorCorrelationMin->cwSet(0);
625  this->emulatorCorrelationMax->cwSet(1);
626  this->m_emulatorCorrelationStrengthAlphaVec->cwSet(emulatorCorrelationStrengthAlpha);
627  this->m_emulatorCorrelationStrengthBetaVec->cwSet(emulatorCorrelationStrengthBeta);
628 
629  this->emulatorCorrelationDomain = new BoxSubset<V, M>(
630  "",
631  *(this->emulatorCorrelationSpace),
632  *(this->emulatorCorrelationMin),
633  *(this->emulatorCorrelationMax));
634 
635  this->m_emulatorCorrelationStrength = new BetaVectorRV<V, M>("",
636  *(this->emulatorCorrelationDomain),
637  *(this->m_emulatorCorrelationStrengthAlphaVec),
638  *(this->m_emulatorCorrelationStrengthBetaVec));
639 
640  // Discrepancy precision
641  this->discrepancyPrecisionMin = new V(this->oneDSpace->zeroVector());
642  this->discrepancyPrecisionMax = new V(this->oneDSpace->zeroVector());
643  this->m_discrepancyPrecisionShapeVec = new V(this->oneDSpace->zeroVector());
644  this->m_discrepancyPrecisionScaleVec = new V(this->oneDSpace->zeroVector());
645  this->discrepancyPrecisionMin->cwSet(0);
646  this->discrepancyPrecisionMax->cwSet(INFINITY);
647  this->m_discrepancyPrecisionShapeVec->cwSet(discrepancyPrecisionShape);
648  this->m_discrepancyPrecisionScaleVec->cwSet(discrepancyPrecisionScale);
649 
650  this->discrepancyPrecisionDomain = new BoxSubset<V, M>(
651  "",
652  *(this->oneDSpace),
653  *(this->discrepancyPrecisionMin),
654  *(this->emulatorPrecisionMax));
655 
656  this->m_discrepancyPrecision = new GammaVectorRV<V, M>("",
657  *(this->discrepancyPrecisionDomain),
658  *(this->m_discrepancyPrecisionShapeVec),
659  *(this->m_discrepancyPrecisionScaleVec));
660 
661  // Discrepancy correlation strength
662  this->discrepancyCorrelationSpace = new VectorSpace<V, M>(
663  this->m_env,
664  "",
665  dimScenario,
666  NULL);
667 
668  this->discrepancyCorrelationMin = new V(
669  this->discrepancyCorrelationSpace->zeroVector());
670  this->discrepancyCorrelationMax = new V(
671  this->discrepancyCorrelationSpace->zeroVector());
672  this->m_discrepancyCorrelationStrengthAlphaVec = new V(
673  this->discrepancyCorrelationSpace->zeroVector());
674  this->m_discrepancyCorrelationStrengthBetaVec = new V(
675  this->discrepancyCorrelationSpace->zeroVector());
676  this->discrepancyCorrelationMin->cwSet(0);
677  this->discrepancyCorrelationMax->cwSet(1);
678  this->m_discrepancyCorrelationStrengthAlphaVec->cwSet(discrepancyCorrelationStrengthAlpha);
679  this->m_discrepancyCorrelationStrengthBetaVec->cwSet(discrepancyCorrelationStrengthBeta);
680 
681  this->discrepancyCorrelationDomain = new BoxSubset<V, M>(
682  "",
683  *(this->discrepancyCorrelationSpace),
684  *(this->discrepancyCorrelationMin),
685  *(this->discrepancyCorrelationMax));
686 
687  this->m_discrepancyCorrelationStrength = new BetaVectorRV<V, M>("",
688  *(this->discrepancyCorrelationDomain),
689  *(this->m_discrepancyCorrelationStrengthAlphaVec),
690  *(this->m_discrepancyCorrelationStrengthBetaVec));
691 
692  // Emulator data precision
693  this->emulatorDataPrecisionMin = new V(this->oneDSpace->zeroVector());
694  this->emulatorDataPrecisionMax = new V(this->oneDSpace->zeroVector());
695  this->m_emulatorDataPrecisionShapeVec = new V(this->oneDSpace->zeroVector());
696  this->m_emulatorDataPrecisionScaleVec = new V(this->oneDSpace->zeroVector());
697  this->emulatorDataPrecisionMin->cwSet(60.0);
698  this->emulatorDataPrecisionMax->cwSet(1e5);
699  this->m_emulatorDataPrecisionShapeVec->cwSet(emulatorDataPrecisionShape);
700  this->m_emulatorDataPrecisionScaleVec->cwSet(emulatorDataPrecisionScale);
701 
702  this->emulatorDataPrecisionDomain = new BoxSubset<V, M>(
703  "",
704  *(this->oneDSpace),
705  *(this->emulatorDataPrecisionMin),
706  *(this->emulatorDataPrecisionMax));
707 
708  this->m_emulatorDataPrecision = new GammaVectorRV<V, M>("",
709  *(this->emulatorDataPrecisionDomain),
710  *(this->m_emulatorDataPrecisionShapeVec),
711  *(this->m_emulatorDataPrecisionScaleVec));
712 
713  // Now form full prior
714  unsigned int dimSum = 4 +
715  dimParameter +
716  dimParameter +
717  dimScenario +
718  dimScenario; // yum
719 
720  this->totalSpace = new VectorSpace<V, M>(
721  this->m_env,
722  "",
723  dimSum,
724  NULL);
725  this->totalMins = new V(this->totalSpace->zeroVector());
726  this->totalMaxs = new V(this->totalSpace->zeroVector());
727 
728  // Hackety hack McHackington. There's no better way to do this unfortunately
729  this->totalMins->cwSet(0);
730  this->totalMaxs->cwSet(1);
731 
732  (*(this->totalMins))[dimParameter] = -INFINITY; // Min mean
733  (*(this->totalMaxs))[dimParameter] = INFINITY; // Max mean
734  (*(this->totalMins))[dimParameter+1] = 0.3; // Min emulator precision
735  (*(this->totalMaxs))[dimParameter+1] = INFINITY; // Max emulator precision
736  (*(this->totalMins))[dimSum-1] = 60.0; // Min emulator data precision
737  (*(this->totalMaxs))[dimSum-1] = 1e5; // Max emulator data precision
738 
739  // Min discrepancy precision
740  (*(this->totalMins))[dimScenario+dimParameter+dimParameter+2] = 0;
741  // Max discrepancy precision
742  (*(this->totalMaxs))[dimScenario+dimParameter+dimParameter+2] = INFINITY;
743 
744  this->totalDomain = new BoxSubset<V, M>(
745  "",
746  *(this->totalSpace),
747  *(this->totalMins),
748  *(this->totalMaxs));
749 
750  this->priors[0] = &(this->m_parameterPrior);
751  this->priors[1] = this->m_emulatorMean;
752  this->priors[2] = this->m_emulatorPrecision;
753  this->priors[3] = this->m_emulatorCorrelationStrength;
754  this->priors[4] = this->m_discrepancyPrecision;
755  this->priors[5] = this->m_discrepancyCorrelationStrength;
756  this->priors[6] = this->m_emulatorDataPrecision;
757 
758  // Finally
759  this->m_totalPrior = new ConcatenatedVectorRV<V, M>(
760  "",
761  this->priors,
762  *(this->totalDomain));
763 }
764 
765 } // End namespace QUESO
766 
~GPMSAFactory()
Destructor.
Definition: GPMSA.C:289
A class representing a uniform vector RV.
A templated class for handling sets.
Definition: VectorSet.h:52
const V & simulationParameter(unsigned int simulationId) const
Return the point in parameterSpace for simulation simulationId.
Definition: GPMSA.C:357
bool m_constructedGP
Definition: GPMSA.h:360
void addSimulations(const std::vector< V * > &simulationScenarios, const std::vector< V * > &simulationParameters, const std::vector< V * > &simulationOutputs)
Adds multiple simulations to this.
Definition: GPMSA.C:489
A class representing a vector RV constructed via Gamma distribution.
Definition: GammaVectorRV.h:62
const BaseEnvironment & env() const
Return the QUESO environment.
Definition: GPMSA.C:440
A templated base class for handling vector RV.
Definition: VectorRV.h:54
virtual double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the scalar function.
Definition: GPMSA.C:73
const std::vector< V * > & simulationParameters() const
Return all points in parameterSpace for all simulations.
Definition: GPMSA.C:369
const ConcatenatedVectorRV< V, M > & prior() const
Definition: GPMSA.C:540
#define queso_require_less_equal_msg(expr1, expr2, msg)
Definition: asserts.h:89
GPMSAEmulator(const VectorSet< V, M > &domain, const VectorSpace< V, M > &m_scenarioSpace, const VectorSpace< V, M > &m_parameterSpace, const VectorSpace< V, M > &m_simulationOutputSpace, const VectorSpace< V, M > &m_experimentOutputSpace, const unsigned int m_numSimulations, const unsigned int m_numExperiments, const std::vector< V * > &m_simulationScenarios, const std::vector< V * > &m_simulationParameters, const std::vector< V * > &m_simulationOutputs, const std::vector< V * > &m_experimentScenarios, const std::vector< V * > &m_experimentOutputs, const M &m_experimentErrors, const ConcatenatedVectorRV< V, M > &m_totalPrior)
Definition: GPMSA.C:32
A class representing a vector RV constructed via Beta distribution.
Definition: BetaVectorRV.h:64
#define queso_error_msg(msg)
Definition: asserts.h:47
GPMSAOptions * m_opts
Definition: GPMSA.h:363
const std::vector< V * > & simulationScenarios() const
Return all points in scenarioSpace for all simulations.
Definition: GPMSA.C:350
A templated (base) class for handling scalar functions.
unsigned int numExperiments() const
Return number of experiments.
Definition: GPMSA.C:303
const std::vector< V * > & experimentScenarios() const
Return all points in scenarioSpace for all experiments.
Definition: GPMSA.C:407
const V & simulationScenario(unsigned int simulationId) const
Return the point in scenarioSpace for simulation simulationId.
Definition: GPMSA.C:338
const V & experimentScenario(unsigned int experimentId) const
Return the point in scenarioSpace for experiment experimentId.
Definition: GPMSA.C:395
const std::vector< V * > & experimentOutputs() const
Return all points in experimentOutputSpace for all experiments.
Definition: GPMSA.C:426
virtual double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the scalar function.
Definition: GPMSA.C:232
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:307
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
#define queso_require_less_msg(expr1, expr2, msg)
Definition: asserts.h:87
virtual ~GPMSAEmulator()
Definition: GPMSA.C:66
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
const VectorSpace< V, M > & parameterSpace() const
Return the vector space in which parameters live.
Definition: GPMSA.C:317
const VectorSpace< V, M > & simulationOutputSpace() const
Return the vector space in which simulations live.
Definition: GPMSA.C:324
This class defines the options that specify the behaviour of the Gaussian process emulator...
Definition: GPMSAOptions.h:40
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:44
GPMSAFactory(const BaseEnvironment &env, GPMSAOptions *opts, const BaseVectorRV< V, M > &parameterPrior, const VectorSpace< V, M > &scenarioSpace, const VectorSpace< V, M > &parameterSpace, const VectorSpace< V, M > &simulationOutputSpace, const VectorSpace< V, M > &experimentOutputSpace, unsigned int numSimulations, unsigned int numExperiments)
Constructor.
Definition: GPMSA.C:243
void addSimulation(V &simulationScenario, V &simulationParameter, V &simulationOutput)
Add a simulation to this.
Definition: GPMSA.C:454
const BaseEnvironment & m_env
Definition: GPMSA.h:260
const std::vector< V * > & simulationOutputs() const
Return all points in simulationOutputSpace for all simulations.
Definition: GPMSA.C:388
void print(std::ostream &os) const
Definition: GPMSA.C:547
unsigned int numSimulations() const
Return number of simulations.
Definition: GPMSA.C:296
A class representing concatenated vector RVs.
void setUpHyperpriors()
Definition: GPMSA.C:555
const M & experimentErrors() const
Return all observation error covarince matrices for all experiments.
Definition: GPMSA.C:433
const V & experimentOutput(unsigned int experimentId) const
Return the experiment output for experiment experimentId.
Definition: GPMSA.C:414
const VectorSpace< V, M > & scenarioSpace() const
Return the vector space in which scenarios live.
Definition: GPMSA.C:310
A class representing a vector space.
Definition: VectorSet.h:49
const V & simulationOutput(unsigned int simulationId) const
Return the simulation output for simulation simulationId.
Definition: GPMSA.C:376
const GPMSAEmulator< V, M > & getGPMSAEmulator() const
Return the GPMSAEmulator likelihood object.
Definition: GPMSA.C:447
int k
Definition: ann_sample.cpp:53
void addExperiments(const std::vector< V * > &experimentScenarios, const std::vector< V * > &experimentOutputs, const M *experimentErrors)
Add all experiments to this.
Definition: GPMSA.C:502
const VectorSpace< V, M > & experimentOutputSpace() const
Return the vector space in which experiments live.
Definition: GPMSA.C:331

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