Skip to content

Commit 513606c

Browse files
committed
Tidy up expectation w.r.t. marginal likelihood
1 parent 4e0c130 commit 513606c

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

include/maths/CPriorDetail.h

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,6 @@ namespace ml
2222
namespace maths
2323
{
2424

25-
//! Compute the expectation of the specified function w.r.t. to the marginal
26-
//! likelihood.
27-
//!
28-
//! This computes the expectation using order three Gauss-Legendre quadrature
29-
//! in \p numberIntervals subdivisions of a high confidence interval for the
30-
//! marginal likelihood.
31-
//!
32-
//! \param f The function to integrate.
33-
//! \param numberIntervals The number intervals to use for integration.
34-
//! \param result Filled in with the result if the expectation could be calculated.
35-
//!
36-
//! \tparam F This must conform to the function type expected by
37-
//! CIntegration::gaussLegendre.
38-
//! \tparam T The return type of the function F which must conform to the type
39-
//! expected by CIntegration::gaussLegendre.
4025
template<typename F, typename T>
4126
bool CPrior::expectation(const F &f,
4227
std::size_t numberIntervals,
@@ -52,16 +37,16 @@ bool CPrior::expectation(const F &f,
5237

5338
result = T();
5439

55-
double n = static_cast<double>(numberIntervals);
56-
TDoubleDoublePr interval =
40+
double n{static_cast<double>(numberIntervals)};
41+
TDoubleDoublePr interval{
5742
this->marginalLikelihoodConfidenceInterval(100.0 - 1.0 / (100.0 * n),
5843
weightStyles,
59-
weight);
60-
double x = interval.first;
61-
double dx = (interval.second - interval.first) / n;
44+
weight)};
45+
double x{interval.first};
46+
double dx{(interval.second - interval.first) / n};
6247

63-
double normalizationFactor = 0.0;
64-
TDouble4Vec1Vec weights(1, weight);
48+
double normalizationFactor{0.0};
49+
TDouble4Vec1Vec weights{weight};
6550
CPrior::CLogMarginalLikelihood logLikelihood(*this, weightStyles, weights);
6651
CCompositeFunctions::CExp<const CPrior::CLogMarginalLikelihood&> likelihood(logLikelihood);
6752
for (std::size_t i = 0u; i < numberIntervals; ++i, x += dx)

0 commit comments

Comments
 (0)