68 "Lanczos",
"Monomial-Proj-GS",
"Monomial-Proj-GS2",
"Monomial-GS",
"Lanczos-GS" };
76 "Householder",
"Householder without Pivoting",
"Classical Gram-Schmidt",
"Modified Gram-Schmidt",
"Modified Gram-Schmidt with Reorthogonalization",
"Modified Gram-Schmidt without Pivoting",
"Modified Gram-Schmidt without Pivoting with Reorthogonalization",
"SVD" };
84 "None",
"Q Squared",
"Q Squared2",
"Q2" };
92 "TRSM",
"GLPK",
"Clp",
"Clp-IP",
"qpOASES",
"Basis Pursuit",
"Orthogonal Matching Pursuit" };
97 template <
class ScalarType>
102 for (
int i=0; i<n; i++)
108 template <
class ScalarType>
110 const ScalarType& y) {
114 for (
int i=0; i<n; i++)
124 for (
int i=0; i<n; i++) {
125 double ew =
std::abs(z.coeff(i)-z2.coeff(i));
126 if (ew > err_z) err_z = ew;
136 int nqp = quad.
size();
137 int npc = basis.
size();
138 double max_err = 0.0;
141 for (
int i=0; i<npc; ++i) {
142 for (
int j=0;
j<npc; ++
j) {
146 for (
int k=0; k<nqp; ++k)
147 err += weights[k]*vals[k][i]*vals[k][
j];
210 for (
int i=0; i<options.
d; i++)
223 #ifdef HAVE_STOKHOS_DAKOTA
224 if (options.
level == -1)
226 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(basis));
229 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(
230 basis, p, 1e-12, Pecos::SLOW_RESTRICTED_GROWTH));
240 basis->computeTripleProductTensor();
251 basis->evaluateBases(point, basis_vals);
253 for (
int i=0; i<options.
d; i++) {
255 x[i].reset(quad_exp);
256 x[i].term(i,1) = 1.0 / basis_vals[i+1];
259 for (
int i=0; i<options.
d2; i++) {
265 results.
z =
g(x2, y);
272 for (
int i=0; i<options.
d2; i++)
273 pces[i] = x2[i].getOrthogPolyApprox();
274 pces[options.
d2] = y.getOrthogPolyApprox();
277 params.
set(
"Reduced Basis Method",
"Monomial Proj Gram-Schmidt");
279 params.
set(
"Reduced Basis Method",
"Monomial Proj Gram-Schmidt2");
281 params.
set(
"Reduced Basis Method",
"Monomial Gram-Schmidt");
283 params.
set(
"Reduced Basis Method",
"Product Lanczos");
285 params.
set(
"Reduced Basis Method",
"Product Lanczos Gram-Schmidt");
290 params.
set(
"Orthogonalization Method",
294 params.
sublist(
"Reduced Quadrature");
296 "Reduced Quadrature Method",
302 red_quad_params.
set(
"Write MPS File",
false);
304 red_quad_params.
set(
"Verbose", options.
verbose);
308 "Orthogonalization Method",
310 red_quad_params.
set(
"Use Q in LP", options.
use_Q);
312 red_quad_params.
set(
"Order Restriction", 2*p);
317 gs_basis->getReducedQuadrature();
327 gs_Cijk = gs_basis->computeTripleProductTensor();
330 gs_exp_params->
set(
"Use Quadrature for Times",
true);
334 gs_basis, gs_Cijk, gs_quad, gs_exp_params));
338 for (
int i=0; i<options.
d2; i++) {
339 x2_gs[i].copyForWrite();
340 x2_gs[i].reset(gs_quad_exp);
341 gs_basis->transformFromOriginalBasis(x2[i].coeff(), x2_gs[i].coeff());
344 gs_basis->transformFromOriginalBasis(y.coeff(), y_gs.coeff());
351 gs_basis->transformToOriginalBasis(z_gs.coeff(), z2.coeff());
365 "This example runs a Gram-Schmidt-based dimension reduction example.\n");
369 CLP.
setOption(
"d", &options.
d,
"Stochastic dimension");
372 CLP.
setOption(
"d2", &options.
d2,
"Intermediate stochastic dimension");
378 CLP.
setOption(
"p_end", &options.
p_end,
"Ending polynomial order");
408 "Sparse grid level (set to -1 to use default)");
416 CLP.
setOption(
"orthogonalization_method",
421 "Orthogonalization method");
431 "Reduced quadrature solver method");
434 CLP.
setOption(
"quad_orthogonalization_method",
439 "Quadrature Orthogonalization method");
443 "Eliminate dependent rows in quadrature constraint matrix");
445 options.
use_Q =
true;
446 CLP.
setOption(
"use-Q",
"no-use-Q", &options.
use_Q,
"Use Q in LP");
450 "Restrict rank in LP");
454 "Value for LP objective function");
458 "Use Projected Lanczos Method");
462 "Use Old Stieltjes Method");
464 CLP.
parse( argc, argv );
466 std::cout <<
"Summary of command line options:" << std::endl
467 <<
"\tquadrature_method = "
470 <<
"\tlevel = " << options.
level
472 <<
"\treduced_basis_method = "
475 <<
"\torthogonalization_method = "
478 <<
"\tquadrature_reduction_method = "
481 <<
"\tsolver_method = "
483 <<
"\tquad_orthogonalization_method = "
488 <<
"\tuse-Q = " << options.
use_Q << std::endl
489 <<
"\trestrict-rank = " << options.
restrict_r << std::endl
491 <<
"\tproject = " << options.
project << std::endl
493 <<
"\tp_begin = " << options.
p_begin << std::endl
494 <<
"\tp_end = " << options.
p_end << std::endl
495 <<
"\tp_truth = " << options.
p_truth << std::endl
496 <<
"\td = " << options.
d << std::endl
497 <<
"\td2 = " << options.
d2 << std::endl
498 <<
"\tpole = " << options.
pole << std::endl
499 <<
"\tshift = " << options.
shift << std::endl
504 <<
"\tverbose = " << options.
verbose << std::endl
505 << std::endl << std::endl;
507 std::stringstream ss;
510 out.setFieldTypePrecision(TO::DOUBLE, 5);
511 out.pushFieldSpec(
"\"Order\"", TO::INT);
512 out.pushFieldSpec(
"\"Basis Size\"", TO::INT);
513 out.pushFieldSpec(
"\"Quad. Size\"", TO::INT);
514 out.pushFieldSpec(
"\"Red. Basis Size\"", TO::INT);
515 out.pushFieldSpec(
"\"Red. Quad. Size\"", TO::INT);
516 out.pushFieldSpec(
"\"Coeff. Error\"", TO::DOUBLE);
517 out.pushFieldSpec(
"\"Red. Coeff. Error\"", TO::DOUBLE);
518 out.pushFieldSpec(
"\"Disc. Orthog. Error\"", TO::DOUBLE);
526 for (
int i=0; i<n; ++i) {
529 results[i].mean_error =
530 std::abs(results_truth.
z.mean()-results[i].z.mean()) /
532 results[i].std_dev_error =
533 std::abs(results_truth.
z.standard_deviation()-results[i].z.standard_deviation()) /
std::abs(results_truth.
z.standard_deviation());
537 results[i].reduced_mean_error =
538 std::abs(results_truth.
z.mean()-results[i].z_red.mean()) /
540 results[i].reduced_std_dev_error =
541 std::abs(results_truth.
z.standard_deviation()-results[i].z_red.standard_deviation()) /
std::abs(results_truth.
z.standard_deviation());
542 results[i].reduced_coeff_error =
coeff_error(results_truth.
z,
546 out.outputField(results[i].basis_size);
547 out.outputField(results[i].quad_size);
548 out.outputField(results[i].reduced_basis_size);
549 out.outputField(results[i].reduced_quad_size);
551 out.outputField(results[i].reduced_coeff_error);
555 std::cout << std::endl << ss.str() << std::endl;
558 catch (std::exception& e) {
559 std::cout << e.what() << std::endl;
static const Reduced_Basis_Method reduced_basis_method_values[]
double reduction_tolerance
static const Quadrature_Reduction_Method quad_reduction_method_values[]
Orthogonalization_Method quad_orthogonalization_method
Sacado::ETPCE::OrthogPoly< double, Stokhos::StandardStorage< int, double > > pce_type
static const int num_quadrature_method
double reduced_std_dev_error
static const int num_reduced_basis_method
Generate a basis from a given set of PCE expansions that is orthogonal with respect to the product me...
static const int num_orthogonalization_method
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
double reduced_mean_error
virtual ordinal_type size() const =0
Get number of quadrature points.
virtual const Teuchos::Array< Teuchos::Array< value_type > > & getBasisAtQuadPoints() const =0
Get values of basis at quadrature points.
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
static const int num_quad_reduction_method
Quadrature_Method quad_method
static const char * orthogonalization_method_names[]
static const char * reduced_basis_method_names[]
Stokhos::LegendreBasis< int, double > basis_type
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
virtual const Teuchos::Array< value_type > & getQuadWeights() const =0
Get quadrature weights.
Quadrature_Reduction_Method
Quadrature_Reduction_Method quad_reduction_method
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
double reduced_coeff_error
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)
double disc_orthog_error(const Stokhos::OrthogPolyBasis< int, double > &basis, const Stokhos::Quadrature< int, double > &quad)
Solver_Method solver_method
virtual const Teuchos::Array< value_type > & norm_squared() const =0
Return array storing norm-squared of each basis polynomial.
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.
Legendre polynomial basis.
Orthogonalization_Method orthogonalization_method
double coeff_error(const pce_type &z, const pce_type &z2)
static const Solver_Method solver_method_values[]
static const int num_solver_method
int main(int argc, char **argv)
static const char * quadrature_method_names[]
static const char * quad_reduction_method_names[]
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
void setDocString(const char doc_string[])
static const char * solver_method_names[]
bool eliminate_dependent_rows
static const Quadrature_Method quadrature_method_values[]
static const Orthogonalization_Method orthogonalization_method_values[]
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...
void compute_pces(bool compute_z_red, int p, const MyOptions &options, MyResults &results)
virtual ordinal_type size() const =0
Return total size of basis.
ScalarType g(const Teuchos::Array< ScalarType > &x, const ScalarType &y)
Reduced_Basis_Method reduced_basis_method