Logarithm of the value of the scalar function. Deprecated.
Default implementation throws an exception.
155 const unsigned int totalOutputs = totalRuns * numOutputs;
157 const unsigned int residualSize = (numOutputs == 1) ? totalOutputs :
160 double prodScenario = 1.0;
161 double prodParameter = 1.0;
162 double prodDiscrepancy = 1.0;
167 unsigned int dimSum = 2 +
178 const unsigned int offset1 = (numOutputs == 1) ?
182 const unsigned int offset1b = offset1 +
186 const unsigned int offset2 = (numOutputs == 1) ?
190 const MpiComm & comm = domainVector.map().Comm();
191 Map z_map(residualSize, 0, comm);
192 M covMatrix(this->
m_env, z_map, residualSize);
196 for (
unsigned int k = 0; k < dimParameter; k++) {
198 (*domainVectorParameter)[k] = domainVector[k];
202 for (
unsigned int i = 0; i < totalRuns; i++) {
215 parameter1 = domainVectorParameter;
224 for (
unsigned int j = 0; j < totalRuns; j++) {
230 if (j < this->m_numExperiments) {
232 parameter2 = domainVectorParameter;
243 unsigned int emulatorCorrStrStart =
244 dimParameter + (this->num_svd_terms < numOutputs) + num_svd_terms;
245 for (
unsigned int k = 0; k < dimScenario; k++) {
246 const double & emulator_corr_strength =
247 domainVector[emulatorCorrStrStart+k];
248 double scenario_param1 =
250 double scenario_param2 =
252 prodScenario *= std::pow(emulator_corr_strength,
253 4.0 * (scenario_param1 - scenario_param2) *
254 (scenario_param1 - scenario_param2));
261 for (
unsigned int k = 0; k < dimParameter; k++) {
262 queso_assert (!
queso_isnan(domainVector[emulatorCorrStrStart+dimScenario+k]));
265 const double & emulator_corr_strength =
266 domainVector[emulatorCorrStrStart+dimScenario+k];
267 double uncertain_param1 =
269 double uncertain_param2 =
271 prodParameter *= std::pow(
272 emulator_corr_strength,
273 4.0 * (uncertain_param1 - uncertain_param2) *
274 (uncertain_param1 - uncertain_param2));
281 for (
unsigned int basis = 0; basis !=
num_svd_terms; ++basis)
286 const double relevant_precision =
287 domainVector[dimParameter + basis +
288 (this->num_svd_terms<numOutputs) + (numOutputs>1)];
289 queso_assert_greater(relevant_precision, 0.0);
291 const unsigned int stridei =
293 const unsigned int offseti =
295 const unsigned int stridej =
297 const unsigned int offsetj =
300 covMatrix(offseti+basis*stridei+i,
301 offsetj+basis*stridej+j) =
302 prodScenario * prodParameter / relevant_precision;
307 if (i < this->m_numExperiments && j < this->m_numExperiments) {
310 prodDiscrepancy = 1.0;
311 unsigned int discrepancyCorrStrStart =
312 dimParameter + num_svd_terms + dimParameter + dimScenario + 1 +
313 (this->num_svd_terms<numOutputs) + (numOutputs > 1);
314 for (
unsigned int k = 0; k < dimScenario; k++) {
315 const double & discrepancy_corr_strength =
316 domainVector[discrepancyCorrStrStart+k];
317 double cross_scenario_param1 =
319 double cross_scenario_param2 =
322 std::pow(discrepancy_corr_strength, 4.0 *
323 (cross_scenario_param1 - cross_scenario_param2) *
324 (cross_scenario_param1 - cross_scenario_param2));
327 const double discrepancy_precision =
328 domainVector[discrepancyCorrStrStart-1];
329 queso_assert_greater(discrepancy_precision, 0);
334 const double R_v = prodDiscrepancy / discrepancy_precision;
335 for (
unsigned int disc = 0; disc != num_discrepancy_bases;
337 covMatrix(disc*m_numExperiments+i,
338 disc*m_numExperiments+j) += R_v;
348 const double experimentalError =
351 queso_assert_greater_equal (experimentalError, 0);
353 const double lambda_y =
355 domainVector[dimSum-1] : 1.0;
357 covMatrix(i,j) += lambda_y * experimentalError;
364 const double emulator_data_precision = domainVector[dimSum-1-(numOutputs>1)];
365 queso_assert_greater(emulator_data_precision, 0);
366 double nugget = 1.0 / emulator_data_precision;
368 for (
unsigned int disc = 0; disc != num_discrepancy_bases;
370 covMatrix(disc*m_numExperiments+i,
371 disc*m_numExperiments+i) += nugget;
378 const double lambda_y =
380 domainVector[dimSum-1] : 1.0;
381 const double inv_lambda_y = 1.0/lambda_y;
384 for (
unsigned int i=0; i != BT_Wy_B_size; ++i)
385 for (
unsigned int j=0; j != BT_Wy_B_size; ++j)
388 const double emulator_precision =
389 domainVector[dimParameter+1];
390 const double inv_emulator_precision = 1.0/emulator_precision;
392 unsigned int KT_K_size =
KT_K_inv.numCols();
393 for (
unsigned int i=0; i != KT_K_size; ++i)
394 for (
unsigned int j=0; j != KT_K_size; ++j)
395 covMatrix(i+offset2,j+offset2) +=
396 KT_K_inv(i,j) * inv_emulator_precision;
402 V sol(covMatrix.invertMultiply(
residual));
405 double minus_2_log_lhd = 0.0;
407 for (
unsigned int i = 0; i < residualSize; i++) {
408 minus_2_log_lhd += sol[i] *
residual[i];
412 for (
unsigned int i = 0; i < residualSize; i++) {
414 std::cout <<
"NaN sol[" << i <<
']' << std::endl;
416 std::cout <<
"NaN residual[" << i <<
']' << std::endl;
418 std::cout <<
"Covariance Matrix:" << std::endl;
419 covMatrix.print(std::cout);
424 queso_assert_greater(minus_2_log_lhd, 0);
426 double cov_det = covMatrix.determinant();
430 std::cout <<
"Non-positive determinant for covMatrix = " << std::endl;
431 covMatrix.print(std::cout);
435 minus_2_log_lhd += std::log(covMatrix.determinant());
438 return -0.5 * minus_2_log_lhd;
std::vector< typename SharedPtr< V >::Type > m_discrepancyBases
const VectorSpace< V, M > & m_parameterSpace
double normalized_uncertain_parameter(unsigned int i, double physical_param) const
Calculate a normalized value from a physical value for the.
unsigned int num_svd_terms
const GPMSAOptions & m_opts
const BaseEnvironment & m_env
Definition of a shared pointer.
const unsigned int m_numExperiments
double normalized_scenario_parameter(unsigned int i, double physical_param) const
Calculate a normalized value from a physical value for the.
const std::vector< typename SharedPtr< V >::Type > & m_simulationParameters
const VectorSpace< V, M > & m_experimentOutputSpace
bool m_calibrateObservationalPrecision
Whether to use an observational error precision hyperparameter.
const std::vector< typename SharedPtr< V >::Type > & m_experimentScenarios
const std::vector< typename SharedPtr< V >::Type > & m_simulationScenarios
const VectorSpace< V, M > & m_scenarioSpace
const unsigned int m_numSimulations
SharedPtr< M >::Type m_observationErrorMatrix