|
28 | 28 | #include <boost/accumulators/accumulators.hpp> |
29 | 29 | #include <boost/accumulators/statistics/stats.hpp> |
30 | 30 | #include <boost/accumulators/statistics/variance.hpp> |
| 31 | +#include <boost/accumulators/statistics/mean.hpp> |
31 | 32 |
|
32 | 33 | #include <iostream> |
33 | 34 | #include <map> |
@@ -146,7 +147,7 @@ Filter& Filter::operator=(Filter&& r) { |
146 | 147 | return *this; |
147 | 148 | } |
148 | 149 |
|
149 | | -Filter::Filter(const Size n, const bool value) : n_(n), constantData_(value), data_(nullptr), deterministic_(true) {} |
| 150 | +Filter::Filter(const Size n, const bool value) : n_(n), constantData_(value), data_(nullptr), deterministic_(n != 0) {} |
150 | 151 |
|
151 | 152 | void Filter::clear() { |
152 | 153 | n_ = 0; |
@@ -370,7 +371,7 @@ RandomVariable& RandomVariable::operator=(RandomVariable&& r) { |
370 | 371 | } |
371 | 372 |
|
372 | 373 | RandomVariable::RandomVariable(const Size n, const Real value, const Real time) |
373 | | - : n_(n), constantData_(value), data_(nullptr), deterministic_(true), time_(time) {} |
| 374 | + : n_(n), constantData_(value), data_(nullptr), deterministic_(n != 0), time_(time) {} |
374 | 375 |
|
375 | 376 | RandomVariable::RandomVariable(const Filter& f, const Real valueTrue, const Real valueFalse, const Real time) { |
376 | 377 | if (!f.initialised()) { |
@@ -1169,11 +1170,10 @@ RandomVariable expectation(const RandomVariable& r) { |
1169 | 1170 | if (r.deterministic()) |
1170 | 1171 | return r; |
1171 | 1172 | resumeCalcStats(); |
1172 | | - Real sum = 0.0; |
| 1173 | + boost::accumulators::accumulator_set<double, boost::accumulators::stats<boost::accumulators::tag::mean>> acc; |
1173 | 1174 | for (Size i = 0; i < r.size(); ++i) |
1174 | | - sum += r[i]; |
1175 | | - stopCalcStats(r.size()); |
1176 | | - return RandomVariable(r.size(), sum / static_cast<Real>(r.size())); |
| 1175 | + acc(r[i]); |
| 1176 | + return RandomVariable(r.size(), boost::accumulators::mean(acc)); |
1177 | 1177 | } |
1178 | 1178 |
|
1179 | 1179 | RandomVariable variance(const RandomVariable& r) { |
|
0 commit comments