queso-0.53.0
GcmZTildeInfo.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/GcmZTildeInfo.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
28 
29 namespace QUESO {
30 
31 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>
33  const GpmsaComputerModelOptions& gcmOptionsObj,
36  :
37  m_env (jj.m_env),
38  m_Cmat_tilde (m_env,jj.m_omega_space.map(),z.m_Cmat_rank),
39  m_z_tilde_space (m_env, "z_tilde_", z.m_Cmat_rank, NULL),
40  m_Lmat (m_env,m_z_tilde_space.map(),z.m_Cmat->numCols()),
41  m_Lmat_t (m_env,z.m_z_space.map(),z.m_Cmat_rank),
42  m_Zvec_tilde_hat (m_z_tilde_space.zeroVector()),
43  m_tmp_Smat_z_tilde (m_z_tilde_space.zeroVector()),
44  m_tmp_Smat_extra_tilde (m_z_tilde_space.zeroVector()),
45  m_tmp_Smat_z_tilde_hat (m_z_tilde_space.zeroVector()),
46  m_tmp_Smat_z_tilde_hat_inv(m_z_tilde_space.zeroVector())
47 {
48  if (m_env.subDisplayFile()) {
49  *m_env.subDisplayFile() << "Entering GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(1)"
50  << std::endl;
51  }
52 
53  std::set<unsigned int> tmpSet;
54  tmpSet.insert(m_env.subId());
55 
56  // Naive formation of 'm_Cmat_tilde'
57  D_M matU(z.m_Cmat->svdMatU());
58  unsigned int uMatRank = matU.rank(0.,1.e-8 ); // todo: should be an option
59  unsigned int uMatRank14 = matU.rank(0.,1.e-14);
60  if (m_env.subDisplayFile()) {
61  *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(1)"
62  << ": matU.numRowsLocal() = " << matU.numRowsLocal()
63  << ", matU.numCols() = " << matU.numCols()
64  << ", matU.rank(0.,1.e-8) = " << uMatRank
65  << ", matU.rank(0.,1.e-14) = " << uMatRank14
66  << std::endl;
67  }
68 
69  if (m_env.checkingLevel() >= 1) {
70  D_M matUcheck(z.m_z_space.zeroVector());
71  D_V vecI(jj.m_omega_space.zeroVector());
72  D_V vecJ(jj.m_omega_space.zeroVector());
73  for (unsigned int i = 0; i < matU.numCols(); ++i) {
74  matU.getColumn(i,vecI);
75  for (unsigned int j = i; j < matU.numCols(); ++j) {
76  matU.getColumn(j,vecJ);
77  matUcheck(i,j) = scalarProduct(vecI,vecJ);
78  }
79  }
80  matUcheck.setPrintHorizontally(false);
81  if (m_env.subDisplayFile()) {
82  *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(1)"
83  << ": m_Cmat_rank = " << z.m_Cmat_rank
84  << ", matUcheck.numRowsLocal() = " << matUcheck.numRowsLocal()
85  << ", matUcheck.numCols() = " << matUcheck.numCols()
86  << ", matUcheck =\n" << matUcheck
87  << std::endl;
88  }
89  }
90 
91  D_V vecJ(jj.m_omega_space.zeroVector());
92  for (unsigned int j = 0; j < z.m_Cmat_rank; ++j) {
93  matU.getColumn(j,vecJ);
94  m_Cmat_tilde.setColumn(j,vecJ);
95  }
96 
97  if (gcmOptionsObj.m_ov.m_dataOutputAllowedSet.find(m_env.subId()) != gcmOptionsObj.m_ov.m_dataOutputAllowedSet.end()) {
98  m_Cmat_tilde.subWriteContents("Ctilde",
99  "Ctilde2",
100  "m",
101  tmpSet);
102  }
103  if (m_env.subDisplayFile()) {
104  *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(1)"
105  << ": m_Cmat_tilde formed (2)"
106  << std::endl;
107  }
108 
109  // Naive formation of 'm_Lmat'
110  m_Cmat_tilde.svdSolve(*(z.m_Cmat),m_Lmat);
111 
113 }
114 
115 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>
117  const GpmsaComputerModelOptions& gcmOptionsObj,
122  :
123  m_env (jj.m_env),
124  m_Cmat_tilde (m_env,jj.m_omega_space.map(),z.m_Cmat_rank),
125  m_z_tilde_space (m_env, "z_tilde_", z.m_Cmat_rank, NULL),
126  m_Lmat (m_env,m_z_tilde_space.map(),z.m_Cmat->numCols()),
127  m_Lmat_t (m_env,z.m_z_space.map(),z.m_Cmat_rank),
128  m_Zvec_tilde_hat (m_z_tilde_space.zeroVector()),
129  m_tmp_Smat_z_tilde (m_z_tilde_space.zeroVector()),
130  m_tmp_Smat_extra_tilde (m_z_tilde_space.zeroVector()),
131  m_tmp_Smat_z_tilde_hat (m_z_tilde_space.zeroVector()),
132  m_tmp_Smat_z_tilde_hat_inv(m_z_tilde_space.zeroVector())
133 {
134  if (m_env.subDisplayFile()) {
135  *m_env.subDisplayFile() << "Entering GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(2)"
136  << std::endl;
137  }
138 
139  std::set<unsigned int> tmpSet;
140  tmpSet.insert(m_env.subId());
141 
142  m_Cmat_tilde.cwSet(0.);
143  m_Cmat_tilde.cwSet( 0, 0,jt.m_Bmat_tilde);
144  m_Cmat_tilde.cwSet(jt.m_Bmat_tilde.numRowsLocal(),jt.m_Bmat_tilde.numCols(),st.m_Kmat_tilde);
145  if (gcmOptionsObj.m_ov.m_dataOutputAllowedSet.find(m_env.subId()) != gcmOptionsObj.m_ov.m_dataOutputAllowedSet.end()) {
146  m_Cmat_tilde.subWriteContents("Ctilde",
147  "Ctilde1",
148  "m",
149  tmpSet);
150  }
151  if (m_env.subDisplayFile()) {
152  *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(2)"
153  << ": m_Cmat_tilde formed (1)"
154  << std::endl;
155  }
156  m_Lmat.cwSet(0.);
157  m_Lmat.cwSet( 0, 0,jt.m_Lbmat);
158  m_Lmat.cwSet(jt.m_Lbmat.numRowsLocal(),jt.m_Lbmat.numCols(),st.m_Lkmat);
159  if (gcmOptionsObj.m_ov.m_dataOutputAllowedSet.find(m_env.subId()) != gcmOptionsObj.m_ov.m_dataOutputAllowedSet.end()) {
160  m_Lmat.subWriteContents("Lmat",
161  "Lmat",
162  "m",
163  tmpSet);
164  }
165  if (m_env.subDisplayFile()) {
166  *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor(2)"
167  << ": m_Lmat_tilde formed"
168  << std::endl;
169  }
170 
171  m_Zvec_tilde_hat.cwSetConcatenated(jt.m_Zvec_tilde_hat_vu,st.m_Zvec_tilde_hat_w); // todo_rrr: not in constructor(1) ???
172 
174 }
175 
176 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>
178 {
179 }
180 
181 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>
182 void
184 {
185  unsigned int cMatTildeRank = m_Cmat_tilde.rank(0.,1.e-8 ); // todo: should be an option
186  unsigned int cMatTildeRank14 = m_Cmat_tilde.rank(0.,1.e-14);
187  if (m_env.subDisplayFile()) {
188  *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::constructor()"
189  << ": m_Cmat_tilde.numRowsLocal() = " << m_Cmat_tilde.numRowsLocal()
190  << ", m_Cmat_tilde.numCols() = " << m_Cmat_tilde.numCols()
191  << ", m_Cmat_tilde.rank(0.,1.e-8) = " << cMatTildeRank
192  << ", m_Cmat_tilde.rank(0.,1.e-14) = " << cMatTildeRank14
193  << std::endl;
194  }
195  queso_require_equal_to_msg(cMatTildeRank, z.m_Cmat_rank, "'m_Cmat_tilde' should have full column rank");
196 
197  queso_require_less_msg(m_Lmat.numRowsGlobal(), m_Lmat.numCols(), "'m_Lmat' should be a 'horizontal' rectangular matrix");
198 
199  //******************************************************************************
200  // Tilde situation: form 'm_Lmat_t'
201  //******************************************************************************
202  m_Lmat_t.fillWithTranspose(0,0,m_Lmat,true,true);
203  unsigned int lMatRank = m_Lmat_t.rank(0.,1.e-8 ); // todo: should be an option
204  unsigned int lMatRank14 = m_Lmat_t.rank(0.,1.e-14);
205  if (m_env.subDisplayFile()) {
206  *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::commonConstructor()"
207  << ": m_Lmat.numRowsLocal() = " << m_Lmat.numRowsLocal()
208  << ", m_Lmat.numCols() = " << m_Lmat.numCols()
209  << ", m_Lmat.rank(0.,1.e-8) = " << lMatRank
210  << ", m_Lmat.rank(0.,1.e-14) = " << lMatRank14
211  << std::endl;
212  }
213 
214  queso_require_equal_to_msg(lMatRank, z.m_Cmat_rank, "'m_Lmat' should have full row rank");
215 
216  if (m_env.checkingLevel() >= 1) {
217  // Check if C == C_tilde * L
218  D_M tmpCmat(m_Cmat_tilde * m_Lmat);
219  tmpCmat -= *z.m_Cmat;
220  double cDiffNorm = tmpCmat.normFrob();
221  if (m_env.subDisplayFile()) {
222  *m_env.subDisplayFile() << "In GcmZTildeInfo<S_V,S_M,D_V,D_M,P_V,P_M,Q_V,Q_M>::commonConstructor()"
223  << ": ||tmpC - C||_2 = " << cDiffNorm
224  << std::endl;
225  }
226  }
227 
228  return;
229 }
230 
231 } // End namespace QUESO
232 
const BaseEnvironment & m_env
Definition: GcmZTildeInfo.h:56
unsigned int m_Cmat_rank
Definition: GcmZInfo.h:65
GcmZTildeInfo(const GpmsaComputerModelOptions &gcmOptionsObj, const GcmJointInfo< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M > &jj, const GcmZInfo< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M > &z)
Definition: GcmZTildeInfo.C:32
std::set< unsigned int > m_dataOutputAllowedSet
const V & zeroVector() const
Returns a vector filled with zeros.
Definition: VectorSpace.C:189
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
double scalarProduct(const GslVector &x, const GslVector &y)
Definition: GslVector.C:1150
VectorSpace< D_V, D_M > m_z_space
Definition: GcmZInfo.h:61
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
#define queso_require_less_msg(expr1, expr2, msg)
Definition: asserts.h:87
D_M * m_Cmat
Definition: GcmZInfo.h:64
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:295
VectorSpace< D_V, D_M > m_omega_space
Definition: GcmJointInfo.h:104
unsigned int checkingLevel() const
Access function to private attribute m_checkingLevel.
Definition: Environment.C:410
void commonConstructor(const GcmZInfo< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M > &z)

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