diff --git a/modules/stochastic_tools/doc/content/source/surrogates/PolynomialChaos.md b/modules/stochastic_tools/doc/content/source/surrogates/PolynomialChaos.md index 192222acf5f2..79aee2ee0193 100644 --- a/modules/stochastic_tools/doc/content/source/surrogates/PolynomialChaos.md +++ b/modules/stochastic_tools/doc/content/source/surrogates/PolynomialChaos.md @@ -6,7 +6,7 @@ Polynomial chaos is a surrogate modeling technique where a quantity of interest (QoI) that is dependent on input parameters is expanded as a sum of orthogonal polynomials. Given a QoI $Q$ dependent on a set of parameters $\vec{\xi}$, the polynomial chaos expansion (PCE) is: -!equation +!equation id=eq:expansion Q(\vec{\xi}) = \sum_{i=1}^{P}q_i\Phi_i(\vec{\xi}) , @@ -42,20 +42,47 @@ The weighting functions are defined by the probability density function of the p | Exponential | $e^{-\xi}$ | Laguerre | $[0,\infty]$ | | Gamma | $\frac{\xi^{\alpha}e^{-\xi}}{\Gamma(\alpha+1)}$ | Generalized Laguerre | $[0,\infty]$ | -The expression in [eq:coeff] can be integrated using many different techniques. One is performing a Monte Carlo integration, +## Computing Coefficients -!equation -q_i = \frac{1}{\left\langle\Phi_i(\vec{\xi}),\Phi_i(\vec{\xi})\right\rangle} \frac{1}{N_{\mathrm{mc}}}\sum_{n=1}^{N_{\mathrm{mc}}} Q(\vec{\xi}_n)\Phi_i(\vec{\xi}_n) , +There are currently two techniques to compute the coefficients in [!eqref](eq:expansion), the first performs the integration described by [!eqref](eq:coeff). For Monte Carlo sampling, the integration is in the form +!equation +q_i = \frac{1}{\left\langle\Phi_i(\vec{\xi}),\Phi_i(\vec{\xi})\right\rangle} \frac{1}{N_{\mathrm{mc}}}\sum_{n=1}^{N_{\mathrm{mc}}} Q(\vec{\xi}_n)\Phi_i(\vec{\xi}_n) . -or using numerical quadrature, +And for using a [QuadratureSampler.md] !equation q_i = \frac{1}{\left\langle\Phi_i(\vec{\xi}),\Phi_i(\vec{\xi})\right\rangle}\sum_{n=1}^{N_q} w_n Q(\vec{\xi}_n)\Phi_i(\vec{\xi}_n) . - The numerical quadrature method is typically much more efficient that than the Monte Carlo method and has the added benefit of exactly integrating the polynomial basis. However, the quadrature suffers from the curse of dimensionality. The naive approach uses a Cartesian product of one-dimensional quadratures, which results in $(\max(k^d_i) + 1)^D$ quadrature points to be sampled. Sparse grids can help mitigate the curse of dimensionality significantly. +The other technique is using ordinary least-squares (OLS) regression, like in [PolynomialRegressionTrainer.md]. In the majority of cases, OLS is more accurate than integration for Monte Carlo sampling, as shown in the figure below. + +!plot scatter caption=Comparison between OLS regression and integration methods for computing polynomial chaos coefficients + data=[{'name': 'OLS', + 'type': 'scatter', + 'x': [16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192], + 'y': [81.6696267803207, 8.454300942177698, 4.926398159556231, + 2.874495194734781, 2.2416013478899863, 1.3479621256735075, + 1.1574930187341494, 0.6939367594300845, 0.5817680465237121, + 0.417989501880757]}, + {'name': 'OLS with Regularization (penalty = 1)', + 'type': 'scatter', + 'x': [16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192], + 'y': [4.91600612112163, 3.94911986807379, 3.4242180431008484, + 2.7094356794174708, 1.6871974555746947, 1.3923862418279123, + 1.1994658425158664, 1.0696251119444582, 0.9079419204733286, + 0.8692326803241464]}, + {'name': 'Integration', + 'type': 'scatter', + 'x': [16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192], + 'y': [80.62685305548119, 57.810722889054325, 45.68405898596861, + 35.58856802819979, 19.925532186155436, 15.879940134036879, + 11.862525598455559, 8.760052389181865, 4.967900255917786, + 3.9340295519499127]}] + layout={'xaxis': {'title': 'Number of Samples', 'type': 'log'}, + 'yaxis': {'title': 'Coefficient RRMSE', 'type': 'log'}} + ## Generating a Tuple In polynomial chaos, a tuple describes the combination of polynomial orders representing the expansion basis ($k_{d,i}$). Again, the naive approach would be to do a tensor product of highest polynomial order, but this is often wasteful since generating a complete monomial basis is usually optimal. Below demonstrates the difference between a tensor basis and a complete monomial basis: diff --git a/modules/stochastic_tools/examples/surrogates/poly_chaos_normal_mc.i b/modules/stochastic_tools/examples/surrogates/poly_chaos_normal_mc.i index c55b2d47479c..517900bf731d 100644 --- a/modules/stochastic_tools/examples/surrogates/poly_chaos_normal_mc.i +++ b/modules/stochastic_tools/examples/surrogates/poly_chaos_normal_mc.i @@ -71,6 +71,7 @@ type = PolynomialChaosTrainer execute_on = timestep_end order = 10 + regression_type = integration distributions = 'k_dist q_dist L_dist Tinf_dist' sampler = sample response = results/data:avg:value @@ -79,6 +80,7 @@ type = PolynomialChaosTrainer execute_on = timestep_end order = 10 + regression_type = integration distributions = 'k_dist q_dist L_dist Tinf_dist' sampler = sample response = results/data:max:value diff --git a/modules/stochastic_tools/examples/surrogates/poly_chaos_uniform_mc.i b/modules/stochastic_tools/examples/surrogates/poly_chaos_uniform_mc.i index 1a357720b174..ad5528d34ff2 100644 --- a/modules/stochastic_tools/examples/surrogates/poly_chaos_uniform_mc.i +++ b/modules/stochastic_tools/examples/surrogates/poly_chaos_uniform_mc.i @@ -71,6 +71,7 @@ type = PolynomialChaosTrainer execute_on = timestep_end order = 10 + regression_type = integration distributions = 'k_dist q_dist L_dist Tinf_dist' sampler = sample response = results/data:avg:value @@ -79,6 +80,7 @@ type = PolynomialChaosTrainer execute_on = timestep_end order = 10 + regression_type = integration distributions = 'k_dist q_dist L_dist Tinf_dist' sampler = sample response = results/data:max:value diff --git a/modules/stochastic_tools/include/surrogates/PolynomialChaosTrainer.h b/modules/stochastic_tools/include/surrogates/PolynomialChaosTrainer.h index 72c1e6ad3758..a5ed27b04208 100644 --- a/modules/stochastic_tools/include/surrogates/PolynomialChaosTrainer.h +++ b/modules/stochastic_tools/include/surrogates/PolynomialChaosTrainer.h @@ -13,9 +13,12 @@ #include "PolynomialQuadrature.h" #include "QuadratureSampler.h" #include "MultiDimPolynomialGenerator.h" +#include "Calculators.h" #include "Distribution.h" +typedef StochasticTools::Calculator, Real> RealCalculator; + class PolynomialChaosTrainer : public SurrogateTrainer { public: @@ -47,6 +50,22 @@ class PolynomialChaosTrainer : public SurrogateTrainer /// The distributions used for sampling std::vector> & _poly; + /// The method in which to perform the regression (0=integration, 1=OLS) + unsigned int _rtype; + + /// The penalty parameter for Ridge regularization + const Real & _ridge_penalty; + /// QuadratureSampler pointer, necessary for applying quadrature weights QuadratureSampler * _quad_sampler; + + /// Calculators used for standardization in linear regression + std::vector> _calculators; + Real _r_sum; + + ///@{ + /// Matrix and rhs for the regression problem + DenseMatrix _matrix; + DenseVector _rhs; + ///@} }; diff --git a/modules/stochastic_tools/src/surrogates/PolynomialChaosTrainer.C b/modules/stochastic_tools/src/surrogates/PolynomialChaosTrainer.C index 9043d4373a96..5f528d20a659 100644 --- a/modules/stochastic_tools/src/surrogates/PolynomialChaosTrainer.C +++ b/modules/stochastic_tools/src/surrogates/PolynomialChaosTrainer.C @@ -21,6 +21,12 @@ PolynomialChaosTrainer::validParams() params.addRequiredParam("order", "Maximum polynomial order."); params.addRequiredParam>( "distributions", "Names of the distributions samples were taken from."); + MooseEnum rtype("integration ols auto", "auto"); + params.addParam( + "regression_type", + rtype, + "The type of regression to perform for finding polynomial coefficents."); + params.addParam("penalty", 0.0, "Ridge regularization penalty factor for OLS regression."); params.suppressParameter("response_type"); return params; @@ -37,6 +43,7 @@ PolynomialChaosTrainer::PolynomialChaosTrainer(const InputParameters & parameter _coeff(declareModelData>("_coeff")), _poly(declareModelData>>( "_poly")), + _ridge_penalty(getParam("penalty")), _quad_sampler(dynamic_cast(&_sampler)) { // Check if number of distributions is correct @@ -44,53 +51,153 @@ PolynomialChaosTrainer::PolynomialChaosTrainer(const InputParameters & parameter paramError("distributions", "Sampler number of columns does not match number of inputted distributions."); - if (_quad_sampler && (!_pvals.empty() || _pcols.size() != _sampler.getNumberOfCols())) + auto rtype_enum = getParam("regression_type"); + if (rtype_enum == "auto") + _rtype = _quad_sampler ? 0 : 1; + else + _rtype = rtype_enum == "integration" ? 0 : 1; + + if (_rtype == 0 && _quad_sampler && + (!_pvals.empty() || _pcols.size() != _sampler.getNumberOfCols())) paramError("sampler", "QuadratureSampler must use all Sampler columns for training, and cannot be" " used with other Reporters - otherwise, quadrature integration does not work."); + if (_rtype == 0 && _ridge_penalty != 0.0) + paramError("penalty", + "Ridge regularization penalty is only relevant if 'regression_type = ols'."); // Make polynomials for (const auto & nm : getParam>("distributions")) _poly.push_back(PolynomialQuadrature::makePolynomial(&getDistributionByName(nm))); + + // Create calculators for standardization + if (_rtype == 1) + { + _calculators.resize(_ncoeff * 3); + for (const auto & term : make_range(_ncoeff)) + { + _calculators[3 * term] = StochasticTools::makeCalculator(MooseEnumItem("mean"), *this); + _calculators[3 * term + 1] = StochasticTools::makeCalculator(MooseEnumItem("stddev"), *this); + _calculators[3 * term + 2] = StochasticTools::makeCalculator(MooseEnumItem("sum"), *this); + } + } } void PolynomialChaosTrainer::preTrain() { - _coeff.clear(); - _coeff.resize(_ncoeff, 0.0); + _coeff.assign(_ncoeff, 0.0); + + if (_rtype == 1) + { + if (getCurrentSampleSize() < _ncoeff) + paramError("order", + "Number of data points (", + getCurrentSampleSize(), + ") must be greater than the number of terms in the polynomial (", + _ncoeff, + ")."); + _matrix.resize(_ncoeff, _ncoeff); + _rhs.resize(_ncoeff); + for (auto & calc : _calculators) + calc->initializeCalculator(); + _r_sum = 0.0; + } } void PolynomialChaosTrainer::train() { - DenseMatrix poly_val(_ndim, _order); - // Evaluate polynomials to avoid duplication + DenseMatrix poly_val(_ndim, _order); for (unsigned int d = 0; d < _ndim; ++d) for (unsigned int i = 0; i < _order; ++i) - poly_val(d, i) = _poly[d]->compute(i, _predictor_row[d]); + poly_val(d, i) = _poly[d]->compute(i, _predictor_row[d], /*normalize=*/_rtype == 0); + + // Evaluate multi-dimensional polynomials + std::vector basis(_ncoeff, 1.0); + for (const auto i : make_range(_ncoeff)) + for (const auto d : make_range(_ndim)) + basis[i] *= poly_val(d, _tuple[i][d]); - // Loop over coefficients - for (std::size_t i = 0; i < _ncoeff; ++i) + // For integration + if (_rtype == 0) { - Real val = *_rval; - // Loop over parameters - for (std::size_t d = 0; d < _ndim; ++d) - val *= poly_val(d, _tuple[i][d]); - - if (_quad_sampler) - val *= _quad_sampler->getQuadratureWeight(_row); - _coeff[i] += val; + const Real fact = (*_rval) * (_quad_sampler ? _quad_sampler->getQuadratureWeight(_row) : 1.0); + for (const auto i : make_range(_ncoeff)) + _coeff[i] += fact * basis[i]; + } + // For least-squares + else + { + // Loop over coefficients + for (const auto i : make_range(_ncoeff)) + { + // Matrix is symmetric, so we'll add the upper diagonal later + for (const auto j : make_range(i + 1)) + _matrix(i, j) += basis[i] * basis[j]; + _rhs(i) += basis[i] * (*_rval); + + for (unsigned int c = i * 3; c < (i + 1) * 3; ++c) + _calculators[c]->updateCalculator(basis[i]); + } + _r_sum += (*_rval); + + if (_ridge_penalty != 0.0) + for (const auto i : make_range(_ncoeff)) + _matrix(i, i) += _ridge_penalty; } } void PolynomialChaosTrainer::postTrain() { - gatherSum(_coeff); + if (_rtype == 0) + { + gatherSum(_coeff); + if (!_quad_sampler) + for (std::size_t i = 0; i < _ncoeff; ++i) + _coeff[i] /= getCurrentSampleSize(); + } + else + { + gatherSum(_matrix.get_values()); + gatherSum(_rhs.get_values()); + for (auto & calc : _calculators) + calc->finalizeCalculator(true); + gatherSum(_r_sum); + + std::vector mu(_ncoeff); + std::vector sig(_ncoeff); + std::vector sum_pf(_ncoeff); + for (const auto i : make_range(_ncoeff)) + { + mu[i] = i > 0 ? _calculators[3 * i]->getValue() : 0.0; + sig[i] = i > 0 ? _calculators[3 * i + 1]->getValue() : 1.0; + sum_pf[i] = _calculators[3 * i + 2]->getValue(); + } + + const Real n = getCurrentSampleSize(); + for (const auto i : make_range(_ncoeff)) + { + for (const auto j : make_range(i + 1)) + { + _matrix(i, j) -= (mu[j] * sum_pf[i] + mu[i] * sum_pf[j]); + _matrix(i, j) += n * mu[i] * mu[j]; + _matrix(i, j) /= (sig[i] * sig[j]); + _matrix(j, i) = _matrix(i, j); + } + _rhs(i) = (_rhs(i) - mu[i] * _r_sum) / sig[i]; + } - if (!_quad_sampler) - for (std::size_t i = 0; i < _ncoeff; ++i) - _coeff[i] /= getCurrentSampleSize(); + DenseVector sol; + _matrix.lu_solve(_rhs, sol); + _coeff = sol.get_values(); + + for (unsigned int i = 1; i < _ncoeff; ++i) + { + _coeff[i] /= sig[i]; + _coeff[0] -= _coeff[i] * mu[i]; + } + } } diff --git a/modules/stochastic_tools/test/tests/surrogates/poly_chaos/gold/ols_test_out.json b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/gold/ols_test_out.json new file mode 100644 index 000000000000..6037feebbe23 --- /dev/null +++ b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/gold/ols_test_out.json @@ -0,0 +1,295 @@ +{ + "reporters": { + "stats": { + "type": "PolynomialChaosReporter", + "values": { + "model_ols": { + "type": "PolynomialChaos const*" + }, + "model_pet_ols": { + "type": "PolynomialChaos const*" + } + } + } + }, + "time_steps": [ + { + "stats": { + "model_ols": { + "coeff": [ + 0.6369616873214548, + 0.8158535541215317, + 0.6066357757671793, + 0.016527635528528897, + 0.2697867137638702, + 0.7296554464299438, + 0.03358557530546633, + 0.8574042765875708, + 0.0027385001701490247, + 0.9350724237877677, + 0.5436249914654226, + 0.7294965609839985, + 0.9127555772777215, + 0.8132702392002721, + 0.04097352393619476 + ], + "ncoeff": 15, + "ndim": 4, + "order": 3, + "poly": [ + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + } + ], + "tuple": [ + [ + 0, + 0, + 0, + 0 + ], + [ + 1, + 0, + 0, + 0 + ], + [ + 0, + 1, + 0, + 0 + ], + [ + 0, + 0, + 1, + 0 + ], + [ + 0, + 0, + 0, + 1 + ], + [ + 2, + 0, + 0, + 0 + ], + [ + 1, + 1, + 0, + 0 + ], + [ + 1, + 0, + 1, + 0 + ], + [ + 1, + 0, + 0, + 1 + ], + [ + 0, + 2, + 0, + 0 + ], + [ + 0, + 1, + 1, + 0 + ], + [ + 0, + 1, + 0, + 1 + ], + [ + 0, + 0, + 2, + 0 + ], + [ + 0, + 0, + 1, + 1 + ], + [ + 0, + 0, + 0, + 2 + ] + ] + }, + "model_pet_ols": { + "coeff": [ + 0.6587883122686778, + 0.8705598620905003, + 0.5915939743144034, + 0.05263693119377235, + 0.27073482499501883, + 0.7133913320478017, + 0.057010209094325213, + 0.867430331594636, + 0.004910016746810539, + 0.9129727203565754, + 0.5763052807613276, + 0.8283040131333552, + 0.9067376813828478, + 0.8450460573001629, + 0.012756457748452528 + ], + "ncoeff": 15, + "ndim": 4, + "order": 3, + "poly": [ + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + } + ], + "tuple": [ + [ + 0, + 0, + 0, + 0 + ], + [ + 1, + 0, + 0, + 0 + ], + [ + 0, + 1, + 0, + 0 + ], + [ + 0, + 0, + 1, + 0 + ], + [ + 0, + 0, + 0, + 1 + ], + [ + 2, + 0, + 0, + 0 + ], + [ + 1, + 1, + 0, + 0 + ], + [ + 1, + 0, + 1, + 0 + ], + [ + 1, + 0, + 0, + 1 + ], + [ + 0, + 2, + 0, + 0 + ], + [ + 0, + 1, + 1, + 0 + ], + [ + 0, + 1, + 0, + 1 + ], + [ + 0, + 0, + 2, + 0 + ], + [ + 0, + 0, + 1, + 1 + ], + [ + 0, + 0, + 0, + 2 + ] + ] + } + }, + "time": 1.0, + "time_step": 1 + } + ] +} diff --git a/modules/stochastic_tools/test/tests/surrogates/poly_chaos/gold/ridge_test_out.json b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/gold/ridge_test_out.json new file mode 100644 index 000000000000..93e487a74f57 --- /dev/null +++ b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/gold/ridge_test_out.json @@ -0,0 +1,303 @@ +{ + "app_name": "main", + "current_time": "Thu Jul 6 10:11:22 2023", + "executable": "/Users/prinzm/projects/moose/modules/stochastic_tools/test/tests/surrogates/poly_chaos/../../../../stochastic_tools-opt", + "executable_time": "Thu Jul 6 09:49:33 2023", + "libmesh_version": "", + "moose_version": "git commit ab3f6df228 on 2023-06-29", + "petsc_version": "3.16.6", + "reporters": { + "stats": { + "type": "PolynomialChaosReporter", + "values": { + "model_ols": { + "type": "PolynomialChaos const*" + }, + "model_pet_ols": { + "type": "PolynomialChaos const*" + } + } + } + }, + "slepc_version": "3.16.2", + "time_steps": [ + { + "stats": { + "model_ols": { + "coeff": [ + 0.31457843096156746, + 0.24083396773631338, + 0.11465842944128411, + 0.01083631744383195, + 0.1465065015893934, + 0.12290301951321941, + -0.021546628651270217, + 0.14667654541057476, + 0.04475259380145579, + 0.12576761523291627, + -0.029275332699672744, + 0.019753953198892223, + 0.1354131783232185, + 0.1401677393969815, + 0.03197555723360114 + ], + "ncoeff": 15, + "ndim": 4, + "order": 3, + "poly": [ + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + } + ], + "tuple": [ + [ + 0, + 0, + 0, + 0 + ], + [ + 1, + 0, + 0, + 0 + ], + [ + 0, + 1, + 0, + 0 + ], + [ + 0, + 0, + 1, + 0 + ], + [ + 0, + 0, + 0, + 1 + ], + [ + 2, + 0, + 0, + 0 + ], + [ + 1, + 1, + 0, + 0 + ], + [ + 1, + 0, + 1, + 0 + ], + [ + 1, + 0, + 0, + 1 + ], + [ + 0, + 2, + 0, + 0 + ], + [ + 0, + 1, + 1, + 0 + ], + [ + 0, + 1, + 0, + 1 + ], + [ + 0, + 0, + 2, + 0 + ], + [ + 0, + 0, + 1, + 1 + ], + [ + 0, + 0, + 0, + 2 + ] + ] + }, + "model_pet_ols": { + "coeff": [ + 0.3218385578019423, + 0.2523296083301419, + 0.11341238833558517, + 0.02235142493877989, + 0.14994948618158732, + 0.120664974464419, + -0.01845253763362933, + 0.14683361051452376, + 0.0461526418095108, + 0.12086802434400433, + -0.026512987214038376, + 0.028543394112937215, + 0.13384136168248167, + 0.1424221168710075, + 0.029900826025355872 + ], + "ncoeff": 15, + "ndim": 4, + "order": 3, + "poly": [ + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + }, + { + "lower_bound": 0.0, + "type": "Legendre", + "upper_bound": 1.0 + } + ], + "tuple": [ + [ + 0, + 0, + 0, + 0 + ], + [ + 1, + 0, + 0, + 0 + ], + [ + 0, + 1, + 0, + 0 + ], + [ + 0, + 0, + 1, + 0 + ], + [ + 0, + 0, + 0, + 1 + ], + [ + 2, + 0, + 0, + 0 + ], + [ + 1, + 1, + 0, + 0 + ], + [ + 1, + 0, + 1, + 0 + ], + [ + 1, + 0, + 0, + 1 + ], + [ + 0, + 2, + 0, + 0 + ], + [ + 0, + 1, + 1, + 0 + ], + [ + 0, + 1, + 0, + 1 + ], + [ + 0, + 0, + 2, + 0 + ], + [ + 0, + 0, + 1, + 1 + ], + [ + 0, + 0, + 0, + 2 + ] + ] + } + }, + "time": 1.0, + "time_step": 1 + } + ] +} diff --git a/modules/stochastic_tools/test/tests/surrogates/poly_chaos/main_2d_mc.i b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/main_2d_mc.i index 99fd0e0dec59..0a4adc60d2ee 100644 --- a/modules/stochastic_tools/test/tests/surrogates/poly_chaos/main_2d_mc.i +++ b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/main_2d_mc.i @@ -77,6 +77,7 @@ distributions = 'D_dist S_dist' sampler = sample response = storage/data:avg:value + regression_type = integration [] [] diff --git a/modules/stochastic_tools/test/tests/surrogates/poly_chaos/ols_test.csv b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/ols_test.csv new file mode 100644 index 000000000000..b7fd650e2982 --- /dev/null +++ b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/ols_test.csv @@ -0,0 +1,101 @@ +x_0,x_1,x_2,x_3,y,y_pet +0.17565562060255901,0.8631789223498866,0.5414612202490917,0.2997118905373848,0.08451495833833284,0.09424164148201741 +0.42268722119765845,0.028319671145462966,0.12428327649956394,0.6706244146936303,0.8099364575783192,0.7787722063703351 +0.6471895115742501,0.6153851114812539,0.38367755426188344,0.997209935789211,0.17119111593964476,0.17390317536639494 +0.9808353387762301,0.6855419844806947,0.6504592762678163,0.6884467305709401,2.2981893351786344,2.310448740224994 +0.3889214239791038,0.13509650502241122,0.7214883401940817,0.5253543224757259,-0.4687858188641847,-0.5203866722729773 +0.31024187555895566,0.4858353588317891,0.8894878343490003,0.9340435159562497,0.5498601531872227,0.5321795401679676 +0.35779519670907023,0.5715298307297609,0.32186939107594215,0.5943000301996968,-0.4566341016246265,-0.32114237484825203 +0.33791122550713326,0.39161900052816123,0.8902743520047923,0.22715759353337972,-0.7353835839129468,-0.6794901082107346 +0.6231871446860424,0.08401534358238483,0.8326441476533978,0.7870983074886834,0.6488070608196173,0.6607264460575857 +0.23936944299295215,0.8764842308107038,0.05856803480519435,0.3361170605456604,1.4983830197279608,1.432384011837195 +0.15027946689483906,0.450339366649287,0.7963242702872942,0.23064220899374743,-0.9953731412088969,-1.0719990411036258 +0.05202130106440961,0.4045518398215282,0.19851304450925533,0.0907530456191219,0.7677181554753032,0.8456666523306832 +0.5803323859868507,0.2986961328189226,0.6719948779563594,0.1995154439682133,-0.5240206305988,-0.5162770828979576 +0.9421131105064978,0.36511016824482856,0.10549527957022953,0.6291081515397092,1.0499815813410853,0.8935715586579639 +0.9271545530678674,0.440377154715784,0.9545904936907372,0.499895813687647,2.521310844570578,2.870301894823988 +0.42522862484907553,0.6202134520153778,0.9950965052353241,0.9489436749377653,1.98912620649233,2.2045592165019015 +0.4600451393090961,0.7577288453082914,0.49742269548761897,0.5293121601967704,-0.009819624477562072,-0.00952583001901027 +0.7857857007138075,0.4146558493556708,0.7344835717887294,0.7111428779897498,0.8148543875709957,0.9866491937998426 +0.9320596866133782,0.1149326332809052,0.7290151170763094,0.9274239286245599,1.7504659243599063,1.689396463886147 +0.9679261899246464,0.014706304965369288,0.8636400902455758,0.9811950400663443,2.8947233021773306,2.5655586069712863 +0.9572101796109636,0.1487640122324979,0.972628813822955,0.8899355557205206,3.3020609262499545,3.250590568746994 +0.8223738275430704,0.4799879238078322,0.23237291963930384,0.8018805787183079,0.29089526764625623,0.3222489403612772 +0.9235301597834695,0.2661302722922926,0.5389344076221869,0.4427528289745315,0.8617332258867334,0.7809497479706549 +0.931017315981155,0.040510711188434634,0.7320061956565608,0.6143732469489966,1.856823700042376,2.2191317968894824 +0.028365365113521057,0.7192197728267403,0.015991729523571974,0.7579510023564281,1.7858878412190031,1.6257783146251696 +0.512758723262078,0.9291042207970062,0.06608249672407474,0.8413172796123832,1.6550348733034927,1.8129950884303585 +0.0666900087671014,0.34430997880412517,0.4302987319478333,0.9660620807840702,-0.46441450213394964,-0.4897001243785733 +0.562231842228457,0.25886459317093224,0.24167571409434496,0.8881183206591798,-0.43741644255875833,-0.4306777334633802 +0.22586942841732438,0.1245547058352835,0.2883307570075776,0.5861230648127328,0.0631403612681143,0.06996288553194939 +0.5540905021732678,0.8097107759127777,0.5604759520061858,0.2884212144312105,0.08283144764787082,0.07040839716162323 +0.4128963426808927,0.8181209709709104,0.6265064624197535,0.9590776426974422,1.2245500621232959,1.390791523725883 +0.3694044110916809,0.5526115105212872,0.5939242016131683,0.84829120827506,-0.3350207123490117,-0.33288716547392516 +0.14547353818653175,0.40651033674812664,0.909958961662297,0.043066888568204176,-1.0864387064733385,-1.0275064413526127 +0.8227062801815019,0.41538403737122465,0.8298039852781027,0.009954560807291957,0.5430945928820659,0.5837818303438795 +0.36504615775827065,0.07863003716563988,0.6526145763366384,0.2738490985995572,-0.3413899488474924,-0.37757383585110776 +0.7026520706597863,0.9438014269420908,0.12681710226124776,0.8647782954007741,1.8845047214051873,2.029573033757822 +0.059464151600338466,0.38077050831088943,0.42977406117857664,0.48884954683346427,-0.44981313067651163,-0.5397534380309009 +0.9764623219360445,0.7756911881018284,0.308857362719261,0.26983678550080015,1.4900310154320087,1.6510625526820866 +0.8631202041893178,0.8813071727376899,0.5107065055436453,0.34429573096232524,1.5603093468674099,1.760576086400597 +0.9949173481609178,0.3159435453677002,0.18271237892656245,0.8800981213040697,0.9376329244629434,0.887013504240254 +0.812335398111254,0.6678894055713512,0.9584136317779519,0.9257145772144187,3.576870514679519,3.6149726904080657 +0.7482485033017541,0.8607014095476777,0.24714674032210748,0.1412465569010316,0.8649778993836226,0.9136746485285724 +0.670061849314936,0.7146185366547527,0.16705292878227218,0.395557273104876,0.49591849002885,0.49503861970528684 +0.9102557662160548,0.561400767550223,0.5783359149262727,0.19412977289079358,0.7137449607779556,0.7352740235450036 +0.5260222486178752,0.5234347273949199,0.08893564024627199,0.9819426931267062,-0.035303455536055184,-0.036807752602548476 +0.5713956004557744,0.006408882664310167,0.7726492012253886,0.9782657138401457,0.4701033601856996,0.5097915504375425 +0.5898700283209505,0.319681636282665,0.1875077157277849,0.6725266339168693,-0.14370610199895703,-0.14224592023685723 +0.19510739845680503,0.5776878925178592,0.6022391763796258,0.962423093124381,-0.10770524676369593,-0.10393772568254295 +0.07226526552987678,0.4999728236586185,0.7440974792826482,0.1772267404746588,-0.9962933952836313,-0.9137688541315496 +0.3880667317845192,0.06289549845497133,0.7258808637757768,0.08776788675948677,-0.2236687985829428,-0.20372352877836133 +0.3950917083579676,0.8735226311207321,0.4723003367500115,0.9126219336408856,1.1027448154346937,1.2320362666653137 +0.7659171177388724,0.9153239601117659,0.12740300904890633,0.07356290533063203,1.4428298172475809,1.4306348049387736 +0.07032625356921807,0.8688542943473193,0.6340699793474432,0.496571693798853,0.6302528938896939,0.6798502912409488 +0.16354341619648027,0.6737334377272737,0.318017387845798,0.7108798632659449,0.069206539109919,0.060227932932747544 +0.4603553288673248,0.5074698605445271,0.7896657324598704,0.09274547552338075,-0.8577554555116607,-0.6915080286918834 +0.5787585033235025,0.19723494729586855,0.8081367518135681,0.4888460361292599,0.03036459979314149,0.027179076255560687 +0.9886953333678197,0.18294332467571872,0.9630191401242673,0.800917036608609,3.336497980647973,3.7190698368131705 +0.4812604965752686,0.8135340641796355,0.6028489052411163,0.6551210639913803,0.6380730969742499,0.7062242449584724 +0.9136907627073889,0.06527041641129139,0.8349882039584006,0.3818147799662388,2.005207954391037,2.0717886001540293 +0.3255456161007044,0.9940267712099843,0.7811905020763782,0.48553513877958776,1.667757994255109,1.5339754261868996 +0.4226283964247812,0.8775289058717961,0.08681487221489415,0.708418756913866,1.2456250132456397,1.2293319090323365 +0.789154623705146,0.7991963797161148,0.3222867247398318,0.7966391827460546,1.1878047632537834,1.152436631632393 +0.22532844187566514,0.3623079504845691,0.41744811220437983,0.5414099836301646,-0.7138103340648356,-0.6891857801228594 +0.11261366554055718,0.40694780063930613,0.0003006901069229073,0.744380726347399,1.0910130794052404,0.8175975823638086 +0.851875912234257,0.13893167912019755,0.7037857692667978,0.8211030883946387,1.1147433250129883,1.0191065538026007 +0.9818283228717938,0.8437905623687267,0.42410648544401286,0.9796887085096565,2.760380052164933,2.7079027773476585 +0.9739844048523552,0.503676979200579,0.7534465385839052,0.9138376676731629,2.4768383890306493,2.852433045430599 +0.47614707196875306,0.8637862410970849,0.7015685660618728,0.2939242559745576,0.39155094451012445,0.3978448541727726 +0.7676522699834736,0.5706847858594991,0.09384515343330624,0.3913804263046642,0.7142435787050574,0.8143011249996917 +0.07374101339780592,0.4761669632169956,0.4285396081429238,0.42373744297044735,-0.47926017732548526,-0.46039137303485317 +0.5863003535907844,0.12269066017607344,0.9337689099568427,0.684050448075033,0.8198762656118062,0.7991589285761863 +0.8237813583927717,0.8968012322637599,0.5833200469234759,0.0402182209046007,1.0475211104067474,0.6390484523456752 +0.711486824117758,0.5690258542633582,0.8259572221703992,0.5321604734743441,0.9173228467985333,0.9598251973754846 +0.8132440953641924,0.9970102930724918,0.35055481136788813,0.1710214400206741,1.60434256317517,1.692115448736686 +0.3916747994539028,0.7530499898656764,0.43922893185830647,0.5883801094292148,-0.03040891114060673,-0.035772310422573755 +0.12735847192167105,0.7261235109339803,0.28008240186649946,0.19061756040401823,0.18309620306081076,0.17418379011146576 +0.8629499985831945,0.5644128211205941,0.48449894234625035,0.8988237652484845,0.8913178591643967,0.8997099872576948 +0.08601243606100262,0.6961544503408927,0.32798228976460253,0.17540974998508108,0.020800544457338976,0.019333007898531842 +0.6747986499672789,0.3628219508629361,0.32989583249393584,0.9436777652291878,-0.3502239226324413,-0.309028586302391 +0.19929834067948615,0.512173657837735,0.024013200671349266,0.16336809113695616,1.3079952875593062,1.2147211015580122 +0.8834187336335619,0.7892475482526763,0.5568354900539902,0.22245339599136027,1.1446859733034527,1.1051944761703132 +0.5577475826213064,0.012146526113612555,0.7129936309379207,0.7167506805637281,0.2181560831877204,0.24772578832154957 +0.6460450235663548,0.6113386842752012,0.07371643262453753,0.24640596905097556,0.6784512224910251,0.6786012689379823 +0.5743780480979319,0.3941867660288976,0.992023228581445,0.9237453573751813,1.5815920913325947,1.4565601494511204 +0.15200790252253704,0.5899605926495307,0.6962151061034566,0.13654341430088612,-1.027696627377569,-1.0422773639359373 +0.31259564710117127,0.7159178469254943,0.9011080934228366,0.34174265020613526,0.13356141403837107,0.13646732782865542 +0.2389437116912806,0.8217920027302146,0.5849826802256783,0.4765884217057704,0.1450737206187869,0.13526337058258897 +0.25615002142789234,0.07265834864832099,0.017891420896975263,0.5799701805640948,1.637795228592926,1.8250334864790196 +0.1911102734600748,0.9755329784268204,0.10747722838614726,0.4520887883271084,1.8776709242380185,1.5231011434976223 +0.39465979707096,0.23231147528553098,0.7487557250039351,0.6437047620803104,-0.5156042097085767,-0.5045937587885526 +0.7257576850518699,0.08280857589649471,0.3527434156964051,0.5198330743342318,0.48756509087491784,0.5199913905475526 +0.42672114373024106,0.040617561872745234,0.1940274549007932,0.9450246483046265,-0.003088571994339262,-0.002675187474742347 +0.1625697247533182,0.8520523324627752,0.8221371590644401,0.391293757078108,0.5539880219738418,0.5740010469379998 +0.4667835198442635,0.8240018076499193,0.6806863255702125,0.8369437364290709,1.2766760260608692,1.4417365822051835 +0.7575965858321237,0.6912714794406046,0.9129741060068781,0.8228071330945887,2.7813130801418215,2.90749326227806 +0.17906268758299326,0.7482242750812449,0.0866813231145428,0.4258562402940216,1.0524797381130577,0.8745938286977041 +0.39675188715342524,0.20216809397548463,0.9379051086359893,0.09477667836116699,-0.43053729720729195,-0.3991857853121158 +0.004899414988575601,0.32292080366397835,0.990744718241222,0.2646951283884399,-0.4873819658321553,-0.5474422113135735 +0.830694265517731,0.17311363702046545,0.5863783547983777,0.958409335179392,0.6069800140521994,0.6250883671763993 +0.7165132345658071,0.9805079751784863,0.5745566490890397,0.9833347065534214,3.0590547800477705,3.056038876756375 diff --git a/modules/stochastic_tools/test/tests/surrogates/poly_chaos/ols_test.i b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/ols_test.i new file mode 100644 index 000000000000..5cb201b54b01 --- /dev/null +++ b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/ols_test.i @@ -0,0 +1,67 @@ +[StochasticTools] +[] + +[Distributions/uniform] + type = Uniform + lower_bound = 0 + upper_bound = 1 +[] + +[Samplers] + [csv] + type = CSVSampler + samples_file = ols_test.csv + column_names = 'x_0 x_1 x_2 x_3' + [] +[] + +[VectorPostprocessors] + [results] + type = CSVReader + csv_file = ols_test.csv + [] +[] + +[GlobalParams] + distributions = 'uniform uniform uniform uniform' + order = 3 +[] + +[Trainers] + [train_ols] + type = PolynomialChaosTrainer + sampler = csv + response = results/y + execute_on = TIMESTEP_BEGIN + [] + [train_pet_ols] + type = PolynomialChaosTrainer + sampler = csv + response = results/y_pet + execute_on = TIMESTEP_BEGIN + [] +[] + +[Surrogates] + [model_ols] + type = PolynomialChaos + trainer = train_ols + [] + [model_pet_ols] + type = PolynomialChaos + trainer = train_pet_ols + [] +[] + +[Reporters] + [stats] + type = PolynomialChaosReporter + pc_name = 'model_ols model_pet_ols' + include_data = true + [] +[] + +[Outputs] + json = true + execute_on = TIMESTEP_END +[] diff --git a/modules/stochastic_tools/test/tests/surrogates/poly_chaos/tests b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/tests index 8d93a8953dfc..c60098e6bc87 100644 --- a/modules/stochastic_tools/test/tests/surrogates/poly_chaos/tests +++ b/modules/stochastic_tools/test/tests/surrogates/poly_chaos/tests @@ -10,6 +10,19 @@ csvdiff = 'main_2d_mc_out_pc_samp_0002.csv' detail = 'MonteCarlo sampler with Uniform distribution, ' [] + [monte_carlo_ols] + type = JSONDiff + input = ols_test.i + jsondiff = ols_test_out.json + detail = 'MonteCarlo sampler with Uniform distribution using least-squares regression, ' + [] + [monte_carlo_ridge] + type = JSONDiff + input = ols_test.i + cli_args = 'Trainers/train_ols/penalty=1.0 Trainers/train_pet_ols/penalty=1.0 Outputs/file_base=ridge_test_out' + jsondiff = ridge_test_out.json + detail = 'MonteCarlo sampler with Uniform distribution using Ridge regression, ' + [] [gauss_legendre_integration] type = CSVDiff input = main_2d_quad.i