25 #include <queso/GcmSimulationInfo.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
31 template <
class S_V,
class S_M,
class P_V,
class P_M,
class Q_V,
class Q_M>
34 bool allOutputsAreScalar,
38 m_env (simulationStorage.env()),
39 m_simulationStorage (simulationStorage),
40 m_simulationModel (simulationModel),
41 m_paper_p_x (simulationStorage.scenarioSpace().dimLocal()),
42 m_paper_xs_asterisks_standard (simulationModel.xs_asterisks_standard()),
43 m_paper_ts_asterisks_standard (simulationModel.ts_asterisks_standard()),
44 m_paper_p_t (simulationStorage.parameterSpace().dimLocal()),
45 m_paper_m (simulationStorage.numSimulations()),
46 m_paper_n_eta (simulationStorage.outputSpace().dimLocal()),
47 m_paper_p_eta (simulationModel.numBasis()),
48 m_paper_m_space (m_env,
"paper_m_", m_paper_m, NULL),
50 m_1lambdaEtaSpace (m_env,
"1lambdaEta_", m_1lambdaEtaDim, NULL),
51 m_1lambdaEtaMins (m_env,m_1lambdaEtaSpace.map(),0.),
52 m_1lambdaEtaMaxs (m_env,m_1lambdaEtaSpace.map(),+INFINITY),
53 m_1lambdaEtaDomain (
"1lambdaEta_",m_1lambdaEtaSpace,m_1lambdaEtaMins,m_1lambdaEtaMaxs),
54 m_1lambdaEtaGammaAVec (m_env,m_1lambdaEtaSpace.map(),simulationModel.optionsObj().m_ov.m_a_eta),
55 m_1lambdaEtaGammaBVec (m_env,m_1lambdaEtaSpace.map(),1./simulationModel.optionsObj().m_ov.m_b_eta),
56 m_1lambdaEtaPriorRv (
"1lambdaEta_",m_1lambdaEtaDomain,m_1lambdaEtaGammaAVec,m_1lambdaEtaGammaBVec),
57 m_like_previous1 (m_1lambdaEtaSpace.zeroVector()),
58 m_tmp_1lambdaEtaVec (m_1lambdaEtaSpace.zeroVector()),
59 m_2lambdaWDim (m_paper_p_eta),
60 m_2lambdaWSpace (m_env,
"2lambdaW_", m_2lambdaWDim, NULL),
61 m_2lambdaWMins (m_env,m_2lambdaWSpace.map(),0.),
62 m_2lambdaWMaxs (m_env,m_2lambdaWSpace.map(),+INFINITY),
63 m_2lambdaWDomain (
"2lambdaW_",m_2lambdaWSpace,m_2lambdaWMins,m_2lambdaWMaxs),
64 m_2lambdaWGammaAVec (m_env,m_2lambdaWSpace.map(),simulationModel.optionsObj().m_ov.m_a_w),
65 m_2lambdaWGammaBVec (m_env,m_2lambdaWSpace.map(),1./simulationModel.optionsObj().m_ov.m_b_w),
66 m_2lambdaWPriorRv (
"2lambdaW_",m_2lambdaWDomain,m_2lambdaWGammaAVec,m_2lambdaWGammaBVec),
67 m_like_previous2 (m_2lambdaWSpace.zeroVector()),
68 m_tmp_2lambdaWVec (m_2lambdaWSpace.zeroVector()),
69 m_3rhoWDim (m_paper_p_eta * (m_paper_p_x + m_paper_p_t)),
70 m_3rhoWSpace (m_env,
"3rhoW_", m_3rhoWDim, NULL),
71 m_3rhoWMins (m_env,m_3rhoWSpace.map(),0.),
72 m_3rhoWMaxs (m_env,m_3rhoWSpace.map(),1.),
73 m_3rhoWDomain (
"3rhoW_",m_3rhoWSpace,m_3rhoWMins,m_3rhoWMaxs),
74 m_3rhoWBetaAVec (m_env,m_3rhoWSpace.map(),simulationModel.optionsObj().m_ov.m_a_rho_w),
75 m_3rhoWBetaBVec (m_env,m_3rhoWSpace.map(),simulationModel.optionsObj().m_ov.m_b_rho_w),
76 m_3rhoWPriorRv (
"3rhoW_",m_3rhoWDomain,m_3rhoWBetaAVec,m_3rhoWBetaBVec),
77 m_like_previous3 (m_3rhoWSpace.zeroVector()),
78 m_tmp_3rhoWVec (m_3rhoWSpace.zeroVector()),
79 m_4lambdaSDim (m_paper_p_eta),
80 m_4lambdaSSpace (m_env,
"4lambdaS_", m_4lambdaSDim, NULL),
81 m_4lambdaSMins (m_env,m_4lambdaSSpace.map(),0.),
82 m_4lambdaSMaxs (m_env,m_4lambdaSSpace.map(),+INFINITY),
83 m_4lambdaSDomain (
"4lambdaS_",m_4lambdaSSpace,m_4lambdaSMins,m_4lambdaSMaxs),
84 m_4lambdaSGammaAVec (m_env,m_4lambdaSSpace.map(),simulationModel.optionsObj().m_ov.m_a_s),
85 m_4lambdaSGammaBVec (m_env,m_4lambdaSSpace.map(),1./simulationModel.optionsObj().m_ov.m_b_s),
86 m_4lambdaSPriorRv (
"4lambdaS_",m_4lambdaSDomain,m_4lambdaSGammaAVec,m_4lambdaSGammaBVec),
87 m_like_previous4 (m_4lambdaSSpace.zeroVector()),
88 m_tmp_4lambdaSVec (m_4lambdaSSpace.zeroVector()),
89 m_eta_size (m_paper_m*m_paper_n_eta),
90 m_eta_space (m_env,
"eta_", m_eta_size, NULL),
91 m_w_size (m_paper_m*m_paper_p_eta),
92 m_w_space (m_env,
"w_", m_w_size, NULL),
93 m_unique_w_space (m_env,
"unique_w_", m_paper_p_eta, NULL),
94 m_Zvec_hat_w (m_w_space.zeroVector()),
95 m_rho_w_space (m_env,
"rho_w_", m_paper_p_x+m_paper_p_t, NULL),
96 m_tmp_rho_w_vec (m_rho_w_space.zeroVector()),
97 m_Rmat_w_is (m_paper_p_eta, (Q_M*) NULL),
98 m_Smat_w_is (m_paper_p_eta, (Q_M*) NULL),
99 m_Smat_w (m_w_space.zeroVector()),
100 m_Smat_w_hat (m_w_space.zeroVector()),
101 m_Rmat_w_hat_w_asterisk_is (m_paper_p_eta, (Q_M*) NULL),
102 m_Smat_w_hat_w_asterisk_is (m_paper_p_eta, (Q_M*) NULL),
103 m_Smat_w_hat_w_asterisk (m_env,m_w_space.map(), m_paper_p_eta),
104 m_Smat_w_hat_w_asterisk_t (m_env,m_unique_w_space.map(),m_w_size),
105 m_Smat_w_asterisk_w_asterisk (m_unique_w_space.zeroVector()),
106 m_Kmat (simulationModel.Kmat()),
107 m_Kmat_eta (simulationModel.Kmat_eta()),
108 m_Kmat_rank (std::min(m_Kmat.numRowsGlobal(),m_Kmat.numCols())),
111 m_a_eta_modifier (0.),
112 m_b_eta_modifier (0.),
114 m_predW_summingRVs_unique_w_meanVec (m_unique_w_space.zeroVector()),
115 m_predW_summingRVs_mean_of_unique_w_covMatrices (m_unique_w_space.zeroVector()),
116 m_predW_summingRVs_covMatrix_of_unique_w_means (m_unique_w_space.zeroVector()),
117 m_predW_summingRVs_corrMatrix_of_unique_w_means (m_unique_w_space.zeroVector())
120 *
m_env.
subDisplayFile() <<
"Entering GcmSimulationInfo<S_V,S_M,P_V,P_M,Q_V,Q_M>::constructor()"
122 <<
", some entities just created (not yet populated)"
123 <<
", m_Zvec_hat_w.sizeLocal() = " <<
m_Zvec_hat_w.sizeLocal()
124 <<
", m_Smat_w.numRowsLocal() = " <<
m_Smat_w.numRowsLocal()
125 <<
", m_Smat_w.numCols() = " <<
m_Smat_w.numCols()
129 std::set<unsigned int> tmpSet;
136 unsigned int kRank14 =
m_Kmat.rank(0.,1.e-14);
139 <<
": m_Kmat.numRowsLocal() = " <<
m_Kmat.numRowsLocal()
140 <<
", m_Kmat.numCols() = " <<
m_Kmat.numCols()
141 <<
", m_Kmat.rank(0.,1.e-8) = " << m_Kmat_rank
142 <<
", m_Kmat.rank(0.,1.e-14) = " << kRank14
146 m_Kmat.subWriteContents(
"K",
155 <<
": m_Zvec_hat_w.sizeLocal() = " <<
m_Zvec_hat_w.sizeLocal()
156 <<
", etaVec_transformed.sizeLocal() = " << etaVec_transformed.sizeLocal()
160 if (allOutputsAreScalar) {
168 Kt.fillWithTranspose(0,0,
m_Kmat,
true,
true);
171 <<
": Kt.numRowsLocal() = " << Kt.numRowsLocal()
172 <<
", Kt.numCols() = " << Kt.numCols()
183 <<
", m_Kt_K just created (not yet populated)"
184 <<
", numRowsLocal() = " <<
m_Kt_K->numRowsLocal()
185 <<
", numCols() = " <<
m_Kt_K->numCols()
192 <<
", m_Kt_K_inv just created (not yet populated)"
193 <<
", numRowsLocal() = " <<
m_Kt_K_inv->numRowsLocal()
200 m_Kt_K->setPrintHorizontally(
false);
202 <<
": finished computing 'm_Kt_K'"
207 m_Kt_K->subWriteContents(
"Kt_K",
214 double ktKLnDeterminant =
m_Kt_K->lnDeterminant();
215 unsigned int ktKRank =
m_Kt_K->rank(0.,1.e-8 );
216 unsigned int ktKRank14 =
m_Kt_K->rank(0.,1.e-14);
219 <<
": m_Kt_K->numRowsLocal() = " <<
m_Kt_K->numRowsLocal()
220 <<
", m_Kt_K->numCols() = " <<
m_Kt_K->numCols()
221 <<
", m_Kt_K->lnDeterminant() = " << ktKLnDeterminant
222 <<
", m_Kt_K->rank(0.,1.e-8) = " << ktKRank
223 <<
", m_Kt_K->rank(0.,1.e-14) = " << ktKRank14
233 <<
": finished computing 'm_Kt_K_inv'"
245 double ktKInvLnDeterminant =
m_Kt_K_inv->lnDeterminant();
246 unsigned int ktKInvRank =
m_Kt_K_inv->rank(0.,1.e-8 );
247 unsigned int ktKInvRank14 =
m_Kt_K_inv->rank(0.,1.e-14);
250 <<
": m_Kt_K_inv->numRowsLocal() = " <<
m_Kt_K_inv->numRowsLocal()
251 <<
", m_Kt_K_inv->numCols() = " <<
m_Kt_K_inv->numCols()
252 <<
", m_Kt_K_inv->lnDeterminant() = " << ktKInvLnDeterminant
253 <<
", m_Kt_K_inv->rank(0.,1.e-8) = " << ktKInvRank
254 <<
", m_Kt_K_inv->rank(0.,1.e-14) = " << ktKInvRank14
271 <<
": m_Kt_K_inv->numRowsLocal() = " <<
m_Kt_K_inv->numRowsLocal()
272 <<
", m_Kt_K_inv->numCols() = " <<
m_Kt_K_inv->numCols()
273 <<
", Kt.numRowsLocal() = " << Kt.numRowsLocal()
274 <<
", Kt.numCols() = " << Kt.numCols()
278 m_Zvec_hat_w = (*m_Kt_K_inv) * (Kt * etaVec_transformed);
285 Q_V tmpVec1(etaVec_transformed - (m_Kmat *
m_Zvec_hat_w));
298 unsigned int sumDims = 0;
299 for (
unsigned int i = 0; i <
m_Smat_w_is.size(); ++i) {
306 <<
": finished instantiating m_Smat_w_is"
311 unsigned int sumNumRows = 0;
312 unsigned int sumNumCols = 0;
321 <<
": finished instantiating the m_Smat_w_hat_w_asterisk_i matrices"
331 *
m_env.
subDisplayFile() <<
"KEY In GcmSimulationInfo<S_V,S_M,P_V,P_M,Q_V,Q_M>::constructor()"
361 *
m_env.
subDisplayFile() <<
"Leaving GcmSimulationInfo<S_V,S_M,P_V,P_M,Q_V,Q_M>::constructor()"
366 template <
class S_V,
class S_M,
class P_V,
class P_M,
class Q_V,
class Q_M>
369 for (
unsigned int i = 0; i < m_Smat_w_hat_w_asterisk_is.size(); ++i) {
370 delete m_Smat_w_hat_w_asterisk_is[i];
371 m_Smat_w_hat_w_asterisk_is[i] = NULL;
372 delete m_Rmat_w_hat_w_asterisk_is[i];
373 m_Rmat_w_hat_w_asterisk_is[i] = NULL;
376 for (
unsigned int i = 0; i < m_Smat_w_is.size(); ++i) {
377 delete m_Smat_w_is[i];
378 m_Smat_w_is[i] = NULL;
379 delete m_Rmat_w_is[i];
380 m_Rmat_w_is[i] = NULL;
unsigned int displayVerbosity() const
unsigned int dimLocal() const
unsigned int m_4lambdaSDim
unsigned int m_2lambdaWDim
const Map & map() const
Map.
std::vector< Q_M * > m_Rmat_w_is
std::vector< Q_M * > m_Smat_w_hat_w_asterisk_is
const VectorSpace< S_V, S_M > & scenarioSpace() const
unsigned int m_paper_n_eta
std::set< unsigned int > m_dataOutputAllowedSet
const V & zeroVector() const
Returns a vector filled with zeros.
#define queso_require_equal_to_msg(expr1, expr2, msg)
unsigned int m_paper_p_eta
GcmSimulationInfo(const GpmsaComputerModelOptions &gcmOptionsObj, bool allOutputsAreScalar, 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)
double scalarProduct(const GslVector &x, const GslVector &y)
P_V m_1lambdaEtaGammaAVec
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
unsigned int MiscUintDebugMessage(unsigned int value, const char *message)
std::vector< Q_M * > m_Smat_w_is
VectorSpace< P_V, P_M > m_paper_m_space
VectorSpace< Q_V, Q_M > m_w_space
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
std::vector< Q_M * > m_Rmat_w_hat_w_asterisk_is
const Q_V & etaVec_transformed(const std::string &debugString) const
unsigned int m_1lambdaEtaDim
const BaseEnvironment & m_env
P_V m_1lambdaEtaGammaBVec