queso-0.53.0
GpmsaComputerModel.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/GpmsaComputerModel.h>
26 #include <queso/GenericScalarFunction.h>
27 #include <queso/SequentialVectorRealizer.h>
28 #include <queso/GslVector.h>
29 #include <queso/GslMatrix.h>
30 
31 namespace QUESO {
32 
33 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
35  const char* prefix,
36  const GcmOptionsValues* alternativeOptionsValues, // dakota
37  const SimulationStorage <S_V,S_M,P_V,P_M,Q_V,Q_M>& simulationStorage,
38  const SimulationModel <S_V,S_M,P_V,P_M,Q_V,Q_M>& simulationModel,
39  const ExperimentStorage <S_V,S_M,D_V,D_M>* experimentStorage,
40  const ExperimentModel <S_V,S_M,D_V,D_M>* experimentModel,
41  const BaseVectorRV <P_V,P_M>* thetaPriorRv)
42  // Handle case of no experiments, that is, experiment pointers == NULL? (todo)
43  :
44  m_env (simulationStorage.env()),
45  m_optionsObj (alternativeOptionsValues),
46  m_s (NULL),
47  m_e (NULL),
48  m_j (NULL),
49  m_z (NULL),
50  m_t (NULL),
51  m_st (NULL),
52  m_jt (NULL),
53  m_zt (NULL),
54  m_thereIsExperimentalData ((experimentStorage != NULL) && (experimentModel != NULL) && (thetaPriorRv != NULL)),
55  m_allOutputsAreScalar (simulationStorage.outputSpace().dimLocal() == 1), // it might become 'false' if there are experiments
56  m_formCMatrix (true), // it will be updated
57  m_cMatIsRankDefficient (false),
58  m_likelihoodFunction (NULL),
59  m_like_counter (MiscUintDebugMessage(0,NULL))
60 {
61  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
62  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
63  << ": prefix = " << prefix
64  << ", alternativeOptionsValues = " << alternativeOptionsValues
65  << ", m_env.optionsInputFileName() = " << m_env.optionsInputFileName()
66  << ", m_thereIsExperimentalData = " << m_thereIsExperimentalData
67  << std::endl;
68  }
69 
70  if ((experimentStorage == NULL) &&
71  (experimentModel == NULL) &&
72  (thetaPriorRv == NULL)) {
73  // Ok
75  queso_require_equal_to_msg(simulationModel.numBasis(), 1, "inconsistent numBasis (1)");
76  }
77  }
78  else if ((experimentStorage != NULL) &&
79  (experimentModel != NULL) &&
80  (thetaPriorRv != NULL)) {
81  // Ok
82  for (unsigned int i = 0; m_allOutputsAreScalar && (i < experimentStorage->numExperiments()); ++i) {
83  m_allOutputsAreScalar = m_allOutputsAreScalar && (experimentStorage->n_ys_transformed()[i] == 1);
84  }
86  queso_require_msg(!((simulationModel.numBasis() != 1) || (experimentModel->numBasis() != 1)), "inconsistent numBasis (2)");
87  }
88  }
89  else {
90  queso_error_msg("inconsistent experimental information");
91  }
92 
93  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
94  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
95  << ": prefix = " << prefix
96  << ", m_allOutputsAreScalar = " << m_allOutputsAreScalar
97  << std::endl;
98  }
99 
101 
102  //********************************************************************************
103  // Handle options
104  //********************************************************************************
105  // If NULL, we create one
106  if (m_optionsObj == NULL) {
107  GcmOptionsValues * tempOptions = new GcmOptionsValues(&m_env, prefix);
108 
109  // We did this dance because scanOptionsValues is not a const method, but
110  // m_optionsObj is a pointer to const
111  m_optionsObj = tempOptions;
112  }
113 
115 
116  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
117  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
118  << ": prefix = " << prefix
119  << ", 'final' m_formCMatrix = " << m_formCMatrix
120  << std::endl;
121  }
122 
123  //********************************************************************************
124  // Open output file // todo_r: is this necessary???
125  //********************************************************************************
126  if ((m_optionsObj->m_dataOutputFileName != "." ) &&
129  UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT, // Yes, always ".m"
131  false,
133  queso_require_msg(m_dataOutputFilePtrSet.ofsVar, "data output file could not be created");
134  }
135 
136  //********************************************************************************
137  // Instantiate:
138  // --> m_s
139  // --> m_e
140  // --> m_j
141  // --> m_z
142  // --> m_t
143  // --> m_st
144  // --> m_jt
145  // --> m_zt
146  //********************************************************************************
147  //********************************************************************************
148  // Instantiate Smat spaces
149  // \Sigma_v:
150  // --> Uses page 576-b
151  // --> Uses R(all x's;\rho_v_i[size p_x]) and formula (2) to "each pair" of experimental input settings
152  // --> \Sigma_v_i = (1/\lambda_v_i).I_|G_i| [X] R(...) is (n.|G_i|) x (n.|G_i|), i = 1,...,F
153  // --> \Sigma_v is (n.p_delta) x (n.p_delta)
154  // \Sigma_u:
155  // --> Uses page 576-b
156  // --> Uses R(all x's,one \theta;\rho_w_i[size p_x+p_t]) and formula (1) to "each pair" of experimental input settings (correlations depend only on x dimensions)
157  // --> \Sigma_u_i = (1/\lambda_w_i).R(...) is n x n, i = 1,...,p_eta
158  // --> \Sigma_u is (n.p_eta) x (n.p_eta)
159  // \Sigma_w:
160  // --> Uses page 575-a
161  // --> Uses R(all x^*'s,all t^*'s;\rho_w_i[size p_x+p_t]) and formula (1) to "each pair" of input settings in the design
162  // --> \Sigma_w_i = (1/\lambda_w_i).R(...) is m x m, i = 1,...,p_eta
163  // --> \Sigma_w is (m.p_eta) x (m.p_eta)
164  // \Sigma_u,w:
165  // --> Uses page 577-a
166  // --> Uses R(all x's,one \theta,all x^*'s,all t^*'s;\rho_w_i[size p_x+p_t]) and formula (1)
167  // --> \Sigma_u,w_i = (1/\lambda_w_i).R(...) is n x m, i = 1,...,p_eta
168  // --> \Sigma_u,w is (n.p_eta) x (m.p_eta)
169  //********************************************************************************
170 
171  // These old options are deprecated. We do this to preserve backwards
172  // compatibility.
173  GpmsaComputerModelOptions * gpmsaComputerModelOptions =
175  m_s = new GcmSimulationInfo<S_V,S_M,P_V,P_M,Q_V,Q_M>(*gpmsaComputerModelOptions,
176  m_allOutputsAreScalar, // csri (new GcmSimulationInfo)
177  simulationStorage,
178  simulationModel);
179  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
180  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
181  << ": finished instantiating m_s"
182  << ", experimentStorage = " << experimentStorage
183  << ", experimentModel = " << experimentModel
184  << ", thetaPriorRv = " << thetaPriorRv
185  << std::endl;
186  }
187 
189  queso_require_equal_to_msg(simulationStorage.scenarioSpace().dimLocal(), experimentStorage->scenarioSpace().dimLocal(), "inconsistent dimension of scenario space");
190 
191  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
192  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
193  << ": about to instantiate m_e"
194  << std::endl;
195  }
196 
197  m_e = new GcmExperimentInfo<S_V,S_M,D_V,D_M,P_V,P_M>(*gpmsaComputerModelOptions,
198  m_allOutputsAreScalar, // csri (new GcmExperimentInfo)
199  *experimentStorage,
200  *experimentModel,
201  *thetaPriorRv);
202  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
203  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
204  << ": finished instantiating m_e"
205  << std::endl;
206  }
207 
208  m_j = new GcmJointInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>(*gpmsaComputerModelOptions,
209  m_allOutputsAreScalar, // csri
210  *m_s,
211  *m_e);
212  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
213  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
214  << ": finished instantiating m_j"
215  << std::endl;
216  }
217 
218  if (m_allOutputsAreScalar) {
220  *m_s,
221  *m_e);
222  }
223  else {
226  *m_s,
227  *m_e,
228  *m_j);
229  }
230  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
231  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
232  << ": finished instantiating m_z"
233  << std::endl;
234  }
235 
237  *m_e);
238  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
239  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
240  << ": finished instantiating m_t"
241  << std::endl;
242  }
243  }
244  else {
245  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
246  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
247  << ": about to instantiate m_z (no experiments)"
248  << std::endl;
249  }
250 
253  *m_s);
254  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
255  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
256  << ": finished instantiating m_z (no experiments)"
257  << std::endl;
258  }
259 
261  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
262  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
263  << ": finished instantiating m_t (no experiments)"
264  << std::endl;
265  }
266  }
267 
268  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
269  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
270  << ": finished instantiating non-tilde auxiliary structures"
271  << std::endl;
272  }
273 
274  this->memoryCheck(0);
275 
276  if (m_formCMatrix) {
277  //********************************************************************************
278  // 'm_Cmat' has been formed: check if it is rank defficient
279  //********************************************************************************
280  if (m_z->m_Cmat_rank < m_z->m_Cmat->numCols()) m_cMatIsRankDefficient = true;
281 
282  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
283  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
284  << ": m_z->m_Cmat_rank = " << m_z->m_Cmat_rank
285  << ", m_z->m_Cmat = " << m_z->m_Cmat
286  << ", m_z->m_Cmat->numCols() = " << m_z->m_Cmat->numCols()
287  << ", m_cMatIsRankDefficient = " << m_cMatIsRankDefficient
288  << std::endl;
289  }
290 
291  if (m_cMatIsRankDefficient == true) {
292  //**********************************************************************************
293  // 'm_Cmat' is rank difficient
294  //**********************************************************************************
296  //********************************************************************************
297  // Use tilde logic
298  //********************************************************************************
300  //******************************************************************************
301  // Tilde situation: form 'm_Bmat_tilde'
302  // Tilde situation: form 'm_vu_tilde_space'
303  // Tilde situation: form 'm_Lbmat'
304  //******************************************************************************
305  m_jt = new GcmJointTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>(*gpmsaComputerModelOptions,*m_e,*m_j);
306 
307  //******************************************************************************
308  // Tilde situation: form 'm_Kmat_tilde'
309  // Tilde situation: form 'm_w_tilde_space'
310  // Tilde situation: form 'm_Lkmat'
311  //******************************************************************************
312  m_st = new GcmSimulationTildeInfo<S_V,S_M,P_V,P_M,Q_V,Q_M>(*gpmsaComputerModelOptions,*m_s);
313 
314  //******************************************************************************
315  // Tilde situation: form 'm_Cmat_tilde'
316  //******************************************************************************
317  m_zt = new GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>(*gpmsaComputerModelOptions,*m_j,*m_z,*m_st,*m_jt);
318  }
319  else {
320  queso_error_msg("incomplete code for the situation 'm_useTildeLogicForRankDefficientC == true' and 'm_thereIsExperimentalData == false'");
321  }
322  } // if (m_useTildeLogicForRankDefficientC)
323  else {
324  //********************************************************************************
325  // Do not use tilde logic
326  //********************************************************************************
328  //******************************************************************************
329  // Naive formation of 'm_Cmat_tilde'
330  //******************************************************************************
331  m_zt = new GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>(*gpmsaComputerModelOptions,*m_j,*m_z);
332  }
333  else {
334  queso_error_msg("incomplete code for the situation 'm_useTildeLogicForRankDefficientC == false' and 'm_thereIsExperimentalData == false'");
335  }
336  }
337  } // if (m_cMatIsRankDefficient)
338  else {
339  //**********************************************************************************
340  // 'm_Cmat' is full rank
341  //**********************************************************************************
342  // Ok. There is nothing extra to be done
343  }
344 
345  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
346  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
347  << ": finished instantiating tilde auxiliary structures"
348  << std::endl;
349  }
350  } // if (m_formCMatrix)
351  else {
352  //********************************************************************************
353  // 'm_Cmat' will not be formed
354  //********************************************************************************
356  // Ok. There is nothing extra to be done
357  }
358  else {
359  // Ok. No experimental data. There is nothing extra to be done // checar
360 
361  // m_env.worldRank(),
362  // "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()",
363  // "incomplete code for the situation 'm_thereIsExperimentalData == false'");
364  }
365  }
366 
367  this->memoryCheck(1);
368 
369  //********************************************************************************
370  // Generate prior sequence
371  //********************************************************************************
373  this->generatePriorSeq();
374  }
375 
376  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
377  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
378  << ": finished generating prior sequence"
379  << std::endl;
380  }
381 
382  this->memoryCheck(2);
383 
384  //********************************************************************************
385  // Instantiate likelihood function object
386  //********************************************************************************
388  ("like_",
389  m_t->m_totalDomain,
391  (void *) this,
392  true); // routine computes [ln(function)]
393 
394  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
395  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
396  << ": finished instantiating likelihood Function"
397  << std::endl;
398  }
399 
400  this->memoryCheck(3);
401 
402  // Done with the old options now, so deallocate
403  delete gpmsaComputerModelOptions;
404 
405  //********************************************************************************
406  // Leave constructor
407  //********************************************************************************
408  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
409  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
410  << ": prefix = " << m_optionsObj->m_prefix
411  << std::endl;
412  }
413 }
414 
415 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
417 {
418  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
419  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::destructor()..."
420  << std::endl;
421  }
422 
423  delete m_zt;
424  delete m_jt;
425  delete m_st;
426  delete m_t;
427  delete m_z;
428  delete m_j;
429  delete m_e;
430  delete m_s;
431 
432  delete m_dataOutputFilePtrSet.ofsVar;
433  if (m_optionsObj) delete m_optionsObj;
434 
435  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
436  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::destructor()"
437  << std::endl;
438  }
439 }
440 
441 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
442 void
444  const MhOptionsValues* alternativeOptionsValues, // dakota
445  const P_V& totalInitialValues,
446  const P_M* totalInitialProposalCovMatrix)
447 {
448  struct timeval timevalBegin;
449  gettimeofday(&timevalBegin, NULL);
450 
451  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
452  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()..."
453  << ": m_optionsObj->m_prefix.c_str() = " << m_optionsObj->m_prefix.c_str()
454  << ", m_env.subComm().NumProc() = " << m_env.subComm().NumProc()
455  << ", my subRank = " << m_env.subRank()
456  << ", totalInitialValues = " << totalInitialValues
457  << std::endl;
458  }
459 
460  m_env.fullComm().Barrier();
461  m_env.fullComm().syncPrintDebugMsg("Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()",1,3000000);
462 
463  queso_require_equal_to_msg(m_t->m_totalPriorRv.imageSet().vectorSpace().dimLocal(), totalInitialValues.sizeLocal(), "'m_totalPriorRv' and 'totalInitialValues' should have equal dimensions");
464 
465  if (totalInitialProposalCovMatrix) {
466  queso_require_equal_to_msg(m_t->m_totalPriorRv.imageSet().vectorSpace().dimLocal(), totalInitialProposalCovMatrix->numRowsLocal(), "'m_totalPriorRv' and 'totalInitialProposalCovMatrix' should have equal dimensions");
467  queso_require_equal_to_msg(totalInitialProposalCovMatrix->numCols(), totalInitialProposalCovMatrix->numRowsGlobal(), "'totalInitialProposalCovMatrix' should be a square matrix");
468  }
469 
470 #if 0
471  P_V currPosition (totalInitialValues);
472  currPosition.cwSet(0.);
473  P_V epsilonVector (currPosition);
474  P_V plusVectorOfLnLikelihoods (currPosition);
475  P_V minusVectorOfLnLikelihoods(currPosition);
476  P_V deltaVectorOfLnLikelihoods(currPosition);
477  P_V vectorOfLnAbsGrads (currPosition);
478 
479  currPosition = totalInitialValues;
480  double referenceValue = staticLikelihoodRoutine(currPosition,
481  NULL,
482  (void *) this,
483  NULL,
484  NULL,
485  NULL);
486 
487  for (unsigned int paramId = 0; paramId < totalInitialValues.sizeLocal(); ++paramId) {
488  currPosition = totalInitialValues;
489  epsilonVector[paramId] = 1.e-8 * totalInitialValues[paramId];
490  if (epsilonVector[paramId] == 0.) epsilonVector[paramId] = 1.e-8;
491 
492  currPosition[paramId] = totalInitialValues[paramId] + epsilonVector[paramId];
493  plusVectorOfLnLikelihoods[paramId] = staticLikelihoodRoutine(currPosition,
494  NULL,
495  (void *) this,
496  NULL,
497  NULL,
498  NULL);
499 
500  currPosition[paramId] = totalInitialValues[paramId] - epsilonVector[paramId];
501  minusVectorOfLnLikelihoods[paramId] = staticLikelihoodRoutine(currPosition,
502  NULL,
503  (void *) this,
504  NULL,
505  NULL,
506  NULL);
507 
508  deltaVectorOfLnLikelihoods[paramId] = plusVectorOfLnLikelihoods[paramId] - minusVectorOfLnLikelihoods[paramId];
509  if (deltaVectorOfLnLikelihoods[paramId] > 0.) {
510  vectorOfLnAbsGrads[paramId] = minusVectorOfLnLikelihoods[paramId] + std::log( std::exp( deltaVectorOfLnLikelihoods[paramId]) - 1. ) - std::log(2.*epsilonVector[paramId]);
511  }
512  else if (deltaVectorOfLnLikelihoods[paramId] == 0.) {
513  vectorOfLnAbsGrads[paramId] = -INFINITY;
514  }
515  else {
516  vectorOfLnAbsGrads[paramId] = plusVectorOfLnLikelihoods [paramId] + std::log( std::exp(-deltaVectorOfLnLikelihoods[paramId]) - 1. ) - std::log(2.*epsilonVector[paramId]);
517  }
518  }
519  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
520  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
521  << ": referenceValue = " << referenceValue
522  << "\n epsilonVector = " << epsilonVector
523  << "\n plusVectorOfLnLikelihoods = " << plusVectorOfLnLikelihoods
524  << "\n minusVectorOfLnLikelihoods = " << minusVectorOfLnLikelihoods
525  << "\n deltaVectorOfLnLikelihoods = " << deltaVectorOfLnLikelihoods
526  << "\n vectorOfLnAbsGrads = " << vectorOfLnAbsGrads
527  << std::endl;
528  }
529 #endif
530 
531  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
532  // << ": passing at point 002"
533  // << std::endl;
534 
535  // Compute output pdf up to a multiplicative constant: Bayesian approach
536  m_t->m_solutionDomain = InstantiateIntersection(m_t->m_totalPriorRv.pdf().domainSet(),m_likelihoodFunction->domainSet());
537 
538  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
539  // << ": passing at point 003"
540  // << std::endl;
541 
542  m_t->m_solutionPdf = new BayesianJointPdf<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
543  m_t->m_totalPriorRv.pdf(),
544  *m_likelihoodFunction,
545  1.,
546  *(m_t->m_solutionDomain));
547 
548  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
549  // << ": passing at point 004"
550  // << std::endl;
551 
552  m_t->m_totalPostRv.setPdf(*(m_t->m_solutionPdf));
553 
554  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
555  // << ": passing at point 005"
556  // << std::endl;
557 
558  // Compute output realizer: Metropolis-Hastings approach
559  m_t->m_chain = new SequenceOfVectors<P_V,P_M>(m_t->m_totalPostRv.imageSet().vectorSpace(),0,m_optionsObj->m_prefix+"chain");
560 
561  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
562  // << ": passing at point 006"
563  // << std::endl;
564 
565  m_t->m_mhSeqGenerator = new MetropolisHastingsSG<P_V,P_M>(m_optionsObj->m_prefix.c_str(), // dakota
566  alternativeOptionsValues,
567  m_t->m_totalPostRv,
568  totalInitialValues,
569  totalInitialProposalCovMatrix);
570 
571  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
572  // << ": passing at point 007"
573  // << std::endl;
574 
575  m_t->m_mhSeqGenerator->generateSequence(*(m_t->m_chain),NULL,NULL);
576 
577  // todo_rr
578  // m_totalPostMean
579  // m_totalPostMedian
580  // m_totalPostMode
581  // m_totalPostMaxLnValue
582  // m_totalMLE
583  // m_totalLikeMaxLnValue
584 
585  m_t->m_solutionRealizer = new SequentialVectorRealizer<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
586  *(m_t->m_chain));
587 
588  m_t->m_totalPostRv.setRealizer(*(m_t->m_solutionRealizer));
589 
590  //m_env.fullComm().syncPrintDebugMsg("In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings(), code place 1",3,3000000);
591 
592  //m_env.fullComm().syncPrintDebugMsg("Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()",1,3000000);
593  m_env.fullComm().Barrier();
594 
595  double totalTime = MiscGetEllapsedSeconds(&timevalBegin);
596  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
597  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()..."
598  << ": m_optionsObj->m_prefix.c_str() = " << m_optionsObj->m_prefix.c_str()
599  << ", m_env.subComm().NumProc() = " << m_env.subComm().NumProc()
600  << ", my subRank = " << m_env.subRank()
601  << ", after " << totalTime
602  << " seconds"
603  << std::endl;
604  }
605 
606  return;
607 }
608 
609 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
610 void
612  const MhOptionsValues* alternativeOptionsValues, // dakota
613  const P_V& totalInitialValues,
614  const P_M* totalInitialProposalCovMatrix)
615 {
616  struct timeval timevalBegin;
617  gettimeofday(&timevalBegin, NULL);
618 
619  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
620  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithLanlMcmc()..."
621  << ": m_optionsObj->m_prefix.c_str() = " << m_optionsObj->m_prefix.c_str()
622  << ", m_env.subComm().NumProc() = " << m_env.subComm().NumProc()
623  << ", my subRank = " << m_env.subRank()
624  << ", totalInitialValues = " << totalInitialValues
625  << std::endl;
626  }
627 
628  m_env.fullComm().Barrier();
629  m_env.fullComm().syncPrintDebugMsg("Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithLanlMcmc()",1,3000000);
630 
631  // ppp
632 
633  m_env.fullComm().syncPrintDebugMsg("Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithLanlMcmc()",1,3000000);
634  m_env.fullComm().Barrier();
635 
636  double totalTime = MiscGetEllapsedSeconds(&timevalBegin);
637  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
638  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithLanlMcmc()..."
639  << ": m_optionsObj->m_prefix.c_str() = " << m_optionsObj->m_prefix.c_str()
640  << ", m_env.subComm().NumProc() = " << m_env.subComm().NumProc()
641  << ", my subRank = " << m_env.subRank()
642  << ", after " << totalTime
643  << " seconds"
644  << std::endl;
645  }
646 
647  return;
648 }
649 
650 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
651 void
653 {
654  struct timeval timevalBegin;
655  gettimeofday(&timevalBegin, NULL);
656 
657  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
658  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMLSampling()..."
659  << ": m_optionsObj->m_prefix.c_str() = " << m_optionsObj->m_prefix.c_str()
660  << ", m_env.subComm().NumProc() = " << m_env.subComm().NumProc()
661  << ", my subRank = " << m_env.subRank()
662  << std::endl;
663  }
664 
665  m_env.fullComm().Barrier();
666  m_env.fullComm().syncPrintDebugMsg("Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMLSampling()",1,3000000);
667 
668  // ppp
669  m_t->m_solutionDomain = InstantiateIntersection(m_t->m_totalPriorRv.pdf().domainSet(),m_likelihoodFunction->domainSet());
670 
671  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
672  // << ": passing at point 003"
673  // << std::endl;
674 
675  m_t->m_solutionPdf = new BayesianJointPdf<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
676  m_t->m_totalPriorRv.pdf(),
677  *m_likelihoodFunction,
678  1.,
679  *(m_t->m_solutionDomain));
680 
681  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
682  // << ": passing at point 004"
683  // << std::endl;
684 
685  m_t->m_totalPostRv.setPdf(*(m_t->m_solutionPdf));
686 
687  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
688  // << ": passing at point 005"
689  // << std::endl;
690 
691  // Compute output realizer: Metropolis-Hastings approach
692  m_t->m_chain = new SequenceOfVectors<P_V,P_M>(m_t->m_totalPostRv.imageSet().vectorSpace(),0,m_optionsObj->m_prefix+"chain");
693 
694  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
695  // << ": passing at point 006"
696  // << std::endl;
697 
698  m_t->m_mlSampler = new MLSampling<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
699  m_t->m_totalPriorRv,
700  *m_likelihoodFunction);
701 
702  //std::cout << "GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMetropolisHastings()"
703  // << ": passing at point 007"
704  // << std::endl;
705 
706  m_t->m_mlSampler->generateSequence(*(m_t->m_chain),NULL,NULL);
707 
708  // todo_rr
709  // m_totalPostMean
710  // m_totalPostMedian
711  // m_totalPostMode
712  // m_totalPostMaxLnValue
713  // m_totalMLE
714  // m_totalLikeMaxLnValue
715 
716  m_t->m_solutionRealizer = new SequentialVectorRealizer<P_V,P_M>(m_optionsObj->m_prefix.c_str(),
717  *(m_t->m_chain));
718 
719  m_t->m_totalPostRv.setRealizer(*(m_t->m_solutionRealizer));
720 
721  m_env.fullComm().syncPrintDebugMsg("Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMLSampling()",1,3000000);
722  m_env.fullComm().Barrier();
723 
724  double totalTime = MiscGetEllapsedSeconds(&timevalBegin);
725  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
726  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::calibrateWithBayesMLSampling()..."
727  << ": m_optionsObj->m_prefix.c_str() = " << m_optionsObj->m_prefix.c_str()
728  << ", m_env.subComm().NumProc() = " << m_env.subComm().NumProc()
729  << ", my subRank = " << m_env.subRank()
730  << ", after " << totalTime
731  << " seconds"
732  << std::endl;
733  }
734 
735  return;
736 }
737 
738 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
739 void
741  const S_V& newScenarioVec,
742  const P_V& newParameterVec,
743  P_V& vuMeanVec,
744  P_M& vuCovMatrix,
745  P_V& vMeanVec,
746  P_M& vCovMatrix,
747  P_V& uMeanVec,
748  P_M& uCovMatrix)
749 {
750  struct timeval timevalBegin;
751  gettimeofday(&timevalBegin, NULL);
752 
753  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
754  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictVUsAtGridPoint(1)"
755  << ", m_predVU_counter = " << m_j->m_predVU_counter
756  << ", newScenarioVec = " << newScenarioVec
757  << ", newParameterVec = " << newParameterVec
758  << std::endl;
759  }
760 
761  queso_require_equal_to_msg(newScenarioVec.sizeLocal(), m_s->m_paper_p_x, "invalid 'newScenarioVec'");
762 
763  queso_require_equal_to_msg(newParameterVec.sizeLocal(), m_s->m_paper_p_t, "invalid 'newParameterVec'");
764 
765  queso_require_equal_to_msg(vuMeanVec.sizeLocal(), (m_e->m_paper_p_delta+m_s->m_paper_p_eta), "invalid 'vuMeanVec'");
766 
767  queso_require_equal_to_msg(vuCovMatrix.numRowsLocal(), (m_e->m_paper_p_delta + m_s->m_paper_p_eta), "invalid 'vuCovMatrix.numRowsLocal()'");
768 
769  queso_require_equal_to_msg(vuCovMatrix.numCols(), (m_e->m_paper_p_delta + m_s->m_paper_p_eta), "invalid 'vuCovMatrix.numCols()'");
770 
771  queso_require_equal_to_msg(vMeanVec.sizeLocal(), m_e->m_paper_p_delta, "invalid 'vMeanVec'");
772 
773  queso_require_equal_to_msg(vCovMatrix.numRowsLocal(), m_e->m_paper_p_delta, "invalid 'vCovMatrix.numRowsLocal()'");
774 
775  queso_require_equal_to_msg(vCovMatrix.numCols(), m_e->m_paper_p_delta, "invalid 'vCovMatrix.numCols()'");
776 
777  queso_require_equal_to_msg(uMeanVec.sizeLocal(), m_s->m_paper_p_eta, "invalid 'uMeanVec'");
778 
779  queso_require_equal_to_msg(uCovMatrix.numRowsLocal(), m_s->m_paper_p_eta, "invalid 'uCovMatrix.numRowsLocal()'");
780 
781  queso_require_equal_to_msg(uCovMatrix.numCols(), m_s->m_paper_p_eta, "invalid 'uCovMatrix.numCols()'");
782 
783  if (m_optionsObj->m_predVUsBySamplingRVs) {
784  }
785 
786  if (m_optionsObj->m_predVUsBySummingRVs) {
787  unsigned int numSamples = (unsigned int) ((double) m_t->m_totalPostRv.realizer().subPeriod())/((double) m_optionsObj->m_predLag);
788  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
789  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictVUsAtGridPoint(1)"
790  << ": m_t->m_totalPostRv.realizer().subPeriod() = " << m_t->m_totalPostRv.realizer().subPeriod()
791  << ", m_optionsObj->m_predLag = " << m_optionsObj->m_predLag
792  << std::endl;
793  }
794 
795  SequenceOfVectors<P_V,P_M> unique_vu_means(m_j->m_unique_vu_space,numSamples,m_optionsObj->m_prefix+"vu_means");
796  P_M mean_of_unique_vu_covMatrices(m_j->m_unique_vu_space.zeroVector());
797 
798  P_V totalSample(m_t->m_totalSpace.zeroVector());
799  P_V muVec1 (m_z->m_z_space.zeroVector());
800  P_V muVec2 (m_j->m_vu_space.zeroVector());
801  P_M sigmaMat11 (m_z->m_z_space.zeroVector());
802  P_M sigmaMat12 (m_env,muVec1.map(),muVec2.sizeGlobal());
803  P_M sigmaMat21 (m_env,muVec2.map(),muVec1.sizeGlobal());
804  P_M sigmaMat22 (m_j->m_vu_space.zeroVector());
805 
806  P_M here_Smat_z_hat_v_asterisk (m_env, m_z->m_z_space.map(), m_e->m_paper_p_delta);
807  P_M here_Smat_z_hat_v_asterisk_t(m_env, m_e->m_unique_v_space.map(), m_z->m_z_size );
808  P_M here_Smat_z_hat_u_asterisk (m_env, m_z->m_z_space.map(), m_s->m_paper_p_eta );
809  P_M here_Smat_z_hat_u_asterisk_t(m_env, m_j->m_unique_u_space.map(), m_z->m_z_size );
810 
811  std::vector<const P_M*> twoMats_uw(2,NULL);
812  std::vector<const P_M*> twoMats_12(2,NULL);
813  std::vector<const P_M*> twoMats_21(2,NULL);
814  std::vector<const P_M*> twoMats_22(2,NULL);
815  for (unsigned int sampleId = 0; sampleId < numSamples; ++sampleId) {
816  m_j->m_predVU_counter++;
817 
818  if (sampleId > 0) {
819  for (unsigned int i = 1; i < m_optionsObj->m_predLag; ++i) { // Yes, '1'
820  m_t->m_totalPostRv.realizer().realization(totalSample);
821  }
822  }
823  m_t->m_totalPostRv.realizer().realization(totalSample);
824 
825  unsigned int currPosition = 0;
826  totalSample.cwExtract(currPosition,m_s->m_tmp_1lambdaEtaVec); // Total of '1' in paper
827  currPosition += m_s->m_tmp_1lambdaEtaVec.sizeLocal();
828  totalSample.cwExtract(currPosition,m_s->m_tmp_2lambdaWVec); // Total of 'p_eta' in paper
829  currPosition += m_s->m_tmp_2lambdaWVec.sizeLocal();
830  totalSample.cwExtract(currPosition,m_s->m_tmp_3rhoWVec); // Total of 'p_eta*(p_x+p_t)' in paper
831  currPosition += m_s->m_tmp_3rhoWVec.sizeLocal();
832  totalSample.cwExtract(currPosition,m_s->m_tmp_4lambdaSVec); // Total of 'p_eta' in matlab code
833  currPosition += m_s->m_tmp_4lambdaSVec.sizeLocal();
834  totalSample.cwExtract(currPosition,m_e->m_tmp_5lambdaYVec); // Total of '1' in paper
835  currPosition += m_e->m_tmp_5lambdaYVec.sizeLocal();
836  totalSample.cwExtract(currPosition,m_e->m_tmp_6lambdaVVec); // Total of 'F' in paper
837  currPosition += m_e->m_tmp_6lambdaVVec.sizeLocal();
838  totalSample.cwExtract(currPosition,m_e->m_tmp_7rhoVVec); // Total of 'F*p_x' in paper
839  currPosition += m_e->m_tmp_7rhoVVec.sizeLocal();
840  totalSample.cwExtract(currPosition,m_e->m_tmp_8thetaVec); // Application specific
841  currPosition += m_e->m_tmp_8thetaVec.sizeLocal();
842  queso_require_equal_to_msg(currPosition, totalSample.sizeLocal(), "'currPosition' and 'totalSample.sizeLocal()' should be equal");
843 
844  //********************************************************************************
845  // Submatrix (1,1): Compute '\Sigma_z_hat' matrix
846  //********************************************************************************
847  // Fill m_Rmat_v_is, m_Smat_v_is, m_Smat_v
848  // Fill m_Rmat_u_is, m_Smat_u_is, m_Smat_u
849  // Fill m_Rmat_w_is, m_Smat_w_is, m_Smat_w
850  // Fill m_Rmat_uw_is, m_Smat_uw_is, m_Smat_uw
851  // Then fill m_tmp_Smat_z
852  // Fill m_Rmat_extra
853  // Then fill m_tmp_Smat_z_hat
854  this->formSigma_z_hat(m_s->m_tmp_1lambdaEtaVec, // todo_rr0: necessary to recompute for every posterior sample?
855  m_s->m_tmp_2lambdaWVec,
856  m_s->m_tmp_3rhoWVec,
857  m_s->m_tmp_4lambdaSVec,
858  m_e->m_tmp_5lambdaYVec,
859  m_e->m_tmp_6lambdaVVec,
860  m_e->m_tmp_7rhoVVec,
861  newParameterVec, //m_e->m_tmp_8thetaVec,
862  m_j->m_predVU_counter);
863 
864  //********************************************************************************
865  // Submatrix (1,2): Compute '\Sigma_z_hat_v_asterisk' matrix
866  // Submatrix (2,1): Compute '\Sigma_z_hat_v_asterisk' transpose matrix
867  //********************************************************************************
868  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
869  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictVUsAtGridPoint(1)"
870  << ", m_predVU_counter = " << m_j->m_predVU_counter
871  << ": about to populate 'm_Smat_v_hat_v_asterisk'"
872  << ", m_e->m_Smat_v_hat_v_asterisk_is.size() = " << m_e->m_Smat_v_hat_v_asterisk_is.size() // 13
873  << ", m_e->m_tmp_rho_v_vec.sizeLocal() = " << m_e->m_tmp_rho_v_vec.sizeLocal() // 1
874  << ", m_e->m_tmp_7rhoVVec.sizeLocal() = " << m_e->m_tmp_7rhoVVec.sizeLocal() // 1
875  << std::endl;
876  }
877  queso_require_equal_to_msg((m_e->m_Smat_v_hat_v_asterisk_is.size() * m_e->m_tmp_rho_v_vec.sizeLocal()), m_e->m_tmp_7rhoVVec.sizeLocal(), "invalid size for 'v' variables");
878  unsigned int initialPos = 0;
879  for (unsigned int i = 0; i < m_e->m_Smat_v_hat_v_asterisk_is.size(); ++i) {
880  m_e->m_tmp_7rhoVVec.cwExtract(initialPos,m_e->m_tmp_rho_v_vec);
881  initialPos += m_e->m_tmp_rho_v_vec.sizeLocal();
882  m_e->m_Rmat_v_hat_v_asterisk_is[i]->cwSet(0.);
883  this->fillR_formula2_for_Sigma_v_hat_v_asterisk(m_s->m_paper_xs_asterisks_standard,
884  m_s->m_paper_ts_asterisks_standard,
885  newScenarioVec,
886  newParameterVec, //m_e->m_tmp_8thetaVec,
887  m_e->m_tmp_rho_v_vec,
888  *(m_e->m_Rmat_v_hat_v_asterisk_is[i]), // IMPORTANT-28
889  m_j->m_predVU_counter);
890  m_e->m_Smat_v_hat_v_asterisk_is[i]->cwSet(0.);
891  // IMPORTANT-28
892  *(m_e->m_Smat_v_hat_v_asterisk_is[i]) = (1./m_e->m_tmp_6lambdaVVec[i]) * *(m_e->m_Rmat_v_hat_v_asterisk_is[i]);
893  }
894  m_e->m_Smat_v_hat_v_asterisk.cwSet(0.);
895  m_e->m_Smat_v_hat_v_asterisk.fillWithBlocksDiagonally(0,0,m_e->m_Smat_v_hat_v_asterisk_is,true,true);
896  m_e->m_Smat_v_hat_v_asterisk_t.fillWithTranspose(0,0,m_e->m_Smat_v_hat_v_asterisk,true,true);
897 
898  here_Smat_z_hat_v_asterisk.cwSet(0.);
899  here_Smat_z_hat_v_asterisk.cwSet(0,0,m_e->m_Smat_v_hat_v_asterisk); // checar
900  here_Smat_z_hat_v_asterisk_t.fillWithTranspose(0,0,here_Smat_z_hat_v_asterisk,true,true);
901 
902  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
903  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictVUsAtGridPoint(1)"
904  << ", m_predVU_counter = " << m_j->m_predVU_counter
905  << ": finished instantiating 'm_Smat_v_hat_v_asterisk'"
906  << std::endl;
907  }
908 
909  //********************************************************************************
910  // Submatrix (1,3): Compute '\Sigma_z_hat_u_asterisk' matrix
911  // Submatrix (3,1): Compute '\Sigma_z_hat_u_asterisk' transpose matrix
912  //********************************************************************************
913  initialPos = 0;
914  for (unsigned int i = 0; i < m_j->m_Smat_u_hat_u_asterisk_is.size(); ++i) {
915  m_s->m_tmp_3rhoWVec.cwExtract(initialPos,m_s->m_tmp_rho_w_vec);
916  initialPos += m_s->m_tmp_rho_w_vec.sizeLocal();
917 
918  m_j->m_Rmat_u_hat_u_asterisk_is[i]->cwSet(0.);
919  this->fillR_formula1_for_Sigma_u_hat_u_asterisk(m_s->m_paper_xs_asterisks_standard,
920  m_s->m_paper_ts_asterisks_standard,
921  newScenarioVec,
922  newParameterVec, //m_e->m_tmp_8thetaVec,
923  m_s->m_tmp_rho_w_vec,
924  *(m_j->m_Rmat_u_hat_u_asterisk_is[i]),
925  m_j->m_predVU_counter);
926  m_j->m_Smat_u_hat_u_asterisk_is[i]->cwSet(0.);
927  *(m_j->m_Smat_u_hat_u_asterisk_is[i]) = (1./m_s->m_tmp_2lambdaWVec[i]) * *(m_j->m_Rmat_u_hat_u_asterisk_is[i]);
928 
929  m_j->m_Rmat_w_hat_u_asterisk_is[i]->cwSet(0.);
930  this->fillR_formula1_for_Sigma_w_hat_u_asterisk(m_s->m_paper_xs_asterisks_standard,
931  m_s->m_paper_ts_asterisks_standard,
932  newScenarioVec,
933  newParameterVec, //m_e->m_tmp_8thetaVec,
934  m_s->m_tmp_rho_w_vec,
935  *(m_j->m_Rmat_w_hat_u_asterisk_is[i]),
936  m_j->m_predVU_counter);
937  m_j->m_Smat_w_hat_u_asterisk_is[i]->cwSet(0.);
938  *(m_j->m_Smat_w_hat_u_asterisk_is[i]) = (1./m_s->m_tmp_2lambdaWVec[i]) * *(m_j->m_Rmat_w_hat_u_asterisk_is[i]);
939  }
940 
941  m_j->m_Smat_u_hat_u_asterisk.cwSet(0.);
942  m_j->m_Smat_u_hat_u_asterisk.fillWithBlocksDiagonally(0,0,m_j->m_Smat_u_hat_u_asterisk_is,true,true);
943  m_j->m_Smat_u_hat_u_asterisk_t.fillWithTranspose(0,0,m_j->m_Smat_u_hat_u_asterisk,true,true);
944 
945  m_j->m_Smat_w_hat_u_asterisk.cwSet(0.);
946  m_j->m_Smat_w_hat_u_asterisk.fillWithBlocksDiagonally(0,0,m_j->m_Smat_w_hat_u_asterisk_is,true,true);
947  m_j->m_Smat_w_hat_u_asterisk_t.fillWithTranspose(0,0,m_j->m_Smat_w_hat_u_asterisk,true,true);
948 
949  twoMats_uw[0] = &m_j->m_Smat_u_hat_u_asterisk;
950  twoMats_uw[1] = &m_j->m_Smat_w_hat_u_asterisk;
951  here_Smat_z_hat_u_asterisk.cwSet(0.);
952  here_Smat_z_hat_u_asterisk.fillWithBlocksVertically(m_e->m_v_size,0,twoMats_uw,true,true); // checar
953  here_Smat_z_hat_u_asterisk_t.fillWithTranspose(0,0,here_Smat_z_hat_u_asterisk,true,true);
954 
955  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
956  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictVUsAtGridPoint(1)"
957  << ", m_predVU_counter = " << m_j->m_predVU_counter
958  << ": finished instantiating '>m_Smat_z_hat_u_asterisk'"
959  << std::endl;
960  }
961 
962  //********************************************************************************
963  // Submatrix (2,2): Compute '\Sigma_v_asterisk_v_asterisk' matrix
964  //********************************************************************************
965  queso_require_equal_to_msg(m_e->m_Smat_v_asterisk_v_asterisk.numRowsLocal(), m_e->m_paper_p_delta, "invalid 'm_Smat_v_asterisk_v_asterisk.numRowsLocal()'");
966  queso_require_equal_to_msg(m_e->m_tmp_6lambdaVVec.sizeLocal(), m_e->m_paper_p_delta, "invalid 'm_tmp_6lambdaVVec.sizeLocal()'");
967 
968  m_e->m_Smat_v_asterisk_v_asterisk.cwSet(0.);
969  for (unsigned int i = 0; i < m_e->m_paper_p_delta; ++i) {
970  m_e->m_Smat_v_asterisk_v_asterisk(i,i) = 1./m_e->m_tmp_6lambdaVVec[i];
971  }
972 
973  //********************************************************************************
974  // Submatrix (3,3): Compute '\Sigma_u_asterisk_u_asterisk' matrix
975  //********************************************************************************
976  queso_require_equal_to_msg(m_j->m_Smat_u_asterisk_u_asterisk.numRowsLocal(), m_s->m_paper_p_eta, "invalid 'm_Smat_u_asterisk_u_asterisk.numRowsLocal()'");
977  queso_require_equal_to_msg(m_s->m_tmp_2lambdaWVec.sizeLocal(), m_s->m_paper_p_eta, "invalid 'm_tmp_2lambdaWVec.sizeLocal()'");
978 
979  m_j->m_Smat_u_asterisk_u_asterisk.cwSet(0.);
980  for (unsigned int i = 0; i < m_s->m_paper_p_eta; ++i) {
981  m_j->m_Smat_u_asterisk_u_asterisk(i,i) = 1./m_s->m_tmp_2lambdaWVec[i] + 1/m_s->m_tmp_4lambdaSVec[i]; // lambda_s
982  }
983 
984  //********************************************************************************
985  // For the current parameter sample, compute the mean vector and the covariance
986  // matrix of the corresponding Gassian RVs 'v' and 'u' conditioned on 'z_hat'
987  // Use the already computed (in constructor) 'm_Zvec_hat'
988  //********************************************************************************
989  P_V unique_vu_vec(m_j->m_unique_vu_space.zeroVector());
990  P_M unique_vu_mat(m_j->m_unique_vu_space.zeroVector());
991 
992  twoMats_12[0] = &here_Smat_z_hat_v_asterisk_t;
993  twoMats_12[1] = &here_Smat_z_hat_u_asterisk_t;
994  twoMats_21[0] = &here_Smat_z_hat_v_asterisk;
995  twoMats_21[1] = &here_Smat_z_hat_u_asterisk;
996  twoMats_22[0] = &m_e->m_Smat_v_asterisk_v_asterisk;
997  twoMats_22[1] = &m_j->m_Smat_u_asterisk_u_asterisk;
998 
999  sigmaMat11 = m_z->m_tmp_Smat_z_hat;
1000  sigmaMat12.fillWithBlocksHorizontally(0,0,twoMats_12,true,true);
1001  sigmaMat21.fillWithBlocksVertically (0,0,twoMats_21,true,true);
1002  sigmaMat22.fillWithBlocksDiagonally (0,0,twoMats_22,true,true);
1003  ComputeConditionalGaussianVectorRV(muVec1,muVec2,sigmaMat11,sigmaMat12,sigmaMat21,sigmaMat22,m_z->m_Zvec_hat,unique_vu_vec,unique_vu_mat);
1004 
1005  unique_vu_means.setPositionValues(sampleId,unique_vu_vec);
1006  m_j->m_predVU_summingRVs_mean_of_unique_vu_covMatrices += unique_vu_mat;
1007  }
1008 
1009  //********************************************************************************
1010  // Final calculations
1011  //********************************************************************************
1012  m_j->m_predVU_summingRVs_mean_of_unique_vu_covMatrices *= (1./(double) numSamples);
1013 
1014  m_j->m_predVU_summingRVs_unique_vu_meanVec = unique_vu_means.unifiedMeanPlain();
1015 
1016  m_j->m_predVU_summingRVs_covMatrix_of_unique_vu_means.cwSet(0.);
1017  m_j->m_predVU_summingRVs_corrMatrix_of_unique_vu_means.cwSet(0.);
1019  unique_vu_means,
1020  unique_vu_means.subSequenceSize(),
1021  m_j->m_predVU_summingRVs_covMatrix_of_unique_vu_means,
1022  m_j->m_predVU_summingRVs_corrMatrix_of_unique_vu_means);
1023 
1024  vuMeanVec = m_j->m_predVU_summingRVs_unique_vu_meanVec;
1025  vuMeanVec.cwExtract(0,vMeanVec);
1026  vuMeanVec.cwExtract(m_e->m_paper_p_delta,uMeanVec);
1027 
1028  P_M vuCovMatrix(m_j->m_unique_vu_space.zeroVector());
1029  vuCovMatrix = m_j->m_predVU_summingRVs_mean_of_unique_vu_covMatrices + m_j->m_predVU_summingRVs_covMatrix_of_unique_vu_means;
1030  vuCovMatrix.cwExtract(0,0,vCovMatrix); // checar
1031  vuCovMatrix.cwExtract(m_e->m_paper_p_delta,m_e->m_paper_p_delta,uCovMatrix); // checar
1032 
1033  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1034  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictVUsAtGridPoint(1)"
1035  << ", m_predVU_counter = " << m_j->m_predVU_counter
1036  << ": finished computing all means and covariances"
1037  << "\n vuMeanVec = " << vuMeanVec
1038  << "\n m_predW_summingRVs_covMatrix_of_unique_vu_means = " << m_j->m_predVU_summingRVs_covMatrix_of_unique_vu_means
1039  << "\n m_predW_summingRVs_mean_of_unique_vu_covMatrices = " << m_j->m_predVU_summingRVs_mean_of_unique_vu_covMatrices
1040  << "\n vuCovMatrix = " << vuCovMatrix
1041  << std::endl;
1042 
1043  }
1044 
1045  mean_of_unique_vu_covMatrices *= (1./(double) numSamples);
1046  }
1047 
1048  if (m_optionsObj->m_predVUsAtKeyPoints) {
1049  }
1050 
1051  double totalTime = MiscGetEllapsedSeconds(&timevalBegin);
1052  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1053  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictVUsAtGridPoint(1)"
1054  << ", m_predVU_counter = " << m_j->m_predVU_counter
1055  << ", newScenarioVec = " << newScenarioVec
1056  << ", after " << totalTime
1057  << " seconds"
1058  << std::endl;
1059  }
1060 
1061  return;
1062 }
1063 
1064 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1065 void
1067  const S_V& newScenarioVec,
1068  const P_V& newParameterVec,
1069  const P_V* forcingSampleVecForDebug, // Usually NULL
1070  P_V& wMeanVec,
1071  P_M& wCovMatrix)
1072 {
1073  struct timeval timevalBegin;
1074  gettimeofday(&timevalBegin, NULL);
1075 
1076  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1077  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictWsAtGridPoint()"
1078  << ", m_predW_counter = " << m_s->m_predW_counter
1079  << ", newScenarioVec = " << newScenarioVec
1080  << ", newParameterVec = " << newParameterVec
1081  << std::endl;
1082  }
1083 
1084  queso_require_equal_to_msg(newScenarioVec.sizeLocal(), m_s->m_paper_p_x, "invalid 'newScenarioVec'");
1085 
1086  queso_require_equal_to_msg(newParameterVec.sizeLocal(), m_s->m_paper_p_t, "invalid 'newParameterVec'");
1087 
1088  queso_require_equal_to_msg(wMeanVec.sizeLocal(), m_s->m_paper_p_eta, "invalid 'wMeanVec'");
1089 
1090  queso_require_equal_to_msg(wCovMatrix.numRowsLocal(), m_s->m_paper_p_eta, "invalid 'wCovMatrix.numRowsLocal()'");
1091 
1092  queso_require_equal_to_msg(wCovMatrix.numCols(), m_s->m_paper_p_eta, "invalid 'wCovMatrix.numCols()'");
1093 
1094  if (m_optionsObj->m_predWsBySamplingRVs) {
1095  }
1096 
1097  if (m_optionsObj->m_predWsBySummingRVs) {
1098  unsigned int numSamples = (unsigned int) ((double) m_t->m_totalPostRv.realizer().subPeriod())/((double) m_optionsObj->m_predLag);
1099  if (forcingSampleVecForDebug) {
1100  numSamples = 1;
1101  }
1102  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1103  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictWsAtGridPoint()"
1104  << ": m_t->m_totalPostRv.realizer().subPeriod() = " << m_t->m_totalPostRv.realizer().subPeriod()
1105  << ", m_optionsObj->m_predLag = " << m_optionsObj->m_predLag
1106  << ", numSamples = " << numSamples
1107  << std::endl;
1108  }
1109 
1110  SequenceOfVectors<P_V,P_M> unique_w_means(m_s->m_unique_w_space,numSamples,m_optionsObj->m_prefix+"w_means");
1111 
1112  P_V totalSample(m_t->m_totalSpace.zeroVector());
1113  P_V muVec1 (m_s->m_unique_w_space.zeroVector());
1114  P_V muVec2 (m_s->m_w_space.zeroVector());
1115  P_M sigmaMat11 (m_s->m_unique_w_space.zeroVector());
1116  P_M sigmaMat12 (m_env,muVec1.map(),muVec2.sizeGlobal());
1117  P_M sigmaMat21 (m_env,muVec2.map(),muVec1.sizeGlobal());
1118  P_M sigmaMat22 (m_s->m_w_space.zeroVector());
1119  for (unsigned int sampleId = 0; sampleId < numSamples; ++sampleId) {
1120  m_s->m_predW_counter++;
1121 
1122  if (sampleId > 0) {
1123  for (unsigned int i = 1; i < m_optionsObj->m_predLag; ++i) { // Yes, '1'
1124  m_t->m_totalPostRv.realizer().realization(totalSample);
1125  }
1126  }
1127  m_t->m_totalPostRv.realizer().realization(totalSample);
1128  if (forcingSampleVecForDebug) {
1129  totalSample = *forcingSampleVecForDebug;
1130  }
1131 
1132  unsigned int currPosition = 0;
1133  totalSample.cwExtract(currPosition,m_s->m_tmp_1lambdaEtaVec); // Total of '1' in paper
1134  currPosition += m_s->m_tmp_1lambdaEtaVec.sizeLocal();
1135  totalSample.cwExtract(currPosition,m_s->m_tmp_2lambdaWVec); // Total of 'p_eta' in paper
1136  currPosition += m_s->m_tmp_2lambdaWVec.sizeLocal();
1137  totalSample.cwExtract(currPosition,m_s->m_tmp_3rhoWVec); // Total of 'p_eta*(p_x+p_t)' in paper
1138  currPosition += m_s->m_tmp_3rhoWVec.sizeLocal();
1139  totalSample.cwExtract(currPosition,m_s->m_tmp_4lambdaSVec); // Total of 'p_eta' in matlab code
1140  currPosition += m_s->m_tmp_4lambdaSVec.sizeLocal();
1141  totalSample.cwExtract(currPosition,m_e->m_tmp_5lambdaYVec); // Total of '1' in paper
1142  currPosition += m_e->m_tmp_5lambdaYVec.sizeLocal();
1143  totalSample.cwExtract(currPosition,m_e->m_tmp_6lambdaVVec); // Total of 'F' in paper
1144  currPosition += m_e->m_tmp_6lambdaVVec.sizeLocal();
1145  totalSample.cwExtract(currPosition,m_e->m_tmp_7rhoVVec); // Total of 'F*p_x' in paper
1146  currPosition += m_e->m_tmp_7rhoVVec.sizeLocal();
1147  totalSample.cwExtract(currPosition,m_e->m_tmp_8thetaVec); // Application specific
1148  currPosition += m_e->m_tmp_8thetaVec.sizeLocal();
1149  queso_require_equal_to_msg(currPosition, totalSample.sizeLocal(), "'currPosition' and 'totalSample.sizeLocal()' should be equal");
1150 
1151  //********************************************************************************
1152  // Submatrix (1,1): Compute '\Sigma_w_hat' matrix
1153  //********************************************************************************
1154  // Fill m_Rmat_w_is, m_Smat_w_is, m_Smat_w
1155  // Then add to m_Smat_w in order to obtain m_Smat_w_hat
1156  this->formSigma_w_hat(m_s->m_tmp_1lambdaEtaVec,
1157  m_s->m_tmp_2lambdaWVec,
1158  m_s->m_tmp_3rhoWVec,
1159  m_s->m_tmp_4lambdaSVec,
1160  newParameterVec, // todo_rr0
1161  m_s->m_predW_counter);
1162 
1163  if (forcingSampleVecForDebug) {
1164  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
1165  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictWsAtGridPoint()"
1166  << ": m_s->m_Smat_w_hat = " << m_s->m_Smat_w_hat
1167  << std::endl;
1168  }
1169  }
1170 
1171  //********************************************************************************
1172  // Submatrix (1,2): Compute '\Sigma_w_hat_w_asterisk' matrix
1173  // Submatrix (2,1): Compute '\Sigma_w_hat_w_asterisk' transpose matrix
1174  //********************************************************************************
1175  unsigned int initialPos = 0;
1176  for (unsigned int i = 0; i < m_s->m_Smat_w_hat_w_asterisk_is.size(); ++i) {
1177  m_s->m_tmp_3rhoWVec.cwExtract(initialPos,m_s->m_tmp_rho_w_vec);
1178  initialPos += m_s->m_tmp_rho_w_vec.sizeLocal();
1179  m_s->m_Rmat_w_hat_w_asterisk_is[i]->cwSet(0.); // This matrix is rectangular: m_paper_m X 1
1180  this->fillR_formula1_for_Sigma_w_hat_w_asterisk(m_s->m_paper_xs_asterisks_standard, // IMPORTANT
1181  m_s->m_paper_ts_asterisks_standard,
1182  newScenarioVec,
1183  newParameterVec,
1184  m_s->m_tmp_rho_w_vec,
1185  *(m_s->m_Rmat_w_hat_w_asterisk_is[i]),
1186  m_s->m_predW_counter);
1187  m_s->m_Smat_w_hat_w_asterisk_is[i]->cwSet(0.);
1188  *(m_s->m_Smat_w_hat_w_asterisk_is[i]) = (1./m_s->m_tmp_2lambdaWVec[i]) * *(m_s->m_Rmat_w_hat_w_asterisk_is[i]);
1189  }
1190  m_s->m_Smat_w_hat_w_asterisk.cwSet(0.);
1191  m_s->m_Smat_w_hat_w_asterisk.fillWithBlocksDiagonally(0,0,m_s->m_Smat_w_hat_w_asterisk_is,true,true);
1192  m_s->m_Smat_w_hat_w_asterisk_t.fillWithTranspose(0,0,m_s->m_Smat_w_hat_w_asterisk,true,true);
1193  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
1194  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictWsAtGridPoint()"
1195  << ", m_predW_counter = " << m_s->m_predW_counter
1196  << ": finished instantiating 'm_Smat_w_hat_w_asterisk'"
1197  << std::endl;
1198  }
1199 
1200  if (forcingSampleVecForDebug) {
1201  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
1202  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictWsAtGridPoint()"
1203  << ": m_s->m_Smat_w_hat_w_asterisk = " << m_s->m_Smat_w_hat_w_asterisk
1204  << std::endl;
1205  }
1206  }
1207 
1208  //********************************************************************************
1209  // Submatrix (2,2): Compute '\Sigma_w_asterisk_w_asterisk' matrix
1210  //********************************************************************************
1211  queso_require_equal_to_msg(m_s->m_Smat_w_asterisk_w_asterisk.numRowsLocal(), m_s->m_paper_p_eta, "invalid 'm_Smat_w_asterisk_w_asterisk.numRowsLocal()'");
1212  queso_require_equal_to_msg(m_s->m_tmp_2lambdaWVec.sizeLocal(), m_s->m_paper_p_eta, "invalid 'm_tmp_2lambdaWVec.sizeLocal()'");
1213 
1214  m_s->m_Smat_w_asterisk_w_asterisk.cwSet(0.);
1215  for (unsigned int i = 0; i < m_s->m_paper_p_eta; ++i) {
1216  m_s->m_Smat_w_asterisk_w_asterisk(i,i) = 1./m_s->m_tmp_2lambdaWVec[i] + 1/m_s->m_tmp_4lambdaSVec[i]; // lambda_s
1217  }
1218 
1219  if (forcingSampleVecForDebug) {
1220  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
1221  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictWsAtGridPoint()"
1222  << ": m_s->m_Smat_w_asterisk_w_asterisk = " << m_s->m_Smat_w_asterisk_w_asterisk
1223  << std::endl;
1224  }
1225  }
1226 
1227  //********************************************************************************
1228  // For the current parameter sample, compute the mean vector and the covariance
1229  // matrix of the corresponding Gassian RV 'w' conditioned on 'w_hat'
1230  // Use the already computed (in constructor) 'm_Zvec_hat_w'
1231  //********************************************************************************
1232  if (forcingSampleVecForDebug) {
1233  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
1234  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictWsAtGridPoint()"
1235  << ": muVec1 = " << muVec1
1236  << ", muVec2 = " << muVec2
1237  << ", m_s->m_Zvec_hat_w = " << m_s->m_Zvec_hat_w
1238  << std::endl;
1239  }
1240  }
1241 
1242  P_V unique_w_vec(m_s->m_unique_w_space.zeroVector());
1243  P_M unique_w_mat(m_s->m_unique_w_space.zeroVector());
1244 
1245  sigmaMat11 = m_s->m_Smat_w_asterisk_w_asterisk;
1246  sigmaMat12 = m_s->m_Smat_w_hat_w_asterisk_t;
1247  sigmaMat21 = m_s->m_Smat_w_hat_w_asterisk;
1248  sigmaMat22 = m_s->m_Smat_w_hat;
1249  ComputeConditionalGaussianVectorRV(muVec1,muVec2,sigmaMat11,sigmaMat12,sigmaMat21,sigmaMat22,m_s->m_Zvec_hat_w,unique_w_vec,unique_w_mat);
1250 
1251  if (forcingSampleVecForDebug) {
1252  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
1253  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictWsAtGridPoint()"
1254  << ", unique_w_vec = " << unique_w_vec
1255  << ", unique_w_mat = " << unique_w_mat
1256  << std::endl;
1257  }
1258  }
1259 
1260  unique_w_means.setPositionValues(sampleId,unique_w_vec);
1261  m_s->m_predW_summingRVs_mean_of_unique_w_covMatrices += unique_w_mat;
1262 
1263  // aqui: display periodic message
1264  }
1265 
1266  //********************************************************************************
1267  // Final calculations
1268  //********************************************************************************
1269  m_s->m_predW_summingRVs_mean_of_unique_w_covMatrices *= (1./(double) numSamples);
1270 
1271  m_s->m_predW_summingRVs_unique_w_meanVec = unique_w_means.unifiedMeanPlain();
1272 
1273  m_s->m_predW_summingRVs_covMatrix_of_unique_w_means.cwSet(0.);
1274  m_s->m_predW_summingRVs_corrMatrix_of_unique_w_means.cwSet(0.);
1276  unique_w_means,
1277  unique_w_means.subSequenceSize(),
1278  m_s->m_predW_summingRVs_covMatrix_of_unique_w_means,
1279  m_s->m_predW_summingRVs_corrMatrix_of_unique_w_means);
1280 
1281  wMeanVec = m_s->m_predW_summingRVs_unique_w_meanVec;
1282  wCovMatrix = m_s->m_predW_summingRVs_mean_of_unique_w_covMatrices + m_s->m_predW_summingRVs_covMatrix_of_unique_w_means;
1283 
1284  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
1285  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictWsAtGridPoint()"
1286  << ", m_predW_counter = " << m_s->m_predW_counter
1287  << ": finished computing all means and covariances"
1288  << "\n wMeanVec = " << wMeanVec
1289  << "\n m_predW_summingRVs_covMatrix_of_unique_w_means = " << m_s->m_predW_summingRVs_covMatrix_of_unique_w_means
1290  << "\n m_predW_summingRVs_mean_of_unique_w_covMatrices = " << m_s->m_predW_summingRVs_mean_of_unique_w_covMatrices
1291  << "\n wCovMatrix = " << wCovMatrix
1292  << std::endl;
1293 
1294  }
1295  }
1296 
1297  if (m_optionsObj->m_predWsAtKeyPoints) {
1298  }
1299 
1300  double totalTime = MiscGetEllapsedSeconds(&timevalBegin);
1301  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1302  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictWsAtGridPoint()"
1303  << ", m_predW_counter = " << m_s->m_predW_counter
1304  << ", newScenarioVec = " << newScenarioVec
1305  << ", newParameterVec = " << newParameterVec
1306  << ", after " << totalTime
1307  << " seconds"
1308  << std::endl;
1309  }
1310 
1311  return;
1312 }
1313 
1314 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1315 void
1317  const S_V& newScenarioVec,
1318  const D_M& newKmat_interp,
1319  const D_M& newDmat,
1320  D_V& simulationOutputMeanVec, // todo_rr: pass as pointer
1321  D_V& discrepancyMeanVec) // todo_rr: pass as pointer
1322 {
1323  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1324  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictExperimentResults()"
1325  << std::endl;
1326  }
1327 
1328  queso_require_equal_to_msg(newScenarioVec.sizeLocal(), m_s->m_paper_p_x, "invalid 'newScenarioVec'");
1329 
1330  queso_require_msg(!((newKmat_interp.numRowsLocal() != m_s->m_paper_n_eta) || (newKmat_interp.numCols() != m_s->m_paper_p_eta)), "invalid 'newKmat_interp'");
1331 
1332  queso_require_msg(!((newDmat.numRowsLocal() != m_s->m_paper_n_eta) || (newDmat.numCols() != m_e->m_paper_p_delta)), "invalid 'newDmat'");
1333 
1334  queso_require_equal_to_msg(simulationOutputMeanVec.sizeLocal(), m_s->m_paper_n_eta, "invalid 'simulationOutputMeanVec'");
1335 
1336  queso_require_equal_to_msg(discrepancyMeanVec.sizeLocal(), m_s->m_paper_n_eta, "invalid 'discrepancyMeanVec'");
1337 
1338  P_V vMeanVec (m_e->m_unique_v_space.zeroVector());
1339  P_M vCovMatrix(m_e->m_unique_v_space.zeroVector());
1340 
1341  // Damon: Had to change m_unique_u_space to m_unique_w_space below. I hope
1342  // it's right. m_s doesn't have a m_unique_u_space
1343  P_V uMeanVec (m_s->m_unique_w_space.zeroVector());
1344  P_M uCovMatrix(m_s->m_unique_w_space.zeroVector());
1345 #if 0
1346  this->predictVUsAtGridPoint(newScenarioVec,
1347  vMeanVec,
1348  vCovMatrix,
1349  uMeanVec,
1350  uCovMatrix);
1351 #endif
1352  simulationOutputMeanVec = newKmat_interp * uMeanVec;
1353  discrepancyMeanVec = newDmat * vMeanVec;
1354 
1355  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1356  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictExperimentResults()"
1357  << std::endl;
1358  }
1359 
1360  return;
1361 }
1362 
1363 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1364 void
1366  const S_V& newScenarioVec,
1367  const P_V& newParameterVec,
1368  Q_V& simulationOutputMeanVec)
1369 {
1370  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1371  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictSimulationOutputs()"
1372  << std::endl;
1373  }
1374 
1375  queso_require_equal_to_msg(newScenarioVec.sizeLocal(), m_s->m_paper_p_x, "invalid 'newScenarioVec'");
1376 
1377  queso_require_equal_to_msg(newParameterVec.sizeLocal(), m_s->m_paper_p_t, "invalid 'newParameterVec'");
1378 
1379  queso_require_equal_to_msg(simulationOutputMeanVec.sizeLocal(), m_s->m_paper_n_eta, "invalid 'simulationOutputMeanVec'");
1380 
1381  P_V wMeanVec (m_s->m_unique_w_space.zeroVector());
1382  P_M wCovMatrix(m_s->m_unique_w_space.zeroVector());
1383  this->predictWsAtGridPoint(newScenarioVec,
1384  newParameterVec,
1385  NULL, // Damon: Adding NULL here; Ernesto left this out
1386  wMeanVec,
1387  wCovMatrix);
1388 
1389  // todo_rr (Should one denormalize qoi here???
1390 
1391  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1392  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::predictSimulationOutputs()"
1393  << std::endl;
1394  }
1395 
1396  return;
1397 }
1398 
1399 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1400 const VectorSpace<P_V,P_M>&
1402 {
1403  queso_require_msg(m_t, "m_t is NULL");
1404  return m_t->m_totalSpace;
1405 }
1406 
1407 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1408 const VectorSpace<P_V,P_M>&
1410 {
1411  queso_require_msg(m_j, "m_j is NULL");
1412  return m_j->m_unique_vu_space;
1413 }
1414 
1415 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1416 const BaseVectorRV<P_V,P_M>&
1418 {
1419  queso_require_msg(m_t, "m_t is NULL");
1420  return m_t->m_totalPriorRv;
1421 }
1422 
1423 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1426 {
1427  queso_require_msg(m_t, "m_t is NULL");
1428  return m_t->m_totalPostRv;
1429 }
1430 
1431 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1432 void
1434 {
1435  return;
1436 }
1437 
1438 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1439 void
1441 {
1442 #if 0
1443  std::cout << "Entering memoryCheck(), m_like_counter = " << m_like_counter << ", codePositionId = " << codePositionId << std::endl;
1444 
1445  double sumZ = 0.;
1446  for (unsigned int i = 0; i < m_z->m_tmp_Smat_z.numRowsLocal(); ++i) {
1447  //std::cout << "i = " << i << std::endl;
1448  for (unsigned int j = 0; j < m_z->m_tmp_Smat_z.numCols(); ++j) {
1449  //std::cout << "j = " << j << std::endl;
1450  sumZ += m_z->m_tmp_Smat_z(i,j);
1451  }
1452  }
1453  //std::cout << "Aqui 000-000, sumZ = " << sumZ << std::endl;
1454 
1455  double sumV = 0.;
1456  for (unsigned int i = 0; i < m_e->m_Smat_v.numRowsLocal(); ++i) {
1457  for (unsigned int j = 0; j < m_e->m_Smat_v.numCols(); ++j) {
1458  sumV += m_e->m_Smat_v(i,j);
1459  }
1460  }
1461 
1462  double sumU = 0.;
1463  for (unsigned int i = 0; i < m_j->m_Smat_u.numRowsLocal(); ++i) {
1464  for (unsigned int j = 0; j < m_j->m_Smat_u.numCols(); ++j) {
1465  sumU += m_j->m_Smat_u(i,j);
1466  }
1467  }
1468 
1469  double sumW = 0.;
1470  for (unsigned int i = 0; i < m_s->m_Smat_w.numRowsLocal(); ++i) {
1471  for (unsigned int j = 0; j < m_s->m_Smat_w.numCols(); ++j) {
1472  sumW += m_s->m_Smat_w(i,j);
1473  }
1474  }
1475 
1476  double sumUW = 0.;
1477  for (unsigned int i = 0; i < m_j->m_Smat_uw.numRowsLocal(); ++i) {
1478  for (unsigned int j = 0; j < m_j->m_Smat_uw.numCols(); ++j) {
1479  sumUW += m_j->m_Smat_uw(i,j);
1480  }
1481  }
1482 
1483  double sumUW_T = 0.;
1484  for (unsigned int i = 0; i < m_j->m_Smat_uw_t.numRowsLocal(); ++i) {
1485  for (unsigned int j = 0; j < m_j->m_Smat_uw_t.numCols(); ++j) {
1486  sumUW_T += m_j->m_Smat_uw_t(i,j);
1487  }
1488  }
1489 
1490  std::cout << "Leaving memoryCheck(), m_like_counter = " << m_like_counter << ", codePositionId = " << codePositionId << std::endl;
1491 #endif
1492  return;
1493 }
1494 
1495 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1496 void
1498 {
1499  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1500  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::generatePriorSeq()..."
1501  << ": m_optionsObj->m_prefix.c_str() = " << m_optionsObj->m_prefix.c_str()
1502  << ", m_optionsObj->m_priorSeqNumSamples = " << m_optionsObj->m_priorSeqNumSamples
1503  << std::endl;
1504  }
1505 
1506  SequenceOfVectors<P_V,P_M> priorSeq(m_t->m_totalSpace,m_optionsObj->m_priorSeqNumSamples,m_optionsObj->m_prefix+"priorSeq");
1507  P_V totalSample(m_t->m_totalSpace.zeroVector());
1508  for (unsigned int sampleId = 0; sampleId < m_optionsObj->m_priorSeqNumSamples; ++sampleId) {
1509  m_t->m_totalPriorRv.realizer().realization(totalSample);
1510  priorSeq.setPositionValues(sampleId,totalSample);
1511  }
1512  priorSeq.unifiedWriteContents(m_optionsObj->m_priorSeqDataOutputFileName,
1513  m_optionsObj->m_priorSeqDataOutputFileType);
1514 
1515  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1516  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::generatePriorSeq()..."
1517  << ": m_optionsObj->m_prefix.c_str() = " << m_optionsObj->m_prefix.c_str()
1518  << std::endl;
1519  }
1520 
1521  return;
1522 }
1523 
1524 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1525 double
1527  const P_V& totalValues,
1528  const P_V* totalDirection,
1529  const void* functionDataPtr,
1530  P_V* gradVector,
1531  P_M* hessianMatrix,
1532  P_V* hessianEffect)
1533 {
1534  return ((GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>*) functionDataPtr)->likelihoodRoutine(totalValues,
1535  totalDirection,
1536  functionDataPtr,
1537  gradVector,
1538  hessianMatrix,
1539  hessianEffect);
1540 }
1541 
1542 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1543 double
1545  const P_V& totalValues,
1546  const P_V* totalDirection,
1547  const void* functionDataPtr,
1548  P_V* gradVector,
1549  P_M* hessianMatrix,
1550  P_V* hessianEffect)
1551 {
1552  struct timeval timevalBegin;
1553  gettimeofday(&timevalBegin, NULL);
1554 
1555  m_like_counter++;
1556  //std::cout << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(), m_like_counter = " << m_like_counter << std::endl;
1557  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1558  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine()..."
1559  << ": m_like_counter = " << m_like_counter
1560  << ", totalValues = " << totalValues
1561  << ", m_env.subComm().NumProc() = " << m_env.subComm().NumProc()
1562  << ", my subRank = " << m_env.subRank()
1563  << ", m_formCMatrix = " << m_formCMatrix
1564  << ", m_cMatIsRankDefficient = " << m_cMatIsRankDefficient
1565  << std::endl;
1566  }
1567 
1568  double lnLikelihoodValue = 0.;
1569 
1570  if (totalDirection &&
1571  functionDataPtr &&
1572  gradVector &&
1573  hessianMatrix &&
1574  hessianEffect) {
1575  // Just to eliminate INTEL compiler warnings
1576  }
1577 
1578  //********************************************************************************
1579  // Total values = (\lambda_eta[1],\lambda_w[p_eta],\rho_w[(p_x+p_t).p_eta],\lambda_y[1],\lambda_v[F],\rho_v[F.p_x],\theta)
1580  //********************************************************************************
1581  queso_require_equal_to(m_s->m_1lambdaEtaSpace.dimLocal(), 1);
1582 
1583  queso_require_equal_to(m_s->m_2lambdaWSpace.dimLocal(),
1584  m_s->m_paper_p_eta);
1585 
1586  queso_require_equal_to(m_s->m_3rhoWSpace.dimLocal(),
1587  (m_s->m_paper_p_eta*(m_s->m_paper_p_x+m_s->m_paper_p_t)));
1588  queso_require_equal_to(m_s->m_4lambdaSSpace.dimLocal(), m_s->m_paper_p_eta);
1589 
1590  if (m_thereIsExperimentalData) {
1591  queso_require_equal_to(m_e->m_5lambdaYSpace.dimLocal(), 1);
1592 
1593  queso_require_equal_to(m_e->m_6lambdaVSpace.dimLocal(),
1594  m_e->m_paper_F);
1595 
1596  queso_require_equal_to(m_e->m_7rhoVSpace.dimLocal(),
1597  m_e->m_paper_F*m_s->m_paper_p_x);
1598  }
1599 
1600  this->memoryCheck(50);
1601 
1602  unsigned int currPosition = 0;
1603  totalValues.cwExtract(currPosition,m_s->m_tmp_1lambdaEtaVec); // Total of '1' in paper
1604  currPosition += m_s->m_tmp_1lambdaEtaVec.sizeLocal();
1605  totalValues.cwExtract(currPosition,m_s->m_tmp_2lambdaWVec); // Total of 'p_eta' in paper
1606  currPosition += m_s->m_tmp_2lambdaWVec.sizeLocal();
1607  totalValues.cwExtract(currPosition,m_s->m_tmp_3rhoWVec); // Total of 'p_eta*(p_x+p_t)' in paper
1608  currPosition += m_s->m_tmp_3rhoWVec.sizeLocal();
1609  totalValues.cwExtract(currPosition,m_s->m_tmp_4lambdaSVec); // Total of 'p_eta' in matlab code
1610  currPosition += m_s->m_tmp_4lambdaSVec.sizeLocal();
1611 
1612  if (m_thereIsExperimentalData) {
1613  totalValues.cwExtract(currPosition,m_e->m_tmp_5lambdaYVec); // Total of '1' in paper
1614  currPosition += m_e->m_tmp_5lambdaYVec.sizeLocal();
1615  totalValues.cwExtract(currPosition,m_e->m_tmp_6lambdaVVec); // Total of 'F' in paper
1616  currPosition += m_e->m_tmp_6lambdaVVec.sizeLocal();
1617  totalValues.cwExtract(currPosition,m_e->m_tmp_7rhoVVec); // Total of 'F*p_x' in paper
1618  currPosition += m_e->m_tmp_7rhoVVec.sizeLocal();
1619  totalValues.cwExtract(currPosition,m_e->m_tmp_8thetaVec); // Application specific
1620  currPosition += m_e->m_tmp_8thetaVec.sizeLocal();
1621  }
1622  queso_require_equal_to_msg(currPosition, totalValues.sizeLocal(), "'currPosition' and 'totalValues.sizeLocal()' should be equal");
1623 
1624  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
1625  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine()"
1626  << ", m_like_counter = " << m_like_counter
1627  << ": finished extracting components from 'totalValues'"
1628  << ", m_tmp_1lambdaEtaVec = " << m_s->m_tmp_1lambdaEtaVec
1629  << ", m_tmp_2lambdaWVec = " << m_s->m_tmp_2lambdaWVec
1630  << ", m_tmp_3rhoWVec = " << m_s->m_tmp_3rhoWVec
1631  << ", m_tmp_4lambdaSVec = " << m_s->m_tmp_4lambdaSVec;
1632  if (m_thereIsExperimentalData) {
1633  *m_env.subDisplayFile() << ", m_tmp_5lambdaYVec = " << m_e->m_tmp_5lambdaYVec
1634  << ", m_tmp_6lambdaVVec = " << m_e->m_tmp_6lambdaVVec
1635  << ", m_tmp_7rhoVVec = " << m_e->m_tmp_7rhoVVec
1636  << ", m_tmp_8thetaVec = " << m_e->m_tmp_8thetaVec;
1637  }
1638  *m_env.subDisplayFile() << std::endl;
1639  }
1640 
1641  //********************************************************************************
1642  // Check if current 'totalValues' has any common values with previous 'totalValues' (todo)
1643  //********************************************************************************
1644  bool here_1_repeats = false;
1645  bool here_2_repeats = false;
1646  bool here_3_repeats = false;
1647  bool here_4_repeats = false;
1648  bool here_5_repeats = false;
1649  bool here_6_repeats = false;
1650  bool here_7_repeats = false;
1651  bool here_8_repeats = false;
1652  if ((m_optionsObj->m_checkAgainstPreviousSample) &&
1653  (m_like_counter == 1 )) {
1654  here_1_repeats = (m_s->m_like_previous1 == m_s->m_tmp_1lambdaEtaVec);
1655  here_2_repeats = (m_s->m_like_previous2 == m_s->m_tmp_2lambdaWVec);
1656  here_3_repeats = (m_s->m_like_previous3 == m_s->m_tmp_3rhoWVec);
1657  here_4_repeats = (m_s->m_like_previous2 == m_s->m_tmp_4lambdaSVec);
1658  if (m_thereIsExperimentalData) {
1659  here_5_repeats = (m_e->m_like_previous5 == m_e->m_tmp_5lambdaYVec);
1660  here_6_repeats = (m_e->m_like_previous6 == m_e->m_tmp_6lambdaVVec);
1661  here_7_repeats = (m_e->m_like_previous7 == m_e->m_tmp_7rhoVVec);
1662  here_8_repeats = (m_e->m_like_previous8 == m_e->m_tmp_8thetaVec);
1663  }
1664  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
1665  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine()"
1666  << ", m_like_counter = " << m_like_counter
1667  << "\n m_like_previous1 = " << m_s->m_like_previous1
1668  << "\n m_like_previous2 = " << m_s->m_like_previous2
1669  << "\n m_like_previous3 = " << m_s->m_like_previous3;
1670  if (m_thereIsExperimentalData) {
1671  *m_env.subDisplayFile() << "\n m_like_previous5 = " << m_e->m_like_previous5
1672  << "\n m_like_previous6 = " << m_e->m_like_previous6
1673  << "\n m_like_previous7 = " << m_e->m_like_previous7
1674  << "\n m_like_previous8 = " << m_e->m_like_previous8;
1675  }
1676  *m_env.subDisplayFile() << std::endl;
1677  }
1678  if (here_1_repeats ||
1679  here_2_repeats ||
1680  here_3_repeats ||
1681  here_4_repeats ||
1682  here_5_repeats ||
1683  here_6_repeats ||
1684  here_7_repeats ||
1685  here_8_repeats) {}; // just to remove compiler warning
1686  }
1687 
1688  lnLikelihoodValue = 0.;
1689  if ((m_formCMatrix ) &&
1690  (m_cMatIsRankDefficient)) {
1691  //********************************************************************************
1692  // 'm_Cmat' is rank defficient
1693  //********************************************************************************
1694  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3/*99*/)) {
1695  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(tilde)"
1696  << ", m_like_counter = " << m_like_counter
1697  << ": going through true 'm_cMatIsRankDefficient' case"
1698  << std::endl;
1699  }
1700 
1701  this->memoryCheck(57);
1702 
1703  if (m_optionsObj->m_useTildeLogicForRankDefficientC) {
1704  //********************************************************************************
1705  // Compute '\Sigma_z_tilde_hat' matrix
1706  //********************************************************************************
1707  // Fill m_Rmat_v_is, m_Smat_v_is, m_Smat_v
1708  // Fill m_Rmat_u_is, m_Smat_u_is, m_Smat_u
1709  // Fill m_Rmat_w_is, m_Smat_w_is, m_Smat_w
1710  // Fill m_Rmat_uw_is, m_Smat_uw_is, m_Smat_uw
1711  // Then fill m_tmp_Smat_z
1712  // Fill m_Rmat_extra
1713  // Then fill m_tmp_Smat_z_tilde_hat
1714  this->formSigma_z_tilde_hat(m_s->m_tmp_1lambdaEtaVec,
1715  m_s->m_tmp_2lambdaWVec,
1716  m_s->m_tmp_3rhoWVec,
1717  m_s->m_tmp_4lambdaSVec,
1718  m_e->m_tmp_5lambdaYVec,
1719  m_e->m_tmp_6lambdaVVec,
1720  m_e->m_tmp_7rhoVVec,
1721  m_e->m_tmp_8thetaVec,
1722  m_like_counter);
1723 
1724  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3/*99*/)) {
1725  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(tilde)"
1726  << ", m_like_counter = " << m_like_counter
1727  << ": finished computing 'm_tmp_Smat_z_tilde_hat' =\n" << m_zt->m_tmp_Smat_z_tilde_hat
1728  << std::endl;
1729  }
1730 
1731  this->memoryCheck(58);
1732 
1733  //********************************************************************************
1734  // Compute the determinant of '\Sigma_z_tilde_hat' matrix
1735  //********************************************************************************
1736  double Smat_z_tilde_hat_lnDeterminant = m_zt->m_tmp_Smat_z_tilde_hat.lnDeterminant();
1737 
1738  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1739  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(tilde)"
1740  << ", m_like_counter = " << m_like_counter
1741  << ": finished computing 'm_tmp_Smat_z_tilde_hat->lnDeterminant()' = " << Smat_z_tilde_hat_lnDeterminant
1742  << std::endl;
1743  }
1744  lnLikelihoodValue += -0.5*Smat_z_tilde_hat_lnDeterminant;
1745 
1746  this->memoryCheck(59);
1747 
1748  //********************************************************************************
1749  // Compute Gaussian contribution
1750  //********************************************************************************
1751  double tmpValue1 = scalarProduct(m_zt->m_Zvec_tilde_hat,m_zt->m_tmp_Smat_z_tilde_hat.invertMultiply(m_zt->m_Zvec_tilde_hat)); // inversion savings
1752  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3/*99*/)) {
1753  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(tilde)"
1754  << ", m_like_counter = " << m_like_counter
1755  << ": finished computing 'tmpValue1 = " << tmpValue1
1756  << std::endl;
1757  }
1758  lnLikelihoodValue += -0.5*tmpValue1;
1759 
1760  this->memoryCheck(60);
1761 
1762  //********************************************************************************
1763  // Include effect of exponent modifiers
1764  //********************************************************************************
1765  double tmpValue2 = m_st->m_a_eta_modifier_tilde*std::log(m_s->m_tmp_1lambdaEtaVec[0]) - m_st->m_b_eta_modifier_tilde*m_s->m_tmp_1lambdaEtaVec[0];
1766  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3/*99*/)) {
1767  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(tilde)"
1768  << ", m_like_counter = " << m_like_counter
1769  << ": finished computing 'tmpValue2 = " << tmpValue2
1770  << std::endl;
1771  }
1772  lnLikelihoodValue += tmpValue2;
1773 
1774  this->memoryCheck(61);
1775 
1776  double tmpValue3 = m_jt->m_a_y_modifier_tilde*std::log(m_e->m_tmp_5lambdaYVec[0]) - m_jt->m_b_y_modifier_tilde*m_e->m_tmp_5lambdaYVec[0];
1777  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3/*99*/)) {
1778  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(tilde)"
1779  << ", m_like_counter = " << m_like_counter
1780  << ": finished computing 'tmpValue3 = " << tmpValue3
1781  << std::endl;
1782  }
1783  lnLikelihoodValue += tmpValue3;
1784 
1785  this->memoryCheck(62);
1786  }
1787  else { // if (m_optionsObj->m_useTildeLogicForRankDefficientC)
1788  queso_error_msg("incomplete code for situation 'm_useTildeLogicForRankDefficientC == false'");
1789  }
1790  }
1791  else { // if (m_formCMatrix) && (m_cMatIsRankDefficient)
1792  //********************************************************************************
1793  // 'm_Cmat' (i) does not exist or (ii) is full rank
1794  //********************************************************************************
1795  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
1796  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(non-tilde)"
1797  << ", m_like_counter = " << m_like_counter
1798  << ": going through case where C matrix (i) does not exist or (ii) is full rank"
1799  << ", m_thereIsExperimentalData = " << m_thereIsExperimentalData
1800  << std::endl;
1801  }
1802 
1803  this->memoryCheck(51);
1804 
1805  //********************************************************************************
1806  // Compute '\Sigma_z_hat' matrix
1807  //********************************************************************************
1808  // Fill m_Rmat_v_is, m_Smat_v_is, m_Smat_v
1809  // Fill m_Rmat_u_is, m_Smat_u_is, m_Smat_u
1810  // Fill m_Rmat_w_is, m_Smat_w_is, m_Smat_w
1811  // Fill m_Rmat_uw_is, m_Smat_uw_is, m_Smat_uw
1812  // Then fill m_tmp_Smat_z
1813  // Fill m_Rmat_extra
1814  // Then fill m_tmp_Smat_z_hat
1815 
1816  if (m_thereIsExperimentalData) {
1817  this->formSigma_z_hat(m_s->m_tmp_1lambdaEtaVec,
1818  m_s->m_tmp_2lambdaWVec,
1819  m_s->m_tmp_3rhoWVec,
1820  m_s->m_tmp_4lambdaSVec,
1821  m_e->m_tmp_5lambdaYVec,
1822  m_e->m_tmp_6lambdaVVec,
1823  m_e->m_tmp_7rhoVVec,
1824  m_e->m_tmp_8thetaVec,
1825  m_like_counter);
1826  }
1827  else {
1828  queso_error_msg("incomplete code for situation 'm_thereIsExperimentalData == false'");
1829 
1830  this->formSigma_z_hat(m_s->m_tmp_1lambdaEtaVec,
1831  m_s->m_tmp_2lambdaWVec,
1832  m_s->m_tmp_3rhoWVec,
1833  m_s->m_tmp_4lambdaSVec,
1834  m_like_counter);
1835  }
1836 
1837  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
1838  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(non-tilde)"
1839  << ", m_like_counter = " << m_like_counter
1840  << ": finished computing 'm_tmp_Smat_z_hat' =\n" << m_z->m_tmp_Smat_z_hat
1841  << std::endl;
1842  }
1843 
1844  this->memoryCheck(52);
1845 
1846  //********************************************************************************
1847  // Compute the determinant of '\Sigma_z_hat' matrix
1848  //********************************************************************************
1849  double Smat_z_hat_lnDeterminant = m_z->m_tmp_Smat_z_hat.lnDeterminant();
1850 
1851  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1852  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(non-tilde)"
1853  << ", m_like_counter = " << m_like_counter
1854  << ": finished computing 'm_tmp_Smat_z_hat.lnDeterminant()' = " << Smat_z_hat_lnDeterminant
1855  << std::endl;
1856  }
1857  lnLikelihoodValue += -0.5*Smat_z_hat_lnDeterminant;
1858 
1859  this->memoryCheck(53);
1860 
1861  //********************************************************************************
1862  // Compute Gaussian contribution
1863  //********************************************************************************
1864  double tmpValue1 = scalarProduct(m_z->m_Zvec_hat,m_z->m_tmp_Smat_z_hat.invertMultiply(m_z->m_Zvec_hat)); // inversion savings
1865  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1866  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(non-tilde)"
1867  << ", m_like_counter = " << m_like_counter
1868  << ": finished computing 'tmpValue1 = " << tmpValue1
1869  << std::endl;
1870  }
1871  lnLikelihoodValue += -0.5*tmpValue1;
1872 
1873  this->memoryCheck(54);
1874 
1875  if (m_allOutputsAreScalar) {
1876  // Do nothing
1877  }
1878  else {
1879  //********************************************************************************
1880  // Include effect of exponent modifiers
1881  //********************************************************************************
1882  double tmpValue2 = m_s->m_a_eta_modifier*std::log(m_s->m_tmp_1lambdaEtaVec[0]) - m_s->m_b_eta_modifier*m_s->m_tmp_1lambdaEtaVec[0];
1883  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1884  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(non-tilde)"
1885  << ", m_like_counter = " << m_like_counter
1886  << ": finished computing 'tmpValue2 = " << tmpValue2
1887  << std::endl;
1888  }
1889  lnLikelihoodValue += tmpValue2;
1890 
1891  this->memoryCheck(55);
1892 
1893  double tmpValue3 = m_j->m_a_y_modifier*std::log(m_e->m_tmp_5lambdaYVec[0]) - m_j->m_b_y_modifier*m_e->m_tmp_5lambdaYVec[0];
1894  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1895  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(non-tilde)"
1896  << ", m_like_counter = " << m_like_counter
1897  << ": finished computing 'tmpValue3 = " << tmpValue3
1898  << std::endl;
1899  }
1900  lnLikelihoodValue += tmpValue3;
1901 
1902  this->memoryCheck(56);
1903 
1904  //for (unsigned int i = 0; i < m_paper_p_eta; ++i) {
1905  // for (unsigned int j = 0; j < (m_paper_p_x + m_paper_p_t); ++j) {
1906  // }
1907  //}
1908  }
1909  }
1910  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3/*99*/)) {
1911  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine()"
1912  << ", m_like_counter = " << m_like_counter
1913  << ": finished computing ln(likelihood)"
1914  << ", lnLikelihoodValue = " << lnLikelihoodValue
1915  << std::endl;
1916  }
1917 
1918  this->memoryCheck(63);
1919 
1920  //******************************************************************************
1921  // Prepare to return
1922  //******************************************************************************
1923  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
1924  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine()"
1925  << ", m_like_counter = " << m_like_counter
1926  << ": starting saving current samples as previous"
1927  << std::endl;
1928  }
1929 
1930  m_t->m_like_previousTotal = totalValues;
1931  m_s->m_like_previous1 = m_s->m_tmp_1lambdaEtaVec;
1932  m_s->m_like_previous2 = m_s->m_tmp_2lambdaWVec;
1933  m_s->m_like_previous3 = m_s->m_tmp_3rhoWVec;
1934  m_s->m_like_previous2 = m_s->m_tmp_4lambdaSVec;
1935  m_e->m_like_previous5 = m_e->m_tmp_5lambdaYVec;
1936  m_e->m_like_previous6 = m_e->m_tmp_6lambdaVVec;
1937  m_e->m_like_previous7 = m_e->m_tmp_7rhoVVec;
1938  m_e->m_like_previous8 = m_e->m_tmp_8thetaVec;
1939 
1940  double totalTime = MiscGetEllapsedSeconds(&timevalBegin);
1941 
1942  //std::cout << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine(), m_like_counter = " << m_like_counter << std::endl;
1943  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
1944  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine()"
1945  << ": m_like_counter = " << m_like_counter
1946  << ", totalValues = " << totalValues
1947  << ", lnLikelihoodValue = " << lnLikelihoodValue
1948  << " after " << totalTime
1949  << " seconds"
1950  << std::endl;
1951  }
1952 
1953  if (m_env.subRank() == 0) {
1954 #if 0
1955  std::cout << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::likelihoodRoutine()"
1956  << ", m_like_counter = " << m_like_counter
1957  << ": totalValues = " << totalValues
1958  << ", lnLikelihoodValue = " << lnLikelihoodValue
1959  << " after " << totalTime
1960  << " seconds"
1961  << std::endl;
1962 #else
1963  //sprintf(syncMsg,"In likelihoodRoutine(), likeCount = %u, total = %11.4e, lnL = %11.4e, time = %11.4e",
1964  // m_like_counter,
1965  // totalValues[0],
1966  // lnLikelihoodValue,
1967  // totalTime);
1968  //m_env.inter0Comm().syncPrintDebugMsg(syncMsg, 0, 1000);
1969 #endif
1970  }
1971 
1972  m_env.subComm().Barrier();
1973 
1974  if (gradVector) {
1975  if (gradVector->sizeLocal() >= 4) {
1976  (*gradVector)[0] = lnLikelihoodValue;
1977  (*gradVector)[1] = 0.;
1978  (*gradVector)[2] = 0.;
1979  (*gradVector)[3] = 0.;
1980  }
1981  }
1982 
1983  if (m_like_counter == 0) {
1984  sleep(1);
1985  queso_error_msg("Exiting in likelihoodRoutine(), on purpose...");
1986  }
1987 
1988  return lnLikelihoodValue;
1989 }
1990 
1991 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
1992 void
1994  const P_V& input_1lambdaEtaVec,
1995  const P_V& input_2lambdaWVec,
1996  const P_V& input_3rhoWVec,
1997  const P_V& input_4lambdaSVec,
1998  const P_V& input_5lambdaYVec,
1999  const P_V& input_6lambdaVVec,
2000  const P_V& input_7rhoVVec,
2001  const P_V& input_8thetaVec,
2002  unsigned int outerCounter)
2003 {
2004  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2005  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(1)"
2006  << ", outerCounter = " << outerCounter
2007  << ": m_formCMatrix = " << m_formCMatrix
2008  << ", m_optionsObj->m_useTildeLogicForRankDefficientC = " << m_optionsObj->m_useTildeLogicForRankDefficientC
2009  << ", m_Cmat = " << m_z->m_Cmat
2010  << ", m_cMatIsRankDefficient = " << m_cMatIsRankDefficient
2011  << std::endl;
2012  }
2013 
2014  queso_require_msg(!m_optionsObj->m_useTildeLogicForRankDefficientC,
2015  "'m_useTildeLogicForRankDefficientC' should be 'false'");
2016 
2017  //********************************************************************************
2018  // Form '\Sigma_z' matrix
2019  //********************************************************************************
2020  // Fill m_Rmat_v_is, m_Smat_v_is, m_Smat_v
2021  // Fill m_Rmat_u_is, m_Smat_u_is, m_Smat_u
2022  // Fill m_Rmat_w_is, m_Smat_w_is, m_Smat_w
2023  // Fill m_Rmat_uw_is, m_Smat_uw_is, m_Smat_uw
2024  this->formSigma_z(input_2lambdaWVec,
2025  input_3rhoWVec,
2026  input_4lambdaSVec,
2027  input_6lambdaVVec,
2028  input_7rhoVVec,
2029  input_8thetaVec,
2030  outerCounter);
2031 
2032  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
2033  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(1)"
2034  << ", outerCounter = " << outerCounter
2035  << ": finished forming 'm_tmp_Smat_z'"
2036  << "\n m_tmp_Smat_z contents = " << m_z->m_tmp_Smat_z
2037  << std::endl;
2038  }
2039 
2040  if (m_env.displayVerbosity() >= 4) {
2041  double sigmaZLnDeterminant = m_z->m_tmp_Smat_z.lnDeterminant();
2042  unsigned int sigmaZRank = m_z->m_tmp_Smat_z.rank(0.,1.e-8 ); // todo: should be an option
2043  unsigned int sigmaZRank14 = m_z->m_tmp_Smat_z.rank(0.,1.e-14);
2044  if (m_env.subDisplayFile()) {
2045  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(1)"
2046  << ", outerCounter = " << outerCounter
2047  << ", m_tmp_Smat_z.numRowsLocal() = " << m_z->m_tmp_Smat_z.numRowsLocal()
2048  << ", m_tmp_Smat_z.numCols() = " << m_z->m_tmp_Smat_z.numCols()
2049  << ", m_tmp_Smat_z.lnDeterminant() = " << sigmaZLnDeterminant
2050  << ", m_tmp_Smat_z.rank(0.,1.e-8) = " << sigmaZRank
2051  << ", m_tmp_Smat_z.rank(0.,1.e-14) = " << sigmaZRank14
2052  << std::endl;
2053  }
2054  }
2055 
2056  std::set<unsigned int> tmpSet;
2057  tmpSet.insert(m_env.subId());
2058  if (outerCounter == 1) {
2059  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2060  m_z->m_tmp_Smat_z.subWriteContents("Sigma_z",
2061  "mat_Sigma_z",
2062  "m",
2063  tmpSet);
2064  }
2065  }
2066 
2067  //********************************************************************************
2068  // Form '\Sigma_{extra}' matrix
2069  //********************************************************************************
2070  if (m_allOutputsAreScalar) {
2071  // ppp
2072  }
2073  else {
2074  m_z->m_tmp_Smat_extra.cwSet(0.);
2075  m_z->m_tmp_Smat_extra.cwSet( 0, 0,(1./input_5lambdaYVec [0]) * *m_j->m_Bop_t__Wy__Bop__inv);
2076  m_z->m_tmp_Smat_extra.cwSet(m_j->m_Bop_t__Wy__Bop__inv->numRowsLocal(),m_j->m_Bop_t__Wy__Bop__inv->numCols(),(1./input_1lambdaEtaVec[0]) * *m_s->m_Kt_K_inv );
2077  }
2078 
2079  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
2080  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(1)"
2081  << ", outerCounter = " << outerCounter
2082  << ": finished forming 'm_tmp_Smat_extra'"
2083  << ", input_5lambdaYVec[0] = " << input_5lambdaYVec[0]
2084  << ", input_1lambdaEtaVec[0] = " << input_1lambdaEtaVec[0]
2085  << "\n m_Bop_t__Wy__Bop__inv = " << *m_j->m_Bop_t__Wy__Bop__inv
2086  << "\n m_Kt_K_inv = " << *m_s->m_Kt_K_inv
2087  << "\n m_tmp_Smat_extra contents = " << m_z->m_tmp_Smat_extra
2088  << std::endl;
2089  }
2090 
2091  if (m_env.displayVerbosity() >= 4) {
2092  double extraLnDeterminant = m_z->m_tmp_Smat_extra.lnDeterminant();
2093  unsigned int extraRank = m_z->m_tmp_Smat_extra.rank(0.,1.e-8 ); // todo: should be an option
2094  unsigned int extraRank14 = m_z->m_tmp_Smat_extra.rank(0.,1.e-14);
2095  if (m_env.subDisplayFile()) {
2096  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(1)"
2097  << ", outerCounter = " << outerCounter
2098  << ", m_tmp_Smat_extra.numRowsLocal() = " << m_z->m_tmp_Smat_extra.numRowsLocal()
2099  << ", m_tmp_Smat_extra.numCols() = " << m_z->m_tmp_Smat_extra.numCols()
2100  << ", m_tmp_Smat_extra.lnDeterminant() = " << extraLnDeterminant
2101  << ", m_tmp_Smat_extra.rank(0.,1.e-8) = " << extraRank
2102  << ", m_tmp_Smat_extra.rank(0.,1.e-14) = " << extraRank14
2103  << std::endl;
2104  }
2105  }
2106 
2107  if (outerCounter == 1) {
2108  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2109  m_z->m_tmp_Smat_extra.subWriteContents("Sigma_extra",
2110  "mat_Sigma_extra",
2111  "m",
2112  tmpSet);
2113  }
2114  }
2115 
2116  //********************************************************************************
2117  // Compute '\Sigma_z_hat' matrix
2118  //********************************************************************************
2119  m_z->m_tmp_Smat_z_hat = m_z->m_tmp_Smat_z + m_z->m_tmp_Smat_extra;
2120 
2121  if (m_env.displayVerbosity() >= 4) {
2122  double zHatLnDeterminant = m_z->m_tmp_Smat_z_hat.lnDeterminant();
2123  unsigned int zHatRank = m_z->m_tmp_Smat_z_hat.rank(0.,1.e-8 ); // todo: should be an option
2124  unsigned int zHatRank14 = m_z->m_tmp_Smat_z_hat.rank(0.,1.e-14);
2125  if (m_env.subDisplayFile()) {
2126  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(1)"
2127  << ", outerCounter = " << outerCounter
2128  << ", m_tmp_Smat_z_hat.numRowsLocal() = " << m_z->m_tmp_Smat_z_hat.numRowsLocal()
2129  << ", m_tmp_Smat_z_hat.numCols() = " << m_z->m_tmp_Smat_z_hat.numCols()
2130  << ", m_tmp_Smat_z_hat.lnDeterminant() = " << zHatLnDeterminant
2131  << ", m_tmp_Smat_z_hat.rank(0.,1.e-8) = " << zHatRank
2132  << ", m_tmp_Smat_z_hat.rank(0.,1.e-14) = " << zHatRank14
2133  << std::endl;
2134  }
2135  }
2136 
2137  if (outerCounter == 1) {
2138  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2139  m_z->m_tmp_Smat_z_hat.subWriteContents("Sigma_z_hat",
2140  "mat_Sigma_z_hat",
2141  "m",
2142  tmpSet);
2143  }
2144  }
2145 
2146  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2147  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(1)"
2148  << ", outerCounter = " << outerCounter
2149  << std::endl;
2150  }
2151 
2152  return;
2153 }
2154 
2155 // Case with no experimental data // checar
2156 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
2157 void
2159  const P_V& input_1lambdaEtaVec,
2160  const P_V& input_2lambdaWVec,
2161  const P_V& input_3rhoWVec,
2162  const P_V& input_4lambdaSVec,
2163  unsigned int outerCounter)
2164 {
2165  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2166  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(2)"
2167  << ", outerCounter = " << outerCounter
2168  << ": m_formCMatrix = " << m_formCMatrix
2169  << ", m_optionsObj->m_useTildeLogicForRankDefficientC = " << m_optionsObj->m_useTildeLogicForRankDefficientC
2170  << ", m_Cmat = " << m_z->m_Cmat
2171  << ", m_cMatIsRankDefficient = " << m_cMatIsRankDefficient
2172  << std::endl;
2173  }
2174 
2175  queso_require_msg(!m_optionsObj->m_useTildeLogicForRankDefficientC,
2176  "'m_useTildeLogicForRankDefficientC' should be 'false'");
2177 
2178  //********************************************************************************
2179  // Form '\Sigma_z' matrix
2180  //********************************************************************************
2181  // Fill m_Rmat_v_is, m_Smat_v_is, m_Smat_v
2182  // Fill m_Rmat_u_is, m_Smat_u_is, m_Smat_u
2183  // Fill m_Rmat_w_is, m_Smat_w_is, m_Smat_w
2184  // Fill m_Rmat_uw_is, m_Smat_uw_is, m_Smat_uw
2185  this->formSigma_z(input_2lambdaWVec,
2186  input_3rhoWVec,
2187  input_4lambdaSVec,
2188  outerCounter);
2189 
2190  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
2191  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(2)"
2192  << ", outerCounter = " << outerCounter
2193  << ": finished forming 'm_tmp_Smat_z'"
2194  << "\n m_tmp_Smat_z contents = " << m_z->m_tmp_Smat_z
2195  << std::endl;
2196  }
2197 
2198  if (m_env.displayVerbosity() >= 4) {
2199  double sigmaZLnDeterminant = m_z->m_tmp_Smat_z.lnDeterminant();
2200  unsigned int sigmaZRank = m_z->m_tmp_Smat_z.rank(0.,1.e-8 ); // todo: should be an option
2201  unsigned int sigmaZRank14 = m_z->m_tmp_Smat_z.rank(0.,1.e-14);
2202  if (m_env.subDisplayFile()) {
2203  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(2)"
2204  << ", outerCounter = " << outerCounter
2205  << ", m_tmp_Smat_z.numRowsLocal() = " << m_z->m_tmp_Smat_z.numRowsLocal()
2206  << ", m_tmp_Smat_z.numCols() = " << m_z->m_tmp_Smat_z.numCols()
2207  << ", m_tmp_Smat_z.lnDeterminant() = " << sigmaZLnDeterminant
2208  << ", m_tmp_Smat_z.rank(0.,1.e-8) = " << sigmaZRank
2209  << ", m_tmp_Smat_z.rank(0.,1.e-14) = " << sigmaZRank14
2210  << std::endl;
2211  }
2212  }
2213 
2214 #if 0 // Case with no experimental data // checar
2215  //********************************************************************************
2216  // Form '\Sigma_{extra}' matrix
2217  //********************************************************************************
2218  if (m_allOutputsAreScalar) {
2219  // ppp
2220  }
2221  else {
2222  m_z->m_tmp_Smat_extra.cwSet(0.);
2223  m_z->m_tmp_Smat_extra.cwSet( 0, 0,(1./input_5lambdaYVec [0]) * *m_j->m_Bop_t__Wy__Bop__inv);
2224  m_z->m_tmp_Smat_extra.cwSet(m_j->m_Bop_t__Wy__Bop__inv->numRowsLocal(),m_j->m_Bop_t__Wy__Bop__inv->numCols(),(1./input_1lambdaEtaVec[0]) * *m_s->m_Kt_K_inv );
2225  }
2226 
2227  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
2228  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(2)"
2229  << ", outerCounter = " << outerCounter
2230  << ": finished forming 'm_tmp_Smat_extra'"
2231  << ", input_5lambdaYVec[0] = " << input_5lambdaYVec[0]
2232  << ", input_1lambdaEtaVec[0] = " << input_1lambdaEtaVec[0]
2233  << "\n m_Bop_t__Wy__Bop__inv = " << *m_j->m_Bop_t__Wy__Bop__inv
2234  << "\n m_Kt_K_inv = " << *m_s->m_Kt_K_inv
2235  << "\n m_tmp_Smat_extra contents = " << m_z->m_tmp_Smat_extra
2236  << std::endl;
2237  }
2238 
2239  if (m_env.displayVerbosity() >= 4) {
2240  double extraLnDeterminant = m_z->m_tmp_Smat_extra.lnDeterminant();
2241  unsigned int extraRank = m_z->m_tmp_Smat_extra.rank(0.,1.e-8 ); // todo: should be an option
2242  unsigned int extraRank14 = m_z->m_tmp_Smat_extra.rank(0.,1.e-14);
2243  if (m_env.subDisplayFile()) {
2244  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(2)"
2245  << ", outerCounter = " << outerCounter
2246  << ", m_tmp_Smat_extra.numRowsLocal() = " << m_z->m_tmp_Smat_extra.numRowsLocal()
2247  << ", m_tmp_Smat_extra.numCols() = " << m_z->m_tmp_Smat_extra.numCols()
2248  << ", m_tmp_Smat_extra.lnDeterminant() = " << extraLnDeterminant
2249  << ", m_tmp_Smat_extra.rank(0.,1.e-8) = " << extraRank
2250  << ", m_tmp_Smat_extra.rank(0.,1.e-14) = " << extraRank14
2251  << std::endl;
2252  }
2253  }
2254 
2255  //********************************************************************************
2256  // Compute '\Sigma_z_hat' matrix
2257  //********************************************************************************
2258  m_z->m_tmp_Smat_z_hat = m_z->m_tmp_Smat_z + m_z->m_tmp_Smat_extra;
2259 
2260  if (m_env.displayVerbosity() >= 4) {
2261  double zHatLnDeterminant = m_z->m_tmp_Smat_z_hat.lnDeterminant();
2262  unsigned int zHatRank = m_z->m_tmp_Smat_z_hat.rank(0.,1.e-8 ); // todo: should be an option
2263  unsigned int zHatRank14 = m_z->m_tmp_Smat_z_hat.rank(0.,1.e-14);
2264  if (m_env.subDisplayFile()) {
2265  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(2)"
2266  << ", outerCounter = " << outerCounter
2267  << ", m_tmp_Smat_z_hat.numRowsLocal() = " << m_z->m_tmp_Smat_z_hat.numRowsLocal()
2268  << ", m_tmp_Smat_z_hat.numCols() = " << m_z->m_tmp_Smat_z_hat.numCols()
2269  << ", m_tmp_Smat_z_hat.lnDeterminant() = " << zHatLnDeterminant
2270  << ", m_tmp_Smat_z_hat.rank(0.,1.e-8) = " << zHatRank
2271  << ", m_tmp_Smat_z_hat.rank(0.,1.e-14) = " << zHatRank14
2272  << std::endl;
2273  }
2274  }
2275 #endif
2276  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2277  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_hat(2)"
2278  << ", outerCounter = " << outerCounter
2279  << std::endl;
2280  }
2281 
2282  return;
2283 }
2284 
2285 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
2286 void
2288  const P_V& input_1lambdaEtaVec,
2289  const P_V& input_2lambdaWVec,
2290  const P_V& input_3rhoWVec,
2291  const P_V& input_4lambdaSVec,
2292  const P_V& input_5lambdaYVec,
2293  const P_V& input_6lambdaVVec,
2294  const P_V& input_7rhoVVec,
2295  const P_V& input_8thetaVec,
2296  unsigned int outerCounter)
2297 {
2298  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2299  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_tilde_hat()"
2300  << ", outerCounter = " << outerCounter
2301  << ": m_formCMatrix = " << m_formCMatrix
2302  << ", m_optionsObj->m_useTildeLogicForRankDefficientC = " << m_optionsObj->m_useTildeLogicForRankDefficientC
2303  << ", m_Cmat = " << m_z->m_Cmat
2304  << ", m_cMatIsRankDefficient = " << m_cMatIsRankDefficient
2305  << std::endl;
2306  }
2307 
2308  queso_require_msg(m_formCMatrix, "'m_Cmat' should have been requested");
2309 
2310  queso_require_msg(m_z->m_Cmat, "'m_Cmat' should have been formed");
2311 
2312  queso_require_msg(m_cMatIsRankDefficient, "'m_Cmat' should be rank defficient");
2313 
2314  queso_require_msg(m_optionsObj->m_useTildeLogicForRankDefficientC, "'m_useTildeLogicForRankDefficientC' should be 'true'");
2315 
2316  //********************************************************************************
2317  // Form '\Sigma_z' matrix
2318  //********************************************************************************
2319  // Fill m_Rmat_v_is, m_Smat_v_is, m_Smat_v
2320  // Fill m_Rmat_u_is, m_Smat_u_is, m_Smat_u
2321  // Fill m_Rmat_w_is, m_Smat_w_is, m_Smat_w
2322  // Fill m_Rmat_uw_is, m_Smat_uw_is, m_Smat_uw
2323  this->formSigma_z(input_2lambdaWVec,
2324  input_3rhoWVec,
2325  input_4lambdaSVec,
2326  input_6lambdaVVec,
2327  input_7rhoVVec,
2328  input_8thetaVec,
2329  outerCounter);
2330 
2331  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
2332  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_tilde_hat()"
2333  << ", outerCounter = " << outerCounter
2334  << ": finished forming 'm_tmp_Smat_z'"
2335  << "\n m_tmp_Smat_z contents = " << m_z->m_tmp_Smat_z
2336  << std::endl;
2337  }
2338 
2339  if (m_env.displayVerbosity() >= 4) {
2340  double sigmaZLnDeterminant = m_z->m_tmp_Smat_z.lnDeterminant();
2341  unsigned int sigmaZRank = m_z->m_tmp_Smat_z.rank(0.,1.e-8 ); // todo: should be an option
2342  unsigned int sigmaZRank14 = m_z->m_tmp_Smat_z.rank(0.,1.e-14);
2343  if (m_env.subDisplayFile()) {
2344  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_tilde_hat()"
2345  << ", outerCounter = " << outerCounter
2346  << ", m_tmp_Smat_z.numRowsLocal() = " << m_z->m_tmp_Smat_z.numRowsLocal()
2347  << ", m_tmp_Smat_z.numCols() = " << m_z->m_tmp_Smat_z.numCols()
2348  << ", m_tmp_Smat_z.lnDeterminant() = " << sigmaZLnDeterminant
2349  << ", m_tmp_Smat_z.rank(0.,1.e-8) = " << sigmaZRank
2350  << ", m_tmp_Smat_z.rank(0.,1.e-14) = " << sigmaZRank14
2351  << std::endl;
2352  }
2353  }
2354 
2355  //********************************************************************************
2356  // Form 'L . \Sigma_z . L^T' matrix
2357  //********************************************************************************
2358  m_zt->m_tmp_Smat_z_tilde = m_zt->m_Lmat * (m_z->m_tmp_Smat_z * m_zt->m_Lmat_t);
2359 
2360  if (m_env.displayVerbosity() >= 4) {
2361  double sigmaZTildeLnDeterminant = m_zt->m_tmp_Smat_z_tilde.lnDeterminant();
2362  unsigned int sigmaZTildeRank = m_zt->m_tmp_Smat_z_tilde.rank(0.,1.e-8 ); // todo: should be an option
2363  unsigned int sigmaZTildeRank14 = m_zt->m_tmp_Smat_z_tilde.rank(0.,1.e-14);
2364  if (m_env.subDisplayFile()) {
2365  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_tilde_hat()"
2366  << ", outerCounter = " << outerCounter
2367  << ", m_tmp_Smat_z_tilde->numRowsLocal() = " << m_zt->m_tmp_Smat_z_tilde.numRowsLocal()
2368  << ", m_tmp_Smat_z_tilde->numCols() = " << m_zt->m_tmp_Smat_z_tilde.numCols()
2369  << ", m_tmp_Smat_z_tilde->lnDeterminant() = " << sigmaZTildeLnDeterminant
2370  << ", m_tmp_Smat_z_tilde->rank(0.,1.e-8) = " << sigmaZTildeRank
2371  << ", m_tmp_Smat_z_tilde->rank(0.,1.e-14) = " << sigmaZTildeRank14
2372  << std::endl;
2373  }
2374  }
2375 
2376  //********************************************************************************
2377  // Form '\Sigma_{extra}_tilde' matrix
2378  //********************************************************************************
2379  m_zt->m_tmp_Smat_extra_tilde.cwSet(0.);
2380  m_zt->m_tmp_Smat_extra_tilde.cwSet( 0, 0,(1./input_5lambdaYVec [0]) * (m_jt->m_Btildet_Wy_Btilde_inv));
2381  m_zt->m_tmp_Smat_extra_tilde.cwSet(m_jt->m_Btildet_Wy_Btilde_inv.numRowsLocal(),m_jt->m_Btildet_Wy_Btilde_inv.numCols(),(1./input_1lambdaEtaVec[0]) * (m_st->m_Ktildet_Ktilde_inv) );
2382 
2383  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
2384  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_tilde_hat()"
2385  << ", outerCounter = " << outerCounter
2386  << ": finished forming 'm_tmp_Smat_extra_tilde'"
2387  << ", input_5lambdaYVec[0] = " << input_5lambdaYVec[0]
2388  << ", input_1lambdaEtaVec[0] = " << input_1lambdaEtaVec[0]
2389  << "\n m_Btildet_Wy_Btilde_inv = " << m_jt->m_Btildet_Wy_Btilde_inv
2390  << "\n m_Ktildet_Ktilde_inv = " << m_st->m_Ktildet_Ktilde_inv
2391  << "\n m_tmp_Smat_extra_tilde contents = " << m_zt->m_tmp_Smat_extra_tilde
2392  << std::endl;
2393  }
2394 
2395  if (m_env.displayVerbosity() >= 4) {
2396  double extraTildeLnDeterminant = m_zt->m_tmp_Smat_extra_tilde.lnDeterminant();
2397  unsigned int extraTildeRank = m_zt->m_tmp_Smat_extra_tilde.rank(0.,1.e-8 ); // todo: should be an option
2398  unsigned int extraTildeRank14 = m_zt->m_tmp_Smat_extra_tilde.rank(0.,1.e-14);
2399  if (m_env.subDisplayFile()) {
2400  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_tilde_hat()"
2401  << ", outerCounter = " << outerCounter
2402  << ", m_tmp_Smat_extra_tilde.numRowsLocal() = " << m_zt->m_tmp_Smat_extra_tilde.numRowsLocal()
2403  << ", m_tmp_Smat_extra_tilde.numCols() = " << m_zt->m_tmp_Smat_extra_tilde.numCols()
2404  << ", m_tmp_Smat_extra_tilde.lnDeterminant() = " << extraTildeLnDeterminant
2405  << ", m_tmp_Smat_extra_tilde.rank(0.,1.e-8) = " << extraTildeRank
2406  << ", m_tmp_Smat_extra_tilde.rank(0.,1.e-14) = " << extraTildeRank14
2407  << std::endl;
2408  }
2409  }
2410 
2411  //********************************************************************************
2412  // Compute '\Sigma_z_tilde_hat' matrix
2413  //********************************************************************************
2414  m_zt->m_tmp_Smat_z_tilde_hat = m_zt->m_tmp_Smat_z_tilde + m_zt->m_tmp_Smat_extra_tilde;
2415 
2416  if (m_env.displayVerbosity() >= 4) {
2417  double zTildeHatLnDeterminant = m_zt->m_tmp_Smat_z_tilde_hat.lnDeterminant();
2418  unsigned int zTildeHatRank = m_zt->m_tmp_Smat_z_tilde_hat.rank(0.,1.e-8 ); // todo: should be an option
2419  unsigned int zTildeHatRank14 = m_zt->m_tmp_Smat_z_tilde_hat.rank(0.,1.e-14);
2420  if (m_env.subDisplayFile()) {
2421  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_tilde_hat()"
2422  << ", outerCounter = " << outerCounter
2423  << ", m_tmp_Smat_z_tilde_hat->numRowsLocal() = " << m_zt->m_tmp_Smat_z_tilde_hat.numRowsLocal()
2424  << ", m_tmp_Smat_z_tilde_hat->numCols() = " << m_zt->m_tmp_Smat_z_tilde_hat.numCols()
2425  << ", m_tmp_Smat_z_tilde_hat->lnDeterminant() = " << zTildeHatLnDeterminant
2426  << ", m_tmp_Smat_z_tilde_hat->rank(0.,1.e-8) = " << zTildeHatRank
2427  << ", m_tmp_Smat_z_tilde_hat->rank(0.,1.e-14) = " << zTildeHatRank14
2428  << std::endl;
2429  }
2430  }
2431 
2432  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2433  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z_tilde_hat()"
2434  << ", outerCounter = " << outerCounter
2435  << std::endl;
2436  }
2437 
2438  return;
2439 }
2440 
2441 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
2442 void
2444  const P_V& input_2lambdaWVec,
2445  const P_V& input_3rhoWVec,
2446  const P_V& input_4lambdaSVec,
2447  const P_V& input_6lambdaVVec,
2448  const P_V& input_7rhoVVec,
2449  const P_V& input_8thetaVec,
2450  unsigned int outerCounter)
2451 {
2452  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2453  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(1)"
2454  << ", outerCounter = " << outerCounter
2455  << std::endl;
2456  }
2457 
2458  std::set<unsigned int> tmpSet;
2459  tmpSet.insert(m_env.subId());
2460 
2461  this->memoryCheck(90);
2462 
2463  // Fill m_Rmat_v_is, m_Smat_v_is, m_Smat_v
2464  // Fill m_Rmat_u_is, m_Smat_u_is, m_Smat_u
2465  // Fill m_Rmat_w_is, m_Smat_w_is, m_Smat_w
2466  // Fill m_Rmat_uw_is, m_Smat_uw_is, m_Smat_uw
2467  //********************************************************************************
2468  // Compute '\Sigma' matrices
2469  // \Sigma_v:
2470  // --> Uses page 576-b
2471  // --> Uses R(all x's;\rho_v_i[size p_x]) and formula (2) to "each pair" of experimental input settings
2472  // --> \Sigma_v_i = (1/\lambda_v_i).I_|G_i| [X] R(...) is (n.|G_i|) x (n.|G_i|), i = 1,...,F
2473  // --> \Sigma_v is (n.p_delta) x (n.p_delta)
2474  // \Sigma_u:
2475  // --> Uses page 576-b
2476  // --> Uses R(all x's,one \theta;\rho_w_i[size p_x+p_t]) and formula (1) to "each pair" of experimental input settings (correlations depend only on x dimensions)
2477  // --> \Sigma_u_i = (1/\lambda_w_i).R(...) is n x n, i = 1,...,p_eta
2478  // --> \Sigma_u is (n.p_eta) x (n.p_eta)
2479  // \Sigma_w:
2480  // --> Uses page 575-a
2481  // --> Uses R(all x^*'s,all t^*'s;\rho_w_i[size p_x+p_t]) and formula (1) to "each pair" of input settings in the design
2482  // --> \Sigma_w_i = (1/\lambda_w_i).R(...) is m x m, i = 1,...,p_eta
2483  // --> \Sigma_w is (m.p_eta) x (m.p_eta)
2484  // \Sigma_u,w:
2485  // --> Uses page 577-a
2486  // --> Uses R(all x's,one \theta,all x^*'s,all t^*'s;\rho_w_i[size p_x+p_t]) and formula (1)
2487  // --> \Sigma_u,w_i = (1/\lambda_w_i).R(...) is n x m, i = 1,...,p_eta
2488  // --> \Sigma_u,w is (n.p_eta) x (m.p_eta)
2489  //********************************************************************************
2490  unsigned int initialPos = 0;
2491  for (unsigned int i = 0; i < m_e->m_Smat_v_i_spaces.size(); ++i) {
2492  input_7rhoVVec.cwExtract(initialPos,m_e->m_tmp_rho_v_vec);
2493  initialPos += m_e->m_tmp_rho_v_vec.sizeLocal();
2494  m_e->m_Rmat_v_is[i]->cwSet(0.);
2495  this->fillR_formula2_for_Sigma_v(m_e->m_paper_xs_standard,
2496  m_e->m_tmp_rho_v_vec,
2497  *(m_e->m_Rmat_v_is[i]), // IMPORTANT-28
2498  outerCounter);
2499 
2500  m_e->m_Smat_v_is[i]->cwSet(0.);
2501  m_e->m_Smat_v_is[i]->fillWithTensorProduct(0,0,*(m_e->m_Imat_v_is[i]),*(m_e->m_Rmat_v_is[i]),true,true); // IMPORTANT-28
2502  *(m_e->m_Smat_v_is[i]) *= (1./input_6lambdaVVec[i]);
2503  }
2504  m_e->m_Smat_v.cwSet(0.);
2505  m_e->m_Smat_v.fillWithBlocksDiagonally(0,0,m_e->m_Smat_v_is,true,true);
2506  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2507  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(1)"
2508  << ", outerCounter = " << outerCounter
2509  << ": finished instantiating 'm_Smat_v'"
2510  << std::endl;
2511  }
2512 
2513  if (outerCounter == 1) {
2514  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2515  m_e->m_Smat_v.subWriteContents("Sigma_v",
2516  "mat_Sigma_v",
2517  "m",
2518  tmpSet);
2519  }
2520  }
2521 
2522  this->memoryCheck(91);
2523 
2524  initialPos = 0;
2525  for (unsigned int i = 0; i < m_j->m_Smat_u_is.size(); ++i) {
2526  input_3rhoWVec.cwExtract(initialPos,m_s->m_tmp_rho_w_vec);
2527  initialPos += m_s->m_tmp_rho_w_vec.sizeLocal();
2528  m_j->m_Rmat_u_is[i]->cwSet(0.);
2529  this->fillR_formula1_for_Sigma_u(m_e->m_paper_xs_standard,
2530  input_8thetaVec,
2531  m_s->m_tmp_rho_w_vec,
2532  *(m_j->m_Rmat_u_is[i]),
2533  outerCounter);
2534 
2535  m_j->m_Smat_u_is[i]->cwSet(0.);
2536  *(m_j->m_Smat_u_is[i]) = (1./input_2lambdaWVec[i]) * *(m_j->m_Rmat_u_is[i]);
2537  for (unsigned int j = 0; j < m_j->m_Smat_u_is[i]->numRowsLocal(); ++j) {
2538  (*(m_j->m_Smat_u_is[i]))(j,j) += 1/m_s->m_tmp_4lambdaSVec[i]; // lambda_s
2539  }
2540  }
2541  m_j->m_Smat_u.cwSet(0.);
2542  m_j->m_Smat_u.fillWithBlocksDiagonally(0,0,m_j->m_Smat_u_is,true,true);
2543  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2544  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(1)"
2545  << ", outerCounter = " << outerCounter
2546  << ": finished instantiating 'm_Smat_u'"
2547  << std::endl;
2548  }
2549 
2550  if (outerCounter == 1) {
2551  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2552  m_j->m_Smat_u.subWriteContents("Sigma_u",
2553  "mat_Sigma_u",
2554  "m",
2555  tmpSet);
2556  }
2557  }
2558 
2559  this->memoryCheck(92);
2560 
2561  initialPos = 0;
2562  for (unsigned int i = 0; i < m_s->m_Smat_w_is.size(); ++i) {
2563  input_3rhoWVec.cwExtract(initialPos,m_s->m_tmp_rho_w_vec);
2564  initialPos += m_s->m_tmp_rho_w_vec.sizeLocal();
2565  m_s->m_Rmat_w_is[i]->cwSet(0.); // This matrix is square: m_paper_m X m_paper_m
2566  this->fillR_formula1_for_Sigma_w(m_s->m_paper_xs_asterisks_standard, // IMPORTANT
2567  m_s->m_paper_ts_asterisks_standard,
2568  m_s->m_tmp_rho_w_vec,
2569  *(m_s->m_Rmat_w_is[i]),
2570  outerCounter);
2571 
2572  m_s->m_Smat_w_is[i]->cwSet(0.);
2573  *(m_s->m_Smat_w_is[i]) = (1./input_2lambdaWVec[i]) * *(m_s->m_Rmat_w_is[i]);
2574 
2575  if ((outerCounter == 1) &&
2576  (i == 0)) {
2577  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2578  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(1)"
2579  << ", outerCounter = " << outerCounter
2580  << ": during the calculation of 'm_Smat_w'"
2581  << "\n m_s->m_paper_xs_asterisks_standard.size() = " << m_s->m_paper_xs_asterisks_standard.size();
2582  for (unsigned int tmpId = 0; tmpId < m_s->m_paper_xs_asterisks_standard.size(); ++tmpId) {
2583  *m_env.subDisplayFile() << "\n m_s->m_paper_xs_asterisks_standard[" << tmpId << "] = "
2584  << *(m_s->m_paper_xs_asterisks_standard[tmpId])
2585  << std::endl;
2586  }
2587  *m_env.subDisplayFile() << "\n m_s->m_paper_ts_asterisks_standard.size() = " << m_s->m_paper_ts_asterisks_standard.size();
2588  for (unsigned int tmpId = 0; tmpId < m_s->m_paper_ts_asterisks_standard.size(); ++tmpId) {
2589  *m_env.subDisplayFile() << "\n m_s->m_paper_ts_asterisks_standard[" << tmpId << "] = "
2590  << *(m_s->m_paper_ts_asterisks_standard[tmpId])
2591  << std::endl;
2592  }
2593  *m_env.subDisplayFile() << "\n m_s->m_tmp_rho_w_vec = " << m_s->m_tmp_rho_w_vec
2594  << "\n (*(m_s->m_Rmat_w_is[i=0]))(0,0) = " << (*(m_s->m_Rmat_w_is[i]))(0,0)
2595  << "\n input_2lambdaWVec[i=0] = " << input_2lambdaWVec[i]
2596  << "\n (*(m_s->m_Smat_w_is[i=0]))(0,0) = " << (*(m_s->m_Smat_w_is[i]))(0,0)
2597  << "\n m_s->m_tmp_4lambdaSVec[i=0] = " << m_s->m_tmp_4lambdaSVec[i]
2598  << std::endl;
2599  }
2600  }
2601 
2602  for (unsigned int j = 0; j < m_s->m_Smat_w_is[i]->numRowsLocal(); ++j) {
2603  (*(m_s->m_Smat_w_is[i]))(j,j) += 1/m_s->m_tmp_4lambdaSVec[i]; // lambda_s
2604  }
2605 
2606  if ((outerCounter == 1) &&
2607  (i == 0)) {
2608  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2609  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(1)"
2610  << ", outerCounter = " << outerCounter
2611  << ": during the calculation of 'm_Smat_w'"
2612  << "\n (*(m_s->m_Smat_w_is[i=0]))(0,0) = " << (*(m_s->m_Smat_w_is[i]))(0,0)
2613  << std::endl;
2614  }
2615  }
2616  }
2617  m_s->m_Smat_w.cwSet(0.);
2618  m_s->m_Smat_w.fillWithBlocksDiagonally(0,0,m_s->m_Smat_w_is,true,true);
2619  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2620  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(1)"
2621  << ", outerCounter = " << outerCounter
2622  << ": finished instantiating 'm_Smat_w'"
2623  << std::endl;
2624  }
2625 
2626  if (outerCounter == 1) {
2627  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2628  m_s->m_Smat_w.subWriteContents("Sigma_w",
2629  "mat_Sigma_w",
2630  "m",
2631  tmpSet);
2632  }
2633  }
2634 
2635  this->memoryCheck(93);
2636 
2637  initialPos = 0;
2638  for (unsigned int i = 0; i < m_j->m_Smat_uw_is.size(); ++i) {
2639  input_3rhoWVec.cwExtract(initialPos,m_s->m_tmp_rho_w_vec);
2640  initialPos += m_s->m_tmp_rho_w_vec.sizeLocal();
2641  m_j->m_Rmat_uw_is[i]->cwSet(0.);
2642  this->fillR_formula1_for_Sigma_uw(m_e->m_paper_xs_standard,
2643  input_8thetaVec,
2644  m_s->m_paper_xs_asterisks_standard,
2645  m_s->m_paper_ts_asterisks_standard,
2646  m_s->m_tmp_rho_w_vec,*(m_j->m_Rmat_uw_is[i]),
2647  outerCounter);
2648 
2649  m_j->m_Smat_uw_is[i]->cwSet(0.);
2650  *(m_j->m_Smat_uw_is[i]) = (1./input_2lambdaWVec[i]) * *(m_j->m_Rmat_uw_is[i]);
2651  }
2652  m_j->m_Smat_uw.cwSet(0.);
2653  m_j->m_Smat_uw.fillWithBlocksDiagonally(0,0,m_j->m_Smat_uw_is,true,true);
2654  m_j->m_Smat_uw_t.fillWithTranspose(0,0,m_j->m_Smat_uw,true,true);
2655  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2656  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(1)"
2657  << ", outerCounter = " << outerCounter
2658  << ": finished instantiating 'm_j->m_Smat_uw'"
2659  << std::endl;
2660  }
2661 
2662  if (outerCounter == 1) {
2663  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2664  m_j->m_Smat_uw.subWriteContents("Sigma_uw",
2665  "mat_Sigma_uw",
2666  "m",
2667  tmpSet);
2668  }
2669  }
2670 
2671  this->memoryCheck(94);
2672 
2673  //********************************************************************************
2674  // Form '\Sigma_z' matrix
2675  //********************************************************************************
2676  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2677  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(1)"
2678  << ", outerCounter = " << outerCounter
2679  << ": m_tmp_Smat_z.numRowsLocal() = " << m_z->m_tmp_Smat_z.numRowsLocal()
2680  << ", m_tmp_Smat_z.numCols() = " << m_z->m_tmp_Smat_z.numCols()
2681  << ", m_Smat_v.numRowsLocal() = " << m_e->m_Smat_v.numRowsLocal()
2682  << ", m_Smat_v.numCols() = " << m_e->m_Smat_v.numCols()
2683  << ", m_Smat_u.numRowsLocal() = " << m_j->m_Smat_u.numRowsLocal()
2684  << ", m_Smat_u.numCols() = " << m_j->m_Smat_u.numCols()
2685  << ", m_Smat_w.numRowsLocal() = " << m_s->m_Smat_w.numRowsLocal()
2686  << ", m_Smat_w.numCols() = " << m_s->m_Smat_w.numCols()
2687  << ", m_Smat_uw.numRowsLocal() = " << m_j->m_Smat_uw.numRowsLocal()
2688  << ", m_Smat_uw.numCols() = " << m_j->m_Smat_uw.numCols()
2689  << ", m_Smat_v_i_spaces.size() = " << m_e->m_Smat_v_i_spaces.size()
2690  << ", m_Smat_u_is.size() = " << m_j->m_Smat_u_is.size()
2691  << ", m_Smat_w_is.size() = " << m_s->m_Smat_w_is.size()
2692  << std::endl;
2693  }
2694 
2695  this->memoryCheck(95);
2696 
2697  m_z->m_tmp_Smat_z.cwSet(0.);
2698  if (m_allOutputsAreScalar) {
2699  // ppp
2700  }
2701  else {
2702  m_z->m_tmp_Smat_z.cwSet(0,0,m_e->m_Smat_v);
2703  m_z->m_tmp_Smat_z.cwSet(m_e->m_Smat_v.numRowsLocal(), m_e->m_Smat_v.numCols(), m_j->m_Smat_u);
2704  m_z->m_tmp_Smat_z.cwSet(m_e->m_Smat_v.numRowsLocal(), m_e->m_Smat_v.numCols()+m_j->m_Smat_u.numCols(),m_j->m_Smat_uw);
2705  m_z->m_tmp_Smat_z.cwSet(m_e->m_Smat_v.numRowsLocal()+m_j->m_Smat_u.numRowsLocal(),m_e->m_Smat_v.numCols(), m_j->m_Smat_uw_t);
2706  m_z->m_tmp_Smat_z.cwSet(m_e->m_Smat_v.numRowsLocal()+m_j->m_Smat_u.numRowsLocal(),m_e->m_Smat_v.numCols()+m_j->m_Smat_u.numCols(),m_s->m_Smat_w);
2707  }
2708 
2709  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2710  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(1)"
2711  << ", outerCounter = " << outerCounter
2712  << std::endl;
2713  }
2714 
2715  return;
2716 }
2717 
2718 // Case with no experimental data // checar
2719 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
2720 void
2722  const P_V& input_2lambdaWVec,
2723  const P_V& input_3rhoWVec,
2724  const P_V& input_4lambdaSVec,
2725  unsigned int outerCounter)
2726 {
2727  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2728  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(2)"
2729  << ", outerCounter = " << outerCounter
2730  << std::endl;
2731  }
2732 
2733  std::set<unsigned int> tmpSet;
2734  tmpSet.insert(m_env.subId());
2735 
2736  this->memoryCheck(90);
2737 
2738  // Fill m_Rmat_v_is, m_Smat_v_is, m_Smat_v
2739  // Fill m_Rmat_u_is, m_Smat_u_is, m_Smat_u
2740  // Fill m_Rmat_w_is, m_Smat_w_is, m_Smat_w
2741  // Fill m_Rmat_uw_is, m_Smat_uw_is, m_Smat_uw
2742  //********************************************************************************
2743  // Compute '\Sigma' matrices
2744  // \Sigma_v:
2745  // --> Uses page 576-b
2746  // --> Uses R(all x's;\rho_v_i[size p_x]) and formula (2) to "each pair" of experimental input settings
2747  // --> \Sigma_v_i = (1/\lambda_v_i).I_|G_i| [X] R(...) is (n.|G_i|) x (n.|G_i|), i = 1,...,F
2748  // --> \Sigma_v is (n.p_delta) x (n.p_delta)
2749  // \Sigma_u:
2750  // --> Uses page 576-b
2751  // --> Uses R(all x's,one \theta;\rho_w_i[size p_x+p_t]) and formula (1) to "each pair" of experimental input settings (correlations depend only on x dimensions)
2752  // --> \Sigma_u_i = (1/\lambda_w_i).R(...) is n x n, i = 1,...,p_eta
2753  // --> \Sigma_u is (n.p_eta) x (n.p_eta)
2754  // \Sigma_w:
2755  // --> Uses page 575-a
2756  // --> Uses R(all x^*'s,all t^*'s;\rho_w_i[size p_x+p_t]) and formula (1) to "each pair" of input settings in the design
2757  // --> \Sigma_w_i = (1/\lambda_w_i).R(...) is m x m, i = 1,...,p_eta
2758  // --> \Sigma_w is (m.p_eta) x (m.p_eta)
2759  // \Sigma_u,w:
2760  // --> Uses page 577-a
2761  // --> Uses R(all x's,one \theta,all x^*'s,all t^*'s;\rho_w_i[size p_x+p_t]) and formula (1)
2762  // --> \Sigma_u,w_i = (1/\lambda_w_i).R(...) is n x m, i = 1,...,p_eta
2763  // --> \Sigma_u,w is (n.p_eta) x (m.p_eta)
2764  //********************************************************************************
2765 #if 0 // Case with no experimental data // checar
2766  unsigned int initialPos = 0;
2767  for (unsigned int i = 0; i < m_e->m_Smat_v_i_spaces.size(); ++i) {
2768  input_7rhoVVec.cwExtract(initialPos,m_e->m_tmp_rho_v_vec);
2769  initialPos += m_e->m_tmp_rho_v_vec.sizeLocal();
2770  m_e->m_Rmat_v_is[i]->cwSet(0.);
2771  this->fillR_formula2_for_Sigma_v(m_e->m_paper_xs_standard,
2772  m_e->m_tmp_rho_v_vec,
2773  *(m_e->m_Rmat_v_is[i]),
2774  outerCounter);
2775 
2776  m_e->m_Smat_v_is[i]->cwSet(0.);
2777  m_e->m_Smat_v_is[i]->fillWithTensorProduct(0,0,*(m_e->m_Imat_v_is[i]),*(m_e->m_Rmat_v_is[i]),true,true);
2778  *(m_e->m_Smat_v_is[i]) *= (1./input_6lambdaVVec[i]);
2779  }
2780  m_e->m_Smat_v.cwSet(0.);
2781  m_e->m_Smat_v.fillWithBlocksDiagonally(0,0,m_e->m_Smat_v_is,true,true);
2782  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2783  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(2)"
2784  << ", outerCounter = " << outerCounter
2785  << ": finished instantiating 'm_Smat_v'"
2786  << std::endl;
2787  }
2788 
2789  if (outerCounter == 1) {
2790  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2791  m_e->m_Smat_v.subWriteContents("Sigma_v",
2792  "mat_Sigma_v",
2793  "m",
2794  tmpSet);
2795  }
2796  }
2797  this->memoryCheck(91);
2798 
2799  initialPos = 0;
2800  for (unsigned int i = 0; i < m_j->m_Smat_u_is.size(); ++i) {
2801  input_3rhoWVec.cwExtract(initialPos,m_s->m_tmp_rho_w_vec);
2802  initialPos += m_s->m_tmp_rho_w_vec.sizeLocal();
2803  m_j->m_Rmat_u_is[i]->cwSet(0.);
2804  this->fillR_formula1_for_Sigma_u(m_e->m_paper_xs_standard,
2805  input_8thetaVec,
2806  m_s->m_tmp_rho_w_vec,
2807  *(m_j->m_Rmat_u_is[i]),
2808  outerCounter);
2809 
2810  m_j->m_Smat_u_is[i]->cwSet(0.);
2811  *(m_j->m_Smat_u_is[i]) = (1./input_2lambdaWVec[i]) * *(m_j->m_Rmat_u_is[i]);
2812  for (unsigned int j = 0; j < m_j->m_Smat_u_is[i]->numRowsLocal(); ++j) {
2813  (*(m_j->m_Smat_u_is[i]))(j,j) += 1/m_s->m_tmp_4lambdaSVec[i]; // lambda_s
2814  }
2815  }
2816  m_j->m_Smat_u.cwSet(0.);
2817  m_j->m_Smat_u.fillWithBlocksDiagonally(0,0,m_j->m_Smat_u_is,true,true);
2818  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2819  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(2)"
2820  << ", outerCounter = " << outerCounter
2821  << ": finished instantiating 'm_Smat_u'"
2822  << std::endl;
2823  }
2824 
2825  if (outerCounter == 1) {
2826  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2827  m_j->m_Smat_u.subWriteContents("Sigma_u",
2828  "mat_Sigma_u",
2829  "m",
2830  tmpSet);
2831  }
2832  }
2833 
2834  this->memoryCheck(92);
2835 
2836  initialPos = 0;
2837  for (unsigned int i = 0; i < m_s->m_Smat_w_is.size(); ++i) {
2838  input_3rhoWVec.cwExtract(initialPos,m_s->m_tmp_rho_w_vec);
2839  initialPos += m_s->m_tmp_rho_w_vec.sizeLocal();
2840  m_s->m_Rmat_w_is[i]->cwSet(0.); // This matrix is square: m_paper_m X m_paper_m
2841  this->fillR_formula1_for_Sigma_w(m_s->m_paper_xs_asterisks_standard,
2842  m_s->m_paper_ts_asterisks_standard,
2843  m_s->m_tmp_rho_w_vec,
2844  *(m_s->m_Rmat_w_is[i]),
2845  outerCounter);
2846 
2847  m_s->m_Smat_w_is[i]->cwSet(0.);
2848  *(m_s->m_Smat_w_is[i]) = (1./input_2lambdaWVec[i]) * *(m_s->m_Rmat_w_is[i]);
2849  for (unsigned int j = 0; j < m_s->m_Smat_w_is[i]->numRowsLocal(); ++j) {
2850  (*(m_s->m_Smat_w_is[i]))(j,j) += 1/m_s->m_tmp_4lambdaSVec[i]; // lambda_s
2851  }
2852  }
2853  m_s->m_Smat_w.cwSet(0.);
2854  m_s->m_Smat_w.fillWithBlocksDiagonally(0,0,m_s->m_Smat_w_is,true,true);
2855  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2856  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(2)"
2857  << ", outerCounter = " << outerCounter
2858  << ": finished instantiating 'm_Smat_w'"
2859  << std::endl;
2860  }
2861 
2862  if (outerCounter == 1) {
2863  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2864  m_s->m_Smat_w.subWriteContents("Sigma_w",
2865  "mat_Sigma_w",
2866  "m",
2867  tmpSet);
2868  }
2869  }
2870 
2871  this->memoryCheck(93);
2872 
2873  initialPos = 0;
2874  for (unsigned int i = 0; i < m_j->m_Smat_uw_is.size(); ++i) {
2875  input_3rhoWVec.cwExtract(initialPos,m_s->m_tmp_rho_w_vec);
2876  initialPos += m_s->m_tmp_rho_w_vec.sizeLocal();
2877  m_j->m_Rmat_uw_is[i]->cwSet(0.);
2878  this->fillR_formula1_for_Sigma_uw(m_e->m_paper_xs_standard,
2879  input_8thetaVec,
2880  m_s->m_paper_xs_asterisks_standard,
2881  m_s->m_paper_ts_asterisks_standard,
2882  m_s->m_tmp_rho_w_vec,*(m_j->m_Rmat_uw_is[i]),
2883  outerCounter);
2884 
2885  m_j->m_Smat_uw_is[i]->cwSet(0.);
2886  *(m_j->m_Smat_uw_is[i]) = (1./input_2lambdaWVec[i]) * *(m_j->m_Rmat_uw_is[i]);
2887  }
2888  m_j->m_Smat_uw.cwSet(0.);
2889  m_j->m_Smat_uw.fillWithBlocksDiagonally(0,0,m_j->m_Smat_uw_is,true,true);
2890  m_j->m_Smat_uw_t.fillWithTranspose(0,0,m_j->m_Smat_uw,true,true);
2891  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2892  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(2)"
2893  << ", outerCounter = " << outerCounter
2894  << ": finished instantiating 'm_j->m_Smat_uw'"
2895  << std::endl;
2896  }
2897 
2898  if (outerCounter == 1) {
2899  if (m_optionsObj->m_dataOutputAllowedSet.find(m_env.subId()) != m_optionsObj->m_dataOutputAllowedSet.end()) {
2900  m_j->m_Smat_uw.subWriteContents("Sigma_uw",
2901  "mat_Sigma_uw",
2902  "m",
2903  tmpSet);
2904  }
2905  }
2906 #endif
2907  this->memoryCheck(94);
2908 
2909  //********************************************************************************
2910  // Form '\Sigma_z' matrix
2911  //********************************************************************************
2912  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2913  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(2)"
2914  << ", outerCounter = " << outerCounter
2915  << ": m_tmp_Smat_z.numRowsLocal() = " << m_z->m_tmp_Smat_z.numRowsLocal()
2916  << ", m_tmp_Smat_z.numCols() = " << m_z->m_tmp_Smat_z.numCols()
2917  << ", m_Smat_v.numRowsLocal() = " << m_e->m_Smat_v.numRowsLocal()
2918  << ", m_Smat_v.numCols() = " << m_e->m_Smat_v.numCols()
2919  << ", m_Smat_u.numRowsLocal() = " << m_j->m_Smat_u.numRowsLocal()
2920  << ", m_Smat_u.numCols() = " << m_j->m_Smat_u.numCols()
2921  << ", m_Smat_w.numRowsLocal() = " << m_s->m_Smat_w.numRowsLocal()
2922  << ", m_Smat_w.numCols() = " << m_s->m_Smat_w.numCols()
2923  << ", m_Smat_uw.numRowsLocal() = " << m_j->m_Smat_uw.numRowsLocal()
2924  << ", m_Smat_uw.numCols() = " << m_j->m_Smat_uw.numCols()
2925  << ", m_Smat_v_i_spaces.size() = " << m_e->m_Smat_v_i_spaces.size()
2926  << ", m_Smat_u_is.size() = " << m_j->m_Smat_u_is.size()
2927  << ", m_Smat_w_is.size() = " << m_s->m_Smat_w_is.size()
2928  << std::endl;
2929  }
2930 
2931  this->memoryCheck(95);
2932 
2933  m_z->m_tmp_Smat_z.cwSet(0.);
2934  if (m_allOutputsAreScalar) {
2935  // ppp
2936  }
2937  else {
2938  m_z->m_tmp_Smat_z.cwSet(0,0,m_e->m_Smat_v);
2939  m_z->m_tmp_Smat_z.cwSet(m_e->m_Smat_v.numRowsLocal(), m_e->m_Smat_v.numCols(), m_j->m_Smat_u);
2940  m_z->m_tmp_Smat_z.cwSet(m_e->m_Smat_v.numRowsLocal(), m_e->m_Smat_v.numCols()+m_j->m_Smat_u.numCols(),m_j->m_Smat_uw);
2941  m_z->m_tmp_Smat_z.cwSet(m_e->m_Smat_v.numRowsLocal()+m_j->m_Smat_u.numRowsLocal(),m_e->m_Smat_v.numCols(), m_j->m_Smat_uw_t);
2942  m_z->m_tmp_Smat_z.cwSet(m_e->m_Smat_v.numRowsLocal()+m_j->m_Smat_u.numRowsLocal(),m_e->m_Smat_v.numCols()+m_j->m_Smat_u.numCols(),m_s->m_Smat_w);
2943  }
2944 
2945  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2946  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_z(2)"
2947  << ", outerCounter = " << outerCounter
2948  << std::endl;
2949  }
2950 
2951  return;
2952 }
2953 
2954 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
2955 void
2957  const P_V& input_1lambdaEtaVec,
2958  const P_V& input_2lambdaWVec,
2959  const P_V& input_3rhoWVec,
2960  const P_V& input_4lambdaSVec,
2961  const P_V& input_8thetaVec,
2962  unsigned int outerCounter)
2963 {
2964  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2965  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_w_hat()"
2966  << ", outerCounter = " << outerCounter
2967  << std::endl;
2968  }
2969 
2970  unsigned int initialPos = 0;
2971  for (unsigned int i = 0; i < m_s->m_Smat_w_is.size(); ++i) {
2972  input_3rhoWVec.cwExtract(initialPos,m_s->m_tmp_rho_w_vec);
2973  initialPos += m_s->m_tmp_rho_w_vec.sizeLocal();
2974  m_s->m_Rmat_w_is[i]->cwSet(0.); // This matrix is square: m_paper_m X m_paper_m
2975  this->fillR_formula1_for_Sigma_w(m_s->m_paper_xs_asterisks_standard,
2976  m_s->m_paper_ts_asterisks_standard,
2977  m_s->m_tmp_rho_w_vec,
2978  *(m_s->m_Rmat_w_is[i]),
2979  outerCounter);
2980 
2981  m_s->m_Smat_w_is[i]->cwSet(0.);
2982  *(m_s->m_Smat_w_is[i]) = (1./input_2lambdaWVec[i]) * *(m_s->m_Rmat_w_is[i]);
2983  for (unsigned int j = 0; j < m_s->m_Smat_w_is[i]->numRowsLocal(); ++j) {
2984  (*(m_s->m_Smat_w_is[i]))(j,j) += 1/m_s->m_tmp_4lambdaSVec[i]; // lambda_s
2985  }
2986  }
2987  m_s->m_Smat_w.cwSet(0.);
2988  m_s->m_Smat_w.fillWithBlocksDiagonally(0,0,m_s->m_Smat_w_is,true,true);
2989  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
2990  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_w_hat()"
2991  << ", outerCounter = " << outerCounter
2992  << ": finished instantiating 'm_Smat_w'"
2993  << std::endl;
2994  }
2995 
2996  if (m_allOutputsAreScalar) {
2997  // ppp
2998  }
2999  else {
3000  m_s->m_Smat_w_hat = m_s->m_Smat_w + (1./input_1lambdaEtaVec[0]) * (*m_s->m_Kt_K_inv);
3001  }
3002 
3003  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3004  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::formSigma_w_hat()"
3005  << ", outerCounter = " << outerCounter
3006  << std::endl;
3007  }
3008 
3009  return;
3010 }
3011 
3012 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
3013 void
3015  const std::vector<const S_V* >& xVecs,
3016  const P_V& rho_v_vec,
3017  D_M& Rmat,
3018  unsigned int outerCounter)
3019 {
3020  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3021  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula2_for_Sigma_v()"
3022  << ", outerCounter = " << outerCounter
3023  << std::endl;
3024  }
3025 
3026  queso_require_equal_to_msg(xVecs.size(), m_e->m_paper_n, "xVecs.size() is wrong");
3027  for (unsigned int i = 0; i < xVecs.size(); ++i) {
3028  queso_require_equal_to_msg(xVecs[i]->sizeLocal(), m_s->m_paper_p_x, "xVecs[i]->sizeLocal() is wrong");
3029  }
3030  queso_require_msg(!((rho_v_vec.sizeLocal() == 0) || (rho_v_vec.sizeLocal() > m_s->m_paper_p_x)), "rho_v_vec.sizeLocal() is wrong");
3031  queso_require_equal_to_msg(Rmat.numRowsLocal(), m_e->m_paper_n, "Rmat.numRowsLocal() is wrong");
3032  queso_require_equal_to_msg(Rmat.numCols(), m_e->m_paper_n, "Rmat.numCols() is wrong");
3033 
3034  S_V vecI(*(xVecs[0]));
3035  S_V vecJ(*(xVecs[0]));
3036  for (unsigned int i = 0; i < m_e->m_paper_n; ++i) {
3037  vecI = *(xVecs[i]);
3038  for (unsigned int j = 0; j < m_e->m_paper_n; ++j) {
3039  vecJ = *(xVecs[j]);
3040  Rmat(i,j) = 1.;
3041  for (unsigned int k = 0; k < m_s->m_paper_p_x; ++k) {
3042  double diffTerm = vecI[k] - vecJ[k];
3043  Rmat(i,j) *= std::pow(rho_v_vec[k],4.*diffTerm*diffTerm);
3044  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
3045  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula2_for_Sigma_v()"
3046  << ", outerCounter = " << outerCounter
3047  << ": i = " << i
3048  << ", j = " << j
3049  << ", k = " << k
3050  << ", vecI[k] = " << vecI[k]
3051  << ", vecJ[k] = " << vecJ[k]
3052  << ", diffTerm = " << diffTerm
3053  << ", rho_v_vec[k] = " << rho_v_vec[k]
3054  << std::endl;
3055  }
3056  }
3057  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99)) {
3058  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula2_for_Sigma_v()"
3059  << ", outerCounter = " << outerCounter
3060  << ": i = " << i
3061  << ", j = " << j
3062  << ", Rmat(i,j) = " << Rmat(i,j)
3063  << std::endl;
3064  }
3065  }
3066  }
3067 
3068  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3069  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula2_for_Sigma_v()"
3070  << ", outerCounter = " << outerCounter
3071  << std::endl;
3072  }
3073 
3074  return;
3075 }
3076 
3077 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
3078 void
3080  const std::vector<const S_V* >& xVecs,
3081  const P_V& tVec,
3082  const P_V& rho_w_vec,
3083  D_M& Rmat,
3084  unsigned int outerCounter)
3085 {
3086  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3087  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_u()"
3088  << ", outerCounter = " << outerCounter
3089  << std::endl;
3090  }
3091 
3092  queso_require_equal_to_msg(xVecs.size(), m_e->m_paper_n, "xVecs.size() is wrong");
3093  for (unsigned int i = 0; i < xVecs.size(); ++i) {
3094  queso_require_equal_to_msg(xVecs[i]->sizeLocal(), m_s->m_paper_p_x, "xVecs[i]->sizeLocal() is wrong");
3095  }
3096  queso_require_equal_to_msg(tVec.sizeLocal(), m_s->m_paper_p_t, "tVec.sizeLocal() is wrong");
3097  queso_require_equal_to_msg(rho_w_vec.sizeLocal(), (m_s->m_paper_p_x+m_s->m_paper_p_t), "rho_w_vec.sizeLocal() is wrong");
3098  queso_require_equal_to_msg(Rmat.numRowsLocal(), m_e->m_paper_n, "Rmat.numRowsLocal() is wrong");
3099  queso_require_equal_to_msg(Rmat.numCols(), m_e->m_paper_n, "Rmat.numCols() is wrong");
3100 
3101  S_V vecI(*(xVecs[0]));
3102  S_V vecJ(*(xVecs[0]));
3103  for (unsigned int i = 0; i < m_e->m_paper_n; ++i) {
3104  vecI = *(xVecs[i]);
3105  for (unsigned int j = 0; j < m_e->m_paper_n; ++j) {
3106  vecJ = *(xVecs[j]);
3107  Rmat(i,j) = 1.;
3108  for (unsigned int k = 0; k < m_s->m_paper_p_x; ++k) { // Yes, just 'p_x', instead of 'p_x + p_t', since 't' is the same for all pairs
3109  double diffTerm = vecI[k] - vecJ[k];
3110  Rmat(i,j) *= std::pow(rho_w_vec[k],4.*diffTerm*diffTerm);
3111  }
3112  }
3113  }
3114 
3115  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3116  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_u()"
3117  << ", outerCounter = " << outerCounter
3118  << std::endl;
3119  }
3120 
3121  return;
3122 }
3123 
3124 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
3125 void
3127  const std::vector<const S_V* >& xVecs,
3128  const std::vector<const P_V* >& tVecs,
3129  const P_V& rho_w_vec,
3130  D_M& Rmat,
3131  unsigned int outerCounter)
3132 {
3133  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3134  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_w()"
3135  << ", outerCounter = " << outerCounter
3136  << std::endl;
3137  }
3138 
3139  queso_require_equal_to_msg(xVecs.size(), m_s->m_paper_m, "xVecs.size() is wrong");
3140  for (unsigned int i = 0; i < xVecs.size(); ++i) {
3141  queso_require_equal_to_msg(xVecs[i]->sizeLocal(), m_s->m_paper_p_x, "xVecs[i]->sizeLocal() is wrong");
3142  }
3143  queso_require_equal_to_msg(tVecs.size(), m_s->m_paper_m, "tVecs.size() is wrong");
3144  for (unsigned int i = 0; i < tVecs.size(); ++i) {
3145  queso_require_equal_to_msg(tVecs[i]->sizeLocal(), m_s->m_paper_p_t, "tVecs[i]->sizeLocal() is wrong");
3146  }
3147  queso_require_equal_to_msg(rho_w_vec.sizeLocal(), (m_s->m_paper_p_x+m_s->m_paper_p_t), "rho_w_vec.sizeLocal() is wrong");
3148  queso_require_equal_to_msg(Rmat.numRowsLocal(), m_s->m_paper_m, "Rmat.numRowsLocal() is wrong");
3149  queso_require_equal_to_msg(Rmat.numCols(), m_s->m_paper_m, "Rmat.numCols() is wrong");
3150 
3151  S_V xVecI(*(xVecs[0]));
3152  S_V xVecJ(*(xVecs[0]));
3153  P_V tVecI(*(tVecs[0]));
3154  P_V tVecJ(*(tVecs[0]));
3155  for (unsigned int i = 0; i < m_s->m_paper_m; ++i) {
3156  xVecI = *(xVecs[i]);
3157  tVecI = *(tVecs[i]);
3158  for (unsigned int j = 0; j < m_s->m_paper_m; ++j) {
3159  xVecJ = *(xVecs[j]);
3160  tVecJ = *(tVecs[j]);
3161  Rmat(i,j) = 1.;
3162  for (unsigned int k = 0; k < m_s->m_paper_p_x; ++k) {
3163  double diffTerm = xVecI[k] - xVecJ[k];
3164  Rmat(i,j) *= std::pow(rho_w_vec[k],4.*diffTerm*diffTerm);
3165  }
3166  for (unsigned int k = 0; k < m_s->m_paper_p_t; ++k) {
3167  double diffTerm = tVecI[k] - tVecJ[k];
3168  Rmat(i,j) *= std::pow(rho_w_vec[m_s->m_paper_p_x+k],4.*diffTerm*diffTerm);
3169  }
3170  }
3171  }
3172 
3173  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3174  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_w()"
3175  << ", outerCounter = " << outerCounter
3176  << std::endl;
3177  }
3178 
3179  return;
3180 }
3181 
3182 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
3183 void
3185  const std::vector<const S_V* >& xVecs1,
3186  const P_V& tVec1,
3187  const std::vector<const S_V* >& xVecs2,
3188  const std::vector<const P_V* >& tVecs2,
3189  const P_V& rho_w_vec,
3190  D_M& Rmat,
3191  unsigned int outerCounter)
3192 {
3193  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3194  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_uw()"
3195  << ", outerCounter = " << outerCounter
3196  << std::endl;
3197  }
3198 
3199  queso_require_equal_to_msg(xVecs1.size(), m_e->m_paper_n, "xVecs1.size() is wrong");
3200  for (unsigned int i = 0; i < xVecs1.size(); ++i) {
3201  queso_require_equal_to_msg(xVecs1[i]->sizeLocal(), m_s->m_paper_p_x, "xVecs1[i]->sizeLocal() is wrong");
3202  }
3203  queso_require_equal_to_msg(tVec1.sizeLocal(), m_s->m_paper_p_t, "tVec1.sizeLocal() is wrong");
3204  queso_require_equal_to_msg(xVecs2.size(), m_s->m_paper_m, "xVecs2.size() is wrong");
3205  for (unsigned int i = 0; i < xVecs2.size(); ++i) {
3206  queso_require_equal_to_msg(xVecs2[i]->sizeLocal(), m_s->m_paper_p_x, "xVecs2[i]->sizeLocal() is wrong");
3207  }
3208  queso_require_equal_to_msg(tVecs2.size(), m_s->m_paper_m, "tVecs2.size() is wrong");
3209  for (unsigned int i = 0; i < tVecs2.size(); ++i) {
3210  queso_require_equal_to_msg(tVecs2[i]->sizeLocal(), m_s->m_paper_p_t, "tVecs2[i]->sizeLocal() is wrong");
3211  }
3212  queso_require_equal_to_msg(rho_w_vec.sizeLocal(), (m_s->m_paper_p_x+m_s->m_paper_p_t), "rho_w_vec.sizeLocal() is wrong");
3213  queso_require_equal_to_msg(Rmat.numRowsLocal(), m_e->m_paper_n, "Rmat.numRowsLocal() is wrong");
3214  queso_require_equal_to_msg(Rmat.numCols(), m_s->m_paper_m, "Rmat.numCols() is wrong");
3215 
3216  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3217  *m_env.subDisplayFile() << "In GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_uw()"
3218  << ", outerCounter = " << outerCounter
3219  << std::endl;
3220  }
3221 
3222  S_V xVecI(*(xVecs1[0]));
3223  S_V xVecJ(*(xVecs2[0]));
3224  P_V tVecI(tVec1);
3225  P_V tVecJ(*(tVecs2[0]));
3226  for (unsigned int i = 0; i < m_e->m_paper_n; ++i) {
3227  xVecI = *(xVecs1[i]);
3228  tVecI = tVec1;
3229  for (unsigned int j = 0; j < m_s->m_paper_m; ++j) {
3230  xVecJ = *(xVecs2[j]);
3231  tVecJ = *(tVecs2[j]);
3232  Rmat(i,j) = 1.;
3233  for (unsigned int k = 0; k < m_s->m_paper_p_x; ++k) {
3234  double diffTerm = xVecI[k] - xVecJ[k];
3235  Rmat(i,j) *= std::pow(rho_w_vec[k],4.*diffTerm*diffTerm);
3236  }
3237  for (unsigned int k = 0; k < m_s->m_paper_p_t; ++k) {
3238  double diffTerm = tVecI[k] - tVecJ[k];
3239  Rmat(i,j) *= std::pow(rho_w_vec[m_s->m_paper_p_x+k],4.*diffTerm*diffTerm);
3240  }
3241  }
3242  }
3243 
3244  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3245  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_uw()"
3246  << ", outerCounter = " << outerCounter
3247  << std::endl;
3248  }
3249 
3250  return;
3251 }
3252 
3253 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
3254 void
3256  const std::vector<const S_V* >& xVecs1,
3257  const std::vector<const P_V* >& tVecs1,
3258  const S_V& xVec2,
3259  const P_V& tVec2,
3260  const P_V& rho_v_vec,
3261  D_M& Rmat,
3262  unsigned int outerCounter)
3263 {
3264  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3265  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula2_for_Sigma_v_hat_v_asterisk()"
3266  << ", outerCounter = " << outerCounter
3267  << std::endl;
3268  }
3269 
3270  queso_require_equal_to_msg(xVecs1.size(), m_s->m_paper_m, "xVecs1.size() is wrong");
3271  for (unsigned int i = 0; i < xVecs1.size(); ++i) {
3272  queso_require_equal_to_msg(xVecs1[i]->sizeLocal(), m_s->m_paper_p_x, "xVecs1[i]->sizeLocal() is wrong");
3273  }
3274  queso_require_equal_to_msg(tVecs1.size(), m_s->m_paper_m, "tVecs1.size() is wrong");
3275  for (unsigned int i = 0; i < tVecs1.size(); ++i) {
3276  queso_require_equal_to_msg(tVecs1[i]->sizeLocal(), m_s->m_paper_p_t, "tVecs1[i]->sizeLocal() is wrong");
3277  }
3278  queso_require_equal_to_msg(xVec2.sizeLocal(), m_s->m_paper_p_x, "xVec2.sizeLocal() is wrong");
3279  queso_require_equal_to_msg(tVec2.sizeLocal(), m_s->m_paper_p_t, "tVec2.sizeLocal() is wrong");
3280  queso_require_msg(!((rho_v_vec.sizeLocal() == 0) || (rho_v_vec.sizeLocal() > m_s->m_paper_p_x)), "rho_v_vec.sizeLocal() is wrong");
3281  queso_require_equal_to_msg(Rmat.numRowsLocal(), m_e->m_paper_n, "Rmat.numRowsLocal() is wrong");
3282  queso_require_equal_to_msg(Rmat.numCols(), 1, "Rmat.numCols() is wrong");
3283 
3284  S_V xVecI(*(xVecs1[0]));
3285  S_V xVecJ(xVec2);
3286  P_V tVecI(*(tVecs1[0]));
3287  P_V tVecJ(tVec2);
3288  for (unsigned int i = 0; i < m_e->m_paper_n; ++i) {
3289  xVecI = *(xVecs1[i]);
3290  tVecI = *(tVecs1[i]);
3291  for (unsigned int j = 0; j < 1; ++j) { // Yes, only '1'
3292  xVecJ = xVec2;
3293  tVecJ = tVec2;
3294  Rmat(i,j) = 1.;
3295  // checar
3296  for (unsigned int k = 0; k < m_s->m_paper_p_x; ++k) {
3297  double diffTerm = xVecI[k] - xVecJ[k];
3298  Rmat(i,j) *= std::pow(rho_v_vec[k],4.*diffTerm*diffTerm);
3299  }
3300  }
3301  }
3302  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3303  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula2_for_Sigma_v_hat_v_asterisk()"
3304  << ", outerCounter = " << outerCounter
3305  << std::endl;
3306  }
3307 
3308  return;
3309 }
3310 
3311 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
3312 void
3314  const std::vector<const S_V* >& xVecs1,
3315  const std::vector<const P_V* >& tVecs1,
3316  const S_V& xVec2,
3317  const P_V& tVec2,
3318  const P_V& rho_w_vec,
3319  D_M& Rmat,
3320  unsigned int outerCounter)
3321 {
3322  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3323  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_u_hat_u_asterisk()"
3324  << ", outerCounter = " << outerCounter
3325  << std::endl;
3326  }
3327  queso_require_equal_to_msg(xVecs1.size(), m_s->m_paper_m, "xVecs1.size() is wrong");
3328  for (unsigned int i = 0; i < xVecs1.size(); ++i) {
3329  queso_require_equal_to_msg(xVecs1[i]->sizeLocal(), m_s->m_paper_p_x, "xVecs1[i]->sizeLocal() is wrong");
3330  }
3331  queso_require_equal_to_msg(tVecs1.size(), m_s->m_paper_m, "tVecs1.size() is wrong");
3332  for (unsigned int i = 0; i < tVecs1.size(); ++i) {
3333  queso_require_equal_to_msg(tVecs1[i]->sizeLocal(), m_s->m_paper_p_t, "tVecs1[i]->sizeLocal() is wrong");
3334  }
3335  queso_require_equal_to_msg(xVec2.sizeLocal(), m_s->m_paper_p_x, "xVec2.sizeLocal() is wrong");
3336  queso_require_equal_to_msg(tVec2.sizeLocal(), m_s->m_paper_p_t, "tVec2.sizeLocal() is wrong");
3337  queso_require_equal_to_msg(rho_w_vec.sizeLocal(), (m_s->m_paper_p_x+m_s->m_paper_p_t), "rho_w_vec.sizeLocal() is wrong");
3338  queso_require_equal_to_msg(Rmat.numRowsLocal(), m_s->m_paper_m, "Rmat.numRowsLocal() is wrong");
3339  queso_require_equal_to_msg(Rmat.numCols(), 1, "Rmat.numCols() is wrong");
3340 
3341  S_V xVecI(*(xVecs1[0]));
3342  S_V xVecJ(xVec2);
3343  P_V tVecI(*(tVecs1[0]));
3344  P_V tVecJ(tVec2);
3345  for (unsigned int i = 0; i < m_s->m_paper_m; ++i) {
3346  xVecI = *(xVecs1[i]);
3347  tVecI = *(tVecs1[i]);
3348  for (unsigned int j = 0; j < 1; ++j) { // Yes, only '1'
3349  xVecJ = xVec2;
3350  tVecJ = tVec2;
3351  Rmat(i,j) = 1.;
3352  // checar
3353  for (unsigned int k = 0; k < m_s->m_paper_p_x; ++k) {
3354  double diffTerm = xVecI[k] - xVecJ[k];
3355  Rmat(i,j) *= std::pow(rho_w_vec[k],4.*diffTerm*diffTerm);
3356  }
3357  for (unsigned int k = 0; k < m_s->m_paper_p_t; ++k) {
3358  double diffTerm = tVecI[k] - tVecJ[k];
3359  Rmat(i,j) *= std::pow(rho_w_vec[m_s->m_paper_p_x+k],4.*diffTerm*diffTerm);
3360  }
3361  }
3362  }
3363  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3364  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_u_hat_u_asterisk()"
3365  << ", outerCounter = " << outerCounter
3366  << std::endl;
3367  }
3368 
3369  return;
3370 }
3371 
3372 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
3373 void
3375  const std::vector<const S_V* >& xVecs1,
3376  const std::vector<const P_V* >& tVecs1,
3377  const S_V& xVec2,
3378  const P_V& tVec2,
3379  const P_V& rho_w_vec,
3380  D_M& Rmat,
3381  unsigned int outerCounter)
3382 {
3383  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3384  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_w_hat_u_asterisk()"
3385  << ", outerCounter = " << outerCounter
3386  << std::endl;
3387  }
3388  queso_require_equal_to_msg(xVecs1.size(), m_s->m_paper_m, "xVecs1.size() is wrong");
3389  for (unsigned int i = 0; i < xVecs1.size(); ++i) {
3390  queso_require_equal_to_msg(xVecs1[i]->sizeLocal(), m_s->m_paper_p_x, "xVecs1[i]->sizeLocal() is wrong");
3391  }
3392  queso_require_equal_to_msg(tVecs1.size(), m_s->m_paper_m, "tVecs1.size() is wrong");
3393  for (unsigned int i = 0; i < tVecs1.size(); ++i) {
3394  queso_require_equal_to_msg(tVecs1[i]->sizeLocal(), m_s->m_paper_p_t, "tVecs1[i]->sizeLocal() is wrong");
3395  }
3396  queso_require_equal_to_msg(xVec2.sizeLocal(), m_s->m_paper_p_x, "xVec2.sizeLocal() is wrong");
3397  queso_require_equal_to_msg(tVec2.sizeLocal(), m_s->m_paper_p_t, "tVec2.sizeLocal() is wrong");
3398  queso_require_equal_to_msg(rho_w_vec.sizeLocal(), (m_s->m_paper_p_x+m_s->m_paper_p_t), "rho_w_vec.sizeLocal() is wrong");
3399  queso_require_equal_to_msg(Rmat.numRowsLocal(), m_s->m_paper_m, "Rmat.numRowsLocal() is wrong");
3400  queso_require_equal_to_msg(Rmat.numCols(), 1, "Rmat.numCols() is wrong");
3401 
3402  S_V xVecI(*(xVecs1[0]));
3403  S_V xVecJ(xVec2);
3404  P_V tVecI(*(tVecs1[0]));
3405  P_V tVecJ(tVec2);
3406  for (unsigned int i = 0; i < m_s->m_paper_m; ++i) {
3407  xVecI = *(xVecs1[i]);
3408  tVecI = *(tVecs1[i]);
3409  for (unsigned int j = 0; j < 1; ++j) { // Yes, only '1'
3410  xVecJ = xVec2;
3411  tVecJ = tVec2;
3412  Rmat(i,j) = 1.;
3413  // checar
3414  for (unsigned int k = 0; k < m_s->m_paper_p_x; ++k) {
3415  double diffTerm = xVecI[k] - xVecJ[k];
3416  Rmat(i,j) *= std::pow(rho_w_vec[k],4.*diffTerm*diffTerm);
3417  }
3418  for (unsigned int k = 0; k < m_s->m_paper_p_t; ++k) {
3419  double diffTerm = tVecI[k] - tVecJ[k];
3420  Rmat(i,j) *= std::pow(rho_w_vec[m_s->m_paper_p_x+k],4.*diffTerm*diffTerm);
3421  }
3422  }
3423  }
3424  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3425  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_w_hat_u_asterisk()"
3426  << ", outerCounter = " << outerCounter
3427  << std::endl;
3428  }
3429 
3430  return;
3431 }
3432 
3433 template <class S_V,class S_M,class D_V,class D_M,class P_V,class P_M,class Q_V,class Q_M>
3434 void
3436  const std::vector<const S_V* >& xVecs1,
3437  const std::vector<const P_V* >& tVecs1,
3438  const S_V& xVec2,
3439  const P_V& tVec2,
3440  const P_V& rho_w_vec,
3441  D_M& Rmat,
3442  unsigned int outerCounter)
3443 {
3444  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3445  *m_env.subDisplayFile() << "Entering GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_w_hat_w_asterisk()"
3446  << ", outerCounter = " << outerCounter
3447  << std::endl;
3448  }
3449 
3450  queso_require_equal_to_msg(xVecs1.size(), m_s->m_paper_m, "xVecs1.size() is wrong");
3451  for (unsigned int i = 0; i < xVecs1.size(); ++i) {
3452  queso_require_equal_to_msg(xVecs1[i]->sizeLocal(), m_s->m_paper_p_x, "xVecs1[i]->sizeLocal() is wrong");
3453  }
3454  queso_require_equal_to_msg(tVecs1.size(), m_s->m_paper_m, "tVecs1.size() is wrong");
3455  for (unsigned int i = 0; i < tVecs1.size(); ++i) {
3456  queso_require_equal_to_msg(tVecs1[i]->sizeLocal(), m_s->m_paper_p_t, "tVecs1[i]->sizeLocal() is wrong");
3457  }
3458  queso_require_equal_to_msg(xVec2.sizeLocal(), m_s->m_paper_p_x, "xVec2.sizeLocal() is wrong");
3459  queso_require_equal_to_msg(tVec2.sizeLocal(), m_s->m_paper_p_t, "tVec2.sizeLocal() is wrong");
3460  queso_require_equal_to_msg(rho_w_vec.sizeLocal(), (m_s->m_paper_p_x+m_s->m_paper_p_t), "rho_w_vec.sizeLocal() is wrong");
3461  queso_require_equal_to_msg(Rmat.numRowsLocal(), m_s->m_paper_m, "Rmat.numRowsLocal() is wrong");
3462  queso_require_equal_to_msg(Rmat.numCols(), 1, "Rmat.numCols() is wrong");
3463 
3464  S_V xVecI(*(xVecs1[0]));
3465  S_V xVecJ(xVec2);
3466  P_V tVecI(*(tVecs1[0]));
3467  P_V tVecJ(tVec2);
3468  for (unsigned int i = 0; i < m_s->m_paper_m; ++i) {
3469  xVecI = *(xVecs1[i]);
3470  tVecI = *(tVecs1[i]);
3471  for (unsigned int j = 0; j < 1; ++j) { // Yes, only '1'
3472  xVecJ = xVec2;
3473  tVecJ = tVec2;
3474  Rmat(i,j) = 1.;
3475  for (unsigned int k = 0; k < m_s->m_paper_p_x; ++k) {
3476  double diffTerm = xVecI[k] - xVecJ[k];
3477  Rmat(i,j) *= std::pow(rho_w_vec[k],4.*diffTerm*diffTerm);
3478  }
3479  for (unsigned int k = 0; k < m_s->m_paper_p_t; ++k) {
3480  double diffTerm = tVecI[k] - tVecJ[k];
3481  Rmat(i,j) *= std::pow(rho_w_vec[m_s->m_paper_p_x+k],4.*diffTerm*diffTerm);
3482  }
3483  }
3484  }
3485 
3486  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 4)) {
3487  *m_env.subDisplayFile() << "Leaving GpmsaComputerModel<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::fillR_formula1_for_Sigma_w_hat_w_asterisk()"
3488  << ", outerCounter = " << outerCounter
3489  << std::endl;
3490  }
3491 
3492  return;
3493 }
3494 
3495 } // End namespace QUESO
3496 
unsigned int displayVerbosity() const
Definition: Environment.C:396
VectorSet< V, M > * InstantiateIntersection(const VectorSet< V, M > &domain1, const VectorSet< V, M > &domain2)
This method calculates the intersection of domain1 and domain2.
unsigned int dimLocal() const
Definition: VectorSpace.C:170
unsigned int numExperiments() const
GcmSimulationInfo< S_V, S_M, P_V, P_M, Q_V, Q_M > * m_s
const V & unifiedMeanPlain() const
Finds the mean value of the unified sequence.
GpmsaComputerModel(const char *prefix, const GcmOptionsValues *alternativeOptionsValues, const SimulationStorage< S_V, S_M, P_V, P_M, Q_V, Q_M > &simulationStorage, const SimulationModel< S_V, S_M, P_V, P_M, Q_V, Q_M > &simulationModel, const ExperimentStorage< S_V, S_M, D_V, D_M > *experimentStorage, const ExperimentModel< S_V, S_M, D_V, D_M > *experimentModel, const BaseVectorRV< P_V, P_M > *thetaPriorRv)
const BaseVectorRV< P_V, P_M > & totalPriorRv() const
void fillR_formula2_for_Sigma_v(const std::vector< const S_V * > &xVecs, const P_V &rho_v_vec, D_M &Rmat, unsigned int outerCounter)
void memoryCheck(unsigned int codePositionId)
void fillR_formula1_for_Sigma_w_hat_u_asterisk(const std::vector< const S_V * > &xVecs1, const std::vector< const P_V * > &tVecs1, const S_V &xVec2, const P_V &tVec2, const P_V &rho_w_vec, D_M &Rmat, unsigned int outerCounter)
A class for handling generic scalar functions.
void calibrateWithLanlMcmc(const MhOptionsValues *alternativeOptionsValues, const P_V &totalInitialValues, const P_M *totalInitialProposalCovMatrix)
#define queso_require_equal_to(expr1, expr2)
Definition: asserts.h:127
A templated class that represents a Metropolis-Hastings generator of samples.
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
void formSigma_z_hat(const P_V &input_1lambdaEtaVec, const P_V &input_2lambdaWVec, const P_V &input_3rhoWVec, const P_V &input_4lambdaSVec, const P_V &input_5lambdaYVec, const P_V &input_6lambdaVVec, const P_V &input_7rhoVVec, const P_V &input_8thetaVec, unsigned int outerCounter)
const GcmOptionsValues * m_optionsObj
FilePtrSetStruct m_dataOutputFilePtrSet
std::ofstream * ofsVar
Provides a stream interface to write data to files.
Definition: Environment.h:81
void fillR_formula1_for_Sigma_u_hat_u_asterisk(const std::vector< const S_V * > &xVecs1, const std::vector< const P_V * > &tVecs1, const S_V &xVec2, const P_V &tVec2, const P_V &rho_w_vec, D_M &Rmat, unsigned int outerCounter)
#define queso_error_msg(msg)
Definition: asserts.h:47
void predictSimulationOutputs(const S_V &newScenarioVec, const P_V &newParameterVec, Q_V &simulationOutputMeanVec)
const VectorSpace< P_V, P_M > & totalSpace() const
void ComputeCovCorrMatricesBetweenVectorSequences(const BaseVectorSequence< P_V, P_M > &subPSeq, const BaseVectorSequence< Q_V, Q_M > &subQSeq, unsigned int subNumSamples, P_M &pqCovMatrix, P_M &pqCorrMatrix)
std::set< unsigned int > m_dataOutputAllowedSet
unsigned int numBasis() const
void formSigma_w_hat(const P_V &input_1lambdaEtaVec, const P_V &input_2lambdaWVec, const P_V &input_3rhoWVec, const P_V &input_4lambdaSVec, const P_V &input_8thetaVec, unsigned int outerCounter)
GcmJointInfo< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M > * m_j
void fillR_formula1_for_Sigma_u(const std::vector< const S_V * > &xVecs, const P_V &tVec, const P_V &rho_w_vec, D_M &Rmat, unsigned int outerCounter)
GcmSimulationTildeInfo< S_V, S_M, P_V, P_M, Q_V, Q_M > * m_st
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
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
double scalarProduct(const GslVector &x, const GslVector &y)
Definition: GslVector.C:1150
void setPositionValues(unsigned int posId, const V &vec)
Set the values in vec at position posId of the sequence.
void fillR_formula1_for_Sigma_w_hat_w_asterisk(const std::vector< const S_V * > &xVecs1, const std::vector< const P_V * > &tVecs1, const S_V &xVec2, const P_V &tVec2, const P_V &rho_w_vec, D_M &Rmat, unsigned int outerCounter)
double MiscGetEllapsedSeconds(struct timeval *timeval0)
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
GcmZTildeInfo< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M > * m_zt
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
unsigned int MiscUintDebugMessage(unsigned int value, const char *message)
void ComputeConditionalGaussianVectorRV(const V &muVec1, const V &muVec2, const M &sigmaMat11, const M &sigmaMat12, const M &sigmaMat21, const M &sigmaMat22, const V &sampleVec2, V &muVec1_cond_on_2, M &sigmaMat11_cond_on_2)
const BaseEnvironment & m_env
GcmExperimentInfo< S_V, S_M, D_V, D_M, P_V, P_M > * m_e
GcmTotalInfo< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M > * m_t
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
Definition: Defines.h:89
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:295
This class provides options for the Metropolis-Hastings generator of samples if no input file is avai...
double likelihoodRoutine(const P_V &totalValues, const P_V *totalDirection, const void *functionDataPtr, P_V *gradVector, P_M *hessianMatrix, P_V *hessianEffect)
const VectorSpace< P_V, P_M > & unique_vu_space() const
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
Definition: MLSampling.C:4023
unsigned int numBasis() const
unsigned int subSequenceSize() const
Size of the sub-sequence of vectors.
const std::vector< unsigned int > & n_ys_transformed() const
A class for handling sequential draws (sampling) from probability density distributions.
A templated class that represents a Multilevel generator of samples.
Definition: MLSampling.h:122
void predictWsAtGridPoint(const S_V &newScenarioVec, const P_V &newParameterVec, const P_V *forcingSampleVecForDebug, P_V &wMeanVec, P_M &wCovMatrix)
void predictVUsAtGridPoint(const S_V &newScenarioVec, const P_V &newParameterVec, P_V &vuMeanVec, P_M &vuCovMatrix, P_V &vMeanVec, P_M &vCovMatrix, P_V &uMeanVec, P_M &uCovMatrix)
void calibrateWithBayesMetropolisHastings(const MhOptionsValues *alternativeOptionsValues, const P_V &totalInitialValues, const P_M *totalInitialProposalCovMatrix)
GcmZInfo< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M > * m_z
GcmJointTildeInfo< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M > * m_jt
void formSigma_z(const P_V &input_2lambdaWVec, const P_V &input_3rhoWVec, const P_V &input_4lambdaSVec, const P_V &input_6lambdaVVec, const P_V &input_7rhoVVec, const P_V &input_8thetaVec, unsigned int outerCounter)
void formSigma_z_tilde_hat(const P_V &input_1lambdaEtaVec, const P_V &input_2lambdaWVec, const P_V &input_3rhoWVec, const P_V &input_4lambdaSVec, const P_V &input_5lambdaYVec, const P_V &input_6lambdaVVec, const P_V &input_7rhoVVec, const P_V &input_8thetaVec, unsigned int outerCounter)
bool openOutputFile(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds, bool writeOver, FilePtrSetStruct &filePtrSet) const
Opens an output file for each sub-environment that was chosen to send data to the file...
Definition: Environment.C:467
void fillR_formula2_for_Sigma_v_hat_v_asterisk(const std::vector< const S_V * > &xVecs1, const std::vector< const P_V * > &tVecs1, const S_V &xVec2, const P_V &tVec2, const P_V &rho_v_vec, D_M &Rmat, unsigned int outerCounter)
void fillR_formula1_for_Sigma_w(const std::vector< const S_V * > &xVecs, const std::vector< const P_V * > &tVecs, const P_V &rho_w_vec, D_M &Rmat, unsigned int outerCounter)
void fillR_formula1_for_Sigma_uw(const std::vector< const S_V * > &xVecs1, const P_V &tVec1, const std::vector< const S_V * > &xVecs2, const std::vector< const P_V * > &tVecs2, const P_V &rho_w_vec, D_M &Rmat, unsigned int outerCounter)
BaseScalarFunction< P_V, P_M > * m_likelihoodFunction
static double staticLikelihoodRoutine(const P_V &totalValues, const P_V *totalDirection, const void *functionDataPtr, P_V *gradVector, P_M *hessianMatrix, P_V *hessianEffect)
void predictExperimentResults(const S_V &newScenarioVec, const D_M &newKmat_interp, const D_M &newDmat, D_V &simulationOutputMeanVec, D_V &discrepancyMeanVec)
const VectorSpace< S_V, S_M > & scenarioSpace() const
int k
Definition: ann_sample.cpp:53
const GenericVectorRV< P_V, P_M > & totalPostRv() const
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const
void print(std::ostream &os) const

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