diff --git a/modules/stochastic_tools/include/reporters/StatisticsReporter.h b/modules/stochastic_tools/include/reporters/StatisticsReporter.h index 0bfe36ff5664..b3bf919bd4e7 100644 --- a/modules/stochastic_tools/include/reporters/StatisticsReporter.h +++ b/modules/stochastic_tools/include/reporters/StatisticsReporter.h @@ -19,17 +19,17 @@ * ReporterContext that utilizes a Calculator object to compute its value and confidence levels */ template -class ReporterStatisticsContext : public ReporterContext +class ReporterStatisticsContext : public ReporterContext>> { public: ReporterStatisticsContext(const libMesh::ParallelObject & other, - ReporterState & state, + ReporterState>> & state, const InType & data, const ReporterProducerEnum & mode, const MooseEnumItem & stat); ReporterStatisticsContext(const libMesh::ParallelObject & other, - ReporterState & state, + ReporterState>> & state, const InType & data, const ReporterProducerEnum & mode, const MooseEnumItem & stat, @@ -54,19 +54,16 @@ class ReporterStatisticsContext : public ReporterContext /// Storage for the BootstrapCalculator for the desired confidence interval calculations (optional) std::unique_ptr> _ci_calc_ptr = nullptr; - - /// The results - std::vector _ci_results; }; template ReporterStatisticsContext::ReporterStatisticsContext( const libMesh::ParallelObject & other, - ReporterState & state, + ReporterState>> & state, const InType & data, const ReporterProducerEnum & mode, const MooseEnumItem & stat) - : ReporterContext(other, state), + : ReporterContext>>(other, state), _data(data), _data_mode(mode), _calc_ptr(StochasticTools::makeCalculator(stat, other)) @@ -76,7 +73,7 @@ ReporterStatisticsContext::ReporterStatisticsContext( template ReporterStatisticsContext::ReporterStatisticsContext( const libMesh::ParallelObject & other, - ReporterState & state, + ReporterState>> & state, const InType & data, const ReporterProducerEnum & mode, const MooseEnumItem & stat, @@ -94,22 +91,22 @@ template void ReporterStatisticsContext::finalize() { - this->_state.value() = _calc_ptr->compute(_data, _data_mode == REPORTER_MODE_DISTRIBUTED); - ReporterContext::finalize(); + this->_state.value().first = _calc_ptr->compute(_data, _data_mode == REPORTER_MODE_DISTRIBUTED); + ReporterContext>>::finalize(); if (_ci_calc_ptr) - _ci_results = _ci_calc_ptr->compute(_data, _data_mode == REPORTER_MODE_DISTRIBUTED); + this->_state.value().second = + _ci_calc_ptr->compute(_data, _data_mode == REPORTER_MODE_DISTRIBUTED); } template void ReporterStatisticsContext::store(nlohmann::json & json) const { - ReporterContext::store(json); + ReporterContext>>::store(json); json["stat"] = _calc_ptr->name(); if (_ci_calc_ptr) json["confidence_intervals"] = {{"method", _ci_calc_ptr->name()}, - {"values", _ci_results}, {"levels", _ci_calc_ptr->levels()}, {"replicates", _ci_calc_ptr->replicates()}, {"seed", _ci_calc_ptr->seed()}}; @@ -140,8 +137,8 @@ class StatisticsReporter : public GeneralReporter // CI Method to be computed (optional) const MooseEnum & _ci_method; - // CI levels to be computed (not a ref. by design since these are computed from input parameter) - const std::vector _ci_levels; + // CI levels to be computed + const std::vector & _ci_levels; // Number of CI replicates to use in Bootstrap methods const unsigned int & _ci_replicates; @@ -149,14 +146,6 @@ class StatisticsReporter : public GeneralReporter // Random seed for producing CI replicates const unsigned int & _ci_seed; - /** - * Helper function for converting confidence levels given in (0, 0.5] into levels in (0, 1). - * For example, levels_in = {0.05, 0.1, 0.5} converts to {0.05 0.1, 0.5, 0.9, 0.95}. - * - * This also performs error checking on the supplied "ci_levels". - */ - std::vector computeLevels(const std::vector & levels_in) const; - /** * Helper for adding statistic reporter values * @@ -176,17 +165,19 @@ StatisticsReporter::declareValueHelper(const ReporterName & r_name) { const std::string s_name = r_name.getCombinedName() + "_" + item.name(); if (_ci_method.isValid()) - declareValueByName>(s_name, - REPORTER_MODE_ROOT, - data, - mode, - item, - _ci_method, - _ci_levels, - _ci_replicates, - _ci_seed); + declareValueByName>, + ReporterStatisticsContext>(s_name, + REPORTER_MODE_ROOT, + data, + mode, + item, + _ci_method, + _ci_levels, + _ci_replicates, + _ci_seed); else - declareValueByName>( + declareValueByName>, + ReporterStatisticsContext>( s_name, REPORTER_MODE_ROOT, data, mode, item); } } diff --git a/modules/stochastic_tools/src/reporters/StatisticsReporter.C b/modules/stochastic_tools/src/reporters/StatisticsReporter.C index 2663067ce470..d412aaba6f55 100644 --- a/modules/stochastic_tools/src/reporters/StatisticsReporter.C +++ b/modules/stochastic_tools/src/reporters/StatisticsReporter.C @@ -46,7 +46,9 @@ StatisticsReporter::validParams() "ci_method", ci, "The method to use for computing confidence level intervals."); params.addParam>( - "ci_levels", "A vector of confidence levels to consider, values must be in (0, 0.5]."); + "ci_levels", + std::vector({0.1, 0.9}), + "A vector of confidence levels to consider, values must be in (0, 1)."); params.addParam( "ci_replicates", 10000, @@ -62,11 +64,25 @@ StatisticsReporter::StatisticsReporter(const InputParameters & parameters) : GeneralReporter(parameters), _compute_stats(getParam("compute")), _ci_method(getParam("ci_method")), - _ci_levels(_ci_method.isValid() ? computeLevels(getParam>("ci_levels")) - : std::vector()), + _ci_levels(getParam>("ci_levels")), _ci_replicates(getParam("ci_replicates")), _ci_seed(getParam("ci_seed")) { + // CI levels error checking + if (_ci_method.isValid()) + { + if (_ci_levels.empty()) + paramError("ci_levels", + "If the 'ci_method' parameter is supplied then the 'ci_levels' must also be " + "supplied with values in (0, 1)."); + + else if (*std::min_element(_ci_levels.begin(), _ci_levels.end()) <= 0) + paramError("ci_levels", "The supplied levels must be greater than zero."); + + else if (*std::max_element(_ci_levels.begin(), _ci_levels.end()) >= 1) + paramError("ci_levels", "The supplied levels must be less than 1.0"); + } + // Stats for Reporters if (isParamValid("reporters")) { @@ -109,32 +125,3 @@ StatisticsReporter::StatisticsReporter(const InputParameters & parameters) else mooseError("The 'vectorpostprocessors' and/or 'reporters' parameters must be defined."); } - -std::vector -StatisticsReporter::computeLevels(const std::vector & levels_in) const -{ - if (levels_in.empty()) - paramError("ci_levels", - "If the 'ci_method' parameter is supplied then the 'ci_levels' must also be " - "supplied with values in (0, 0.5]."); - - else if (*std::min_element(levels_in.begin(), levels_in.end()) <= 0) - paramError("ci_levels", "The supplied levels must be greater than zero."); - - else if (*std::max_element(levels_in.begin(), levels_in.end()) > 0.5) - paramError("ci_levels", "The supplied levels must be less than or equal to 0.5"); - - std::list levels_out; - for (auto it = levels_in.rbegin(); it != levels_in.rend(); ++it) - { - if (*it == 0.5) - levels_out.push_back(*it); - - else - { - levels_out.push_front(*it); - levels_out.push_back(1 - *it); - } - } - return std::vector(levels_out.begin(), levels_out.end()); -} diff --git a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_reporter_ci_out.json b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_reporter_ci_out.json index 9ac450ef67a1..97e8be715e0f 100644 --- a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_reporter_ci_out.json +++ b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_reporter_ci_out.json @@ -18,176 +18,176 @@ "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 8.0, - 10.0, - 10.0 - ] + "seed": 1 }, "object_name": "stats", "stat": "MAX", - "type": "double", - "value": 10.0, + "type": "std::pair >", + "value": [ + 10.0, + [ + 8.0, + 10.0 + ] + ], "value_name": "const/const_MAX" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 4.4, - 6.0, - 7.6 - ] + "seed": 1 }, "object_name": "stats", "stat": "MEAN", - "type": "double", - "value": 6.0, + "type": "std::pair >", + "value": [ + 6.0, + [ + 4.4, + 7.6 + ] + ], "value_name": "const/const_MEAN" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 2.0, - 2.0, - 4.0 - ] + "seed": 1 }, "object_name": "stats", "stat": "MIN", - "type": "double", - "value": 2.0, + "type": "std::pair >", + "value": [ + 2.0, + [ + 2.0, + 4.0 + ] + ], "value_name": "const/const_MIN" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 11.135528725660043, - 14.832396974191326, - 17.88854381999832 - ] + "seed": 1 }, "object_name": "stats", "stat": "NORM2", - "type": "double", - "value": 14.832396974191326, + "type": "std::pair >", + "value": [ + 14.832396974191326, + [ + 11.135528725660043, + 17.88854381999832 + ] + ], "value_name": "const/const_NORM2" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 2.0, - 4.0, - 5.0 - ] + "seed": 1 }, "object_name": "stats", "stat": "RATIO", - "type": "double", - "value": 5.0, + "type": "std::pair >", + "value": [ + 5.0, + [ + 2.0, + 5.0 + ] + ], "value_name": "const/const_RATIO" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 1.6733200530681511, - 2.8284271247461903, - 3.63318042491699 - ] + "seed": 1 }, "object_name": "stats", "stat": "STDDEV", - "type": "double", - "value": 3.1622776601683795, + "type": "std::pair >", + "value": [ + 3.1622776601683795, + [ + 1.6733200530681511, + 3.63318042491699 + ] + ], "value_name": "const/const_STDDEV" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 0.7483314773547882, - 1.2649110640673518, - 1.6248076809271919 - ] + "seed": 1 }, "object_name": "stats", "stat": "STDERR", - "type": "double", - "value": 1.4142135623730951, + "type": "std::pair >", + "value": [ + 1.4142135623730951, + [ + 0.7483314773547882, + 1.6248076809271919 + ] + ], "value_name": "const/const_STDERR" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 22.0, - 30.0, - 38.0 - ] + "seed": 1 }, "object_name": "stats", "stat": "SUM", - "type": "double", - "value": 30.0, + "type": "std::pair >", + "value": [ + 30.0, + [ + 22.0, + 38.0 + ] + ], "value_name": "const/const_SUM" } ], diff --git a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_reporter_out.json b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_reporter_out.json index dcc9bdbe6b0a..0f3be37adac9 100644 --- a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_reporter_out.json +++ b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_reporter_out.json @@ -29,113 +29,161 @@ { "object_name": "stats", "stat": "MAX", - "type": "double", - "value": 500.0, + "type": "std::pair >", + "value": [ + 500.0, + [] + ], "value_name": "const/int_MAX" }, { "object_name": "stats", "stat": "MEAN", - "type": "double", - "value": 300.0, + "type": "std::pair >", + "value": [ + 300.0, + [] + ], "value_name": "const/int_MEAN" }, { "object_name": "stats", "stat": "MIN", - "type": "double", - "value": 100.0, + "type": "std::pair >", + "value": [ + 100.0, + [] + ], "value_name": "const/int_MIN" }, { "object_name": "stats", "stat": "NORM2", - "type": "double", - "value": 741.6198487095663, + "type": "std::pair >", + "value": [ + 741.6198487095663, + [] + ], "value_name": "const/int_NORM2" }, { "object_name": "stats", "stat": "RATIO", - "type": "double", - "value": 5.0, + "type": "std::pair >", + "value": [ + 5.0, + [] + ], "value_name": "const/int_RATIO" }, { "object_name": "stats", "stat": "STDDEV", - "type": "double", - "value": 158.11388300841898, + "type": "std::pair >", + "value": [ + 158.11388300841898, + [] + ], "value_name": "const/int_STDDEV" }, { "object_name": "stats", "stat": "STDERR", - "type": "double", - "value": 70.71067811865476, + "type": "std::pair >", + "value": [ + 70.71067811865476, + [] + ], "value_name": "const/int_STDERR" }, { "object_name": "stats", "stat": "SUM", - "type": "double", - "value": 1500.0, + "type": "std::pair >", + "value": [ + 1500.0, + [] + ], "value_name": "const/int_SUM" }, { "object_name": "stats", "stat": "MAX", - "type": "double", - "value": 10.0, + "type": "std::pair >", + "value": [ + 10.0, + [] + ], "value_name": "const/real_MAX" }, { "object_name": "stats", "stat": "MEAN", - "type": "double", - "value": 6.0, + "type": "std::pair >", + "value": [ + 6.0, + [] + ], "value_name": "const/real_MEAN" }, { "object_name": "stats", "stat": "MIN", - "type": "double", - "value": 2.0, + "type": "std::pair >", + "value": [ + 2.0, + [] + ], "value_name": "const/real_MIN" }, { "object_name": "stats", "stat": "NORM2", - "type": "double", - "value": 14.832396974191326, + "type": "std::pair >", + "value": [ + 14.832396974191326, + [] + ], "value_name": "const/real_NORM2" }, { "object_name": "stats", "stat": "RATIO", - "type": "double", - "value": 5.0, + "type": "std::pair >", + "value": [ + 5.0, + [] + ], "value_name": "const/real_RATIO" }, { "object_name": "stats", "stat": "STDDEV", - "type": "double", - "value": 3.1622776601683795, + "type": "std::pair >", + "value": [ + 3.1622776601683795, + [] + ], "value_name": "const/real_STDDEV" }, { "object_name": "stats", "stat": "STDERR", - "type": "double", - "value": 1.4142135623730951, + "type": "std::pair >", + "value": [ + 1.4142135623730951, + [] + ], "value_name": "const/real_STDERR" }, { "object_name": "stats", "stat": "SUM", - "type": "double", - "value": 30.0, + "type": "std::pair >", + "value": [ + 30.0, + [] + ], "value_name": "const/real_SUM" } ], diff --git a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_vpp_ci_out.json b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_vpp_ci_out.json index 3962303c38da..6230aaeda047 100644 --- a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_vpp_ci_out.json +++ b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_vpp_ci_out.json @@ -6,176 +6,176 @@ "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 4.0, - 5.0, - 5.0 - ] + "seed": 1 }, "object_name": "stats", "stat": "MAX", - "type": "double", - "value": 5.0, + "type": "std::pair >", + "value": [ + 5.0, + [ + 4.0, + 5.0 + ] + ], "value_name": "const/value_MAX" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 2.2, - 3.0, - 3.8 - ] + "seed": 1 }, "object_name": "stats", "stat": "MEAN", - "type": "double", - "value": 3.0, + "type": "std::pair >", + "value": [ + 3.0, + [ + 2.2, + 3.8 + ] + ], "value_name": "const/value_MEAN" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 1.0, - 1.0, - 2.0 - ] + "seed": 1 }, "object_name": "stats", "stat": "MIN", - "type": "double", - "value": 1.0, + "type": "std::pair >", + "value": [ + 1.0, + [ + 1.0, + 2.0 + ] + ], "value_name": "const/value_MIN" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 5.5677643628300215, - 7.416198487095663, - 8.94427190999916 - ] + "seed": 1 }, "object_name": "stats", "stat": "NORM2", - "type": "double", - "value": 7.416198487095663, + "type": "std::pair >", + "value": [ + 7.416198487095663, + [ + 5.5677643628300215, + 8.94427190999916 + ] + ], "value_name": "const/value_NORM2" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 2.0, - 4.0, - 5.0 - ] + "seed": 1 }, "object_name": "stats", "stat": "RATIO", - "type": "double", - "value": 5.0, + "type": "std::pair >", + "value": [ + 5.0, + [ + 2.0, + 5.0 + ] + ], "value_name": "const/value_RATIO" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 0.8366600265340756, - 1.4142135623730951, - 1.816590212458495 - ] + "seed": 1 }, "object_name": "stats", "stat": "STDDEV", - "type": "double", - "value": 1.5811388300841898, + "type": "std::pair >", + "value": [ + 1.5811388300841898, + [ + 0.8366600265340756, + 1.816590212458495 + ] + ], "value_name": "const/value_STDDEV" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 0.3741657386773941, - 0.6324555320336759, - 0.8124038404635959 - ] + "seed": 1 }, "object_name": "stats", "stat": "STDERR", - "type": "double", - "value": 0.7071067811865476, + "type": "std::pair >", + "value": [ + 0.7071067811865476, + [ + 0.3741657386773941, + 0.8124038404635959 + ] + ], "value_name": "const/value_STDERR" }, { "confidence_intervals": { "levels": [ 0.1, - 0.5, 0.9 ], "method": "percentile", "replicates": 10000, - "seed": 1, - "values": [ - 11.0, - 15.0, - 19.0 - ] + "seed": 1 }, "object_name": "stats", "stat": "SUM", - "type": "double", - "value": 15.0, + "type": "std::pair >", + "value": [ + 15.0, + [ + 11.0, + 19.0 + ] + ], "value_name": "const/value_SUM" } ], diff --git a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_vpp_out.json b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_vpp_out.json index f8bef7070870..be0bcffd15e5 100644 --- a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_vpp_out.json +++ b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/gold/statistics_vpp_out.json @@ -5,57 +5,81 @@ { "object_name": "stats", "stat": "MAX", - "type": "double", - "value": 5.0, + "type": "std::pair >", + "value": [ + 5.0, + [] + ], "value_name": "const/value_MAX" }, { "object_name": "stats", "stat": "MEAN", - "type": "double", - "value": 3.0, + "type": "std::pair >", + "value": [ + 3.0, + [] + ], "value_name": "const/value_MEAN" }, { "object_name": "stats", "stat": "MIN", - "type": "double", - "value": 1.0, + "type": "std::pair >", + "value": [ + 1.0, + [] + ], "value_name": "const/value_MIN" }, { "object_name": "stats", "stat": "NORM2", - "type": "double", - "value": 7.416198487095663, + "type": "std::pair >", + "value": [ + 7.416198487095663, + [] + ], "value_name": "const/value_NORM2" }, { "object_name": "stats", "stat": "RATIO", - "type": "double", - "value": 5.0, + "type": "std::pair >", + "value": [ + 5.0, + [] + ], "value_name": "const/value_RATIO" }, { "object_name": "stats", "stat": "STDDEV", - "type": "double", - "value": 1.5811388300841898, + "type": "std::pair >", + "value": [ + 1.5811388300841898, + [] + ], "value_name": "const/value_STDDEV" }, { "object_name": "stats", "stat": "STDERR", - "type": "double", - "value": 0.7071067811865476, + "type": "std::pair >", + "value": [ + 0.7071067811865476, + [] + ], "value_name": "const/value_STDERR" }, { "object_name": "stats", "stat": "SUM", - "type": "double", - "value": 15.0, + "type": "std::pair >", + "value": [ + 15.0, + [] + ], "value_name": "const/value_SUM" } ], diff --git a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/statistics_reporter_ci.i b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/statistics_reporter_ci.i index 365c2999b73e..deae6e7bf411 100644 --- a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/statistics_reporter_ci.i +++ b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/statistics_reporter_ci.i @@ -12,7 +12,6 @@ reporters = 'const/const' compute = 'min max sum mean stddev norm2 ratio stderr' ci_method = percentile - ci_levels = '0.1 0.5' [] [] diff --git a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/statistics_vpp_ci.i b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/statistics_vpp_ci.i index d214147d880a..cb8e09582e2e 100644 --- a/modules/stochastic_tools/test/tests/reporters/statistics_reporter/statistics_vpp_ci.i +++ b/modules/stochastic_tools/test/tests/reporters/statistics_reporter/statistics_vpp_ci.i @@ -11,7 +11,6 @@ vectorpostprocessors = 'const' compute = 'min max sum mean stddev norm2 ratio stderr' ci_method = percentile - ci_levels = '0.1 0.5' [] [Outputs/out]