21 template <
typename ordinal_type,
typename scalar_type>
36 template <
typename ordinal_type,
typename scalar_type>
69 "This example runs a Stieltjes-based dimension reduction example.\n");
72 CLP.
setOption(
"n", &n,
"Number of random variables");
75 CLP.
setOption(
"m", &m,
"Number of intermediate variables");
78 CLP.
setOption(
"pmin", &pmin,
"Starting expansion order");
81 CLP.
setOption(
"pmax", &pmax,
"Final expansion order");
86 "Measure transformation method");
88 bool normalize =
false;
89 CLP.
setOption(
"normalize",
"unnormalize", &normalize,
90 "Normalize PC basis");
92 bool project_integrals =
false;
93 CLP.
setOption(
"project",
"no_project", &project_integrals,
96 #ifdef HAVE_STOKHOS_DAKOTA
97 bool sparse_grid =
true;
98 CLP.
setOption(
"sparse",
"tensor", &sparse_grid,
99 "Use Sparse or Tensor grid");
101 bool sparse_grid =
false;
104 double rank_threshold = 1.0e-12;
105 CLP.
setOption(
"rank_threshold", &rank_threshold,
"Rank threshold");
107 double reduction_tolerance = 1.0e-12;
108 CLP.
setOption(
"reduction_tolerance", &reduction_tolerance,
"Quadrature reduction tolerance");
110 bool verbose =
false;
111 CLP.
setOption(
"verbose",
"quient", &verbose,
114 CLP.
parse( argc, argv );
116 std::cout <<
"Summary of command line options:" << std::endl
117 <<
"\tm = " << m << std::endl
118 <<
"\tn = " << n << std::endl
120 <<
"\tnormalize = " << normalize << std::endl
121 <<
"\tproject = " << project_integrals << std::endl
122 <<
"\tsparse = " << sparse_grid << std::endl
123 <<
"\trank_threshold = " << rank_threshold << std::endl
124 <<
"\treduction_tolerance = " << reduction_tolerance << std::endl;
126 int np = pmax-pmin+1;
134 double pt_true = 0.0;
136 SDM0 B0(n,n), Q0, R0;
144 for (
int p=pmin; p<=pmax; p++) {
146 std::cout <<
"p = " << p;
149 for (
int i=0; i<n; i++)
153 std::cout <<
", basis sz = " << basis->size();
157 #ifdef HAVE_STOKHOS_DAKOTA
160 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(basis, p));
165 std::cout <<
", quad sz = " << quad->size();
169 basis->computeTripleProductTensor();
177 for (
int i=0; i<n; i++) {
179 x[i].reset(quad_exp);
183 x[i].term(i, 1) = 1.0;
188 for (
int i=0; i<m; i++)
189 for (
int j=0;
j<n;
j++)
203 for (
int i=0; i<n; i++)
204 x0[i] = x[i].evaluate(eval_pt);
210 params.
set(
"Verbose", verbose);
212 params.
set(
"Reduced Basis Method",
"Monomial Proj Gram-Schmidt");
214 params.
set(
"Reduced Basis Method",
"Product Lanczos");
216 params.
set(
"Reduced Basis Method",
"Product Lanczos");
217 params.
set(
"Use Old Stieltjes Method",
true);
219 params.
set(
"Project", project_integrals);
220 params.
set(
"Normalize", normalize);
221 params.
set(
"Rank Threshold", rank_threshold);
223 params.
sublist(
"Reduced Quadrature");
224 red_quad_params.
set(
"Reduction Tolerance", reduction_tolerance);
225 red_quad_params.
set(
"Verbose", verbose);
227 for (
int i=0; i<m; i++)
228 pces[i] = f[i].getOrthogPolyApprox();
233 gs_basis->getReducedQuadrature();
238 gs_exp_params->
set(
"Use Quadrature for Times",
true);
245 std::cout <<
", red. basis sz = " <<gs_basis->size();
246 std::cout <<
", red. quad sz = " << gs_quad->size();
249 for (
int i=0; i<m; i++) {
250 f_st(i).copyForWrite();
251 f_st(i).reset(st_quad_exp);
252 gs_basis->transformFromOriginalBasis(
f(i).coeff(), f_st(i).coeff());
260 gs_basis->transformToOriginalBasis(g_st.coeff(), g2.coeff());
266 mean[idx] = g.mean();
267 mean_st[idx] = g2.mean();
268 std_dev[idx] = g.standard_deviation();
269 std_dev_st[idx] = g2.standard_deviation();
270 pt[idx] = g.evaluate(eval_pt);
271 pt_st[idx] = g2.evaluate(eval_pt);
274 std::cout << std::endl;
279 std::cout <<
"Statistical error:" << std::endl;
281 << std::setw(wi) <<
"mean" <<
" "
282 << std::setw(wi) <<
"mean_st" <<
" "
283 << std::setw(wi) <<
"std_dev" <<
" "
284 << std::setw(wi) <<
"std_dev_st" <<
" "
285 << std::setw(wi) <<
"point" <<
" "
286 << std::setw(wi) <<
"point_st" << std::endl;
287 for (
int p=pmin; p<pmax; p++) {
288 std::cout.precision(3);
289 std::cout.setf(std::ios::scientific);
290 std::cout << p <<
" "
291 << std::setw(wi) <<
rel_err(mean[idx], mean[np-1]) <<
" "
292 << std::setw(wi) <<
rel_err(mean_st[idx], mean[np-1]) <<
" "
293 << std::setw(wi) <<
rel_err(std_dev[idx], std_dev[np-1]) <<
" "
294 << std::setw(wi) <<
rel_err(std_dev_st[idx], std_dev[np-1])
296 << std::setw(wi) <<
rel_err(pt[idx], pt_true) <<
" "
297 << std::setw(wi) <<
rel_err(pt_st[idx], pt_true)
303 catch (std::exception& e) {
304 std::cout << e.what() << std::endl;
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
Sacado::ETPCE::OrthogPoly< double, Stokhos::StandardStorage< int, double > > pce_type
void QR_MGS(ordinal_type k, const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, const Teuchos::Array< scalar_type > &w, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &Q, Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &R)
Compute thin QR using modified Gram-Schmidt.
Teuchos::SerialDenseVector< int, double > SDV0
Generate a basis from a given set of PCE expansions that is orthogonal with respect to the product me...
ScalarType dot(const SerialDenseVector< OrdinalType, ScalarType > &x) const
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::SerialDenseMatrix< int, pce_type > SDM
Stokhos::LegendreBasis< int, double > basis_type
Teuchos::SerialDenseVector< int, pce_type > SDV
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)
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
void f_func(const Teuchos::SerialDenseMatrix< ordinal_type, scalar_type > &A, const Teuchos::SerialDenseVector< ordinal_type, scalar_type > &x, double shift, Teuchos::SerialDenseVector< ordinal_type, scalar_type > &f)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
const MT_METHOD mt_method_values[]
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(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.
Teuchos::SerialDenseMatrix< int, double > SDM0
Legendre polynomial basis.
OrdinalType numCols() const
int main(int argc, char **argv)
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
void setDocString(const char doc_string[])
double rel_err(double a, double b)
scalar_type g_func(const Teuchos::SerialDenseVector< ordinal_type, scalar_type > &f)
const char * mt_method_names[]
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...
ScalarType g(const Teuchos::Array< ScalarType > &x, const ScalarType &y)