27 "This example runs a Gram-Schmidt-based dimension reduction example.\n");
30 CLP.
setOption(
"d", &d,
"Stochastic dimension");
33 CLP.
setOption(
"p", &p,
"Polynomial order");
35 CLP.
parse( argc, argv );
39 for (
int i=0; i<d; i++)
44 std::cout <<
"original basis size = " << basis->size() << std::endl;
49 for (
int i=0; i<d; i++) {
60 std::cout <<
"original quadrature size = " << quad->size() << std::endl;
64 basis->computeTripleProductTensor();
72 quad_exp.
times(w,v,u);
79 params.
set(
"Reduced Basis Method",
"Monomial Proj Gram-Schmidt");
84 gs_basis->getReducedQuadrature();
87 gs_basis->transformFromOriginalBasis(u.coeff(), u_gs.coeff());
88 gs_basis->transformFromOriginalBasis(v.coeff(), v_gs.coeff());
90 std::cout <<
"reduced basis size = " << gs_basis->size() << std::endl;
91 std::cout <<
"reduced quadrature size = " << gs_quad->size() << std::endl;
94 gs_basis->transformToOriginalBasis(u_gs.coeff(), u2.coeff());
95 gs_basis->transformToOriginalBasis(v_gs.coeff(), v2.
coeff());
98 for (
int i=0; i<basis->size(); i++) {
101 if (eu > err_u) err_u = eu;
102 if (ev > err_v) err_v = ev;
104 std::cout <<
"error in u transformation = " << err_u << std::endl;
105 std::cout <<
"error in v transformation = " << err_v << std::endl;
114 gs_exp_params->
set(
"Use Quadrature for Times",
true);
121 gs_quad_exp.
times(w_gs, u_gs, v_gs);
124 gs_basis->transformToOriginalBasis(w_gs.
coeff(), w2.
coeff());
126 std::cout.precision(12);
127 std::cout <<
"w = " << std::endl << w;
128 std::cout <<
"w2 = " << std::endl << w2;
129 std::cout <<
"w_gs = " << std::endl << w_gs;
132 for (
int i=0; i<basis->size(); i++) {
134 if (ew > err_w) err_w = ew;
137 std::cout.setf(std::ios::scientific);
138 std::cout <<
"w.mean() = " << w.mean() << std::endl
139 <<
"w2.mean() = " << w2.mean() << std::endl
141 <<
std::abs(w.mean()-w2.mean()) << std::endl
142 <<
"w.std_dev() = " << w.standard_deviation() << std::endl
143 <<
"w2.std_dev() = " << w2.standard_deviation() << std::endl
144 <<
"std_dev error = "
145 <<
std::abs(w.standard_deviation()-w2.standard_deviation())
147 <<
"w coeff error = " << err_w << std::endl;
150 catch (std::exception& e) {
151 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 &&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...