queso-0.53.0
Public Member Functions | Public Attributes | List of all members
QUESO::GPMSAEmulator< V, M > Class Template Reference

#include <GPMSA.h>

Inheritance diagram for QUESO::GPMSAEmulator< V, M >:
Inheritance graph
[legend]
Collaboration diagram for QUESO::GPMSAEmulator< V, M >:
Collaboration graph
[legend]

Public Member Functions

 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)
 
virtual ~GPMSAEmulator ()
 
virtual double lnValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Logarithm of the value of the scalar function. More...
 
virtual double actualValue (const V &domainVector, const V *domainDirection, V *gradVector, M *hessianMatrix, V *hessianEffect) const
 Actual value of the scalar function. More...
 
- Public Member Functions inherited from QUESO::BaseScalarFunction< V, M >
 BaseScalarFunction (const char *prefix, const VectorSet< V, M > &domainSet)
 Default constructor. More...
 
virtual ~BaseScalarFunction ()
 Destructor. More...
 
const VectorSet< V, M > & domainSet () const
 Access to the protected attribute m_domainSet: domain set of the scalar function. More...
 

Public Attributes

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
 

Additional Inherited Members

- Protected Attributes inherited from QUESO::BaseScalarFunction< V, M >
const BaseEnvironmentm_env
 
std::string m_prefix
 
const VectorSet< V, M > & m_domainSet
 Domain set of the scalar function. More...
 

Detailed Description

template<class V = GslVector, class M = GslMatrix>
class QUESO::GPMSAEmulator< V, M >

Definition at line 46 of file GPMSA.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::GPMSAEmulator< V, M >::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 at line 32 of file GPMSA.C.

47  :
48  BaseScalarFunction<V, M>("", m_totalPrior.imageSet()),
62 {
63 }
const VectorSpace< V, M > & m_experimentOutputSpace
Definition: GPMSA.h:81
const std::vector< V * > & m_experimentScenarios
Definition: GPMSA.h:89
const std::vector< V * > & m_experimentOutputs
Definition: GPMSA.h:90
const std::vector< V * > & m_simulationOutputs
Definition: GPMSA.h:88
const M & m_experimentErrors
Definition: GPMSA.h:93
const unsigned int m_numSimulations
Definition: GPMSA.h:83
const std::vector< V * > & m_simulationScenarios
Definition: GPMSA.h:86
const std::vector< V * > & m_simulationParameters
Definition: GPMSA.h:87
const VectorSpace< V, M > & m_parameterSpace
Definition: GPMSA.h:79
const unsigned int m_numExperiments
Definition: GPMSA.h:84
const ConcatenatedVectorRV< V, M > & m_totalPrior
Definition: GPMSA.h:95
const VectorSpace< V, M > & m_scenarioSpace
Definition: GPMSA.h:78
const VectorSpace< V, M > & m_simulationOutputSpace
Definition: GPMSA.h:80
template<class V , class M >
QUESO::GPMSAEmulator< V, M >::~GPMSAEmulator ( )
virtual

Definition at line 66 of file GPMSA.C.

67 {
68  // Do nothing?
69 }

Member Function Documentation

template<class V , class M >
double QUESO::GPMSAEmulator< V, M >::actualValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Actual value of the scalar function.

Implements QUESO::BaseScalarFunction< V, M >.

Definition at line 232 of file GPMSA.C.

237 {
238  // Do nothing?
239  return 1.0;
240 }
template<class V , class M >
double QUESO::GPMSAEmulator< V, M >::lnValue ( const V &  domainVector,
const V *  domainDirection,
V *  gradVector,
M *  hessianMatrix,
V *  hessianEffect 
) const
virtual

Logarithm of the value of the scalar function.

Implements QUESO::BaseScalarFunction< V, M >.

Definition at line 73 of file GPMSA.C.

References k.

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 }
const std::vector< V * > & m_experimentScenarios
Definition: GPMSA.h:89
const std::vector< V * > & m_experimentOutputs
Definition: GPMSA.h:90
const std::vector< V * > & m_simulationOutputs
Definition: GPMSA.h:88
const M & m_experimentErrors
Definition: GPMSA.h:93
const unsigned int m_numSimulations
Definition: GPMSA.h:83
const std::vector< V * > & m_simulationScenarios
Definition: GPMSA.h:86
const std::vector< V * > & m_simulationParameters
Definition: GPMSA.h:87
const VectorSpace< V, M > & m_parameterSpace
Definition: GPMSA.h:79
const unsigned int m_numExperiments
Definition: GPMSA.h:84
const VectorSpace< V, M > & m_scenarioSpace
Definition: GPMSA.h:78
int k
Definition: ann_sample.cpp:53

Member Data Documentation

template<class V = GslVector, class M = GslMatrix>
const M& QUESO::GPMSAEmulator< V, M >::m_experimentErrors

Definition at line 93 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const std::vector<V *>& QUESO::GPMSAEmulator< V, M >::m_experimentOutputs

Definition at line 90 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const VectorSpace<V, M>& QUESO::GPMSAEmulator< V, M >::m_experimentOutputSpace

Definition at line 81 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const std::vector<V *>& QUESO::GPMSAEmulator< V, M >::m_experimentScenarios

Definition at line 89 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const unsigned int QUESO::GPMSAEmulator< V, M >::m_numExperiments

Definition at line 84 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const unsigned int QUESO::GPMSAEmulator< V, M >::m_numSimulations

Definition at line 83 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const VectorSpace<V, M>& QUESO::GPMSAEmulator< V, M >::m_parameterSpace

Definition at line 79 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const VectorSpace<V, M>& QUESO::GPMSAEmulator< V, M >::m_scenarioSpace

Definition at line 78 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const std::vector<V *>& QUESO::GPMSAEmulator< V, M >::m_simulationOutputs

Definition at line 88 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const VectorSpace<V, M>& QUESO::GPMSAEmulator< V, M >::m_simulationOutputSpace

Definition at line 80 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const std::vector<V *>& QUESO::GPMSAEmulator< V, M >::m_simulationParameters

Definition at line 87 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const std::vector<V *>& QUESO::GPMSAEmulator< V, M >::m_simulationScenarios

Definition at line 86 of file GPMSA.h.

template<class V = GslVector, class M = GslMatrix>
const ConcatenatedVectorRV<V, M>& QUESO::GPMSAEmulator< V, M >::m_totalPrior

Definition at line 95 of file GPMSA.h.


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

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