Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions bin/autodetect/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ int main(int argc, char** argv) {
}()};

if (persistInterval >= 0 && persister == nullptr) {
LOG_FATAL(<< "Periodic persistence cannot be enabled using the "
"'persistInterval' argument "
"unless a place to persist to has been specified "
"using the 'persist' argument");
LOG_FATAL(<< "Periodic persistence cannot be enabled using the 'persistInterval' argument "
"unless a place to persist to has been specified using the 'persist' argument");
return EXIT_FAILURE;
}

Expand Down
6 changes: 2 additions & 4 deletions bin/categorize/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ int main(int argc, char** argv) {
}()};

if (persistInterval >= 0 && persister == nullptr) {
LOG_FATAL(<< "Periodic persistence cannot be enabled using the "
"'persistInterval' argument "
"unless a place to persist to has been specified "
"using the 'persist' argument");
LOG_FATAL(<< "Periodic persistence cannot be enabled using the 'persistInterval' argument "
"unless a place to persist to has been specified using the 'persist' argument");
return EXIT_FAILURE;
}
using TBackgroundPersisterCUPtr = const std::unique_ptr<ml::api::CBackgroundPersister>;
Expand Down
41 changes: 15 additions & 26 deletions include/maths/CConstantPrior.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,14 @@ class MATHS_EXPORT CConstantPrior : public CPrior {
virtual bool needsOffset() const;

//! No-op.
virtual double adjustOffset(const TWeightStyleVec& weightStyle,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights);
virtual double adjustOffset(const TDouble1Vec& samples,
const TDoubleWeightsAry1Vec& weights);

//! Returns zero.
virtual double offset() const;

//! Set the constant if it hasn't been set.
virtual void addSamples(const TWeightStyleVec& weightStyle,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights);
virtual void addSamples(const TDouble1Vec& samples, const TDoubleWeightsAry1Vec& weights);

//! No-op.
virtual void propagateForwardsByTime(double time);
Expand All @@ -96,53 +93,45 @@ class MATHS_EXPORT CConstantPrior : public CPrior {
virtual double marginalLikelihoodMean() const;

//! Returns constant or zero if unset (by equidistribution).
virtual double
marginalLikelihoodMode(const TWeightStyleVec& weightStyles = TWeights::COUNT_VARIANCE,
const TDouble4Vec& weights = TWeights::UNIT) const;
virtual double marginalLikelihoodMode(const TDoubleWeightsAry& weights = TWeights::UNIT) const;

//! All confidence intervals are the point [constant, constant].
virtual TDoubleDoublePr marginalLikelihoodConfidenceInterval(
double percentage,
const TWeightStyleVec& weightStyles = TWeights::COUNT_VARIANCE,
const TDouble4Vec& weights = TWeights::UNIT) const;
virtual TDoubleDoublePr
marginalLikelihoodConfidenceInterval(double percentage,
const TDoubleWeightsAry& weights = TWeights::UNIT) const;

//! Get the variance of the marginal likelihood.
virtual double
marginalLikelihoodVariance(const TWeightStyleVec& weightStyles = TWeights::COUNT_VARIANCE,
const TDouble4Vec& weights = TWeights::UNIT) const;
marginalLikelihoodVariance(const TDoubleWeightsAry& weights = TWeights::UNIT) const;

//! Returns a large value if all samples are equal to the constant
//! and zero otherwise.
virtual maths_t::EFloatingPointErrorStatus
jointLogMarginalLikelihood(const TWeightStyleVec& weightStyles,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights,
jointLogMarginalLikelihood(const TDouble1Vec& samples,
const TDoubleWeightsAry1Vec& weights,
double& result) const;

//! Get \p numberSamples times the constant.
virtual void sampleMarginalLikelihood(std::size_t numberSamples, TDouble1Vec& samples) const;

//! A large number if any sample is less than the constant and
//! zero otherwise.
virtual bool minusLogJointCdf(const TWeightStyleVec& weightStyles,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights,
virtual bool minusLogJointCdf(const TDouble1Vec& samples,
const TDoubleWeightsAry1Vec& weights,
double& lowerBound,
double& upperBound) const;

//! A large number if any sample is larger than the constant and
//! zero otherwise.
virtual bool minusLogJointCdfComplement(const TWeightStyleVec& weightStyles,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights,
virtual bool minusLogJointCdfComplement(const TDouble1Vec& samples,
const TDoubleWeightsAry1Vec& weights,
double& lowerBound,
double& upperBound) const;

//! Returns one if all samples equal the constant and one otherwise.
virtual bool probabilityOfLessLikelySamples(maths_t::EProbabilityCalculation calculation,
const TWeightStyleVec& weightStyles,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights,
const TDoubleWeightsAry1Vec& weights,
double& lowerBound,
double& upperBound,
maths_t::ETail& tail) const;
Expand Down
58 changes: 16 additions & 42 deletions include/maths/CGammaRateConjugate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <maths/CDoublePrecisionStorage.h>
#include <maths/CEqualWithTolerance.h>
#include <maths/CPrior.h>
#include <maths/Constants.h>
#include <maths/ImportExport.h>

namespace ml {
Expand Down Expand Up @@ -142,30 +143,21 @@ class MATHS_EXPORT CGammaRateConjugate : public CPrior {
//! This samples the current marginal likelihood and uses these samples
//! to reconstruct the prior with adjusted offset.
//!
//! \param[in] weightStyles Controls the interpretation of the weight(s)
//! that are associated with each sample. See maths_t::ESampleWeightStyle
//! for more details.
//! \param[in] samples The samples from which to determine the offset.
//! \param[in] weights The weights of each sample in \p samples.
//! \return The penalty to apply in model selection.
virtual double adjustOffset(const TWeightStyleVec& weightStyles,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights);
virtual double adjustOffset(const TDouble1Vec& samples,
const TDoubleWeightsAry1Vec& weights);

//! Get the current offset.
virtual double offset() const;

//! Update the prior with a collection of independent samples from the
//! gamma variable.
//!
//! \param[in] weightStyles Controls the interpretation of the weight(s)
//! that are associated with each sample. See maths_t::ESampleWeightStyle
//! for more details.
//! \param[in] samples A collection of samples of the variable.
//! \param[in] weights The weights of each sample in \p samples.
virtual void addSamples(const TWeightStyleVec& weightStyles,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights);
virtual void addSamples(const TDouble1Vec& samples, const TDoubleWeightsAry1Vec& weights);

//! Propagate the prior density function forwards by \p time.
//!
Expand All @@ -184,14 +176,11 @@ class MATHS_EXPORT CGammaRateConjugate : public CPrior {
virtual double marginalLikelihoodMean() const;

//! Get the mode of the marginal likelihood function.
virtual double
marginalLikelihoodMode(const TWeightStyleVec& weightStyles = TWeights::COUNT_VARIANCE,
const TDouble4Vec& weights = TWeights::UNIT) const;
virtual double marginalLikelihoodMode(const TDoubleWeightsAry& weights = TWeights::UNIT) const;

//! Get the variance of the marginal likelihood.
virtual double
marginalLikelihoodVariance(const TWeightStyleVec& weightStyles = TWeights::COUNT_VARIANCE,
const TDouble4Vec& weights = TWeights::UNIT) const;
marginalLikelihoodVariance(const TDoubleWeightsAry& weights = TWeights::UNIT) const;

//! Get the \p percentage symmetric confidence interval for the marginal
//! likelihood function, i.e. the values \f$a\f$ and \f$b\f$ such that:
Expand All @@ -203,29 +192,23 @@ class MATHS_EXPORT CGammaRateConjugate : public CPrior {
//! the percentage of interest \p percentage.
//!
//! \param[in] percentage The percentage of interest.
//! \param[in] weightStyles Optional variance scale weight styles.
//! \param[in] weights Optional variance scale weights.
//! \note \p percentage should be in the range [0.0, 100.0).
virtual TDoubleDoublePr marginalLikelihoodConfidenceInterval(
double percentage,
const TWeightStyleVec& weightStyles = TWeights::COUNT_VARIANCE,
const TDouble4Vec& weights = TWeights::UNIT) const;
virtual TDoubleDoublePr
marginalLikelihoodConfidenceInterval(double percentage,
const TDoubleWeightsAry& weights = TWeights::UNIT) const;

//! Compute the log marginal likelihood function at \p samples integrating
//! over the prior density function for the gamma rate.
//!
//! \param[in] weightStyles Controls the interpretation of the weight(s)
//! that are associated with each sample. See maths_t::ESampleWeightStyle
//! for more details.
//! \param[in] samples A collection of samples of the variable.
//! \param[in] weights The weights of each sample in \p samples.
//! \param[out] result Filled in with the joint likelihood of \p samples.
//! \note The samples are assumed to be independent and identically
//! distributed.
virtual maths_t::EFloatingPointErrorStatus
jointLogMarginalLikelihood(const TWeightStyleVec& weightStyles,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights,
jointLogMarginalLikelihood(const TDouble1Vec& samples,
const TDoubleWeightsAry1Vec& weights,
double& result) const;

//! Sample the marginal likelihood function.
Expand All @@ -240,9 +223,6 @@ class MATHS_EXPORT CGammaRateConjugate : public CPrior {
//! Compute minus the log of the joint c.d.f. of the marginal likelihood
//! at \p samples.
//!
//! \param[in] weightStyles Controls the interpretation of the weight(s)
//! that are associated with each sample. See maths_t::ESampleWeightStyle
//! for more details.
//! \param[in] samples The samples of interest.
//! \param[in] weights The weights of each sample in \p samples. For the
//! count variance scale weight style the weight is interpreted as a scale
Expand All @@ -269,9 +249,8 @@ class MATHS_EXPORT CGammaRateConjugate : public CPrior {
//! \f$(0,\infty)\f$, i.e. a value of zero is not well defined and
//! a value of infinity is not well handled. (Very large values are
//! handled though.)
virtual bool minusLogJointCdf(const TWeightStyleVec& weightStyles,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights,
virtual bool minusLogJointCdf(const TDouble1Vec& samples,
const TDoubleWeightsAry1Vec& weights,
double& lowerBound,
double& upperBound) const;

Expand All @@ -281,9 +260,8 @@ class MATHS_EXPORT CGammaRateConjugate : public CPrior {
//! can return is the minimum double rather than epsilon.
//!
//! \see minusLogJointCdf for more details.
virtual bool minusLogJointCdfComplement(const TWeightStyleVec& weightStyles,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights,
virtual bool minusLogJointCdfComplement(const TDouble1Vec& samples,
const TDoubleWeightsAry1Vec& weights,
double& lowerBound,
double& upperBound) const;

Expand All @@ -292,9 +270,6 @@ class MATHS_EXPORT CGammaRateConjugate : public CPrior {
//!
//! \param[in] calculation The style of the probability calculation
//! (see CTools::EProbabilityCalculation for details).
//! \param[in] weightStyles Controls the interpretation of the weight(s)
//! that are associated with each sample. See maths_t::ESampleWeightStyle
//! for more details.
//! \param[in] samples The samples of interest.
//! \param[in] weights The weights. See minusLogJointCdf for discussion.
//! \param[out] lowerBound Filled in with the probability of the set
Expand All @@ -308,9 +283,8 @@ class MATHS_EXPORT CGammaRateConjugate : public CPrior {
//! i.e. a value of zero is not well defined and a value of infinity
//! is not well handled. (Very large values are handled though.)
virtual bool probabilityOfLessLikelySamples(maths_t::EProbabilityCalculation calculation,
const TWeightStyleVec& weightStyles,
const TDouble1Vec& samples,
const TDouble4Vec1Vec& weights,
const TDoubleWeightsAry1Vec& weights,
double& lowerBound,
double& upperBound,
maths_t::ETail& tail) const;
Expand Down
Loading