25 #include <queso/GPMSA.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
31 template <
class V,
class M>
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,
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)
65 template <
class V,
class M>
71 template <
class V,
class M>
74 const V * domainDirection,
77 V * hessianEffect)
const
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();
105 V residual(gpSpace.zeroVector());
106 M covMatrix(residual);
114 for (
unsigned int i = 0; i < totalDim; i++) {
115 for (
unsigned int j = 0; j < totalDim; j++) {
118 if (i < this->m_numExperiments) {
120 scenario1 =
new V(*((this->m_experimentScenarios)[i]));
123 parameter1 =
new V(*((this->m_simulationParameters)[0]));
124 for (
unsigned int k = 0;
k < dimParameter;
k++) {
125 (*parameter1)[
k] = domainVector[
k];
130 new V(*((this->m_simulationScenarios)[i-this->m_numExperiments]));
132 new V(*((this->m_simulationParameters)[i-this->m_numExperiments]));
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];
144 new V(*((this->m_simulationScenarios)[j-this->m_numExperiments]));
146 new V(*((this->m_simulationParameters)[j-this->m_numExperiments]));
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]));
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]));
166 double emPrecision = domainVector[dimParameter+1];
167 covMatrix(i, j) = prodScenario * prodParameter /
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 +
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]));
189 covMatrix(i, j) += prodDiscrepancy /
190 domainVector[discrepancyCorrStrStart-1];
191 covMatrix(i, j) += (this->m_experimentErrors)(i, j);
199 unsigned int dimSum = 4 +
204 double nugget = 1.0 / domainVector[dimSum-1];
205 covMatrix(i, i) += nugget;
209 for (
unsigned int i = 0; i < this->m_numExperiments; i++) {
211 residual[i] = (*((this->m_experimentOutputs)[i]))[0];
213 for (
unsigned int i = 0; i < this->m_numSimulations; i++) {
215 residual[i+this->m_numExperiments] = (*((this->m_simulationOutputs)[i]))[0];
219 V sol(covMatrix.invertMultiply(residual));
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];
227 return -0.5 * minus_2_log_lhd;
230 template <
class V,
class M>
233 const V * domainDirection,
236 V * hessianEffect)
const
242 template <
class V,
class M>
251 unsigned int numSimulations,
252 unsigned int numExperiments)
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),
288 template <
class V,
class M>
294 template <
class V,
class M>
298 return this->m_numSimulations;
301 template <
class V,
class M>
305 return this->m_numExperiments;
308 template <
class V,
class M>
312 return this->m_scenarioSpace;
315 template <
class V,
class M>
319 return this->m_parameterSpace;
322 template <
class V,
class M>
326 return this->m_simulationOutputSpace;
329 template <
class V,
class M>
333 return this->m_experimentOutputSpace;
336 template <
class V,
class M>
339 unsigned int simulationId)
const
345 return *(this->m_simulationScenarios[simulationId]);
348 template <
class V,
class M>
349 const std::vector<V *> &
352 return this->m_simulationScenarios;
355 template <
class V,
class M>
358 unsigned int simulationId)
const
364 return *(this->m_simulationParameters[simulationId]);
367 template <
class V,
class M>
368 const std::vector<V *> &
371 return this->m_simulationParameters;
374 template <
class V,
class M>
377 unsigned int simulationId)
const
383 return *(this->m_simulationOutputs[simulationId]);
386 template <
class V,
class M>
387 const std::vector<V *> &
390 return this->m_simulationOutputs;
393 template <
class V,
class M>
396 unsigned int experimentId)
const
402 return *(this->m_experimentScenarios[experimentId]);
405 template <
class V,
class M>
406 const std::vector<V *> &
409 return this->m_experimentScenarios;
412 template <
class V,
class M>
415 unsigned int experimentId)
const
421 return *(this->m_experimentOutputs[experimentId]);
424 template <
class V,
class M>
425 const std::vector<V *> &
428 return this->m_experimentOutputs;
431 template <
class V,
class M>
435 return *(this->m_experimentErrors);
438 template <
class V,
class M>
445 template <
class V,
class M>
449 return *(this->gpmsaEmulator);
452 template <
class V,
class M>
455 V & simulationParameter,
456 V & simulationOutput)
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++;
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;
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));
487 template <
class V,
class M>
490 const std::vector<V *> & simulationScenarios,
491 const std::vector<V *> & simulationParameters,
492 const std::vector<V *> & simulationOutputs)
494 for (
unsigned int i = 0; i < this->m_numSimulations; i++) {
495 this->addSimulation(*(simulationScenarios[i]), *(simulationParameters[i]),
496 *(simulationOutputs[i]));
500 template <
class V,
class M>
503 const std::vector<V *> & experimentScenarios,
504 const std::vector<V *> & experimentOutputs,
505 const M * experimentErrors)
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];
513 this->m_experimentErrors = experimentErrors;
514 this->m_numExperimentAdds += experimentScenarios.size();
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;
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));
538 template <
class V,
class M>
542 return *(this->m_totalPrior);
545 template <
class V,
class M>
553 template <
class V,
class M>
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;
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);
579 *(this->emulatorMeanMin),
580 *(this->emulatorMeanMax));
584 *(this->emulatorMeanDomain));
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);
599 *(this->emulatorPrecisionMin),
600 *(this->emulatorPrecisionMax));
603 *(this->emulatorPrecisionDomain),
604 *(this->m_emulatorPrecisionShapeVec),
605 *(this->m_emulatorPrecisionScaleVec));
608 unsigned int dimScenario = (this->scenarioSpace()).dimLocal();
609 unsigned int dimParameter = (this->parameterSpace()).dimLocal();
613 dimScenario + dimParameter,
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);
631 *(this->emulatorCorrelationSpace),
632 *(this->emulatorCorrelationMin),
633 *(this->emulatorCorrelationMax));
636 *(this->emulatorCorrelationDomain),
637 *(this->m_emulatorCorrelationStrengthAlphaVec),
638 *(this->m_emulatorCorrelationStrengthBetaVec));
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);
653 *(this->discrepancyPrecisionMin),
654 *(this->emulatorPrecisionMax));
657 *(this->discrepancyPrecisionDomain),
658 *(this->m_discrepancyPrecisionShapeVec),
659 *(this->m_discrepancyPrecisionScaleVec));
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);
683 *(this->discrepancyCorrelationSpace),
684 *(this->discrepancyCorrelationMin),
685 *(this->discrepancyCorrelationMax));
688 *(this->discrepancyCorrelationDomain),
689 *(this->m_discrepancyCorrelationStrengthAlphaVec),
690 *(this->m_discrepancyCorrelationStrengthBetaVec));
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);
705 *(this->emulatorDataPrecisionMin),
706 *(this->emulatorDataPrecisionMax));
709 *(this->emulatorDataPrecisionDomain),
710 *(this->m_emulatorDataPrecisionShapeVec),
711 *(this->m_emulatorDataPrecisionScaleVec));
714 unsigned int dimSum = 4 +
725 this->totalMins =
new V(this->totalSpace->zeroVector());
726 this->totalMaxs =
new V(this->totalSpace->zeroVector());
729 this->totalMins->cwSet(0);
730 this->totalMaxs->cwSet(1);
732 (*(this->totalMins))[dimParameter] = -INFINITY;
733 (*(this->totalMaxs))[dimParameter] = INFINITY;
734 (*(this->totalMins))[dimParameter+1] = 0.3;
735 (*(this->totalMaxs))[dimParameter+1] = INFINITY;
736 (*(this->totalMins))[dimSum-1] = 60.0;
737 (*(this->totalMaxs))[dimSum-1] = 1e5;
740 (*(this->totalMins))[dimScenario+dimParameter+dimParameter+2] = 0;
742 (*(this->totalMaxs))[dimScenario+dimParameter+dimParameter+2] = INFINITY;
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;
762 *(this->totalDomain));
~GPMSAFactory()
Destructor.
A class representing a uniform vector RV.
A templated class for handling sets.
const V & simulationParameter(unsigned int simulationId) const
Return the point in parameterSpace for simulation simulationId.
void addSimulations(const std::vector< V * > &simulationScenarios, const std::vector< V * > &simulationParameters, const std::vector< V * > &simulationOutputs)
Adds multiple simulations to this.
A class representing a vector RV constructed via Gamma distribution.
const BaseEnvironment & env() const
Return the QUESO environment.
A templated base class for handling vector RV.
virtual double lnValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Logarithm of the value of the scalar function.
const std::vector< V * > & simulationParameters() const
Return all points in parameterSpace for all simulations.
const ConcatenatedVectorRV< V, M > & prior() const
#define queso_require_less_equal_msg(expr1, expr2, msg)
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)
A class representing a vector RV constructed via Beta distribution.
#define queso_error_msg(msg)
const std::vector< V * > & simulationScenarios() const
Return all points in scenarioSpace for all simulations.
A templated (base) class for handling scalar functions.
unsigned int numExperiments() const
Return number of experiments.
const std::vector< V * > & experimentScenarios() const
Return all points in scenarioSpace for all experiments.
const V & simulationScenario(unsigned int simulationId) const
Return the point in scenarioSpace for simulation simulationId.
const V & experimentScenario(unsigned int experimentId) const
Return the point in scenarioSpace for experiment experimentId.
const std::vector< V * > & experimentOutputs() const
Return all points in experimentOutputSpace for all experiments.
virtual double actualValue(const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
Actual value of the scalar function.
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
#define queso_require_msg(asserted, msg)
#define queso_require_less_msg(expr1, expr2, msg)
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
const VectorSpace< V, M > & parameterSpace() const
Return the vector space in which parameters live.
const VectorSpace< V, M > & simulationOutputSpace() const
Return the vector space in which simulations live.
This class defines the options that specify the behaviour of the Gaussian process emulator...
Class representing a subset of a vector space shaped like a hypercube.
GPMSAFactory(const BaseEnvironment &env, GPMSAOptions *opts, const BaseVectorRV< V, M > ¶meterPrior, const VectorSpace< V, M > &scenarioSpace, const VectorSpace< V, M > ¶meterSpace, const VectorSpace< V, M > &simulationOutputSpace, const VectorSpace< V, M > &experimentOutputSpace, unsigned int numSimulations, unsigned int numExperiments)
Constructor.
void addSimulation(V &simulationScenario, V &simulationParameter, V &simulationOutput)
Add a simulation to this.
const BaseEnvironment & m_env
const std::vector< V * > & simulationOutputs() const
Return all points in simulationOutputSpace for all simulations.
void print(std::ostream &os) const
unsigned int numSimulations() const
Return number of simulations.
A class representing concatenated vector RVs.
const M & experimentErrors() const
Return all observation error covarince matrices for all experiments.
const V & experimentOutput(unsigned int experimentId) const
Return the experiment output for experiment experimentId.
const VectorSpace< V, M > & scenarioSpace() const
Return the vector space in which scenarios live.
A class representing a vector space.
const V & simulationOutput(unsigned int simulationId) const
Return the simulation output for simulation simulationId.
const GPMSAEmulator< V, M > & getGPMSAEmulator() const
Return the GPMSAEmulator likelihood object.
void addExperiments(const std::vector< V * > &experimentScenarios, const std::vector< V * > &experimentOutputs, const M *experimentErrors)
Add all experiments to this.
const VectorSpace< V, M > & experimentOutputSpace() const
Return the vector space in which experiments live.