61 "This example runs a Gram-Schmidt-based dimension reduction example.\n");
64 CLP.
setOption(
"d", &d,
"Stochastic dimension");
67 CLP.
setOption(
"p", &p,
"Polynomial order");
69 CLP.
parse( argc, argv );
73 for (
int i=0; i<d; i++)
78 std::cout <<
"original basis size = " << basis->size() << std::endl;
83 for (
int i=0; i<d; i++) {
94 std::cout <<
"original quadrature size = " << quad->size() << std::endl;
98 basis->computeTripleProductTensor();
106 quad_exp.
times(w,v,u);
113 params.
set(
"Reduced Basis Method",
"Monomial Proj Gram-Schmidt");
118 gs_basis->getReducedQuadrature();
121 gs_basis->transformFromOriginalBasis(u.coeff(), u_gs.coeff());
122 gs_basis->transformFromOriginalBasis(v.coeff(), v_gs.coeff());
124 std::cout <<
"reduced basis size = " << gs_basis->size() << std::endl;
125 std::cout <<
"reduced quadrature size = " << gs_quad->size() << std::endl;
128 gs_basis->transformToOriginalBasis(u_gs.coeff(), u2.coeff());
129 gs_basis->transformToOriginalBasis(v_gs.coeff(), v2.
coeff());
132 for (
int i=0; i<basis->size(); i++) {
135 if (eu > err_u) err_u = eu;
136 if (ev > err_v) err_v = ev;
138 std::cout <<
"error in u transformation = " << err_u << std::endl;
139 std::cout <<
"error in v transformation = " << err_v << std::endl;
148 gs_exp_params->
set(
"Use Quadrature for Times",
true);
155 gs_quad_exp.
times(w_gs, u_gs, v_gs);
158 gs_basis->transformToOriginalBasis(w_gs.
coeff(), w2.
coeff());
160 std::cout.precision(12);
161 std::cout <<
"w = " << std::endl << w;
162 std::cout <<
"w2 = " << std::endl << w2;
163 std::cout <<
"w_gs = " << std::endl << w_gs;
166 for (
int i=0; i<basis->size(); i++) {
168 if (ew > err_w) err_w = ew;
171 std::cout.setf(std::ios::scientific);
172 std::cout <<
"w.mean() = " << w.mean() << std::endl
173 <<
"w2.mean() = " << w2.mean() << std::endl
175 <<
std::abs(w.mean()-w2.mean()) << std::endl
176 <<
"w.std_dev() = " << w.standard_deviation() << std::endl
177 <<
"w2.std_dev() = " << w2.standard_deviation() << std::endl
178 <<
"std_dev error = "
179 <<
std::abs(w.standard_deviation()-w2.standard_deviation())
181 <<
"w coeff error = " << err_w << std::endl;
184 catch (std::exception& e) {
185 std::cout << e.what() << std::endl;
void sin(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
void times(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a, const OrthogPolyApprox< ordinal_type, value_type, node_type > &b)
Generate a basis from a given set of PCE expansions that is orthogonal with respect to the product me...
void exp(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
pointer coeff()
Return coefficient array.
Stokhos::LegendreBasis< int, double > basis_type
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
virtual Teuchos::RCP< Stokhos::ReducedPCEBasis< ordinal_type, value_type > > createReducedBasis(ordinal_type p, const Teuchos::Array< Stokhos::OrthogPolyApprox< ordinal_type, value_type > > &pce, const Teuchos::RCP< const Stokhos::Quadrature< ordinal_type, value_type > > &quad, const Teuchos::RCP< const Stokhos::Sparse3Tensor< ordinal_type, value_type > > &Cijk) const
Get reduced quadrature object.
Legendre polynomial basis.
int main(int argc, char **argv)
void setDocString(const char doc_string[])
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...