34 "Lanczos",
"Monomial-Proj-GS",
"Monomial-Proj-GS2",
"Monomial-GS",
"Lanczos-GS" };
42 "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" };
50 "None",
"Q Squared",
"Q Squared2",
"Q2" };
58 "TRSM",
"GLPK",
"Clp",
"Clp-IP",
"qpOASES",
"Basis Pursuit",
"Orthogonal Matching Pursuit" };
63 template <
class ScalarType>
68 for (
int i=0; i<n; i++)
74 template <
class ScalarType>
76 const ScalarType& y) {
80 for (
int i=0; i<n; i++)
90 for (
int i=0; i<n; i++) {
91 double ew =
std::abs(z.coeff(i)-z2.coeff(i));
92 if (ew > err_z) err_z = ew;
102 int nqp = quad.
size();
103 int npc = basis.
size();
104 double max_err = 0.0;
107 for (
int i=0; i<npc; ++i) {
108 for (
int j=0;
j<npc; ++
j) {
112 for (
int k=0; k<nqp; ++k)
113 err += weights[k]*vals[k][i]*vals[k][
j];
176 for (
int i=0; i<options.
d; i++)
189 #ifdef HAVE_STOKHOS_DAKOTA
190 if (options.
level == -1)
192 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(basis));
195 Teuchos::rcp(
new Stokhos::SparseGridQuadrature<int,double>(
196 basis, p, 1e-12, Pecos::SLOW_RESTRICTED_GROWTH));
206 basis->computeTripleProductTensor();
217 basis->evaluateBases(point, basis_vals);
219 for (
int i=0; i<options.
d; i++) {
221 x[i].reset(quad_exp);
222 x[i].term(i,1) = 1.0 / basis_vals[i+1];
225 for (
int i=0; i<options.
d2; i++) {
231 results.
z =
g(x2, y);
238 for (
int i=0; i<options.
d2; i++)
239 pces[i] = x2[i].getOrthogPolyApprox();
240 pces[options.
d2] = y.getOrthogPolyApprox();
243 params.
set(
"Reduced Basis Method",
"Monomial Proj Gram-Schmidt");
245 params.
set(
"Reduced Basis Method",
"Monomial Proj Gram-Schmidt2");
247 params.
set(
"Reduced Basis Method",
"Monomial Gram-Schmidt");
249 params.
set(
"Reduced Basis Method",
"Product Lanczos");
251 params.
set(
"Reduced Basis Method",
"Product Lanczos Gram-Schmidt");
256 params.
set(
"Orthogonalization Method",
260 params.
sublist(
"Reduced Quadrature");
262 "Reduced Quadrature Method",
268 red_quad_params.
set(
"Write MPS File",
false);
270 red_quad_params.
set(
"Verbose", options.
verbose);
274 "Orthogonalization Method",
276 red_quad_params.
set(
"Use Q in LP", options.
use_Q);
278 red_quad_params.
set(
"Order Restriction", 2*p);
283 gs_basis->getReducedQuadrature();
293 gs_Cijk = gs_basis->computeTripleProductTensor();
296 gs_exp_params->
set(
"Use Quadrature for Times",
true);
300 gs_basis, gs_Cijk, gs_quad, gs_exp_params));
304 for (
int i=0; i<options.
d2; i++) {
305 x2_gs[i].copyForWrite();
306 x2_gs[i].reset(gs_quad_exp);
307 gs_basis->transformFromOriginalBasis(x2[i].coeff(), x2_gs[i].coeff());
310 gs_basis->transformFromOriginalBasis(y.coeff(), y_gs.coeff());
317 gs_basis->transformToOriginalBasis(z_gs.coeff(), z2.coeff());
331 "This example runs a Gram-Schmidt-based dimension reduction example.\n");
335 CLP.
setOption(
"d", &options.
d,
"Stochastic dimension");
338 CLP.
setOption(
"d2", &options.
d2,
"Intermediate stochastic dimension");
344 CLP.
setOption(
"p_end", &options.
p_end,
"Ending polynomial order");
374 "Sparse grid level (set to -1 to use default)");
382 CLP.
setOption(
"orthogonalization_method",
387 "Orthogonalization method");
397 "Reduced quadrature solver method");
400 CLP.
setOption(
"quad_orthogonalization_method",
405 "Quadrature Orthogonalization method");
409 "Eliminate dependent rows in quadrature constraint matrix");
411 options.
use_Q =
true;
412 CLP.
setOption(
"use-Q",
"no-use-Q", &options.
use_Q,
"Use Q in LP");
416 "Restrict rank in LP");
420 "Value for LP objective function");
424 "Use Projected Lanczos Method");
428 "Use Old Stieltjes Method");
430 CLP.
parse( argc, argv );
432 std::cout <<
"Summary of command line options:" << std::endl
433 <<
"\tquadrature_method = "
436 <<
"\tlevel = " << options.
level
438 <<
"\treduced_basis_method = "
441 <<
"\torthogonalization_method = "
444 <<
"\tquadrature_reduction_method = "
447 <<
"\tsolver_method = "
449 <<
"\tquad_orthogonalization_method = "
454 <<
"\tuse-Q = " << options.
use_Q << std::endl
455 <<
"\trestrict-rank = " << options.
restrict_r << std::endl
457 <<
"\tproject = " << options.
project << std::endl
459 <<
"\tp_begin = " << options.
p_begin << std::endl
460 <<
"\tp_end = " << options.
p_end << std::endl
461 <<
"\tp_truth = " << options.
p_truth << std::endl
462 <<
"\td = " << options.
d << std::endl
463 <<
"\td2 = " << options.
d2 << std::endl
464 <<
"\tpole = " << options.
pole << std::endl
465 <<
"\tshift = " << options.
shift << std::endl
470 <<
"\tverbose = " << options.
verbose << std::endl
471 << std::endl << std::endl;
473 std::stringstream ss;
476 out.setFieldTypePrecision(TO::DOUBLE, 5);
477 out.pushFieldSpec(
"\"Order\"", TO::INT);
478 out.pushFieldSpec(
"\"Basis Size\"", TO::INT);
479 out.pushFieldSpec(
"\"Quad. Size\"", TO::INT);
480 out.pushFieldSpec(
"\"Red. Basis Size\"", TO::INT);
481 out.pushFieldSpec(
"\"Red. Quad. Size\"", TO::INT);
482 out.pushFieldSpec(
"\"Coeff. Error\"", TO::DOUBLE);
483 out.pushFieldSpec(
"\"Red. Coeff. Error\"", TO::DOUBLE);
484 out.pushFieldSpec(
"\"Disc. Orthog. Error\"", TO::DOUBLE);
492 for (
int i=0; i<n; ++i) {
495 results[i].mean_error =
496 std::abs(results_truth.
z.mean()-results[i].z.mean()) /
498 results[i].std_dev_error =
499 std::abs(results_truth.
z.standard_deviation()-results[i].z.standard_deviation()) /
std::abs(results_truth.
z.standard_deviation());
503 results[i].reduced_mean_error =
504 std::abs(results_truth.
z.mean()-results[i].z_red.mean()) /
506 results[i].reduced_std_dev_error =
507 std::abs(results_truth.
z.standard_deviation()-results[i].z_red.standard_deviation()) /
std::abs(results_truth.
z.standard_deviation());
508 results[i].reduced_coeff_error =
coeff_error(results_truth.
z,
512 out.outputField(results[i].basis_size);
513 out.outputField(results[i].quad_size);
514 out.outputField(results[i].reduced_basis_size);
515 out.outputField(results[i].reduced_quad_size);
517 out.outputField(results[i].reduced_coeff_error);
521 std::cout << std::endl << ss.str() << std::endl;
524 catch (std::exception& e) {
525 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
#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
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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