diff --git a/bin/autodetect/Main.cc b/bin/autodetect/Main.cc index 83cf8f7603..5148e3cd55 100644 --- a/bin/autodetect/Main.cc +++ b/bin/autodetect/Main.cc @@ -65,7 +65,7 @@ int main(int argc, char **argv) { - typedef ml::autodetect::CCmdLineParser::TStrVec TStrVec; + using TStrVec = ml::autodetect::CCmdLineParser::TStrVec; // Read command line options std::string limitConfigFile; @@ -216,7 +216,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - typedef boost::scoped_ptr TScopedDataSearcherP; + using TScopedDataSearcherP = boost::scoped_ptr; TScopedDataSearcherP restoreSearcher; if (ioMgr.restoreStream() != 0) { @@ -236,14 +236,14 @@ int main(int argc, char **argv) } } - typedef boost::scoped_ptr TScopedDataAdderP; + using TScopedDataAdderP = boost::scoped_ptr; TScopedDataAdderP persister; if (ioMgr.persistStream() != 0) { persister.reset(new ml::api::CSingleStreamDataAdder(ioMgr.persistStream())); } - typedef boost::scoped_ptr TScopedBackgroundPersisterP; + using TScopedBackgroundPersisterP = boost::scoped_ptr; TScopedBackgroundPersisterP periodicPersister; if (persistInterval >= 0) { @@ -258,7 +258,7 @@ int main(int argc, char **argv) *persister)); } - typedef boost::scoped_ptr TScopedInputParserP; + using TScopedInputParserP = boost::scoped_ptr; TScopedInputParserP inputParser; if (lengthEncodedInput) { diff --git a/bin/categorize/Main.cc b/bin/categorize/Main.cc index 2095e9f981..9220b89d45 100644 --- a/bin/categorize/Main.cc +++ b/bin/categorize/Main.cc @@ -150,7 +150,7 @@ int main(int argc, char **argv) } ml::api::CFieldConfig fieldConfig(categorizationFieldName); - typedef boost::scoped_ptr TScopedDataSearcherP; + using TScopedDataSearcherP = boost::scoped_ptr; TScopedDataSearcherP restoreSearcher; if (ioMgr.restoreStream() != 0) { @@ -170,14 +170,14 @@ int main(int argc, char **argv) } } - typedef boost::scoped_ptr TScopedDataAdderP; + using TScopedDataAdderP = boost::scoped_ptr; TScopedDataAdderP persister; if (ioMgr.persistStream() != 0) { persister.reset(new ml::api::CSingleStreamDataAdder(ioMgr.persistStream())); } - typedef boost::scoped_ptr TScopedBackgroundPersisterP; + using TScopedBackgroundPersisterP = boost::scoped_ptr; TScopedBackgroundPersisterP periodicPersister; if (persistInterval >= 0) { @@ -192,7 +192,7 @@ int main(int argc, char **argv) *persister)); } - typedef boost::scoped_ptr TScopedInputParserP; + using TScopedInputParserP = boost::scoped_ptr; TScopedInputParserP inputParser; if (lengthEncodedInput) { diff --git a/bin/normalize/Main.cc b/bin/normalize/Main.cc index bf6e82234b..0a2db22756 100644 --- a/bin/normalize/Main.cc +++ b/bin/normalize/Main.cc @@ -120,7 +120,7 @@ int main(int argc, char **argv) modelConfig.perPartitionNormalization(perPartitionNormalization); // There's a choice of input and output formats for the numbers to be normalised - typedef boost::scoped_ptr TScopedInputParserP; + using TScopedInputParserP = boost::scoped_ptr; TScopedInputParserP inputParser; if (lengthEncodedInput) { @@ -132,7 +132,7 @@ int main(int argc, char **argv) ml::api::CCsvInputParser::COMMA)); } - typedef boost::scoped_ptr TScopedOutputHandlerP; + using TScopedOutputHandlerP = boost::scoped_ptr; TScopedOutputHandlerP outputWriter; if (writeCsv) { diff --git a/include/core/CFloatStorage.h b/include/core/CFloatStorage.h index 8ac3962501..9a500c9ae8 100644 --- a/include/core/CFloatStorage.h +++ b/include/core/CFloatStorage.h @@ -21,11 +21,9 @@ #include +#include #include -#include - - namespace ml { namespace core @@ -35,7 +33,7 @@ namespace { const int MAX_PRECISE_INTEGER_FLOAT( static_cast( - ::pow(10.0, + std::pow(10.0, static_cast(std::numeric_limits::digits10)) ) - 1 ); diff --git a/include/core/Constants.h b/include/core/Constants.h index 3a7fbdf20b..4819d62d0b 100644 --- a/include/core/Constants.h +++ b/include/core/Constants.h @@ -18,8 +18,8 @@ #include +#include #include -#include namespace ml { @@ -47,13 +47,13 @@ const core_t::TTime WEEK = 604800; const core_t::TTime YEAR = 31449600; //! Log of min double. -const double LOG_MIN_DOUBLE = ::log(std::numeric_limits::min()); +const double LOG_MIN_DOUBLE = std::log(std::numeric_limits::min()); //! Log of max double. -const double LOG_MAX_DOUBLE = ::log(std::numeric_limits::max()); +const double LOG_MAX_DOUBLE = std::log(std::numeric_limits::max()); //! Log of double epsilon. -const double LOG_DOUBLE_EPSILON = ::log(std::numeric_limits::epsilon()); +const double LOG_DOUBLE_EPSILON = std::log(std::numeric_limits::epsilon()); //! Log of two. const double LOG_TWO = 0.693147180559945; diff --git a/include/maths/CCompositeFunctions.h b/include/maths/CCompositeFunctions.h index 7758ebcb82..24808aeefe 100644 --- a/include/maths/CCompositeFunctions.h +++ b/include/maths/CCompositeFunctions.h @@ -21,10 +21,9 @@ #include #include +#include #include -#include - namespace ml { namespace maths @@ -225,19 +224,19 @@ class MATHS_EXPORT CCompositeFunctions inline T operator()(double x) const { static const double LOG_MIN_DOUBLE = - ::log(std::numeric_limits::min()); + std::log(std::numeric_limits::min()); double fx = m_F(x); - return fx < LOG_MIN_DOUBLE ? 0.0 : ::exp(fx); + return fx < LOG_MIN_DOUBLE ? 0.0 : std::exp(fx); } //! For function return success/fail and taking result as argument. inline bool operator()(double x, T &result) const { static const double LOG_MIN_DOUBLE = - ::log(std::numeric_limits::min()); + std::log(std::numeric_limits::min()); if (m_F(x, result)) { - result = result < LOG_MIN_DOUBLE ? 0.0 : ::exp(result); + result = result < LOG_MIN_DOUBLE ? 0.0 : std::exp(result); return true; } return false; diff --git a/include/maths/CEqualWithTolerance.h b/include/maths/CEqualWithTolerance.h index 663c65a7c3..f9a0fd942f 100644 --- a/include/maths/CEqualWithTolerance.h +++ b/include/maths/CEqualWithTolerance.h @@ -22,8 +22,6 @@ #include -#include - namespace ml { namespace maths diff --git a/include/maths/CGradientDescent.h b/include/maths/CGradientDescent.h index 37ae307c2f..c3f891265b 100644 --- a/include/maths/CGradientDescent.h +++ b/include/maths/CGradientDescent.h @@ -22,6 +22,7 @@ #include #include +#include #include #include diff --git a/include/maths/CGramSchmidt.h b/include/maths/CGramSchmidt.h index 586c799676..00306989cb 100644 --- a/include/maths/CGramSchmidt.h +++ b/include/maths/CGramSchmidt.h @@ -154,7 +154,7 @@ class MATHS_EXPORT CGramSchmidt : private core::CNonInstantiatable << ", norm = " << n << ", eps = " << eps); - if (::fabs(n) > eps) + if (std::fabs(n) > eps) { divide(x[current], n); ++current; diff --git a/include/maths/CInformationCriteria.h b/include/maths/CInformationCriteria.h index 80d5bb7117..e1380d7cdc 100644 --- a/include/maths/CInformationCriteria.h +++ b/include/maths/CInformationCriteria.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -196,7 +197,7 @@ class CSphericalGaussianInfoCriterion m_Likelihood += ni * log(ni) - 0.5 * m_D * ni * ( 1.0 + core::constants::LOG_TWO_PI - + ::log(upper * vi / m_D)); + + std::log(upper * vi / m_D)); } else { @@ -215,7 +216,7 @@ class CSphericalGaussianInfoCriterion return 0.0; } - double logN = ::log(m_N); + double logN = std::log(m_N); double p = (m_D * m_K + 2.0 * m_K - 1.0); switch (TYPE) { @@ -327,7 +328,7 @@ class CGaussianInfoCriterion return 0.0; } - double logN = ::log(m_N); + double logN = std::log(m_N); double p = (m_D * (1.0 + 0.5 * (m_D + 1.0)) * m_K + m_K - 1.0); switch (TYPE) { diff --git a/include/maths/CIntegration.h b/include/maths/CIntegration.h index b9d2e30568..207ad0e3a8 100644 --- a/include/maths/CIntegration.h +++ b/include/maths/CIntegration.h @@ -29,11 +29,10 @@ #include #include +#include #include #include -#include - namespace ml { namespace maths @@ -223,7 +222,7 @@ class MATHS_EXPORT CIntegration //! of the integral is returned. This is intended to support integration //! where the integrand is very small and may underflow double. This is //! handled by renormalizing the integral so only underflows if values - //! are less than ::exp(-std::numeric_limits::max()), so really + //! are less than std::exp(-std::numeric_limits::max()), so really //! very small! //! //! \param[in] function The log of the function to integrate. @@ -270,7 +269,7 @@ class MATHS_EXPORT CIntegration double fmax = *std::max_element(fx, fx + ORDER); for (unsigned int i = 0; i < ORDER; ++i) { - fx[i] = ::exp(fx[i] - fmax); + fx[i] = std::exp(fx[i] - fmax); } // Quadrature. @@ -279,7 +278,7 @@ class MATHS_EXPORT CIntegration result += weights[i] * fx[i]; } result *= range; - result = result <= 0.0 ? core::constants::LOG_MIN_DOUBLE : fmax + ::log(result); + result = result <= 0.0 ? core::constants::LOG_MIN_DOUBLE : fmax + std::log(result); return true; } @@ -333,7 +332,7 @@ class MATHS_EXPORT CIntegration corrections.reserve(fIntervals.size()); for (std::size_t i = 0u; i < fIntervals.size(); ++i) { - corrections.push_back(::fabs(fIntervals[i])); + corrections.push_back(std::fabs(fIntervals[i])); } for (std::size_t i = 0u; @@ -341,7 +340,7 @@ class MATHS_EXPORT CIntegration ++i) { std::size_t n = intervals.size(); - double cutoff = tolerance * ::fabs(result) / static_cast(n); + double cutoff = tolerance * std::fabs(result) / static_cast(n); std::size_t end = 0u; for (std::size_t j = 0u; j < corrections.size(); ++j) @@ -415,13 +414,13 @@ class MATHS_EXPORT CIntegration double correction = fjNew - fjOld; if (i + 1 < refinements) { - corrections[j] = ::fabs(correction); + corrections[j] = std::fabs(correction); corrections.resize(corrections.size() + splitsPerRefinement - 1, - ::fabs(correction)); + std::fabs(correction)); } result += correction; - cutoff = tolerance * ::fabs(result) / static_cast(n); + cutoff = tolerance * std::fabs(result) / static_cast(n); } } diff --git a/include/maths/CKMeansOnline.h b/include/maths/CKMeansOnline.h index 87aee95cfa..723f7622be 100644 --- a/include/maths/CKMeansOnline.h +++ b/include/maths/CKMeansOnline.h @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -385,7 +386,7 @@ class CKMeansOnline return; } - double alpha = ::exp(-m_DecayRate * time); + double alpha = std::exp(-m_DecayRate * time); LOG_TRACE("alpha = " << alpha); this->age(alpha); @@ -471,7 +472,7 @@ class CKMeansOnline } else { - std::size_t ni_ = static_cast(::ceil(ni)); + std::size_t ni_ = static_cast(std::ceil(ni)); TDoublePoint v(m_Clusters[i].second); sampleGaussian(ni_, m, v.diagonal(), categorySamples); } @@ -485,7 +486,7 @@ class CKMeansOnline LOG_TRACE("weights = " << core::CContainerPrinter::print(weights)); TDoublePointVec final; - final.reserve(static_cast(::ceil(std::accumulate(weights.begin(), weights.end(), 0.0)))); + final.reserve(static_cast(std::ceil(std::accumulate(weights.begin(), weights.end(), 0.0)))); TDoubleMeanAccumulator sample; for (;;) { diff --git a/include/maths/CKdTree.h b/include/maths/CKdTree.h index 5bb38dba99..877cc72cb2 100644 --- a/include/maths/CKdTree.h +++ b/include/maths/CKdTree.h @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -349,7 +350,7 @@ class CKdTree nextCoordinate, nearest, distanceToNearest); - if (secondary && ::fabs(distanceToHyperplane) < distanceToNearest) + if (secondary && std::fabs(distanceToHyperplane) < distanceToNearest) { nearest = this->nearestNeighbour(point, *secondary, @@ -386,7 +387,7 @@ class CKdTree std::size_t nextCoordinate = (coordinate + 1) % m_Dimension; this->nearestNeighbours(point, *primary, nextCoordinate, nearest); - if (secondary && ::fabs(distanceToHyperplane) < nearest.biggest().first) + if (secondary && std::fabs(distanceToHyperplane) < nearest.biggest().first) { this->nearestNeighbours(point, *secondary, nextCoordinate, nearest); } diff --git a/include/maths/CLinearAlgebra.h b/include/maths/CLinearAlgebra.h index abe47a8b57..d4d63fa683 100644 --- a/include/maths/CLinearAlgebra.h +++ b/include/maths/CLinearAlgebra.h @@ -1017,7 +1017,7 @@ struct SVector double result = 0.0; for (std::size_t i = 0u; i < m_X.size(); ++i) { - result += ::fabs(static_cast(m_X[i])); + result += std::fabs(static_cast(m_X[i])); } return result; } diff --git a/include/maths/CLinearAlgebraTools.h b/include/maths/CLinearAlgebraTools.h index 4e766d5f54..338d4ab4ba 100644 --- a/include/maths/CLinearAlgebraTools.h +++ b/include/maths/CLinearAlgebraTools.h @@ -55,7 +55,7 @@ struct SSqrt { for (std::size_t i = 0u; i < d; ++i) { - result(i) = ::sqrt(result(i)); + result(i) = std::sqrt(result(i)); } } }; @@ -70,7 +70,7 @@ struct SSqrt { for (std::size_t j = 0u; j <= i; ++j) { - result(i, j) = ::sqrt(result(i, j)); + result(i, j) = std::sqrt(result(i, j)); } } } @@ -264,7 +264,7 @@ struct SFabs { for (std::size_t i = 0u; i < d; ++i) { - result(i) = ::fabs(result(i)); + result(i) = std::fabs(result(i)); } } }; @@ -279,7 +279,7 @@ struct SFabs { for (std::size_t j = 0u; j <= i; ++j) { - result(i, j) = ::fabs(result(i, j)); + result(i, j) = std::fabs(result(i, j)); } } } @@ -740,7 +740,7 @@ void scaleCovariances(std::size_t i, T scale, CSymmetricMatrixNxN &m) { - scale = ::sqrt(scale); + scale = std::sqrt(scale); for (std::size_t j = 0u; j < m.columns(); ++j) { if (i == j) @@ -768,7 +768,7 @@ void scaleCovariances(std::size_t i, T scale, CSymmetricMatrix &m) { - scale = ::sqrt(scale); + scale = std::sqrt(scale); for (std::size_t j = 0u; j < m.columns(); ++j) { if (i == j) diff --git a/include/maths/CMixtureDistribution.h b/include/maths/CMixtureDistribution.h index 533df0d0b0..bc7b7f898f 100644 --- a/include/maths/CMixtureDistribution.h +++ b/include/maths/CMixtureDistribution.h @@ -31,11 +31,10 @@ #include #include +#include #include #include -#include - namespace ml { namespace maths @@ -620,7 +619,7 @@ double quantile(const CMixtureDistribution &distribution, const double q) LOG_ERROR("Unable to bracket quantile = " << q << ", (a,b) = (" << a << "," << b << ")" << ", (f(a),f(b)) = (" << fa << "," << fb << ")"); - result = ::fabs(fa) < ::fabs(fb) ? a : b; + result = std::fabs(fa) < std::fabs(fb) ? a : b; } else { diff --git a/include/maths/CModelWeight.h b/include/maths/CModelWeight.h index 60154b2fb8..396e0fc64e 100644 --- a/include/maths/CModelWeight.h +++ b/include/maths/CModelWeight.h @@ -23,9 +23,7 @@ #include -#include -#include - +#include namespace ml { diff --git a/include/maths/CMultimodalPriorUtils.h b/include/maths/CMultimodalPriorUtils.h index c1f9a748ad..31017f43af 100644 --- a/include/maths/CMultimodalPriorUtils.h +++ b/include/maths/CMultimodalPriorUtils.h @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -138,7 +139,7 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable double countVarianceScale = 1.0; try { - seasonalScale = ::sqrt(maths_t::seasonalVarianceScale(weightStyles, weights)); + seasonalScale = std::sqrt(maths_t::seasonalVarianceScale(weightStyles, weights)); countVarianceScale = maths_t::countVarianceScale(weightStyles, weights); } catch (const std::exception &e) @@ -163,7 +164,7 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable { continue; } - if (maxLikelihood.add(::log(w) + likelihood)) + if (maxLikelihood.add(std::log(w) + likelihood)) { result = mode[0]; } @@ -258,8 +259,8 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable return support; } - double p1 = ::log((1.0 - percentage) / 2.0); - double p2 = ::log((1.0 + percentage) / 2.0); + double p1 = std::log((1.0 - percentage) / 2.0); + double p2 = std::log((1.0 + percentage) / 2.0); CLogCdf fl(CLogCdf::E_Lower, prior, weightStyles, weights); CLogCdf fu(CLogCdf::E_Upper, prior, weightStyles, weights); @@ -401,8 +402,8 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable for (std::size_t i = 0u; i < samples.size(); ++i) { double n = maths_t::countForUpdate(weightStyles, weights[i]); - double seasonalScale = ::sqrt(maths_t::seasonalVarianceScale(weightStyles, weights[i])); - double logSeasonalScale = seasonalScale != 1.0 ? ::log(seasonalScale) : 0.0; + double seasonalScale = std::sqrt(maths_t::seasonalVarianceScale(weightStyles, weights[i])); + double logSeasonalScale = seasonalScale != 1.0 ? std::log(seasonalScale) : 0.0; sample[0] = mean + (samples[i] - mean) / seasonalScale; weight[0][0] = maths_t::countVarianceScale(weightStyles, weights[i]); @@ -457,12 +458,12 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable { double w = modes[modeLogLikelihoods[j].first].weight(); // Divide through by the largest value to avoid underflow. - sampleLikelihood += w * ::exp(modeLogLikelihoods[j].second - maxLogLikelihood); + sampleLikelihood += w * std::exp(modeLogLikelihoods[j].second - maxLogLikelihood); Z += w; } sampleLikelihood /= Z; - double sampleLogLikelihood = n * (::log(sampleLikelihood) + maxLogLikelihood); + double sampleLogLikelihood = n * (std::log(sampleLikelihood) + maxLogLikelihood); LOG_TRACE("sample = " << core::CContainerPrinter::print(sample) << ", maxLogLikelihood = " << maxLogLikelihood @@ -658,8 +659,8 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable << core::CContainerPrinter::print(samples)); return false; } - lowerBound = ::exp(-lowerBound); - upperBound = ::exp(-upperBound); + lowerBound = std::exp(-lowerBound); + upperBound = std::exp(-upperBound); tail = maths_t::E_LeftTail; break; @@ -735,7 +736,7 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable { double w = mode.weight() / Z; double centre = mode.s_Prior->marginalLikelihoodMode(weightStyles, weight[0]); - double spread = ::sqrt(mode.s_Prior->marginalLikelihoodVariance(weightStyles, weight[0])); + double spread = std::sqrt(mode.s_Prior->marginalLikelihoodVariance(weightStyles, weight[0])); calculator.addMode(w, centre, spread); tail_ = tail_ | (x < centre ? maths_t::E_LeftTail : maths_t::E_RightTail); } @@ -751,14 +752,14 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable { wt[0] = l; minusLogJointCdf(modes, weightStyles, wt, weight, lb, ub); - sampleLowerBound += ::exp(std::min(-lb, -ub)); - sampleUpperBound += ::exp(std::max(-lb, -ub)); + sampleLowerBound += std::exp(std::min(-lb, -ub)); + sampleUpperBound += std::exp(std::max(-lb, -ub)); } else { wt[0] = l; minusLogJointCdf(modes, weightStyles, wt, weight, lb, ub); - sampleUpperBound += ::exp(std::max(-lb, -ub)); + sampleUpperBound += std::exp(std::max(-lb, -ub)); } double r; @@ -767,14 +768,14 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable { wt[0] = r; minusLogJointCdfComplement(modes, weightStyles, wt, weight, lb, ub); - sampleLowerBound += ::exp(std::min(-lb, -ub)); - sampleUpperBound += ::exp(std::max(-lb, -ub)); + sampleLowerBound += std::exp(std::min(-lb, -ub)); + sampleUpperBound += std::exp(std::max(-lb, -ub)); } else { wt[0] = r; minusLogJointCdfComplement(modes, weightStyles, wt, weight, lb, ub); - sampleUpperBound += ::exp(std::max(-lb, -ub)); + sampleUpperBound += std::exp(std::max(-lb, -ub)); } double p = 0.0; @@ -810,8 +811,8 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable << core::CContainerPrinter::print(samples)); return false; } - lowerBound = ::exp(-lowerBound); - upperBound = ::exp(-upperBound); + lowerBound = std::exp(-lowerBound); + upperBound = std::exp(-upperBound); tail = maths_t::E_RightTail; break; } @@ -992,13 +993,13 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable for (std::size_t i = 0; i < samples.size(); ++i) { double n = maths_t::count(weightStyles, weights[i]); - double seasonalScale = ::sqrt(maths_t::seasonalVarianceScale(weightStyles, weights[i])); + double seasonalScale = std::sqrt(maths_t::seasonalVarianceScale(weightStyles, weights[i])); double countVarianceScale = maths_t::countVarianceScale(weightStyles, weights[i]); if (isNonInformative(modes)) { - lowerBound -= n * ::log(CTools::IMPROPER_CDF); - upperBound -= n * ::log(CTools::IMPROPER_CDF); + lowerBound -= n * std::log(CTools::IMPROPER_CDF); + upperBound -= n * std::log(CTools::IMPROPER_CDF); continue; } @@ -1042,12 +1043,12 @@ class MATHS_EXPORT CMultimodalPriorUtils : private core::CNonInstantiatable // Divide through by the largest value to avoid underflow. // Remember we are working with minus logs so the largest // value corresponds to the smallest log. - sampleLowerBound.add(::exp(-(modeLowerBounds[j] - minLowerBound[0])), w); - sampleUpperBound.add(::exp(-(modeUpperBounds[j] - minUpperBound[0])), w); + sampleLowerBound.add(std::exp(-(modeLowerBounds[j] - minLowerBound[0])), w); + sampleUpperBound.add(std::exp(-(modeUpperBounds[j] - minUpperBound[0])), w); } - lowerBound += n * std::max(minLowerBound[0] - ::log(CBasicStatistics::mean(sampleLowerBound)), 0.0); - upperBound += n * std::max(minUpperBound[0] - ::log(CBasicStatistics::mean(sampleUpperBound)), 0.0); + lowerBound += n * std::max(minLowerBound[0] - std::log(CBasicStatistics::mean(sampleLowerBound)), 0.0); + upperBound += n * std::max(minUpperBound[0] - std::log(CBasicStatistics::mean(sampleUpperBound)), 0.0); LOG_TRACE("sample = " << core::CContainerPrinter::print(sample) << ", sample -log(c.d.f.) = [" diff --git a/include/maths/CMultivariateMultimodalPrior.h b/include/maths/CMultivariateMultimodalPrior.h index 80110871fa..0f40def01c 100644 --- a/include/maths/CMultivariateMultimodalPrior.h +++ b/include/maths/CMultivariateMultimodalPrior.h @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -473,7 +474,7 @@ class CMultivariateMultimodalPrior : public CMultivariatePrior mode.s_Prior->propagateForwardsByTime(time); } - this->numberSamples(this->numberSamples() * ::exp(-this->scaledDecayRate() * time)); + this->numberSamples(this->numberSamples() * std::exp(-this->scaledDecayRate() * time)); LOG_TRACE("numberSamples = " << this->numberSamples()); } @@ -518,7 +519,7 @@ class CMultivariateMultimodalPrior : public CMultivariatePrior double Z = 0.0; for (auto &weight : weights) { - weight = ::exp(weight - maxWeight[0]); + weight = std::exp(weight - maxWeight[0]); Z += weight; } for (std::size_t i = 0u; i < weights.size(); ++i) @@ -528,7 +529,7 @@ class CMultivariateMultimodalPrior : public CMultivariatePrior return {TUnivariatePriorPtr(new CMultimodalPrior(this->dataType(), this->decayRate(), modes)), - Z > 0.0 ? maxWeight[0] + ::log(Z) : 0.0}; + Z > 0.0 ? maxWeight[0] + std::log(Z) : 0.0}; } //! Compute the bivariate prior marginalizing over the variables @@ -578,7 +579,7 @@ class CMultivariateMultimodalPrior : public CMultivariatePrior double Z = 0.0; for (auto &weight : weights) { - weight = ::exp(weight - maxWeight[0]); + weight = std::exp(weight - maxWeight[0]); Z += weight; } for (std::size_t i = 0u; i < weights.size(); ++i) @@ -587,7 +588,7 @@ class CMultivariateMultimodalPrior : public CMultivariatePrior } return {TPriorPtr(new CMultivariateMultimodalPrior<2>(this->dataType(), modes)), - Z > 0.0 ? maxWeight[0] + ::log(Z) : 0.0}; + Z > 0.0 ? maxWeight[0] + std::log(Z) : 0.0}; } //! Get the support for the marginal likelihood function. @@ -711,7 +712,7 @@ class CMultivariateMultimodalPrior : public CMultivariatePrior { continue; } - if (modeLikelihood.add(::log(w) + likelihood)) + if (modeLikelihood.add(std::log(w) + likelihood)) { result = TPoint(mode[0]); } @@ -836,7 +837,7 @@ class CMultivariateMultimodalPrior : public CMultivariatePrior double logSeasonalScale = 0.0; for (std::size_t j = 0u; j < seasonalScale.dimension(); ++j) { - logSeasonalScale += ::log(seasonalScale(j)); + logSeasonalScale += std::log(seasonalScale(j)); } TPoint x(samples[i]); diff --git a/include/maths/CMultivariateNormalConjugate.h b/include/maths/CMultivariateNormalConjugate.h index 871c53051e..bff6bc2864 100644 --- a/include/maths/CMultivariateNormalConjugate.h +++ b/include/maths/CMultivariateNormalConjugate.h @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -351,7 +352,7 @@ class CMultivariateNormalConjugate : public CMultivariatePrior return; } - double alpha = ::exp(-this->scaledDecayRate() * time); + double alpha = std::exp(-this->scaledDecayRate() * time); m_GaussianPrecision = alpha * m_GaussianPrecision + (1.0 - alpha) * TPoint(NON_INFORMATIVE_PRECISION); @@ -457,8 +458,8 @@ class CMultivariateNormalConjugate : public CMultivariatePrior double mean = m1 + c12.transpose() * c22SolvexcMinusm2; double variance = std::max(c11 - c12.transpose() * c22.solve(c12), - MINIMUM_COEFFICIENT_OF_VARIATION * ::fabs(mean)); - double weight = 0.5 * (::log(variance) - (xc - m2).transpose() * c22SolvexcMinusm2); + MINIMUM_COEFFICIENT_OF_VARIATION * std::fabs(mean)); + double weight = 0.5 * (std::log(variance) - (xc - m2).transpose() * c22SolvexcMinusm2); LOG_TRACE("mean = " << mean << ", variance = " << variance << ", weight = " << weight); @@ -689,14 +690,14 @@ class CMultivariateNormalConjugate : public CMultivariatePrior if (logLikelihood > maxLogLikelihood) { - sum *= ::exp(maxLogLikelihood - logLikelihood); + sum *= std::exp(maxLogLikelihood - logLikelihood); maxLogLikelihood = logLikelihood; } - sum += ::exp(logLikelihood - maxLogLikelihood); + sum += std::exp(logLikelihood - maxLogLikelihood); n += 1.0; } - result = maxLogLikelihood + ::log(sum / n); + result = maxLogLikelihood + std::log(sum / n); } else { @@ -936,7 +937,7 @@ class CMultivariateNormalConjugate : public CMultivariatePrior TDenseVector diag = precision.singularValues(); for (std::size_t i = 0u; i < rank; ++i) { - diag(i) = 1.0 / ::sqrt(diag(i)); + diag(i) = 1.0 / std::sqrt(diag(i)); } for (std::size_t i = rank; i < N; ++i) { @@ -964,7 +965,7 @@ class CMultivariateNormalConjugate : public CMultivariatePrior A.setZero(); for (std::size_t i = 0, k = 0u; i < rank; ++i) { - A(i,i) = ::sqrt(chi[i * n + s]); + A(i,i) = std::sqrt(chi[i * n + s]); for (std::size_t j = 0u; j < i; ++j, ++k) { A(i,j) = normal[(s * rank * (rank - 1)) / 2 + k]; @@ -1186,7 +1187,7 @@ class CMultivariateNormalConjugate : public CMultivariatePrior covariancePost.add(x, n / countVarianceScale); for (std::size_t j = 0u; j < N; ++j) { - logCountVarianceScales -= 0.5 * ::log(countVarianceScale(j)); + logCountVarianceScales -= 0.5 * std::log(countVarianceScale(j)); } } } @@ -1206,8 +1207,8 @@ class CMultivariateNormalConjugate : public CMultivariatePrior double logGaussianPrecisionPost = 0.0; for (std::size_t i = 0u; i < N; ++i) { - logGaussianPrecisionPrior += ::log(m_GaussianPrecision(i)); - logGaussianPrecisionPost += ::log(m_GaussianPrecision(i) + scaledNumberSamples(i)); + logGaussianPrecisionPrior += std::log(m_GaussianPrecision(i)); + logGaussianPrecisionPost += std::log(m_GaussianPrecision(i) + scaledNumberSamples(i)); } double wishartDegreesFreedomPrior = m_WishartDegreesFreedom; double wishartDegreesFreedomPost = m_WishartDegreesFreedom + numberSamples; diff --git a/include/maths/CPackedBitVector.h b/include/maths/CPackedBitVector.h index 102a7aeffa..dd4ea16019 100644 --- a/include/maths/CPackedBitVector.h +++ b/include/maths/CPackedBitVector.h @@ -24,11 +24,11 @@ #include +#include #include #include #include -#include #include @@ -112,7 +112,7 @@ class MATHS_EXPORT CPackedBitVector : private boost::equality_comparable< CPacke //! Euclidean norm. double euclidean(void) const { - return ::sqrt(this->inner(*this)); + return std::sqrt(this->inner(*this)); } //! Manhattan norm. diff --git a/include/maths/CRadialBasisFunction.h b/include/maths/CRadialBasisFunction.h index 099c253d86..4936191609 100644 --- a/include/maths/CRadialBasisFunction.h +++ b/include/maths/CRadialBasisFunction.h @@ -18,8 +18,6 @@ #include -#include - namespace ml { namespace maths diff --git a/include/maths/CRandomProjectionClusterer.h b/include/maths/CRandomProjectionClusterer.h index d84b9de768..2db2804f4c 100644 --- a/include/maths/CRandomProjectionClusterer.h +++ b/include/maths/CRandomProjectionClusterer.h @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -463,7 +464,7 @@ class CRandomProjectionClustererBatch : public CRandomProjectionClusterer double Zij = 0.0; for (std::size_t k = 0u; k < pij.size(); ++k) { - pij[k] = ::exp(pij[k] - pmax); + pij[k] = std::exp(pij[k] - pmax); Zij += pij[k]; } for (std::size_t k = 0u; k < pij.size(); ++k) @@ -585,7 +586,7 @@ class CRandomProjectionClustererBatch : public CRandomProjectionClusterer // a given cluster. for (std::size_t c = 0u; c < nci; ++c) { - double wic = ::log(Wi[c]) - 0.5 * this->logDeterminant(Ci[c]); + double wic = std::log(Wi[c]) - 0.5 * this->logDeterminant(Ci[c]); LOG_TRACE(" w(" << i << "," << c << ") = " << wic); for (std::size_t j = 0u; j < h; ++j) { @@ -605,7 +606,7 @@ class CRandomProjectionClustererBatch : public CRandomProjectionClusterer double Z = 0.0; for (std::size_t c = 0u; c < nci; ++c) { - Pi[j](c) = ::exp(Pi[j](c) - Pmax); + Pi[j](c) = std::exp(Pi[j](c) - Pmax); Z += Pi[j](c); } for (std::size_t c = 0u; c < nci; ++c) @@ -621,7 +622,7 @@ class CRandomProjectionClustererBatch : public CRandomProjectionClusterer S_[j].resize(j + 1); for (std::size_t k = 0u; k <= j; ++k) { - S_[j][k].add(-::log(std::max(Pi[j].inner(Pi[k]), + S_[j][k].add(-std::log(std::max(Pi[j].inner(Pi[k]), boost::numeric::bounds::smallest()))); } } @@ -708,7 +709,7 @@ class CRandomProjectionClustererBatch : public CRandomProjectionClusterer double result = 0.0; for (std::size_t i = 0u, rank = static_cast(svd.rank()); i < rank; ++i) { - result += ::log(svd.singularValues()[i]); + result += std::log(svd.singularValues()[i]); } return result; } diff --git a/include/maths/CSolvers.h b/include/maths/CSolvers.h index c7cac5fde7..a4f624f374 100644 --- a/include/maths/CSolvers.h +++ b/include/maths/CSolvers.h @@ -29,13 +29,12 @@ #include #include +#include #include #include #include #include -#include - namespace ml { namespace maths @@ -143,7 +142,7 @@ class MATHS_EXPORT CSolvers double &fx) { tolerance = std::max(tolerance, - ::sqrt(std::numeric_limits::epsilon())); + std::sqrt(std::numeric_limits::epsilon())); const double golden = 0.3819660; if (fa < fb) @@ -167,9 +166,9 @@ class MATHS_EXPORT CSolvers { double xm = bisect(a, b); - double t1 = tolerance * (::fabs(x) + 0.25); + double t1 = tolerance * (std::fabs(x) + 0.25); double t2 = 2.0 * t1; - if (fx <= lb || ::fabs(x - xm) <= (t2 - (b - a) / 2.0)) + if (fx <= lb || std::fabs(x - xm) <= (t2 - (b - a) / 2.0)) { break; } @@ -187,12 +186,12 @@ class MATHS_EXPORT CSolvers { p = -p; } - q = ::fabs(q); + q = std::fabs(q); double td = sLast; - sLast = ::fabs(s); + sLast = std::fabs(s); - if (::fabs(p) >= q * td / 2.0 + if (std::fabs(p) >= q * td / 2.0 || p <= q * (a - x) || p >= q * (b - x)) { @@ -295,9 +294,9 @@ class MATHS_EXPORT CSolvers double minStep = step; double maxStep = step * step; step = fa == fb ? - maxStep : std::min(std::max( ::fabs(b - a) - / ::fabs(fb - fa) - * ::fabs(fb), + maxStep : std::min(std::max( std::fabs(b - a) + / std::fabs(fb - fa) + * std::fabs(fb), minStep), maxStep); } a = b; @@ -616,7 +615,7 @@ class MATHS_EXPORT CSolvers return false; } - if (::fabs(fa) < ::fabs(fb)) + if (std::fabs(fa) < std::fabs(fb)) { std::swap(a, b); std::swap(fa, fb); @@ -636,8 +635,8 @@ class MATHS_EXPORT CSolvers double e = (3.0 * a + b) / 4.0; if ( (!(((s > e) && (s < b)) || ((s < e) && (s > b)))) - || ( bisected && ((::fabs(s - b) >= ::fabs(b - c) / 2.0) || equal(b, c))) - || (!bisected && ((::fabs(s - b) >= ::fabs(c - d) / 2.0) || equal(c, d)))) + || ( bisected && ((std::fabs(s - b) >= std::fabs(b - c) / 2.0) || equal(b, c))) + || (!bisected && ((std::fabs(s - b) >= std::fabs(c - d) / 2.0) || equal(c, d)))) { // Use bisection. s = bisect(a, b); @@ -671,7 +670,7 @@ class MATHS_EXPORT CSolvers fb = fs; } - if (::fabs(fa) < ::fabs(fb)) + if (std::fabs(fa) < std::fabs(fb)) { std::swap(a, b); std::swap(fa, fb); @@ -1076,7 +1075,7 @@ class MATHS_EXPORT CSolvers << ", f_(x) = " << fx - fc << ", f_(b) = " << fb - fc); - const double eps = ::sqrt(std::numeric_limits::epsilon()) * b; + const double eps = std::sqrt(std::numeric_limits::epsilon()) * b; CEqualWithTolerance equal(CToleranceTypes::E_AbsoluteTolerance, eps); LOG_TRACE("eps = " << eps); diff --git a/include/maths/CSphericalCluster.h b/include/maths/CSphericalCluster.h index ad6f1812e1..433da3d899 100644 --- a/include/maths/CSphericalCluster.h +++ b/include/maths/CSphericalCluster.h @@ -24,7 +24,7 @@ #include -#include +#include namespace ml { @@ -197,7 +197,7 @@ std::ostream &operator<<(std::ostream &o, { return o << static_cast(cluster) << " (" << cluster.annotation().s_Count - << "," << ::sqrt(cluster.annotation().s_Variance) << ")"; + << "," << std::sqrt(cluster.annotation().s_Variance) << ")"; } } diff --git a/include/maths/CSpline.h b/include/maths/CSpline.h index 6f939031db..27ed6ff8ed 100644 --- a/include/maths/CSpline.h +++ b/include/maths/CSpline.h @@ -26,12 +26,11 @@ #include #include +#include +#include #include #include -#include - - namespace ml { namespace maths @@ -345,7 +344,7 @@ class CSpline : public CSplineTypes case E_Linear: for (std::size_t i = 1u; i < n; ++i) { - result += ::fabs((this->values()[i] - this->values()[i-1])); + result += std::fabs((this->values()[i] - this->values()[i-1])); } break; @@ -363,7 +362,7 @@ class CSpline : public CSplineTypes double descriminant = bi * bi - 3.0 * ai * ci; if (descriminant < 0.0) { - result += ::fabs(((ai * h + bi) * h + ci) * h); + result += std::fabs(((ai * h + bi) * h + ci) * h); continue; } double rl = CTools::truncate(a - ( bi + descriminant) / 3.0 / ai, a, b); @@ -372,9 +371,9 @@ class CSpline : public CSplineTypes { std::swap(rl, rr); } - result += ::fabs(((ai * (rl - a) + bi) * (rl - a) + ci) * (rl - a)) - + ::fabs(((ai * (rr - rl) + bi) * (rr - rl) + ci) * (rr - rl)) - + ::fabs(((ai * (b - rr) + bi) * (b - rr) + ci) * (b - rr)); + result += std::fabs(((ai * (rl - a) + bi) * (rl - a) + ci) * (rl - a)) + + std::fabs(((ai * (rr - rl) + bi) * (rr - rl) + ci) * (rr - rl)) + + std::fabs(((ai * (b - rr) + bi) * (b - rr) + ci) * (b - rr)); } break; } diff --git a/include/maths/CToolsDetail.h b/include/maths/CToolsDetail.h index 73892dd20b..021b7aa36e 100644 --- a/include/maths/CToolsDetail.h +++ b/include/maths/CToolsDetail.h @@ -27,6 +27,7 @@ #include #include +#include #include namespace ml @@ -41,15 +42,15 @@ CTools::CMixtureProbabilityOfLessLikelySample::CSmoothedKernel::CSmoothedK m_LogF(logf), m_LogF0(logF0), m_K(k), - m_Scale(::exp(m_LogF0) * (1.0 + ::exp(-k))) + m_Scale(std::exp(m_LogF0) * (1.0 + std::exp(-k))) {} template void CTools::CMixtureProbabilityOfLessLikelySample::CSmoothedKernel::k(double k) { - double f0 = m_Scale / (1.0 + ::exp(-m_K)); + double f0 = m_Scale / (1.0 + std::exp(-m_K)); m_K = k; - m_Scale = f0 * (1.0 + ::exp(-k)); + m_Scale = f0 * (1.0 + std::exp(-k)); } template @@ -79,13 +80,13 @@ bool CTools::CMixtureProbabilityOfLessLikelySample::CSmoothedKernel::opera { return true; } - double fx = ::exp(logFx); + double fx = std::exp(logFx); if (fx < 1.0 + core::constants::LOG_DOUBLE_EPSILON / m_K) { result = m_Scale * fx; return true; } - result = m_Scale / (1.0 + ::exp(m_K * (fx - 1.0))) * fx; + result = m_Scale / (1.0 + std::exp(m_K * (fx - 1.0))) * fx; return true; } diff --git a/include/maths/CXMeansOnline.h b/include/maths/CXMeansOnline.h index 709a6c43ae..f880aa4e73 100644 --- a/include/maths/CXMeansOnline.h +++ b/include/maths/CXMeansOnline.h @@ -38,6 +38,7 @@ #include +#include #include #include @@ -191,7 +192,7 @@ class CXMeansOnline : public CClusterer > //! Propagate the cluster forwards by \p time. void propagateForwardsByTime(double time) { - double alpha = ::exp(-this->scaledDecayRate() * time); + double alpha = std::exp(-this->scaledDecayRate() * time); m_Covariances.age(alpha); m_Structure.age(alpha); } @@ -215,7 +216,7 @@ class CXMeansOnline : public CClusterer > //! This is defined as the trace of the sample covariance matrix. double spread(void) const { - return ::sqrt( CBasicStatistics::maximumLikelihoodCovariances(m_Covariances).trace() + return std::sqrt( CBasicStatistics::maximumLikelihoodCovariances(m_Covariances).trace() / static_cast(N)); } @@ -263,7 +264,7 @@ class CXMeansOnline : public CClusterer > { return likelihood; } - return likelihood + ::log(this->weight(calc)); + return likelihood + std::log(this->weight(calc)); } //! Get \p numberSamples from this cluster. @@ -616,7 +617,7 @@ class CXMeansOnline : public CClusterer > //! Get the scaled decay rate for use by propagateForwardsByTime. double scaledDecayRate(void) const { - return ::pow(0.5, static_cast(N)) * m_DecayRate; + return std::pow(0.5, static_cast(N)) * m_DecayRate; } private: @@ -905,7 +906,7 @@ class CXMeansOnline : public CClusterer > double normalizer = 0.0; for (std::size_t i = 0u; i < result.size(); ++i) { - result[i].second = ::exp(result[i].second - renormalizer); + result[i].second = std::exp(result[i].second - renormalizer); normalizer += result[i].second; } double pmax = 0.0; @@ -962,7 +963,7 @@ class CXMeansOnline : public CClusterer > // Normalize the likelihood values. double p0 = 1.0; - double p1 = ::exp(likelihood1 - likelihood0); + double p1 = std::exp(likelihood1 - likelihood0); double normalizer = p0 + p1; p0 /= normalizer; p1 /= normalizer; @@ -1039,7 +1040,7 @@ class CXMeansOnline : public CClusterer > LOG_ERROR("Can't propagate backwards in time"); return; } - m_HistoryLength *= ::exp(-m_DecayRate * time); + m_HistoryLength *= std::exp(-m_DecayRate * time); for (std::size_t i = 0u; i < m_Clusters.size(); ++i) { m_Clusters[i].propagateForwardsByTime(time); @@ -1210,7 +1211,7 @@ class CXMeansOnline : public CClusterer > { count += m_Clusters[i].count(); } - double scale = std::max(m_HistoryLength * (1.0 - ::exp(-m_InitialDecayRate)), 1.0); + double scale = std::max(m_HistoryLength * (1.0 - std::exp(-m_InitialDecayRate)), 1.0); count *= m_MinimumClusterFraction / scale; result = std::max(result, count); } diff --git a/include/test/CRandomNumbersDetail.h b/include/test/CRandomNumbersDetail.h index b01d74497f..e957a39a83 100644 --- a/include/test/CRandomNumbersDetail.h +++ b/include/test/CRandomNumbersDetail.h @@ -112,8 +112,8 @@ void CRandomNumbers::generateRandomMultivariateNormals(const TSizeVec &sizes, Eigen::Matrix rotation = Eigen::Matrix::Identity(); for (std::size_t j = 1u; j < coordinates.size(); j += 2) { - double ct = ::cos(thetas[j/2]); - double st = ::sin(thetas[j/2]); + double ct = std::cos(thetas[j/2]); + double st = std::sin(thetas[j/2]); Eigen::Matrix r = Eigen::Matrix::Identity(); r(coordinates[j/2], coordinates[j/2]) = ct; diff --git a/lib/api/CBaseTokenListDataTyper.cc b/lib/api/CBaseTokenListDataTyper.cc index 4fee420995..5d3c2d747a 100644 --- a/lib/api/CBaseTokenListDataTyper.cc +++ b/lib/api/CBaseTokenListDataTyper.cc @@ -24,19 +24,16 @@ #include #include +#include #include #include #include -#include - - namespace ml { namespace api { - // Initialise statics const std::string CBaseTokenListDataTyper::PRETOKENISED_TOKEN_FIELD("..."); @@ -580,7 +577,7 @@ size_t CBaseTokenListDataTyper::minMatchingWeight(size_t weight, double threshol // enforce this. Using floor + 1 due to threshold check being exclusive. // If threshold check is changed to inclusive, change formula to ceil // (without the + 1). - return static_cast(::floor(double(weight) * threshold + EPSILON)) + 1; + return static_cast(std::floor(double(weight) * threshold + EPSILON)) + 1; } size_t CBaseTokenListDataTyper::maxMatchingWeight(size_t weight, double threshold) @@ -599,7 +596,7 @@ size_t CBaseTokenListDataTyper::maxMatchingWeight(size_t weight, double threshol // enforce this. Using ceil - 1 due to threshold check being exclusive. // If threshold check is changed to inclusive, change formula to floor // (without the - 1). - return static_cast(::ceil(double(weight) / threshold - EPSILON)) - 1; + return static_cast(std::ceil(double(weight) / threshold - EPSILON)) - 1; } size_t CBaseTokenListDataTyper::idForToken(const std::string &token) diff --git a/lib/api/unittest/CMockDataAdder.h b/lib/api/unittest/CMockDataAdder.h index bc6855cb5a..0277babf9b 100644 --- a/lib/api/unittest/CMockDataAdder.h +++ b/lib/api/unittest/CMockDataAdder.h @@ -34,12 +34,12 @@ class CMockDataAdder : public ml::core::CDataAdder { public: - typedef std::vector TStrVec; - typedef std::map TStrStrVecMap; - typedef TStrStrVecMap::const_iterator TStrStrVecMapCItr; - typedef std::map TStrOStreamPMap; - typedef TStrOStreamPMap::const_iterator TStrOStreamPMapCItr; - typedef TStrOStreamPMap::iterator TStrOStreamPMapItr; + using TStrVec = std::vector; + using TStrStrVecMap = std::map; + using TStrStrVecMapCItr = TStrStrVecMap::const_iterator; + using TStrOStreamPMap = std::map; + using TStrOStreamPMapCItr = TStrOStreamPMap::const_iterator; + using TStrOStreamPMapItr = TStrOStreamPMap::iterator; public: CMockDataAdder(void); diff --git a/lib/config/CAutoconfigurer.cc b/lib/config/CAutoconfigurer.cc index f62115bd7f..60fdb9490b 100644 --- a/lib/config/CAutoconfigurer.cc +++ b/lib/config/CAutoconfigurer.cc @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -54,7 +55,7 @@ bool reportProgress(uint64_t records) { static const double LOG_10 = maths::CTools::fastLog(10.0); double log10 = maths::CTools::fastLog(static_cast(records) / 100.0) / LOG_10; - uint64_t nextPow10 = static_cast(::pow(10, ::ceil(log10))); + uint64_t nextPow10 = static_cast(std::pow(10, std::ceil(log10))); return records % std::max(nextPow10, uint64_t(100)) == 0; } diff --git a/lib/config/CDataCountStatistics.cc b/lib/config/CDataCountStatistics.cc index 8598118406..8aa012acfd 100644 --- a/lib/config/CDataCountStatistics.cc +++ b/lib/config/CDataCountStatistics.cc @@ -38,6 +38,7 @@ #include #include +#include namespace ml { @@ -51,8 +52,8 @@ using TBoolVec = std::vector; //! We sample a subset of short bucket lengths buckets for runtime. TBoolVec bucketSampleMask(core_t::TTime bucketLength) { - double n = ::ceil(std::max(3600.0 / static_cast(bucketLength), 1.0)); - TBoolVec result(static_cast(::sqrt(n)), true); + double n = std::ceil(std::max(3600.0 / static_cast(bucketLength), 1.0)); + TBoolVec result(static_cast(std::sqrt(n)), true); result.resize(static_cast(n), false); return result; } @@ -352,7 +353,7 @@ bool CDataCountStatistics::samplePartition(std::size_t partition) const } maths::CPRNG::CXorOShiro128Plus rng(partition); double n = static_cast(m_Partitions.size()); - double p = 1.0 - 0.99 * std::min(::floor(0.1 * n) / 1000.0, 1.0); + double p = 1.0 - 0.99 * std::min(std::floor(0.1 * n) / 1000.0, 1.0); return maths::CSampling::uniformSample(rng, 0.0, 1.0) < p; } diff --git a/lib/config/CDataSemantics.cc b/lib/config/CDataSemantics.cc index f92237d632..88199c6b83 100644 --- a/lib/config/CDataSemantics.cc +++ b/lib/config/CDataSemantics.cc @@ -23,6 +23,8 @@ #include +#include + namespace ml { namespace config @@ -71,7 +73,7 @@ class CMixtureData { double ci = maths::CBasicStatistics::count(m_Categories[i]); double vi = maths::CBasicStatistics::maximumLikelihoodVariance(m_Categories[i]); - double si = std::max(3.0 * ::sqrt(vi), 1.0 / boost::math::constants::root_two_pi()); + double si = std::max(3.0 * std::sqrt(vi), 1.0 / boost::math::constants::root_two_pi()); scale.add(static_cast(counts[i]) / si, ci); } return maths::CBasicStatistics::mean(scale); @@ -99,7 +101,7 @@ class CMixtureData double ci = maths::CBasicStatistics::count(m_Categories[i]); double mi = maths::CBasicStatistics::mean(m_Categories[i]); double vi = maths::CBasicStatistics::maximumLikelihoodVariance(m_Categories[i]); - double si = std::max(::sqrt(vi), 1.0 / boost::math::constants::root_two_pi()); + double si = std::max(std::sqrt(vi), 1.0 / boost::math::constants::root_two_pi()); m_Gmm.weights().push_back(ci / m_Count); m_Gmm.modes().push_back(boost::math::normal_distribution<>(mi, si)); } @@ -288,7 +290,7 @@ bool CDataSemantics::GMMGoodFit(void) const std::size_t N = m_EmpiricalDistribution.size(); LOG_TRACE("N = " << N); - double logc = ::log(m_Count); + double logc = std::log(m_Count); double smallest = m_Smallest[0].asDouble(); double offset = std::max(-smallest + 1.0, 0.0); LOG_TRACE("offset = " << offset); @@ -299,7 +301,7 @@ bool CDataSemantics::GMMGoodFit(void) const ++i) { double ni = static_cast(i->second); - categoricalBIC -= 2.0 * ni * ::log(ni / m_Count); + categoricalBIC -= 2.0 * ni * std::log(ni / m_Count); } LOG_TRACE("categorical BIC = " << categoricalBIC); @@ -332,7 +334,7 @@ bool CDataSemantics::GMMGoodFit(void) const double xi = smallest + scale * (i->first.asDouble() - smallest); double ni = static_cast(i->second); light.add(xi, ni); - heavy.add(::log(xi + offset), ni); + heavy.add(std::log(xi + offset), ni); } try @@ -349,9 +351,9 @@ bool CDataSemantics::GMMGoodFit(void) const double xi = smallest + scale * (i->first.asDouble() - smallest); double ni = static_cast(i->second); double fx = light.pdf(xi); - double gx = 1.0 / (xi + offset) * heavy.pdf(::log(xi + offset)); - lightGmmBIC -= 2.0 * ni * (fx == 0.0 ? boost::numeric::bounds::lowest() : ::log(fx)); - heavyGmmBIC -= 2.0 * ni * (gx == 0.0 ? boost::numeric::bounds::lowest() : ::log(gx)); + double gx = 1.0 / (xi + offset) * heavy.pdf(std::log(xi + offset)); + lightGmmBIC -= 2.0 * ni * (fx == 0.0 ? boost::numeric::bounds::lowest() : std::log(fx)); + heavyGmmBIC -= 2.0 * ni * (gx == 0.0 ? boost::numeric::bounds::lowest() : std::log(gx)); } LOG_TRACE("light BIC = " << lightGmmBIC << ", heavy BIC = " << heavyGmmBIC); diff --git a/lib/config/CDataSummaryStatistics.cc b/lib/config/CDataSummaryStatistics.cc index a6ce0f01b5..efac163592 100644 --- a/lib/config/CDataSummaryStatistics.cc +++ b/lib/config/CDataSummaryStatistics.cc @@ -27,6 +27,8 @@ #include +#include + namespace ml { namespace config @@ -39,7 +41,7 @@ using TDerefSecondGreater = core::CFunctional::SDereference(::ceil(1.5 * static_cast(n))); + return static_cast(std::ceil(1.5 * static_cast(n))); } const std::size_t DS_NUMBER_HASHES = 7; diff --git a/lib/config/CLongTailPenalty.cc b/lib/config/CLongTailPenalty.cc index 0ddf4808df..62bd3474a9 100644 --- a/lib/config/CLongTailPenalty.cc +++ b/lib/config/CLongTailPenalty.cc @@ -28,6 +28,8 @@ #include +#include + namespace ml { namespace config @@ -173,9 +175,9 @@ double CLongTailPenalty::penaltyFor(TSizeUInt64UMap &tail, TSizeUInt64UMap &tota double penalty = CTools::logInterpolate(this->params().highCardinalityHighTailFraction(), this->params().highCardinalityMaximumTailFraction(), 1.0, std::min(10.0 / total, 1.0), rare / total); - result.add(::sqrt(-std::min(maths::CTools::fastLog(penalty), 0.0)), total); + result.add(std::sqrt(-std::min(maths::CTools::fastLog(penalty), 0.0)), total); } - return ::exp(-::pow(maths::CBasicStatistics::mean(result), 2.0)); + return std::exp(-std::pow(maths::CBasicStatistics::mean(result), 2.0)); } } diff --git a/lib/config/CLowInformationContentPenalty.cc b/lib/config/CLowInformationContentPenalty.cc index 51e230862a..38d7b2d1d7 100644 --- a/lib/config/CLowInformationContentPenalty.cc +++ b/lib/config/CLowInformationContentPenalty.cc @@ -21,7 +21,7 @@ #include #include -#include +#include namespace ml { @@ -29,7 +29,7 @@ namespace config { namespace { -const double LOG_MIN = 0.5 * ::log(0.9 * constants::DETECTOR_SCORE_EPSILON / constants::MAXIMUM_DETECTOR_SCORE); +const double LOG_MIN = 0.5 * std::log(0.9 * constants::DETECTOR_SCORE_EPSILON / constants::MAXIMUM_DETECTOR_SCORE); } CLowInformationContentPenalty::CLowInformationContentPenalty(const CAutoconfigurerParams ¶ms) : @@ -60,18 +60,18 @@ void CLowInformationContentPenalty::penaltyFromMe(CDetectorSpecification &spec) double cardinality = static_cast(summary->distinctCount()); double entropy = summary->entropy(); double penalty = cardinality == 1.0 ? - 0.0 : ::exp(CTools::interpolate(this->params().lowLengthRangeForInfoContent(), - this->params().minimumLengthRangeForInfoContent(), - 0.0, LOG_MIN, maximumLength - minimumLength)) - * ::exp(CTools::interpolate(this->params().lowMaximumLengthForInfoContent(), - this->params().minimumMaximumLengthForInfoContent(), - 0.0, LOG_MIN, maximumLength)) - * ::exp(CTools::logInterpolate(this->params().lowEntropyForInfoContent(), - this->params().minimumEntropyForInfoContent(), - 0.0, LOG_MIN, entropy / ::log(cardinality))) - * ::exp(CTools::logInterpolate(this->params().lowDistinctCountForInfoContent(), - this->params().minimumDistinctCountForInfoContent(), - LOG_MIN, 0.0, cardinality)); + 0.0 : std::exp(CTools::interpolate(this->params().lowLengthRangeForInfoContent(), + this->params().minimumLengthRangeForInfoContent(), + 0.0, LOG_MIN, maximumLength - minimumLength)) + * std::exp(CTools::interpolate(this->params().lowMaximumLengthForInfoContent(), + this->params().minimumMaximumLengthForInfoContent(), + 0.0, LOG_MIN, maximumLength)) + * std::exp(CTools::logInterpolate(this->params().lowEntropyForInfoContent(), + this->params().minimumEntropyForInfoContent(), + 0.0, LOG_MIN, entropy / std::log(cardinality))) + * std::exp(CTools::logInterpolate(this->params().lowDistinctCountForInfoContent(), + this->params().minimumDistinctCountForInfoContent(), + LOG_MIN, 0.0, cardinality)); std::string description; if (penalty < 1.0) { diff --git a/lib/config/CLowVariationPenalty.cc b/lib/config/CLowVariationPenalty.cc index c5c4357f06..8ea40dd4ea 100644 --- a/lib/config/CLowVariationPenalty.cc +++ b/lib/config/CLowVariationPenalty.cc @@ -24,6 +24,7 @@ #include +#include #include namespace ml @@ -47,8 +48,8 @@ const double INF = boost::numeric::bounds::highest(); template double cov(const MOMENTS &moments) { - double m = ::fabs(maths::CBasicStatistics::mean(moments)); - double sd = ::sqrt(maths::CBasicStatistics::maximumLikelihoodVariance(moments)); + double m = std::fabs(maths::CBasicStatistics::mean(moments)); + double sd = std::sqrt(maths::CBasicStatistics::maximumLikelihoodVariance(moments)); return sd == 0.0 ? 0.0 : (m == 0.0 ? INF : sd / m); } @@ -72,7 +73,7 @@ void penaltyImpl(const CAutoconfigurerParams ¶ms, proportionWithLowVariation += 1.0; } } - penalty = std::min(::exp(maths::CBasicStatistics::mean(penalty_)), 1.0); + penalty = std::min(std::exp(maths::CBasicStatistics::mean(penalty_)), 1.0); proportionWithLowVariation /= static_cast(moments.size()); } @@ -98,7 +99,7 @@ struct SDistinctCountPenalty proportionWithLowVariation += 1.0; } } - penalty = std::min(::exp(maths::CBasicStatistics::mean(penalty_)), 1.0); + penalty = std::min(std::exp(maths::CBasicStatistics::mean(penalty_)), 1.0); proportionWithLowVariation /= static_cast(moments.size()); } }; @@ -125,7 +126,7 @@ struct SInfoContentPenalty proportionWithLowVariation += 1.0; } } - penalty = std::min(::exp(maths::CBasicStatistics::mean(penalty_)), 1.0); + penalty = std::min(std::exp(maths::CBasicStatistics::mean(penalty_)), 1.0); proportionWithLowVariation /= static_cast(moments.size()); } }; diff --git a/lib/config/CNotEnoughDataPenalty.cc b/lib/config/CNotEnoughDataPenalty.cc index 13ad75569c..3790791c88 100644 --- a/lib/config/CNotEnoughDataPenalty.cc +++ b/lib/config/CNotEnoughDataPenalty.cc @@ -27,6 +27,7 @@ #include +#include #include namespace ml @@ -170,7 +171,7 @@ void CNotEnoughDataPenalty::penaltyFor(const TUInt64Vec &bucketCounts, } } - double penalty = std::min(::exp(maths::CBasicStatistics::mean(penalty_)), 1.0); + double penalty = std::min(std::exp(maths::CBasicStatistics::mean(penalty_)), 1.0); std::size_t index = this->params().penaltyIndexFor(bid, IGNORE_EMPTY[i]); indices.push_back(index); penalties.push_back(penalty); diff --git a/lib/config/CPenalty.cc b/lib/config/CPenalty.cc index e38092a912..197a11e3c5 100644 --- a/lib/config/CPenalty.cc +++ b/lib/config/CPenalty.cc @@ -22,6 +22,8 @@ #include #include +#include + namespace ml { namespace config @@ -118,7 +120,7 @@ void CPenalty::penalize(CDetectorSpecification &spec) const double CPenalty::score(double penalty) { - return constants::DETECTOR_SCORE_EPSILON * ::floor( constants::MAXIMUM_DETECTOR_SCORE * penalty + return constants::DETECTOR_SCORE_EPSILON * std::floor( constants::MAXIMUM_DETECTOR_SCORE * penalty / constants::DETECTOR_SCORE_EPSILON); } diff --git a/lib/config/CPolledDataPenalty.cc b/lib/config/CPolledDataPenalty.cc index 0250eabb17..dcda292f0a 100644 --- a/lib/config/CPolledDataPenalty.cc +++ b/lib/config/CPolledDataPenalty.cc @@ -27,8 +27,8 @@ #include #include +#include #include -#include namespace ml { @@ -76,7 +76,7 @@ void CPolledDataPenalty::penaltyFromMe(CDetectorSpecification &spec) const indices.insert(indices.end(), indices_.begin(), indices_.end()); std::fill_n(std::back_inserter(penalties), indices_.size(), - ::pow(0.1, static_cast(stats->timeRange()) + std::pow(0.1, static_cast(stats->timeRange()) / static_cast(*interval) / LOG_TENTH_NUMBER_POLLING_INTERVALS)); std::fill_n(std::back_inserter(descriptions), diff --git a/lib/config/CSparseCountPenalty.cc b/lib/config/CSparseCountPenalty.cc index bc9617304d..986d0c219c 100644 --- a/lib/config/CSparseCountPenalty.cc +++ b/lib/config/CSparseCountPenalty.cc @@ -26,6 +26,7 @@ #include +#include #include namespace ml @@ -203,7 +204,7 @@ void CSparseCountPenalty::penaltyFromMe(CDetectorSpecification &spec) const double scale = static_cast(longest) / static_cast(candidates[bid]); for (std::size_t j = 0u; j < xq[bid].size(); ++j) { - xq[bid][j] = scale * means[bid] + ::sqrt(scale) * (xq[bid][j] - means[bid]); + xq[bid][j] = scale * means[bid] + std::sqrt(scale) * (xq[bid][j] - means[bid]); } } } @@ -226,7 +227,7 @@ void CSparseCountPenalty::penaltyFromMe(CDetectorSpecification &spec) const { std::size_t index = this->params().penaltyIndexFor(bid, IGNORE_EMPTY[iid]); indices.push_back(index); - double penalty = ::exp(maths::CBasicStatistics::mean(penalties_[bid])); + double penalty = std::exp(maths::CBasicStatistics::mean(penalties_[bid])); std::string description; if (penalty < 1.0) { diff --git a/lib/config/CTooMuchDataPenalty.cc b/lib/config/CTooMuchDataPenalty.cc index 89c11bb174..41437fca43 100644 --- a/lib/config/CTooMuchDataPenalty.cc +++ b/lib/config/CTooMuchDataPenalty.cc @@ -25,6 +25,7 @@ #include #include +#include #include namespace ml @@ -166,7 +167,7 @@ void CTooMuchDataPenalty::penaltyFor(const TUInt64Vec &bucketCounts, if (maths::CBasicStatistics::count(penalizedOccupancy) > 0.95 * static_cast(mi.size())) { - double penalty = std::min(::exp(maths::CBasicStatistics::mean(penalty_)), 1.0); + double penalty = std::min(std::exp(maths::CBasicStatistics::mean(penalty_)), 1.0); std::size_t index = this->params().penaltyIndexFor(bid, true); indices.push_back(index); penalties.push_back(penalty); diff --git a/lib/config/CTools.cc b/lib/config/CTools.cc index 2a989b0154..a7e07a0b0e 100644 --- a/lib/config/CTools.cc +++ b/lib/config/CTools.cc @@ -22,8 +22,8 @@ #include #include +#include #include -#include namespace ml { @@ -59,7 +59,7 @@ double CTools::interpolate(double a, double b, double pa, double pb, double x) double CTools::powInterpolate(double p, double a, double b, double pa, double pb, double x) { - return maths::CTools::truncate(pa + (pb - pa) * ::pow((x - a) / (b - a), p), + return maths::CTools::truncate(pa + (pb - pa) * std::pow((x - a) / (b - a), p), std::min(pa, pb), std::max(pa, pb)); } @@ -77,27 +77,27 @@ std::string CTools::prettyPrint(double d) char buf[20]; ::memset(buf, 0, sizeof(buf)); - if (::fabs(d) <= 1e-3) + if (std::fabs(d) <= 1e-3) { std::sprintf(buf, "%.2e", d); } - else if (::fabs(d) < 0.1) + else if (std::fabs(d) < 0.1) { std::sprintf(buf, "%.3f", d); } - else if (::fabs(d) < 1.0) + else if (std::fabs(d) < 1.0) { std::sprintf(buf, "%.2f", d); } - else if (::fabs(d) < 1e2) + else if (std::fabs(d) < 1e2) { std::sprintf(buf, "%.1f", d); } - else if (::fabs(d) < 1e5) + else if (std::fabs(d) < 1e5) { std::sprintf(buf, "%.0f", d); } - else if (::fabs(d) < 1e13) + else if (std::fabs(d) < 1e13) { std::sprintf(buf, "%.0f", d); char *end = std::find(buf, buf + 20, '\0'); diff --git a/lib/config/unittest/CDataSummaryStatisticsTest.cc b/lib/config/unittest/CDataSummaryStatisticsTest.cc index b3715f719c..e23ca01093 100644 --- a/lib/config/unittest/CDataSummaryStatisticsTest.cc +++ b/lib/config/unittest/CDataSummaryStatisticsTest.cc @@ -181,7 +181,7 @@ void CDataSummaryStatisticsTest::testCategoricalTopN(void) double exact = static_cast(counts[i]); double approx = static_cast(topn[i].second); - double error = ::fabs(exact - approx) / exact; + double error = std::fabs(exact - approx) / exact; CPPUNIT_ASSERT_EQUAL(categories[freq[i]], topn[i].first); CPPUNIT_ASSERT(error < 0.05); @@ -245,9 +245,9 @@ void CDataSummaryStatisticsTest::testNumericBasicStatistics(void) LOG_DEBUG("*** Log-Normal ***"); double location = 1.0; - double scale = ::sqrt(2.0); + double scale = std::sqrt(2.0); - boost::math::lognormal_distribution<> lognormal(1.0, ::sqrt(2.0)); + boost::math::lognormal_distribution<> lognormal(1.0, std::sqrt(2.0)); LOG_DEBUG("distribution median = " << boost::math::median(lognormal)); TMeanAccumulator meanError; @@ -263,9 +263,9 @@ void CDataSummaryStatisticsTest::testNumericBasicStatistics(void) } LOG_DEBUG("median = " << summary.median()); - CPPUNIT_ASSERT(::fabs(summary.median() - boost::math::median(lognormal)) < 0.25); + CPPUNIT_ASSERT(std::fabs(summary.median() - boost::math::median(lognormal)) < 0.25); - meanError.add( ::fabs(summary.median() - boost::math::median(lognormal)) + meanError.add( std::fabs(summary.median() - boost::math::median(lognormal)) / boost::math::median(lognormal)); } @@ -290,7 +290,7 @@ void CDataSummaryStatisticsTest::testNumericDistribution(void) rng.generateLogNormalSamples(1.0, 3.0, 10000, samples); - boost::math::lognormal_distribution<> d(1.0, ::sqrt(3.0)); + boost::math::lognormal_distribution<> d(1.0, std::sqrt(3.0)); config::CNumericDataSummaryStatistics statistics(false); for (std::size_t i = 0u; i < samples.size(); ++i) @@ -313,7 +313,7 @@ void CDataSummaryStatisticsTest::testNumericDistribution(void) double fexpected = boost::math::pdf(d, std::max(chart[i].first, 0.0)); double f = chart[i].second; LOG_DEBUG("x = " << chart[i].first << ", fexpected(x) = " << fexpected << ", f(x) = " << f); - meanAbsError.add(::fabs(f - fexpected)); + meanAbsError.add(std::fabs(f - fexpected)); mean.add(fexpected); } @@ -338,7 +338,7 @@ void CDataSummaryStatisticsTest::testNumericDistribution(void) samples.insert(samples.end(), modeSamples.begin(), modeSamples.end()); double weights[] = { 1.0 / 5.5, 2.0 / 5.5, 1.5 / 5.5, 1.0 / 5.5 }; - boost::math::normal_distribution<> m0(10.0, ::sqrt(10.0)); + boost::math::normal_distribution<> m0(10.0, std::sqrt(10.0)); boost::math::gamma_distribution<> m1(100.0, 1.0); boost::math::normal_distribution<> m2(200.0, 10.0); boost::math::gamma_distribution<> m3(100.0, 5.0); @@ -365,8 +365,8 @@ void CDataSummaryStatisticsTest::testNumericDistribution(void) + weights[3] * boost::math::pdf(m3, chart[i].first); double f = chart[i].second; LOG_DEBUG("x = " << chart[i].first << ", fexpected(x) = " << fexpected << ", f(x) = " << f); - meanAbsError.add(::fabs(f - fexpected)); - meanRelError.add(::fabs(::log(f) - ::log(fexpected)) / ::fabs(::log(fexpected))); + meanAbsError.add(std::fabs(f - fexpected)); + meanRelError.add(std::fabs(std::log(f) - std::log(fexpected)) / std::fabs(std::log(fexpected))); } LOG_DEBUG("meanAbsError = " << maths::CBasicStatistics::mean(meanAbsError)); diff --git a/lib/config/unittest/CReportWriterTest.cc b/lib/config/unittest/CReportWriterTest.cc index 4878b7de6b..5b0ad3b285 100644 --- a/lib/config/unittest/CReportWriterTest.cc +++ b/lib/config/unittest/CReportWriterTest.cc @@ -143,7 +143,7 @@ void CReportWriterTest::testPretty(void) const std::string &code = codes[index[0]]; stats2[2].add(time, code); - double range = weight_ > 1.0 ? ::sqrt(weight_) : weight_ * weight_; + double range = weight_ > 1.0 ? std::sqrt(weight_) : weight_ * weight_; rng.generateUniformSamples(weight_ - range / 2.0, weight_ + range / 2.0, 1, weight); stats3.add(time, core::CStringUtils::typeToString(weight[0])); diff --git a/lib/core/CIEEE754.cc b/lib/core/CIEEE754.cc index 86944e34f0..0741dd13d3 100644 --- a/lib/core/CIEEE754.cc +++ b/lib/core/CIEEE754.cc @@ -15,7 +15,7 @@ #include -#include +#include namespace ml { @@ -29,24 +29,24 @@ double CIEEE754::round(double value, EPrecision precision) // the values are close to max double. int exponent; - double mantissa = ::frexp(value, &exponent); + double mantissa = std::frexp(value, &exponent); switch (precision) { case E_HalfPrecision: { - static double PRECISION = 2048.0; + static const double PRECISION = 2048.0; mantissa = mantissa < 0.0 ? - ::ceil(mantissa * PRECISION - 0.5) / PRECISION : - ::floor(mantissa * PRECISION + 0.5) / PRECISION; + std::ceil(mantissa * PRECISION - 0.5) / PRECISION : + std::floor(mantissa * PRECISION + 0.5) / PRECISION; break; } case E_SinglePrecision: { - static double PRECISION = 16777216.0; + static const double PRECISION = 16777216.0; mantissa = mantissa < 0.0 ? - ::ceil(mantissa * PRECISION - 0.5) / PRECISION : - ::floor(mantissa * PRECISION + 0.5) / PRECISION; + std::ceil(mantissa * PRECISION - 0.5) / PRECISION : + std::floor(mantissa * PRECISION + 0.5) / PRECISION; break; } case E_DoublePrecision: @@ -54,7 +54,7 @@ double CIEEE754::round(double value, EPrecision precision) break; } - return ::ldexp(mantissa, exponent); + return std::ldexp(mantissa, exponent); } } diff --git a/lib/core/CStringUtils.cc b/lib/core/CStringUtils.cc index 12afb9b217..48725003bd 100644 --- a/lib/core/CStringUtils.cc +++ b/lib/core/CStringUtils.cc @@ -20,12 +20,12 @@ #include #include +#include #include #include #include #include -#include #include #include #include @@ -451,19 +451,19 @@ std::string CStringUtils::typeToStringPrecise(double d, switch (precision) { case CIEEE754::E_HalfPrecision: - ret = ::fabs(d) < 1.0 && d != 0.0 ? + ret = std::fabs(d) < 1.0 && d != 0.0 ? ::sprintf(buf, "%.2e", clampToReadable(CIEEE754::round(d, CIEEE754::E_HalfPrecision))) : ::sprintf(buf, "%.3g", clampToReadable(CIEEE754::round(d, CIEEE754::E_HalfPrecision))); break; case CIEEE754::E_SinglePrecision: - ret = ::fabs(d) < 1.0 && d != 0.0 ? + ret = std::fabs(d) < 1.0 && d != 0.0 ? ::sprintf(buf, "%.6e", clampToReadable(CIEEE754::round(d, CIEEE754::E_SinglePrecision))) : ::sprintf(buf, "%.7g", clampToReadable(CIEEE754::round(d, CIEEE754::E_SinglePrecision))); break; case CIEEE754::E_DoublePrecision: - ret = ::fabs(d) < 1.0 && d != 0.0 ? + ret = std::fabs(d) < 1.0 && d != 0.0 ? ::sprintf(buf, "%.14e", clampToReadable(d)) : ::sprintf(buf, "%.15g", clampToReadable(d)); break; diff --git a/lib/core/CWindowsError_Windows.cc b/lib/core/CWindowsError_Windows.cc index a9643c83f7..f2933281f5 100644 --- a/lib/core/CWindowsError_Windows.cc +++ b/lib/core/CWindowsError_Windows.cc @@ -17,8 +17,7 @@ #include #include -#include - +#include namespace { diff --git a/lib/core/unittest/CIEEE754Test.cc b/lib/core/unittest/CIEEE754Test.cc index 0210225b6b..5fab7cec01 100644 --- a/lib/core/unittest/CIEEE754Test.cc +++ b/lib/core/unittest/CIEEE754Test.cc @@ -18,11 +18,10 @@ #include #include +#include #include #include -#include - using namespace ml; using namespace core; @@ -70,9 +69,9 @@ void CIEEE754Test::testRound(void) } { // Check rounding for very large numbers. - double test5 = 0.49999998 * ::pow(2.0, 1023.0); + double test5 = 0.49999998 * std::pow(2.0, 1023.0); std::ostringstream o1; - o1 << std::setprecision(10) << 0.4999999702 * ::pow(2, 1023.0); + o1 << std::setprecision(10) << 0.4999999702 * std::pow(2, 1023.0); std::ostringstream o2; o2 << std::setprecision(10) << CIEEE754::round(test5, CIEEE754::E_SinglePrecision); LOG_DEBUG("test5 " << o1.str() << " " << o2.str()); @@ -80,9 +79,9 @@ void CIEEE754Test::testRound(void) } { // Check rounding for very large numbers. - double test6 = 0.499999998 * ::pow(2.0, 1023.0); + double test6 = 0.499999998 * std::pow(2.0, 1023.0); std::ostringstream o1; - o1 << std::setprecision(10) << ::pow(2.0, 1022.0); + o1 << std::setprecision(10) << std::pow(2.0, 1022.0); std::ostringstream o2; o2 << std::setprecision(10) << CIEEE754::round(test6, CIEEE754::E_SinglePrecision); LOG_DEBUG("test6 " << o1.str() << " " << o2.str()); diff --git a/lib/core/unittest/CPersistUtilsTest.cc b/lib/core/unittest/CPersistUtilsTest.cc index 9f44565af7..db96982bf7 100644 --- a/lib/core/unittest/CPersistUtilsTest.cc +++ b/lib/core/unittest/CPersistUtilsTest.cc @@ -21,15 +21,14 @@ #include #include -#include -#include -#include - #include #include #include -#include +#include +#include +#include +#include using namespace ml; @@ -92,7 +91,7 @@ struct SEqual { bool operator()(double lhs, double rhs) const { - return ::fabs(lhs - rhs) <= 1e-5 * std::max(::fabs(lhs), ::fabs(rhs)); + return std::fabs(lhs - rhs) <= 1e-5 * std::max(std::fabs(lhs), std::fabs(rhs)); } template diff --git a/lib/maths/CAgglomerativeClusterer.cc b/lib/maths/CAgglomerativeClusterer.cc index dafb9ae7de..84be1d0eaf 100644 --- a/lib/maths/CAgglomerativeClusterer.cc +++ b/lib/maths/CAgglomerativeClusterer.cc @@ -26,12 +26,11 @@ #include #include +#include #include #include #include -#include - namespace ml { namespace maths @@ -148,7 +147,7 @@ struct SWard double sb = sizes[b]; double sx = sizes[x]; distance(distanceMatrix, b, x) = - ::sqrt( (sa + sx) * distance(distanceMatrix, a, x) + std::sqrt( (sa + sx) * distance(distanceMatrix, a, x) + (sb + sx) * distance(distanceMatrix, b, x) - sx * distance(distanceMatrix, a, b)) / (sa + sb + sx); diff --git a/lib/maths/CBasicStatistics.cc b/lib/maths/CBasicStatistics.cc index b5ae71e066..45777d73e7 100644 --- a/lib/maths/CBasicStatistics.cc +++ b/lib/maths/CBasicStatistics.cc @@ -17,11 +17,9 @@ #include #include +#include #include -#include - - namespace ml { namespace maths diff --git a/lib/maths/CConstantPrior.cc b/lib/maths/CConstantPrior.cc index d2b575f9cf..b3b151bb34 100644 --- a/lib/maths/CConstantPrior.cc +++ b/lib/maths/CConstantPrior.cc @@ -26,13 +26,12 @@ #include +#include #include #include #include #include -#include - namespace ml { namespace maths @@ -60,7 +59,7 @@ const std::string CONSTANT_TAG("a"); const std::string EMPTY_STRING; -const double LOG_TWO = ::log(2.0); +const double LOG_TWO = std::log(2.0); } diff --git a/lib/maths/CCooccurrences.cc b/lib/maths/CCooccurrences.cc index 3aebf17a5e..bf88626a0e 100644 --- a/lib/maths/CCooccurrences.cc +++ b/lib/maths/CCooccurrences.cc @@ -27,6 +27,7 @@ #include +#include #include namespace ml @@ -202,7 +203,7 @@ void seed(const TPackedBitVectorVec &indicators, { theta[i] += pow2(projected[j][i]); } - theta[i] = ::acos(::sqrt(theta[i])); + theta[i] = std::acos(std::sqrt(theta[i])); } COrderings::simultaneousSort(theta, mask); for (std::size_t i = 1u; i < n; ++i) @@ -281,7 +282,7 @@ void searchForMostSignificantCooccurrences(const TPackedBitVectorVec &indicators { for (std::size_t j = 0u; j < n; ++j) { - thetas[i][j] = ::acos(thetas[i][j]); + thetas[i][j] = std::acos(thetas[i][j]); } COrderings::simultaneousSort(thetas[i], masks[i]); } @@ -295,7 +296,7 @@ void searchForMostSignificantCooccurrences(const TPackedBitVectorVec &indicators double lambda = mostSignificant.biggest().s_Nxy / (mostSignificant.biggest().s_Nx * mostSignificant.biggest().s_Ny); - double bound = 2.0 * ::asin(1.0 - lambda); + double bound = 2.0 * std::asin(1.0 - lambda); computeFilter(masks[0], thetas[0], i, bound, candidates); for (std::size_t j = 1u; !candidates.empty() && j < p; ++j) @@ -385,10 +386,10 @@ double significance(double nxy, double nx, double ny, double n) double px = nx / n; double py = ny / n; - double lambda = n * ( -g * px * py * ::log(g) - + px * (1.0 - g * py) * ::log((1.0 - py) / (1.0 - g * py)) - + py * (1.0 - g * px) * ::log((1.0 - px) / (1.0 - g * px)) - + (1.0 - px - py + g*px*py) * ::log((1.0 - px) * (1.0 - py) / (1.0 - px - py + g*px*py))); + double lambda = n * ( -g * px * py * std::log(g) + + px * (1.0 - g * py) * std::log((1.0 - py) / (1.0 - g * py)) + + py * (1.0 - g * px) * std::log((1.0 - px) / (1.0 - g * px)) + + (1.0 - px - py + g*px*py) * std::log((1.0 - px) * (1.0 - py) / (1.0 - px - py + g*px*py))); boost::math::chi_squared_distribution<> chi(1.0); @@ -496,7 +497,7 @@ void CCooccurrences::topNBySignificance(std::size_t n, } } - std::size_t p = static_cast(std::max(::sqrt(static_cast(dimension)), 1.0) + 0.5); + std::size_t p = static_cast(std::max(std::sqrt(static_cast(dimension)), 1.0) + 0.5); TMostSignificant mostSignificant(n); searchForMostSignificantCooccurrences(m_Indicators, lengths, mask, p, mostSignificant); diff --git a/lib/maths/CCountMinSketch.cc b/lib/maths/CCountMinSketch.cc index 22d1e081b0..bd431f32cd 100644 --- a/lib/maths/CCountMinSketch.cc +++ b/lib/maths/CCountMinSketch.cc @@ -25,6 +25,7 @@ #include +#include #include namespace ml @@ -227,7 +228,7 @@ double CCountMinSketch::delta(void) const { return 0.0; } - return ::exp(-static_cast(m_Rows)); + return std::exp(-static_cast(m_Rows)); } double CCountMinSketch::oneMinusDeltaError(void) const diff --git a/lib/maths/CDecayRateController.cc b/lib/maths/CDecayRateController.cc index e5ba3b627e..180780701c 100644 --- a/lib/maths/CDecayRateController.cc +++ b/lib/maths/CDecayRateController.cc @@ -29,7 +29,7 @@ #include #include -#include +#include namespace ml { diff --git a/lib/maths/CEntropySketch.cc b/lib/maths/CEntropySketch.cc index de09760e45..1741dbec45 100644 --- a/lib/maths/CEntropySketch.cc +++ b/lib/maths/CEntropySketch.cc @@ -23,6 +23,8 @@ #include +#include + namespace ml { namespace maths @@ -48,9 +50,9 @@ double CEntropySketch::calculate(void) const double h = 0.0; for (std::size_t i = 0u; i < m_Yi.size(); ++i) { - h += ::exp(m_Yi[i] / static_cast(m_Y)); + h += std::exp(m_Yi[i] / static_cast(m_Y)); } - return -::log(h / static_cast(m_Yi.size())); + return -std::log(h / static_cast(m_Yi.size())); } void CEntropySketch::generateProjection(std::size_t category, TDoubleVec &projection) @@ -60,9 +62,9 @@ void CEntropySketch::generateProjection(std::size_t category, TDoubleVec &projec for (std::size_t i = 0u; i < projection.size(); i += 2) { double w1 = boost::math::double_constants::pi * (projection[i] - 0.5); - double w2 = -::log(projection[i+1]); - projection[i / 2] = ::tan(w1) * (boost::math::double_constants::half_pi - w1) - + ::log(w2 * ::cos(w1) / (boost::math::double_constants::half_pi - w1)); + double w2 = -std::log(projection[i+1]); + projection[i / 2] = std::tan(w1) * (boost::math::double_constants::half_pi - w1) + + std::log(w2 * std::cos(w1) / (boost::math::double_constants::half_pi - w1)); } projection.resize(m_Yi.size()); LOG_TRACE("projection = " << core::CContainerPrinter::print(projection)); diff --git a/lib/maths/CGammaRateConjugate.cc b/lib/maths/CGammaRateConjugate.cc index f13b198ee2..9749279895 100644 --- a/lib/maths/CGammaRateConjugate.cc +++ b/lib/maths/CGammaRateConjugate.cc @@ -41,14 +41,13 @@ #include #include +#include #include #include #include #include #include -#include - namespace ml { namespace maths @@ -73,7 +72,7 @@ const double NON_INFORMATIVE_COUNT = 3.5; double minimumCoefficientOfVariation(bool isInteger, double mean) { return std::max(MINIMUM_COEFFICIENT_OF_VARIATION, - isInteger ? ::sqrt(1.0 / 12.0) / mean : 0.0); + isInteger ? std::sqrt(1.0 / 12.0) / mean : 0.0); } //! Apply the minimum coefficient of variation constraint to the sample @@ -120,8 +119,8 @@ void truncateVariance(bool isInteger, // we should bound the mean of log(x(i)) by: // log(mean(x(i))) - 1/2 * "minimum coefficient variation"^2 - double sampleDeviation = ::sqrt(CBasicStatistics::variance(moments)); - double sampleMean = std::max(::fabs(CBasicStatistics::mean(moments)), 1e-8); + double sampleDeviation = std::sqrt(CBasicStatistics::variance(moments)); + double sampleMean = std::max(std::fabs(CBasicStatistics::mean(moments)), 1e-8); double cov = sampleDeviation / sampleMean; double covMin = minimumCoefficientOfVariation(isInteger, sampleMean); if (cov < covMin) @@ -130,7 +129,7 @@ void truncateVariance(bool isInteger, moments.s_Moments[1] += extraDeviation * extraDeviation; } - double maxLogMean = ::log(moments.s_Moments[0]) - covMin * covMin / 2.0; + double maxLogMean = std::log(moments.s_Moments[0]) - covMin * covMin / 2.0; logMean.s_Moments[0] = std::min(double(logMean.s_Moments[0]), double(maxLogMean)); } } @@ -199,7 +198,7 @@ double maximumLikelihoodShape(double oldShape, double oldTarget = 0.0; if (oldNumber * oldMean > 0.0) { - oldTarget = ::log(oldNumber * oldMean) - CBasicStatistics::mean(oldLogMean); + oldTarget = std::log(oldNumber * oldMean) - CBasicStatistics::mean(oldLogMean); } double newNumber = CBasicStatistics::count(newMoments); @@ -209,7 +208,7 @@ double maximumLikelihoodShape(double oldShape, { return 0.0; } - double target = ::log(newNumber * newMean) - CBasicStatistics::mean(newLogMean); + double target = std::log(newNumber * newMean) - CBasicStatistics::mean(newLogMean); // Fall back to method of moments if maximum-likelihood fails. double bestGuess = 1.0; @@ -246,7 +245,7 @@ double maximumLikelihoodShape(double oldShape, // Choose the growth factors so we will typically bracket the root // in one iteration and not overshoot too much. Again we truncate // the values so that bracketing loop is well behaved. - double dTarget = ::fabs(target - oldTarget); + double dTarget = std::fabs(target - oldTarget); downFactor = CTools::truncate(1.0 - 2.0 * dTarget / gradient, MIN_DOWN_FACTOR, 1.0 - EPS); @@ -528,7 +527,7 @@ bool evaluateFunctionOnJointDistribution(const TWeightStyleVec &weightStyles, double scaledLikelihoodShape = likelihoodShape / varianceScale; double scaledPriorRate = varianceScale * priorRate; boost::math::beta_distribution<> beta(scaledLikelihoodShape, priorShape); - double z = CTools::sign(x) * ::fabs(x / (scaledPriorRate + x)); + double z = CTools::sign(x) * std::fabs(x / (scaledPriorRate + x)); LOG_TRACE("x = " << x << ", z = " << z); result = aggregate(result, func(beta, z), n); @@ -762,7 +761,7 @@ class CLogMarginalLikelihood : core::CNonCopyable this->addErrorStatus(maths_t::E_FpOverflowed); return false; } - logSamplesSum += n * (m_LikelihoodShape / varianceScale - 1.0) * ::log(sample); + logSamplesSum += n * (m_LikelihoodShape / varianceScale - 1.0) * std::log(sample); sampleSum += n / varianceScale * sample; } } @@ -775,7 +774,7 @@ class CLogMarginalLikelihood : core::CNonCopyable result = m_Constant + logSamplesSum - - m_ImpliedShape * ::log(m_PriorRate + sampleSum) + - m_ImpliedShape * std::log(m_PriorRate + sampleSum) - logSeasonalScaleSum; return true; @@ -809,7 +808,7 @@ class CLogMarginalLikelihood : core::CNonCopyable { logVarianceScaleSum -= m_LikelihoodShape / varianceScale - * ::log(varianceScale); + * std::log(varianceScale); logGammaScaledLikelihoodShape += n * boost::math::lgamma(m_LikelihoodShape / varianceScale); scaledImpliedShape += n * m_LikelihoodShape / varianceScale; @@ -826,7 +825,7 @@ class CLogMarginalLikelihood : core::CNonCopyable LOG_TRACE("numberSamples = " << m_NumberSamples); - m_Constant = m_PriorShape * ::log(m_PriorRate) + m_Constant = m_PriorShape * std::log(m_PriorRate) - boost::math::lgamma(m_PriorShape) + logVarianceScaleSum - logGammaScaledLikelihoodShape @@ -1089,18 +1088,18 @@ void CGammaRateConjugate::addSamples(const TWeightStyleVec &weightStyles, double shift_ = - shift + boost::math::digamma(m_LikelihoodShape / varianceScale) - + ::log(varianceScale); + + std::log(varianceScale); if (this->isInteger()) { - double logxInvPlus1 = ::log(1.0 / x + 1.0); - double logxPlus1 = ::log(x + 1.0); + double logxInvPlus1 = std::log(1.0 / x + 1.0); + double logxPlus1 = std::log(x + 1.0); m_LogSamplesMean.add(x * logxInvPlus1 + logxPlus1 - 1.0 - shift_, n / varianceScale); m_SampleMoments.add(x + 0.5, n / varianceScale); } else { - m_LogSamplesMean.add(::log(x) - shift_, n / varianceScale); + m_LogSamplesMean.add(std::log(x) - shift_, n / varianceScale); m_SampleMoments.add(x, n / varianceScale); } } @@ -1185,7 +1184,7 @@ void CGammaRateConjugate::propagateForwardsByTime(double time) TMeanVarAccumulator sampleMoments = m_SampleMoments; double count = CBasicStatistics::count(m_LogSamplesMean); - double alpha = ::exp(-this->decayRate() * time); + double alpha = std::exp(-this->decayRate() * time); alpha = count > detail::NON_INFORMATIVE_COUNT ? (alpha * count + (1.0 - alpha) * detail::NON_INFORMATIVE_COUNT) / count : 1.0; if (alpha < 1.0) @@ -1468,7 +1467,7 @@ void CGammaRateConjugate::sampleMarginalLikelihood(std::size_t numberSamples, numberSamples = std::min(numberSamples, static_cast(this->numberSamples() + 0.5)); double mean = CBasicStatistics::mean(m_SampleMoments) - m_Offset; - double deviation = ::sqrt(CBasicStatistics::variance(m_SampleMoments)); + double deviation = std::sqrt(CBasicStatistics::variance(m_SampleMoments)); double root_two = boost::math::double_constants::root_two; switch (numberSamples) @@ -1790,7 +1789,7 @@ void CGammaRateConjugate::print(const std::string &indent, std::string &result) { } double mean = CBasicStatistics::mean(m_SampleMoments); - double deviation = ::sqrt(CBasicStatistics::variance(m_SampleMoments)); + double deviation = std::sqrt(CBasicStatistics::variance(m_SampleMoments)); result += "mean = " + core::CStringUtils::typeToStringPretty(mean - m_Offset) + " sd = " + core::CStringUtils::typeToStringPretty(deviation); } diff --git a/lib/maths/CGramSchmidt.cc b/lib/maths/CGramSchmidt.cc index d37d4f8a07..98918bbfec 100644 --- a/lib/maths/CGramSchmidt.cc +++ b/lib/maths/CGramSchmidt.cc @@ -77,7 +77,7 @@ const CGramSchmidt::TVector &CGramSchmidt::divide(TVector &x, double s) double CGramSchmidt::norm(const TDoubleVec &x) { - return ::sqrt(inner(x, x)); + return std::sqrt(inner(x, x)); } double CGramSchmidt::norm(const TVector &x) diff --git a/lib/maths/CInformationCriteria.cc b/lib/maths/CInformationCriteria.cc index 28f060ed9f..98bae1e95a 100644 --- a/lib/maths/CInformationCriteria.cc +++ b/lib/maths/CInformationCriteria.cc @@ -38,7 +38,7 @@ double logDeterminant_(const MATRIX &covariance, double upper) double epsilon = svd.threshold() * svd.singularValues()(0); for (int i = 0u; i < svd.singularValues().size(); ++i) { - result += ::log(std::max(upper * svd.singularValues()(i), epsilon)); + result += std::log(std::max(upper * svd.singularValues()(i), epsilon)); } return result; } diff --git a/lib/maths/CIntegerTools.cc b/lib/maths/CIntegerTools.cc index 6815f4aa53..cdc07dbc94 100644 --- a/lib/maths/CIntegerTools.cc +++ b/lib/maths/CIntegerTools.cc @@ -17,9 +17,8 @@ #include -#include - #include +#include namespace ml { @@ -29,7 +28,7 @@ namespace maths bool CIntegerTools::isInteger(double value, double tolerance) { double integerPart; - double remainder = ::modf(value, &integerPart); + double remainder = std::modf(value, &integerPart); return remainder <= tolerance * integerPart; } diff --git a/lib/maths/CIntegration.cc b/lib/maths/CIntegration.cc index c7bd734624..d95b1153ca 100644 --- a/lib/maths/CIntegration.cc +++ b/lib/maths/CIntegration.cc @@ -17,8 +17,6 @@ #include -#include - namespace ml { namespace maths diff --git a/lib/maths/CKMeansOnline1d.cc b/lib/maths/CKMeansOnline1d.cc index 151e8bd278..051518b08d 100644 --- a/lib/maths/CKMeansOnline1d.cc +++ b/lib/maths/CKMeansOnline1d.cc @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -90,7 +91,7 @@ double logLikelihoodFromCluster(const TDouble1Vec &sample, { return likelihood; } - return likelihood + ::log(normal.numberSamples()); + return likelihood + std::log(normal.numberSamples()); } } // detail:: @@ -200,7 +201,7 @@ bool CKMeansOnline1d::clusterSpread(std::size_t index, double &result) const LOG_ERROR("Cluster " << index << " doesn't exist"); return false; } - result = ::sqrt(m_Clusters[index].marginalLikelihoodVariance()); + result = std::sqrt(m_Clusters[index].marginalLikelihoodVariance()); return true; } @@ -238,8 +239,8 @@ void CKMeansOnline1d::cluster(const double &point, double likelihoodRight = detail::logLikelihoodFromCluster(sample, *rightCluster); double renormalizer = std::max(likelihoodLeft, likelihoodRight); - double pLeft = ::exp(likelihoodLeft - renormalizer); - double pRight = ::exp(likelihoodRight - renormalizer); + double pLeft = std::exp(likelihoodLeft - renormalizer); + double pRight = std::exp(likelihoodRight - renormalizer); double normalizer = pLeft + pRight; pLeft /= normalizer; pRight /= normalizer; diff --git a/lib/maths/CKMostCorrelated.cc b/lib/maths/CKMostCorrelated.cc index b606590991..e1f0555766 100644 --- a/lib/maths/CKMostCorrelated.cc +++ b/lib/maths/CKMostCorrelated.cc @@ -35,6 +35,7 @@ #include #include +#include #include namespace bg = boost::geometry; @@ -293,8 +294,8 @@ void CKMostCorrelated::add(std::size_t X, double x) if (CBasicStatistics::count(moments) > 2.0) { double m = CBasicStatistics::mean(moments); - double sd = ::sqrt(CBasicStatistics::variance(moments)); - if (sd > 10.0 * std::numeric_limits::epsilon() * ::fabs(m)) + double sd = std::sqrt(CBasicStatistics::variance(moments)); + if (sd > 10.0 * std::numeric_limits::epsilon() * std::fabs(m)) { projected = m_Projections.back() * (x - m) / sd; m_CurrentProjected[X] += projected; @@ -620,7 +621,7 @@ void CKMostCorrelated::mostCorrelated(TCorrelationVec &result) const std::size_t X = points[i].second; const TVectorPackedBitVectorPr &px = m_Projected.at(X); - TVector width(::sqrt(threshold)); + TVector width(std::sqrt(threshold)); nearest.clear(); { bgm::box box((px.first - width).to().toBoostArray(), @@ -697,7 +698,7 @@ void CKMostCorrelated::nextProjection(void) m_Projected.clear(); - double factor = ::exp(-m_DecayRate); + double factor = std::exp(-m_DecayRate); m_MaximumCount *= factor; for (std::size_t i = 0u; i < m_Moments.size(); ++i) { @@ -816,14 +817,14 @@ double CKMostCorrelated::SCorrelation::distance(double amax) const { return static_cast(NUMBER_PROJECTIONS) * amax - * 2.0 * (1.0 - ::fabs(CBasicStatistics::mean(s_Correlation))); + * 2.0 * (1.0 - std::fabs(CBasicStatistics::mean(s_Correlation))); } double CKMostCorrelated::SCorrelation::absCorrelation(void) const { - return ::fabs(CBasicStatistics::mean(s_Correlation)) + return std::fabs(CBasicStatistics::mean(s_Correlation)) - ( 1.0 / std::max(CBasicStatistics::count(s_Correlation), 2.0) - + ::sqrt(CBasicStatistics::variance(s_Correlation))); + + std::sqrt(CBasicStatistics::variance(s_Correlation))); } double CKMostCorrelated::SCorrelation::correlation(const TVector &px, diff --git a/lib/maths/CLassoLogisticRegression.cc b/lib/maths/CLassoLogisticRegression.cc index 0a8a71dc42..34c0d37ccc 100644 --- a/lib/maths/CLassoLogisticRegression.cc +++ b/lib/maths/CLassoLogisticRegression.cc @@ -25,7 +25,7 @@ #include #include -#include +#include namespace ml { @@ -46,12 +46,12 @@ using TDoubleVec = std::vector; //! iterative solver. double F(double r, double delta) { - r = ::fabs(r); + r = std::fabs(r); if (r <= delta) { return 0.25; } - double s = ::exp(r - delta); + double s = std::exp(r - delta); return 1.0 / (2.0 + s + 1.0 / s); } @@ -120,11 +120,11 @@ double logLikelihood(const MATRIX &x, for (std::size_t i = 0u; i < f.size(); ++i) { - result -= ::log(1.0 + ::exp(-f[i] * y[i])); + result -= std::log(1.0 + std::exp(-f[i] * y[i])); } for (std::size_t j = 0u; j < beta.size(); ++j) { - result -= lambda[j] * ::fabs(beta[j]); + result -= lambda[j] * std::fabs(beta[j]); } return result; @@ -169,8 +169,8 @@ void CLG(std::size_t maxIterations, double xy = xij * y[i]; double xx = xij * xij; double ri = r[i]; - num[j] += xy / (1.0 + ::exp(ri)); - den[j] += xx * F(ri, Dj * ::fabs(xij)); + num[j] += xy / (1.0 + std::exp(ri)); + den[j] += xx * F(ri, Dj * std::fabs(xij)); } } @@ -188,7 +188,7 @@ void CLG(std::size_t maxIterations, double dbj = CTools::truncate(dvj, -Dj, +Dj); beta[j] += dbj; - delta[j] = std::max(2.0 * ::fabs(dbj), Dj / 2.0); + delta[j] = std::max(2.0 * std::fabs(dbj), Dj / 2.0); if (dbj != 0.0 || j+1 == d) { for (iterator itr = x.beginRows(j); itr != x.endRows(j); ++itr) @@ -209,8 +209,8 @@ void CLG(std::size_t maxIterations, double xy = xij * y[i]; double xx = xij * xij; double ri = r[i]; - numjPlus1 += xy / (1.0 + ::exp(ri)); - denjPlus1 += xx * F(ri, DjPlus1 * ::fabs(xij)); + numjPlus1 += xy / (1.0 + std::exp(ri)); + denjPlus1 += xx * F(ri, DjPlus1 * std::fabs(xij)); } } } @@ -226,8 +226,8 @@ void CLG(std::size_t maxIterations, double sum = 0.0; for (std::size_t i = 0u; i < r.size(); ++i) { - dsum += ::fabs(r[i] - rlast[i]); - sum += ::fabs(r[i]); + dsum += std::fabs(r[i] - rlast[i]); + sum += std::fabs(r[i]); } LOG_TRACE("sum |dr| = " << dsum << ", sum |r| = " << sum); if (dsum < eps * (1.0 + sum)) @@ -465,7 +465,7 @@ bool CLogisticRegressionModel::operator()(const TDoubleVec &x, { r -= m_Beta[i].second * x[m_Beta[i].first]; } - probability = 1.0 / (1.0 + ::exp(-r)); + probability = 1.0 / (1.0 + std::exp(-r)); return true; } @@ -494,7 +494,7 @@ double CLogisticRegressionModel::operator()(const TSizeDoublePrVec &x) const ++j; } } - return 1.0 / (1.0 + ::exp(-r)); + return 1.0 / (1.0 + std::exp(-r)); } namespace @@ -798,7 +798,7 @@ void CLassoLogisticRegression::doLearnHyperparameter(EHyperparametersSt std::size_t n = m_X.size(); LOG_DEBUG("d = " << m_D << ", n = " << n); - double lambda = ::sqrt(l22Norm(m_X) / 2.0); + double lambda = std::sqrt(l22Norm(m_X) / 2.0); m_Lambda = lambda; if (n <= 1) { diff --git a/lib/maths/CLinearAlgebraTools.cc b/lib/maths/CLinearAlgebraTools.cc index a00aac625e..c5a2ab59f0 100644 --- a/lib/maths/CLinearAlgebraTools.cc +++ b/lib/maths/CLinearAlgebraTools.cc @@ -109,7 +109,7 @@ class CGaussianLogLikelihood } result = -0.5 * ( residual(0) * residual(0) / covariance_(0, 0) + core::constants::LOG_TWO_PI - + ::log(covariance_(0, 0))); + + std::log(covariance_(0, 0))); return maths_t::E_FpNoErrors; default: @@ -135,7 +135,7 @@ class CGaussianLogLikelihood double logDeterminant = 0.0; for (std::size_t i = 0u; i < rank; ++i) { - logDeterminant += ::log(covariance.singularValues()(i)); + logDeterminant += std::log(covariance.singularValues()(i)); } result = -0.5 * ( residual.inner(y) + static_cast(rank) * core::constants::LOG_TWO_PI @@ -188,7 +188,7 @@ class CSampleGaussian { LOG_TRACE("# intervals = " << numberIntervals); result.reserve(rank * numberIntervals); - double scale = ::sqrt(static_cast(rank)); + double scale = std::sqrt(static_cast(rank)); LOG_TRACE("scale = " << scale) for (std::size_t i = 0u; i < rank; ++i) @@ -197,7 +197,7 @@ class CSampleGaussian try { double variance = covariance.singularValues()(i); - boost::math::normal_distribution<> normal(0.0, ::sqrt(variance)); + boost::math::normal_distribution<> normal(0.0, std::sqrt(variance)); LOG_TRACE("[U]_{.i} = " << covariance.matrixU().col(i).transpose()) LOG_TRACE("variance = " << variance); LOG_TRACE("u = " << u); @@ -251,7 +251,7 @@ class CLogDeterminant { return maths_t::E_FpOverflowed; } - result = ::log(m_(0, 0)); + result = std::log(m_(0, 0)); return maths_t::E_FpNoErrors; default: @@ -264,13 +264,13 @@ class CLogDeterminant std::size_t rank = static_cast(svd.rank()); if (!ignoreSingularSubspace && rank < d) { - result = static_cast(d - rank) * ::log(svd.threshold() * svd.singularValues()(0)); + result = static_cast(d - rank) * std::log(svd.threshold() * svd.singularValues()(0)); return maths_t::E_FpOverflowed; } result = 0.0; for (std::size_t i = 0u; i < rank; ++i) { - result += ::log(svd.singularValues()(i)); + result += std::log(svd.singularValues()(i)); } return maths_t::E_FpNoErrors; } diff --git a/lib/maths/CLogTDistribution.cc b/lib/maths/CLogTDistribution.cc index 09864e566e..753dc16ae8 100644 --- a/lib/maths/CLogTDistribution.cc +++ b/lib/maths/CLogTDistribution.cc @@ -21,7 +21,7 @@ #include #include -#include +#include namespace ml { @@ -106,8 +106,8 @@ double mode(const CLogTDistribution &distribution) double location = distribution.location(); - return ::exp(location - (degreesFreedom + 1.0) / 2.0 - + ::sqrt(square(degreesFreedom + 1.0) / 4.0 + return std::exp(location - (degreesFreedom + 1.0) / 2.0 + + std::sqrt(square(degreesFreedom + 1.0) / 4.0 - degreesFreedom * squareScale)); } @@ -131,8 +131,8 @@ CLogTDistribution::TOptionalDouble localMinimum(const CLogTDistribution &distrib double location = distribution.location(); - return ::exp(location - (degreesFreedom + 1.0) / 2.0 - - ::sqrt(square(degreesFreedom + 1.0) / 4.0 + return std::exp(location - (degreesFreedom + 1.0) / 2.0 + - std::sqrt(square(degreesFreedom + 1.0) / 4.0 - degreesFreedom * squareScale)); } @@ -171,7 +171,7 @@ double pdf(const CLogTDistribution &distribution, double x) double scale = distribution.scale(); double location = distribution.location(); - double value = (::log(x) - location) / scale; + double value = (std::log(x) - location) / scale; return CTools::safePdf(students, value) / scale / x; } @@ -202,7 +202,7 @@ double cdf(const CLogTDistribution &distribution, double x) double scale = distribution.scale(); double location = distribution.location(); - double value = (::log(x) - location) / scale; + double value = (std::log(x) - location) / scale; return CTools::safeCdf(students, value); } @@ -227,7 +227,7 @@ double cdfComplement(const CLogTDistribution &distribution, double x) double scale = distribution.scale(); double location = distribution.location(); - double value = (::log(x) - location) / scale; + double value = (std::log(x) - location) / scale; return CTools::safeCdfComplement(students, value); } @@ -244,7 +244,7 @@ double quantile(const CLogTDistribution &distribution, double q) double scale = distribution.scale(); double location = distribution.location(); - return ::exp(scale * y_q + location); + return std::exp(scale * y_q + location); } } diff --git a/lib/maths/CModelWeight.cc b/lib/maths/CModelWeight.cc index bedd548bd3..757389cbab 100644 --- a/lib/maths/CModelWeight.cc +++ b/lib/maths/CModelWeight.cc @@ -22,7 +22,7 @@ #include #include -#include +#include namespace ml { @@ -35,18 +35,18 @@ namespace // We use short field names to reduce the state size const std::string LOG_WEIGHT_TAG("a"); const std::string LONG_TERM_LOG_WEIGHT_TAG("c"); -const double LOG_SMALLEST_WEIGHT = ::log(CTools::smallestProbability()); +const double LOG_SMALLEST_WEIGHT = std::log(CTools::smallestProbability()); } CModelWeight::CModelWeight(double weight) : - m_LogWeight(::log(weight)), + m_LogWeight(std::log(weight)), m_LongTermLogWeight(m_LogWeight) {} CModelWeight::operator double(void) const { - return m_LogWeight < LOG_SMALLEST_WEIGHT ? 0.0 : ::exp(m_LogWeight); + return m_LogWeight < LOG_SMALLEST_WEIGHT ? 0.0 : std::exp(m_LogWeight); } double CModelWeight::logWeight(void) const diff --git a/lib/maths/CMultimodalPrior.cc b/lib/maths/CMultimodalPrior.cc index 5bfa8e8486..d475bd2e4f 100644 --- a/lib/maths/CMultimodalPrior.cc +++ b/lib/maths/CMultimodalPrior.cc @@ -490,14 +490,14 @@ double CMultimodalPrior::nearestMarginalLikelihoodMean(double value) const } double mean = m_Modes[0].s_Prior->marginalLikelihoodMean(); - double distance = ::fabs(value - mean); + double distance = std::fabs(value - mean); double result = mean; for (std::size_t i = 1u; i < m_Modes.size(); ++i) { mean = m_Modes[i].s_Prior->marginalLikelihoodMean(); - if (::fabs(value - mean) < distance) + if (std::fabs(value - mean) < distance) { - distance = ::fabs(value - mean); + distance = std::fabs(value - mean); result = mean; } } diff --git a/lib/maths/CMultinomialConjugate.cc b/lib/maths/CMultinomialConjugate.cc index c5cf5f9cc6..1b1ad4c547 100644 --- a/lib/maths/CMultinomialConjugate.cc +++ b/lib/maths/CMultinomialConjugate.cc @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -544,7 +545,7 @@ void CMultinomialConjugate::propagateForwardsByTime(double time) return; } - double alpha = ::exp(-this->decayRate() * time); + double alpha = std::exp(-this->decayRate() * time); // We want to increase the variance of each category while holding // its mean constant s.t. in the limit t -> inf var -> inf. The mean @@ -936,10 +937,10 @@ bool CMultinomialConjugate::minusLogJointCdf(const TWeightStyleVec &weightStyles // the log blows up. lowerBound = sampleLowerBound == 0.0 || lowerBound == MAX_DOUBLE ? MAX_DOUBLE : - lowerBound - n * ::log(sampleLowerBound); + lowerBound - n * std::log(sampleLowerBound); upperBound = sampleUpperBound == 0.0 || upperBound == MAX_DOUBLE ? MAX_DOUBLE : - upperBound - n * ::log(sampleUpperBound); + upperBound - n * std::log(sampleUpperBound); } return true; @@ -970,10 +971,10 @@ bool CMultinomialConjugate::minusLogJointCdfComplement(const TWeightStyleVec &we // the log blows up. lowerBound = sampleLowerBound == 0.0 || lowerBound == MAX_DOUBLE ? MAX_DOUBLE : - lowerBound - n * ::log(sampleLowerBound); + lowerBound - n * std::log(sampleLowerBound); upperBound = sampleUpperBound == 0.0 || upperBound == MAX_DOUBLE ? MAX_DOUBLE : - upperBound - n * ::log(sampleUpperBound); + upperBound - n * std::log(sampleUpperBound); } return true; diff --git a/lib/maths/CMultivariateConstantPrior.cc b/lib/maths/CMultivariateConstantPrior.cc index f609e35aca..cf5a10fb96 100644 --- a/lib/maths/CMultivariateConstantPrior.cc +++ b/lib/maths/CMultivariateConstantPrior.cc @@ -35,8 +35,6 @@ #include #include -#include - namespace ml { namespace maths diff --git a/lib/maths/CMultivariateMultimodalPrior.cc b/lib/maths/CMultivariateMultimodalPrior.cc index bc30ce05af..52d6609433 100644 --- a/lib/maths/CMultivariateMultimodalPrior.cc +++ b/lib/maths/CMultivariateMultimodalPrior.cc @@ -110,12 +110,12 @@ maths_t::EFloatingPointErrorStatus { double w = modes[likelihood.first].weight(); // Divide through by the largest value to avoid underflow. - sampleLikelihood += w * ::exp(likelihood.second - maxLogLikelihood); + sampleLikelihood += w * std::exp(likelihood.second - maxLogLikelihood); Z += w; } sampleLikelihood /= Z; - result = (::log(sampleLikelihood) + maxLogLikelihood); + result = (std::log(sampleLikelihood) + maxLogLikelihood); LOG_TRACE("sample = " << core::CContainerPrinter::print(sample) << ", maxLogLikelihood = " << maxLogLikelihood diff --git a/lib/maths/CMultivariateOneOfNPrior.cc b/lib/maths/CMultivariateOneOfNPrior.cc index 696f0cfa00..8f1c6a2930 100644 --- a/lib/maths/CMultivariateOneOfNPrior.cc +++ b/lib/maths/CMultivariateOneOfNPrior.cc @@ -36,11 +36,10 @@ #include #include +#include #include #include -#include - namespace ml { namespace maths @@ -209,7 +208,7 @@ void modelAcceptPersistInserter(const CModelWeight &weight, const double DERATE = 0.99999; const double MINUS_INF = DERATE * boost::numeric::bounds::lowest(); const double INF = DERATE * boost::numeric::bounds::highest(); -const double LOG_INITIAL_WEIGHT = ::log(1e-6); +const double LOG_INITIAL_WEIGHT = std::log(1e-6); const double MINIMUM_SIGNIFICANT_WEIGHT = 0.01; } @@ -492,7 +491,7 @@ void CMultivariateOneOfNPrior::propagateForwardsByTime(double time) CScopeCanonicalizeWeights canonicalize(m_Models); - double alpha = ::exp(-this->scaledDecayRate() * time); + double alpha = std::exp(-this->scaledDecayRate() * time); for (auto &model : m_Models) { @@ -529,13 +528,13 @@ CMultivariateOneOfNPrior::univariate(const TSize10Vec &marginalize, models.emplace_back(1.0, prior.first); weights.push_back(prior.second + model.first.logWeight()); maxWeight.add(weights.back()); - Z += ::exp(model.first.logWeight()); + Z += std::exp(model.first.logWeight()); } } for (std::size_t i = 0u; i < weights.size(); ++i) { - models[i].first *= ::exp(weights[i] - maxWeight[0]) / Z; + models[i].first *= std::exp(weights[i] - maxWeight[0]) / Z; } return std::make_pair(TUnivariatePriorPtr(new COneOfNPrior(models, this->dataType(), this->decayRate())), @@ -568,13 +567,13 @@ CMultivariateOneOfNPrior::bivariate(const TSize10Vec &marginalize, models.emplace_back(1.0, prior.first); weights.push_back(prior.second + model.first.logWeight()); maxWeight.add(weights.back()); - Z += ::exp(model.first.logWeight()); + Z += std::exp(model.first.logWeight()); } } for (std::size_t i = 0u; i < weights.size(); ++i) { - models[i].first *= ::exp(weights[i] - maxWeight[0]) / Z; + models[i].first *= std::exp(weights[i] - maxWeight[0]) / Z; } return std::make_pair(TPriorPtr(new CMultivariateOneOfNPrior(2, models, this->dataType(), this->decayRate())), @@ -711,7 +710,7 @@ TDouble10Vec CMultivariateOneOfNPrior::marginalLikelihoodMode(const TWeightStyle sample[0] = model.second->marginalLikelihoodMode(weightStyles, weights); double logLikelihood; model.second->jointLogMarginalLikelihood(weightStyles, sample, sampleWeights, logLikelihood); - updateMean(sample[0], model.first * ::exp(logLikelihood), result, w); + updateMean(sample[0], model.first * std::exp(logLikelihood), result, w); } } @@ -762,7 +761,7 @@ CMultivariateOneOfNPrior::jointLogMarginalLikelihood(const TWeightStyleVec &weig logLikelihoods.push_back(logLikelihood); maxLogLikelihood.add(logLikelihood); } - Z += ::exp(model.first.logWeight()); + Z += std::exp(model.first.logWeight()); } } @@ -774,7 +773,7 @@ CMultivariateOneOfNPrior::jointLogMarginalLikelihood(const TWeightStyleVec &weig for (auto logLikelihood : logLikelihoods) { - result += ::exp(logLikelihood - maxLogLikelihood[0]); + result += std::exp(logLikelihood - maxLogLikelihood[0]); } result = maxLogLikelihood[0] + CTools::fastLog(result / Z); @@ -936,7 +935,7 @@ CMultivariateOneOfNPrior::TDouble3Vec CMultivariateOneOfNPrior::weights(void) co TDouble3Vec result = this->logWeights(); for (auto &weight : result) { - weight = ::exp(weight); + weight = std::exp(weight); } return result; } @@ -949,9 +948,9 @@ CMultivariateOneOfNPrior::TDouble3Vec CMultivariateOneOfNPrior::logWeights(void) for (const auto &model : m_Models) { result.push_back(model.first.logWeight()); - Z += ::exp(result.back()); + Z += std::exp(result.back()); } - Z = ::log(Z); + Z = std::log(Z); for (auto &weight : result) { weight -= Z; @@ -999,7 +998,7 @@ std::string CMultivariateOneOfNPrior::debugWeights(void) const } const double CMultivariateOneOfNPrior::MAXIMUM_RELATIVE_ERROR = 1e-3; -const double CMultivariateOneOfNPrior::LOG_MAXIMUM_RELATIVE_ERROR = ::log(MAXIMUM_RELATIVE_ERROR); +const double CMultivariateOneOfNPrior::LOG_MAXIMUM_RELATIVE_ERROR = std::log(MAXIMUM_RELATIVE_ERROR); } } diff --git a/lib/maths/CMultivariatePrior.cc b/lib/maths/CMultivariatePrior.cc index 0c7c893077..bd4407c21d 100644 --- a/lib/maths/CMultivariatePrior.cc +++ b/lib/maths/CMultivariatePrior.cc @@ -341,8 +341,8 @@ bool CMultivariatePrior::probabilityOfLessLikelySamples(maths_t::EProbabilityCal LOG_TRACE("lb = " << core::CContainerPrinter::print(lb) << ", ub = " << core::CContainerPrinter::print(ub)); - lowerBound = ::sqrt(lb[0] * lb[1]); - upperBound = ::sqrt(ub[0] * ub[1]); + lowerBound = std::sqrt(lb[0] * lb[1]); + upperBound = std::sqrt(ub[0] * ub[1]); return true; } @@ -427,7 +427,7 @@ std::string CMultivariatePrior::printMarginalLikelihoodFunction(std::size_t x, s sample[0][1] = y_; double l; xyMargin->jointLogMarginalLikelihood(CConstantWeights::COUNT, sample, weight, l); - likelihood << ::exp(l) << " "; + likelihood << std::exp(l) << " "; } likelihood << core_t::LINE_ENDING; } @@ -479,7 +479,7 @@ double CMultivariatePrior::unmarginalizedParameters(void) const double CMultivariatePrior::scaledDecayRate(void) const { - return ::pow(0.5, static_cast(this->dimension())) * this->decayRate(); + return std::pow(0.5, static_cast(this->dimension())) * this->decayRate(); } void CMultivariatePrior::addSamples(double n) diff --git a/lib/maths/CNaturalBreaksClassifier.cc b/lib/maths/CNaturalBreaksClassifier.cc index 9f3b6f015f..9eb167f69b 100644 --- a/lib/maths/CNaturalBreaksClassifier.cc +++ b/lib/maths/CNaturalBreaksClassifier.cc @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include @@ -136,7 +136,7 @@ double CNaturalBreaksClassifier::percentile(double p) const if (percentileCount < count) { double mean = CBasicStatistics::mean(m_Categories[i]); - double deviation = ::sqrt(CBasicStatistics::maximumLikelihoodVariance(m_Categories[i])); + double deviation = std::sqrt(CBasicStatistics::maximumLikelihoodVariance(m_Categories[i])); if (deviation == 0.0) { return mean; @@ -155,14 +155,14 @@ double CNaturalBreaksClassifier::percentile(double p) const // Left truncate by the assignment boundary between // this and the left category. See deviation for // details. - double n1 = ::sqrt(CBasicStatistics::count(m_Categories[i-1])); + double n1 = std::sqrt(CBasicStatistics::count(m_Categories[i-1])); double m1 = CBasicStatistics::mean(m_Categories[i-1]); - double d1 = ::sqrt(CBasicStatistics::maximumLikelihoodVariance(m_Categories[i-1])); + double d1 = std::sqrt(CBasicStatistics::maximumLikelihoodVariance(m_Categories[i-1])); double n2 = count; double m2 = mean; double d2 = deviation; - double w1 = ::sqrt(n2 * d2); - double w2 = ::sqrt(n1 * d1); + double w1 = std::sqrt(n2 * d2); + double w2 = std::sqrt(n1 * d1); double xl = (w1 * m1 + w2 * m2) / (w1 + w2); LOG_TRACE("Left truncate to " << xl); x = std::max(x, xl); @@ -175,11 +175,11 @@ double CNaturalBreaksClassifier::percentile(double p) const double n1 = count; double m1 = mean; double d1 = deviation; - double n2 = ::sqrt(CBasicStatistics::count(m_Categories[i+1])); + double n2 = std::sqrt(CBasicStatistics::count(m_Categories[i+1])); double m2 = CBasicStatistics::mean(m_Categories[i+1]); - double d2 = ::sqrt(CBasicStatistics::maximumLikelihoodVariance(m_Categories[i+1])); - double w1 = ::sqrt(n2 * d2); - double w2 = ::sqrt(n1 * d1); + double d2 = std::sqrt(CBasicStatistics::maximumLikelihoodVariance(m_Categories[i+1])); + double w1 = std::sqrt(n2 * d2); + double w2 = std::sqrt(n1 * d1); double xr = (w1 * m1 + w2 * m2) / (w1 + w2); LOG_TRACE("Right truncate to " << xr); x = std::min(x, xr); @@ -464,7 +464,7 @@ void CNaturalBreaksClassifier::propagateForwardsByTime(double time) return; } - double alpha = ::exp(-m_DecayRate * time); + double alpha = std::exp(-m_DecayRate * time); LOG_TRACE("alpha = " << alpha); LOG_TRACE("categories = " << core::CContainerPrinter::print(m_Categories)); @@ -534,7 +534,7 @@ void CNaturalBreaksClassifier::sample(std::size_t numberSamples, for (std::size_t i = 0u; i < m_Categories.size(); ++i) { double ni = static_cast(numberSamples) * weights[i]; - std::size_t ni_ = static_cast(::ceil(ni)); + std::size_t ni_ = static_cast(std::ceil(ni)); double m = CBasicStatistics::mean(m_Categories[i]); double v = CBasicStatistics::maximumLikelihoodVariance(m_Categories[i]); @@ -898,7 +898,7 @@ double CNaturalBreaksClassifier::deviation(const TTuple &category) double count = CBasicStatistics::count(category); double variance = CBasicStatistics::maximumLikelihoodVariance(category); - return ::sqrt(count * variance); + return std::sqrt(count * variance); } double CNaturalBreaksClassifier::variation(const TTuple &category) diff --git a/lib/maths/CNormalMeanPrecConjugate.cc b/lib/maths/CNormalMeanPrecConjugate.cc index a0998c2d06..dec149d34f 100644 --- a/lib/maths/CNormalMeanPrecConjugate.cc +++ b/lib/maths/CNormalMeanPrecConjugate.cc @@ -610,7 +610,7 @@ void CNormalMeanPrecConjugate::reset(maths_t::EDataType dataType, if (m_GaussianPrecision > 1.5) { - double truncatedMean = std::max(::fabs(m_GaussianMean), 1e-8); + double truncatedMean = std::max(std::fabs(m_GaussianMean), 1e-8); double minimumDeviation = truncatedMean * MINIMUM_COEFFICIENT_OF_VARIATION; double minimumRate = (m_GaussianPrecision - 1.0) * minimumDeviation * minimumDeviation; m_GammaRate = std::max(m_GammaRate, minimumRate); @@ -785,7 +785,7 @@ void CNormalMeanPrecConjugate::addSamples(const TWeightStyleVec &weightStyles, if (m_GaussianPrecision > 1.5) { - double truncatedMean = std::max(::fabs(m_GaussianMean), 1e-8); + double truncatedMean = std::max(std::fabs(m_GaussianMean), 1e-8); double minimumDeviation = truncatedMean * MINIMUM_COEFFICIENT_OF_VARIATION; double minimumRate = (2.0 * m_GammaShape - 1.0) * minimumDeviation * minimumDeviation; m_GammaRate = std::max(m_GammaRate, minimumRate); diff --git a/lib/maths/COrdinal.cc b/lib/maths/COrdinal.cc index 624e29a344..9def93aaa2 100644 --- a/lib/maths/COrdinal.cc +++ b/lib/maths/COrdinal.cc @@ -17,8 +17,8 @@ #include +#include #include -#include #include #include diff --git a/lib/maths/CPoissonMeanConjugate.cc b/lib/maths/CPoissonMeanConjugate.cc index 9f7a4a9543..7bb3554c08 100644 --- a/lib/maths/CPoissonMeanConjugate.cc +++ b/lib/maths/CPoissonMeanConjugate.cc @@ -38,14 +38,13 @@ #include #include +#include #include #include #include #include #include -#include - namespace ml { namespace maths @@ -173,7 +172,7 @@ bool evaluateFunctionOnJointDistribution(const TWeightStyleVec &weightStyles, double mean = shape / rate; if (mean > MINIMUM_GAUSSIAN_MEAN) { - double deviation = ::sqrt((rate + 1.0) / rate * mean); + double deviation = std::sqrt((rate + 1.0) / rate * mean); boost::math::normal_distribution<> normal(mean, deviation); result = aggregate(result, func(normal, x), n); } @@ -451,7 +450,7 @@ void CPoissonMeanConjugate::propagateForwardsByTime(double time) return; } - double alpha = ::exp(-this->decayRate() * time); + double alpha = std::exp(-this->decayRate() * time); // We want to increase the variance of the gamma distribution // while holding its mean constant s.t. in the limit t -> inf @@ -685,8 +684,8 @@ CPoissonMeanConjugate::jointLogMarginalLikelihood(const TWeightStyleVec &weightS double impliedRate = m_Rate + numberSamples; result = boost::math::lgamma(impliedShape) - + m_Shape * ::log(m_Rate) - - impliedShape * ::log(impliedRate) + + m_Shape * std::log(m_Rate) + - impliedShape * std::log(impliedRate) - sampleLogFactorialSum - boost::math::lgamma(m_Shape); } @@ -771,7 +770,7 @@ void CPoissonMeanConjugate::sampleMarginalLikelihood(std::size_t numberSamples, try { - boost::math::normal_distribution<> normal(mean, ::sqrt(variance)); + boost::math::normal_distribution<> normal(mean, std::sqrt(variance)); for (std::size_t i = 1u; i < numberSamples; ++i) { @@ -1002,7 +1001,7 @@ void CPoissonMeanConjugate::print(const std::string &indent, return; } result += "mean = " + core::CStringUtils::typeToStringPretty(this->marginalLikelihoodMean()) - + " sd = " + core::CStringUtils::typeToStringPretty(::sqrt(this->marginalLikelihoodVariance())); + + " sd = " + core::CStringUtils::typeToStringPretty(std::sqrt(this->marginalLikelihoodVariance())); } std::string CPoissonMeanConjugate::printJointDensityFunction(void) const @@ -1028,7 +1027,7 @@ std::string CPoissonMeanConjugate::printJointDensityFunction(void) const // Calculate the first point and increment at which to plot the p.d.f. double mean = boost::math::mean(gamma); - double dev = ::sqrt(boost::math::variance(gamma)); + double dev = std::sqrt(boost::math::variance(gamma)); double increment = RANGE * dev / (POINTS - 1.0); double x = std::max(mean - RANGE * dev / 2.0, 0.0); diff --git a/lib/maths/CPrior.cc b/lib/maths/CPrior.cc index f5147c3e35..a44d5cf78b 100644 --- a/lib/maths/CPrior.cc +++ b/lib/maths/CPrior.cc @@ -29,13 +29,12 @@ #include #include +#include #include #include #include #include -#include - namespace ml { namespace maths diff --git a/lib/maths/CProbabilityCalibrator.cc b/lib/maths/CProbabilityCalibrator.cc index ba628eb2e5..62e5915286 100644 --- a/lib/maths/CProbabilityCalibrator.cc +++ b/lib/maths/CProbabilityCalibrator.cc @@ -25,6 +25,7 @@ #include #include +#include #include namespace ml @@ -42,14 +43,14 @@ const double DISCRETIZATION_FACTOR = 100.0; uint32_t discreteProbability(const double probability) { return static_cast(DISCRETIZATION_FACTOR - * -::log(probability) + 0.5); + * -std::log(probability) + 0.5); } //! Convert a discrete probability integer into the //! approximate probability which generated it. double rawProbability(const uint32_t &discreteProbability) { - return ::exp(-static_cast(discreteProbability) + return std::exp(-static_cast(discreteProbability) / DISCRETIZATION_FACTOR); } diff --git a/lib/maths/CQDigest.cc b/lib/maths/CQDigest.cc index 6475223066..fa5a1f4bc5 100644 --- a/lib/maths/CQDigest.cc +++ b/lib/maths/CQDigest.cc @@ -30,13 +30,12 @@ #include #include +#include #include #include #include #include -#include - namespace ml { namespace maths @@ -170,7 +169,7 @@ void CQDigest::propagateForwardsByTime(double time) return; } - double alpha = ::exp(-m_DecayRate * time); + double alpha = std::exp(-m_DecayRate * time); m_N = m_Root->age(alpha); diff --git a/lib/maths/CQuantileSketch.cc b/lib/maths/CQuantileSketch.cc index 7efdaa0ab7..c43199df17 100644 --- a/lib/maths/CQuantileSketch.cc +++ b/lib/maths/CQuantileSketch.cc @@ -452,9 +452,9 @@ bool CQuantileSketch::checkInvariants(void) const { count += m_Knots[i].second; } - if (::fabs(m_Count - count) > 10.0 * EPS * m_Count) + if (std::fabs(m_Count - count) > 10.0 * EPS * m_Count) { - LOG_ERROR("Count mismatch: error " << ::fabs(m_Count - count) << "/" << m_Count); + LOG_ERROR("Count mismatch: error " << std::fabs(m_Count - count) << "/" << m_Count); return false; } return true; diff --git a/lib/maths/CRadialBasisFunction.cc b/lib/maths/CRadialBasisFunction.cc index 8e4941f242..796a7ca001 100644 --- a/lib/maths/CRadialBasisFunction.cc +++ b/lib/maths/CRadialBasisFunction.cc @@ -22,8 +22,7 @@ #include #include -#include - +#include namespace ml { @@ -50,7 +49,7 @@ double gaussianSquareDerivative(double x, double r = scale * (x - centre); return scale * (boost::math::double_constants::root_two_pi * boost::math::erf(boost::math::double_constants::root_two * r) - - 4.0 * r * ::exp(-2.0 * r * r)) / 4.0; + - 4.0 * r * std::exp(-2.0 * r * r)) / 4.0; } //! The indefinite integral @@ -65,14 +64,14 @@ double gaussianProduct(double x, { double ss = scale1 + scale2; double sd = scale2 - scale1; - double scale = ::sqrt((ss * ss + sd * sd) / 2.0); + double scale = std::sqrt((ss * ss + sd * sd) / 2.0); double m = (scale1 * scale1 * centre1 + scale2 * scale2 * centre2) / (scale * scale); double d = scale1 * scale2 * (centre2 - centre1); return boost::math::double_constants::root_pi - * ::exp(-d * d / (scale * scale)) + * std::exp(-d * d / (scale * scale)) * boost::math::erf(scale * (x - m)) / (2.0 * scale); } @@ -90,7 +89,7 @@ double inverseQuadraticSquareDerivative(double x, return scale * ( 3.0 * r / d + 2.0 * r / (d * d) - 8.0 * r / (d * d * d) - + 3.0 * ::atan(r)) / 12.0; + + 3.0 * std::atan(r)) / 12.0; } //! The indefinite integral @@ -111,19 +110,19 @@ double inverseQuadraticProduct(double x, if (sd == 0.0 && d == 0.0) { - return (r1 / (1.0 + r1 * r1) + ::atan(r1)) / (2.0 * scale1); + return (r1 / (1.0 + r1 * r1) + std::atan(r1)) / (2.0 * scale1); } if ((d * d) > 1.0) { - return ( scale1 * scale2 / d * ::log((1.0 + r1 * r1) / (1.0 + r2 * r2)) - + scale1 * (1.0 - (ss * sd) / (d * d)) * ::atan(r1) - + scale2 * (1.0 + (ss * sd) / (d * d)) * ::atan(r2)) + return ( scale1 * scale2 / d * std::log((1.0 + r1 * r1) / (1.0 + r2 * r2)) + + scale1 * (1.0 - (ss * sd) / (d * d)) * std::atan(r1) + + scale2 * (1.0 + (ss * sd) / (d * d)) * std::atan(r2)) / ((1.0 + (ss * ss) / (d * d)) * (d * d + sd * sd)); } - return ( scale1 * scale2 * d * ::log((1.0 + r1 * r1) / (1.0 + r2 * r2)) - + (d * d - ss * sd) * scale1 * ::atan(r1) - + (d * d + ss * sd) * scale2 * ::atan(r2)) + return ( scale1 * scale2 * d * std::log((1.0 + r1 * r1) / (1.0 + r2 * r2)) + + (d * d - ss * sd) * scale1 * std::atan(r1) + + (d * d + ss * sd) * scale2 * std::atan(r2)) / ((d * d + ss * ss) * (d * d + sd * sd)); } @@ -144,7 +143,7 @@ double CGaussianBasisFunction::value(double x, { double r = x - centre; double y = scale * r; - return ::exp(-y * y); + return std::exp(-y * y); } double CGaussianBasisFunction::derivative(double x, @@ -153,7 +152,7 @@ double CGaussianBasisFunction::derivative(double x, { double r = x - centre; double y = scale * r; - return -2.0 * scale * y * ::exp(-y * y); + return -2.0 * scale * y * std::exp(-y * y); } bool CGaussianBasisFunction::scale(double distance, @@ -164,7 +163,7 @@ bool CGaussianBasisFunction::scale(double distance, { return false; } - result = ::sqrt(-::log(value)) / distance; + result = std::sqrt(-std::log(value)) / distance; return true; } @@ -340,8 +339,8 @@ double CInverseQuadraticBasisFunction::mean(double a, return (fmax + fmin) / 2.0; } - return std::max((::atan(scale * (b - centre)) - - ::atan(scale * (a - centre))) / scale / (b - a), 0.0); + return std::max((std::atan(scale * (b - centre)) + - std::atan(scale * (a - centre))) / scale / (b - a), 0.0); } double CInverseQuadraticBasisFunction::meanSquareDerivative(double a, @@ -396,7 +395,7 @@ bool CInverseQuadraticBasisFunction::scale(double distance, { return false; } - result = ::sqrt((1.0 - value) / value) / distance; + result = std::sqrt((1.0 - value) / value) / distance; return true; } diff --git a/lib/maths/CSampling.cc b/lib/maths/CSampling.cc index 75af1d7ee4..e2a28aadf8 100644 --- a/lib/maths/CSampling.cc +++ b/lib/maths/CSampling.cc @@ -35,14 +35,13 @@ #include #include +#include #include #include #include #include #include -#include - namespace ml { namespace maths @@ -102,7 +101,7 @@ double doNormalSample(RNG &rng, double mean, double variance) LOG_ERROR("Invalid variance " << variance); return mean; } - boost::random::normal_distribution normal(mean, ::sqrt(variance)); + boost::random::normal_distribution normal(mean, std::sqrt(variance)); return normal(rng); } @@ -122,7 +121,7 @@ void doNormalSample(RNG &rng, double mean, double variance, std::size_t n, TDoub } result.reserve(n); - boost::random::normal_distribution normal(mean, ::sqrt(variance)); + boost::random::normal_distribution normal(mean, std::sqrt(variance)); for (std::size_t i = 0u; i < n; ++i) { result.push_back(normal(rng)); @@ -357,7 +356,7 @@ bool doMultivariateNormalSample(RNG &rng, stddevs.reserve(d); for (std::size_t i = 0u; i < d; ++i) { - stddevs.push_back(::sqrt(std::max(S(i), 0.0))); + stddevs.push_back(std::sqrt(std::max(S(i), 0.0))); } LOG_TRACE("Singular values of C = " << S.transpose()); LOG_TRACE("stddevs = " << core::CContainerPrinter::print(stddevs)); @@ -421,7 +420,7 @@ void doMultivariateNormalSample(RNG &rng, T stddevs[N] = {}; for (std::size_t i = 0u; i < N; ++i) { - stddevs[i] = ::sqrt(std::max(S(i), 0.0)); + stddevs[i] = std::sqrt(std::max(S(i), 0.0)); } { @@ -886,16 +885,16 @@ void CSampling::weightedSample(std::size_t n, { // We need to re-normalize so that the probabilities sum to one. double number = weights[i] * static_cast(n) / totalWeight; - choices.push_back((number - ::floor(number) < 0.5) ? 0u : 1u); - remainders[0].push_back(number - ::floor(number)); - remainders[1].push_back(number - ::ceil(number)); + choices.push_back((number - std::floor(number) < 0.5) ? 0u : 1u); + remainders[0].push_back(number - std::floor(number)); + remainders[1].push_back(number - std::ceil(number)); totalRemainder += remainders[choices.back()].back(); } // The remainder will be integral so checking against 0.5 avoids // floating point problems. - if (::fabs(totalRemainder) > 0.5) + if (std::fabs(totalRemainder) > 0.5) { LOG_TRACE("ideal choice function = " << core::CContainerPrinter::print(choices)); @@ -906,7 +905,7 @@ void CSampling::weightedSample(std::size_t n, if ( (totalRemainder > 0.0 && choices[i] == 0u) || (totalRemainder < 0.0 && choices[i] == 1u)) { - candidates.emplace_back(-::fabs(remainders[choices[i]][i]), i); + candidates.emplace_back(-std::fabs(remainders[choices[i]][i]), i); } } std::sort(candidates.begin(), candidates.end()); @@ -914,7 +913,7 @@ void CSampling::weightedSample(std::size_t n, << core::CContainerPrinter::print(candidates)); for (std::size_t i = 0u; - i < candidates.size() && ::fabs(totalRemainder) > 0.5; + i < candidates.size() && std::fabs(totalRemainder) > 0.5; ++i) { std::size_t j = candidates[i].second; @@ -932,7 +931,7 @@ void CSampling::weightedSample(std::size_t n, double number = weights[i] * static_cast(n) / totalWeight; sampling.push_back(static_cast( - choices[i] == 0u ? ::floor(number) : ::ceil(number))); + choices[i] == 0u ? std::floor(number) : std::ceil(number))); } } @@ -955,7 +954,7 @@ void CSampling::normalSampleQuantiles(double mean, try { - boost::math::normal_distribution<> normal(mean, ::sqrt(variance)); + boost::math::normal_distribution<> normal(mean, std::sqrt(variance)); sampleQuantiles(normal, n, result); } catch (const std::exception &e) diff --git a/lib/maths/CSeasonalComponent.cc b/lib/maths/CSeasonalComponent.cc index 63f3de1e7c..f4ee5365a7 100644 --- a/lib/maths/CSeasonalComponent.cc +++ b/lib/maths/CSeasonalComponent.cc @@ -355,7 +355,7 @@ core_t::TTime CSeasonalComponent::jitter(core_t::TTime time) core_t::TTime a{time_.startOfWindow(time)}; core_t::TTime b{a + time_.windowLength() - 1}; double jitter{0.5 * m_Bucketing.minimumBucketLength() - * (f <= 0.5 ? ::sqrt(2.0 * f) - 1.0 : ::sqrt(2.0 * (f - 0.5)))}; + * (f <= 0.5 ? std::sqrt(2.0 * f) - 1.0 : std::sqrt(2.0 * (f - 0.5)))}; result = CTools::truncate(result + static_cast(jitter + 0.5), a, b); } return result; diff --git a/lib/maths/CStatisticalTests.cc b/lib/maths/CStatisticalTests.cc index b5eb13400c..31588cd054 100644 --- a/lib/maths/CStatisticalTests.cc +++ b/lib/maths/CStatisticalTests.cc @@ -62,9 +62,9 @@ double significance(double lambda) double termbf = 0.0; for (std::size_t j = 1; j <= 100; ++j) { - double term = fac * ::exp(t2 * static_cast(j * j)); + double term = fac * std::exp(t2 * static_cast(j * j)); sum += term; - if (::fabs(term) <= EPS1 * termbf || ::fabs(term) <= EPS2 * sum) + if (std::fabs(term) <= EPS1 * termbf || std::fabs(term) <= EPS2 * sum) { return sum; } @@ -159,10 +159,10 @@ double CStatisticalTests::twoSampleKS(TDoubleVec x, TDoubleVec y) } double Fx = static_cast(i) / static_cast(nx); double Fy = static_cast(j) / static_cast(ny); - D = std::max(D, ::fabs(Fx - Fy)); + D = std::max(D, std::fabs(Fx - Fy)); } - double neff = ::sqrt( static_cast(nx) + double neff = std::sqrt( static_cast(nx) * static_cast(ny) / static_cast(nx + ny)); double result = significance((neff + 0.12 + 0.11/neff) * D); @@ -298,10 +298,10 @@ double CStatisticalTests::CCramerVonMises::pValue(void) const // m = ab/(b-a) * log(f(b)/f(a)) // c = b/(b-a) * log(f(b)/f(a)) + log(f(a)) - double m = a*b / (b - a) * ::log((fb) / (fa)); - double c = b / (b - a) * ::log((fb) / (fa)) + ::log(fa); + double m = a*b / (b - a) * std::log((fb) / (fa)); + double c = b / (b - a) * std::log((fb) / (fa)) + std::log(fa); - double p = 1.0 - ::exp(-m / t + c); + double p = 1.0 - std::exp(-m / t + c); LOG_TRACE("p = 1.0 - exp(" << -m << " / T + " << c << ") = " << p); return p; } @@ -313,9 +313,9 @@ double CStatisticalTests::CCramerVonMises::pValue(void) const // m = 1/(a-b) * log((1-f(b))/(1-f(a))) // c = a/(a-b) * log((1-f(b))/(1-f(a))) + log(1-f(a)) - double m = 1.0 / (a - b) * ::log((1.0 - fb) / (1.0 - fa)); - double c = a / (a - b) * ::log((1.0 - fb) / (1.0 - fa)) + ::log(1.0 - fa); - double p = ::exp(-m * t + c); + double m = 1.0 / (a - b) * std::log((1.0 - fb) / (1.0 - fa)); + double c = a / (a - b) * std::log((1.0 - fb) / (1.0 - fa)) + std::log(1.0 - fa); + double p = std::exp(-m * t + c); LOG_TRACE("p = exp(" << -m << " T + " << c << ") = " << p); return p; diff --git a/lib/maths/CTools.cc b/lib/maths/CTools.cc index 6d14849651..548b5edd3b 100644 --- a/lib/maths/CTools.cc +++ b/lib/maths/CTools.cc @@ -503,7 +503,7 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const negative_binomia double x, maths_t::ETail &tail) const { - x = ::floor(x); + x = std::floor(x); double px = 0.0; @@ -611,7 +611,7 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const negative_binomia double logOneMinusP = std::log(1 - p); - b1 = ::floor(m + std::log( std::max(fx, MIN_DOUBLE) + b1 = std::floor(m + std::log( std::max(fx, MIN_DOUBLE) / std::max(fm, MIN_DOUBLE)) / logOneMinusP); f1 = safePdf(negativeBinomial, b1); b2 = b1; @@ -676,11 +676,11 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const negative_binomia } catch (const std::exception &e) { - if (::fabs(f1 - fx) < 10.0 * EPSILON * fx) + if (std::fabs(f1 - fx) < 10.0 * EPSILON * fx) { y = b1; } - else if (::fabs(f2 - fx) < 10.0 * EPSILON * fx) + else if (std::fabs(f2 - fx) < 10.0 * EPSILON * fx) { y = b2; } @@ -747,7 +747,7 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const lognormal &logNo * (logx - logNormal.location())); double m = boost::math::mode(logNormal); this->tail(x, m, tail); - double y = m * ::exp(x > m ? -discriminant : discriminant); + double y = m * std::exp(x > m ? -discriminant : discriminant); if (x > y) { std::swap(x, y); @@ -852,11 +852,11 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const CLogTDistributio } catch (const std::exception &e) { - if (::fabs(f1 - fx) < 10.0 * EPSILON * fx) + if (std::fabs(f1 - fx) < 10.0 * EPSILON * fx) { y = b1; } - else if (::fabs(f2 - fx) < 10.0 * EPSILON * fx) + else if (std::fabs(f2 - fx) < 10.0 * EPSILON * fx) { y = b2; } @@ -910,13 +910,13 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const CLogTDistributio double s = logt.scale(); // Initialize the bracket. - double fl = pdf(logt, ::exp(l)); + double fl = pdf(logt, std::exp(l)); double scale = std::sqrt(v) * s; double bound = 0.0; double fBound = POS_INF; if (fl < fx) { - bound = ::exp(l); + bound = std::exp(l); fBound = fl; } else @@ -924,7 +924,7 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const CLogTDistributio double t1 = l + std::log(fl / fx); double t2 = (l - scale) / 8.0 + std::log(scale / 3.0); double k0 = 8.0 * (t1 + (v + 1.0) * t2) / (v + 9.0); - bound = std::max(::exp(l), ::exp(k0)); + bound = std::max(std::exp(l), std::exp(k0)); fBound = pdf(logt, bound); } double b1 = fBound < fx ? m : bound; @@ -940,7 +940,7 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const CLogTDistributio // of early exit based on an upper bound for the bracket. Note // that we accelerate the growth if we don't bracket the root // quickly and fallback to the bound if we haven't bracketed - double step = std::max(b2, ::exp(l) - b2); + double step = std::max(b2, std::exp(l) - b2); double growthFactor = 1.0; for (;;) { @@ -1000,11 +1000,11 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const CLogTDistributio } catch (const std::exception &e) { - if (::fabs(f1 - fx) < 10.0 * EPSILON * fx) + if (std::fabs(f1 - fx) < 10.0 * EPSILON * fx) { y = b1; } - else if (::fabs(f2 - fx) < 10.0 * EPSILON * fx) + else if (std::fabs(f2 - fx) < 10.0 * EPSILON * fx) { y = b2; } @@ -1094,7 +1094,7 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const gamma &gamma_, y[(i + 1) % 2] = x + m * std::log(y[i % 2] / x); LOG_TRACE("y = " << y[(i + 1) % 2]); if (++i == MAX_ITERATIONS - || ::fabs(y[1] - y[0]) < CONVERGENCE_TOLERANCE * std::max(y[0], y[1])) + || std::fabs(y[1] - y[0]) < CONVERGENCE_TOLERANCE * std::max(y[0], y[1])) { break; } @@ -1122,10 +1122,10 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const gamma &gamma_, for (;;) { - y[(i + 1) % 2] = x * ::exp(-(x - y[i % 2]) / m); + y[(i + 1) % 2] = x * std::exp(-(x - y[i % 2]) / m); LOG_TRACE("y = " << y[(i + 1) % 2]); if (++i == MAX_ITERATIONS - || ::fabs(y[1] - y[0]) < CONVERGENCE_TOLERANCE * std::max(y[0], y[1])) + || std::fabs(y[1] - y[0]) < CONVERGENCE_TOLERANCE * std::max(y[0], y[1])) { break; } @@ -1136,7 +1136,7 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const gamma &gamma_, double fy = safePdf(gamma_, y[i % 2]); LOG_TRACE("f(x) = " << fx << ", f(y) = " << fy); - if (::fabs(fx - fy) <= PDF_TOLERANCE * std::max(fx, fy)) + if (std::fabs(fx - fy) <= PDF_TOLERANCE * std::max(fx, fy)) { if (x > y[i % 2]) { @@ -1212,18 +1212,18 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const gamma &gamma_, << ", iterations = " << maxIterations << ", f(candidate) = " << safePdf(gamma_, candidate) - fx); - if (::fabs(safePdf(gamma_, candidate) - fx) < ::fabs(fy - fx)) + if (std::fabs(safePdf(gamma_, candidate) - fx) < std::fabs(fy - fx)) { y[i % 2] = candidate; } } catch (const std::exception &e) { - if (::fabs(fa - fx) < 10.0 * EPSILON * fx) + if (std::fabs(fa - fx) < 10.0 * EPSILON * fx) { y[i % 2] = a; } - else if (::fabs(fb - fx) < 10.0 * EPSILON * fx) + else if (std::fabs(fb - fx) < 10.0 * EPSILON * fx) { y[i % 2] = b; } @@ -1353,9 +1353,9 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const beta &beta_, double k = (beta_.alpha() - 1.0) / (beta_.beta() - 1.0); for (;;) { - y[(i + 1) % 2] = 1.0 - ::exp(k * std::log(x / y[i % 2])) * (1.0 - x); + y[(i + 1) % 2] = 1.0 - std::exp(k * std::log(x / y[i % 2])) * (1.0 - x); if (++i == MAX_ITERATIONS - || ::fabs(y[1] - y[0]) < CONVERGENCE_TOLERANCE) + || std::fabs(y[1] - y[0]) < CONVERGENCE_TOLERANCE) { break; } @@ -1394,9 +1394,9 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const beta &beta_, double k = (beta_.beta() - 1.0) / (beta_.alpha() - 1.0); for (;;) { - y[(i + 1) % 2] = ::exp(k * std::log((1.0 - x) / (1.0 - y[i % 2]))) * x; + y[(i + 1) % 2] = std::exp(k * std::log((1.0 - x) / (1.0 - y[i % 2]))) * x; if (++i == MAX_ITERATIONS - || ::fabs(y[1] - y[0]) < CONVERGENCE_TOLERANCE) + || std::fabs(y[1] - y[0]) < CONVERGENCE_TOLERANCE) { break; } @@ -1423,7 +1423,7 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const beta &beta_, try { double error = sp.second ? fy - fx : fx - fy; - if (::fabs(error) <= PDF_TOLERANCE * std::max(fx, fy)) + if (std::fabs(error) <= PDF_TOLERANCE * std::max(fx, fy)) { if (x > y[i % 2]) { @@ -1493,18 +1493,18 @@ double CTools::CProbabilityOfLessLikelySample::operator()(const beta &beta_, << ", f(candidate) = " << safePdf(beta_, candidate) - fx << ", eps = " << eps); - if (::fabs(safePdf(beta_, candidate) - fx) < ::fabs(fy - fx)) + if (std::fabs(safePdf(beta_, candidate) - fx) < std::fabs(fy - fx)) { y[i % 2] = candidate; } } catch (const std::exception &e) { - if (::fabs(fBracket.first - fx) < 10.0 * EPSILON * fx) + if (std::fabs(fBracket.first - fx) < 10.0 * EPSILON * fx) { y[i % 2] = bracket.first; } - else if (::fabs(fBracket.second - fx) < 10.0 * EPSILON * fx) + else if (std::fabs(fBracket.second - fx) < 10.0 * EPSILON * fx) { y[i % 2] = bracket.second; } @@ -1670,8 +1670,8 @@ double CTools::SIntervalExpectation::operator()(const normal &normal_, double s = std::sqrt(2.0) * sd; double a_ = a == NEG_INF ? a : (a - mean) / s; double b_ = b == POS_INF ? b : (b - mean) / s; - double expa = a_ == NEG_INF ? 0.0 : ::exp(-a_ * a_); - double expb = b_ == POS_INF ? 0.0 : ::exp(-b_ * b_); + double expa = a_ == NEG_INF ? 0.0 : std::exp(-a_ * a_); + double expb = b_ == POS_INF ? 0.0 : std::exp(-b_ * b_); double erfa = a_ == NEG_INF ? -1.0 : boost::math::erf(a_); double erfb = b_ == POS_INF ? 1.0 : boost::math::erf(b_); @@ -1718,8 +1718,8 @@ double CTools::SIntervalExpectation::operator()(const lognormal &logNormal, if (erfb - erfa < std::sqrt(EPSILON)) { - double expa = loga == NEG_INF ? 0.0 : ::exp(-a_ * a_); - double expb = logb == POS_INF ? 0.0 : ::exp(-b_ * b_); + double expa = loga == NEG_INF ? 0.0 : std::exp(-a_ * a_); + double expb = logb == POS_INF ? 0.0 : std::exp(-b_ * b_); return expa == expb ? (2.0 * a / (a + b)) * b : (expa + expb) / (expa / a + expb / b); @@ -1755,8 +1755,8 @@ double CTools::SIntervalExpectation::operator()(const gamma &gamma_, if (gamb - gama < std::sqrt(EPSILON)) { - double expa = a <= 0.0 ? 0.0 : ::exp((shape - 1.0) * std::log(a) - rate * a); - double expb = b == POS_INF ? 0.0 : ::exp((shape - 1.0) * std::log(b) - rate * b); + double expa = a <= 0.0 ? 0.0 : std::exp((shape - 1.0) * std::log(a) - rate * a); + double expb = b == POS_INF ? 0.0 : std::exp((shape - 1.0) * std::log(b) - rate * b); return (a * expa + b * expb) / (expa + expb); } @@ -2161,7 +2161,7 @@ double CTools::inverseDeviation(double deviation) { // We invert the linear scaling of the log probability // into the range (1.0, 50.0]. - result = ::exp(-(MINUS_LOG_SMALL_PROBABILITY + result = std::exp(-(MINUS_LOG_SMALL_PROBABILITY + (MINUS_LOG_MINUSCULE_PROBABILITY - MINUS_LOG_SMALL_PROBABILITY) * (deviation - SMALL_PROBABILITY_DEVIATION) / (MINUSCULE_PROBABILITY_DEVIATION - SMALL_PROBABILITY_DEVIATION))); @@ -2170,7 +2170,7 @@ double CTools::inverseDeviation(double deviation) { // We invert the linear scaling of the log probability // into the range (50.0, 100.0]. - result = ::exp(-(MINUS_LOG_MINUSCULE_PROBABILITY + result = std::exp(-(MINUS_LOG_MINUSCULE_PROBABILITY + (MINUS_LOG_SMALLEST_PROBABILITY - MINUS_LOG_MINUSCULE_PROBABILITY) * (deviation - MINUSCULE_PROBABILITY_DEVIATION) / (MAX_DEVIATION - MINUSCULE_PROBABILITY_DEVIATION))); diff --git a/lib/maths/CTrendTests.cc b/lib/maths/CTrendTests.cc index e273a1309c..a11f681d1e 100644 --- a/lib/maths/CTrendTests.cc +++ b/lib/maths/CTrendTests.cc @@ -634,7 +634,7 @@ CCalendarCyclicTest::TOptionalFeature CCalendarCyclicTest::test(void) const double s = stat.second.s_Significance; if ( stat.second.s_Repeats >= MINIMUM_REPEATS && e > errorThreshold * x - && ::pow(s, r) < MAXIMUM_SIGNIFICANCE) + && std::pow(s, r) < MAXIMUM_SIGNIFICANCE) { result.add({e, stat.second.s_Offset, feature}); } diff --git a/lib/maths/CXMeansOnline1d.cc b/lib/maths/CXMeansOnline1d.cc index 2f77c9298a..b6ee2fd3b0 100644 --- a/lib/maths/CXMeansOnline1d.cc +++ b/lib/maths/CXMeansOnline1d.cc @@ -42,14 +42,13 @@ #include #include +#include #include #include #include #include #include -#include - namespace ml { namespace maths @@ -128,7 +127,7 @@ logLikelihoodFromCluster(double point, return status; } - result = likelihood + ::log(probability); + result = likelihood + std::log(probability); return status; } @@ -292,14 +291,14 @@ void BICGain(maths_t::EDataType dataType, double n = CBasicStatistics::count(mv); double m = mean(dataType, mv); double v = variance(dataType, mv); - if (v <= MINIMUM_COEFFICIENT_OF_VARIATION * ::fabs(m)) + if (v <= MINIMUM_COEFFICIENT_OF_VARIATION * std::fabs(m)) { return; } // Log-normal (method of moments) - double s = ::log(1.0 + v / pow2(m + logNormalOffset)); - double l = ::log(m + logNormalOffset) - s / 2.0; + double s = std::log(1.0 + v / pow2(m + logNormalOffset)); + double l = std::log(m + logNormalOffset) - s / 2.0; // Gamma (method of moments) double a = pow2(m + gammaOffset) / v; double b = (m + gammaOffset) / v; @@ -318,25 +317,25 @@ void BICGain(maths_t::EDataType dataType, try { // Mixture of log-normals (method of moments) - double sl = ::log(1.0 + vl / pow2(ml + logNormalOffset)); - double ll = ::log(ml + logNormalOffset) - sl / 2.0; - double sr = ::log(1.0 + vr / pow2(mr + logNormalOffset)); - double lr = ::log(mr + logNormalOffset) - sr / 2.0; + double sl = std::log(1.0 + vl / pow2(ml + logNormalOffset)); + double ll = std::log(ml + logNormalOffset) - sl / 2.0; + double sr = std::log(1.0 + vr / pow2(mr + logNormalOffset)); + double lr = std::log(mr + logNormalOffset) - sr / 2.0; // Mixture of gammas (method of moments) double al = pow2(ml + gammaOffset) / vl; double bl = (ml + gammaOffset) / vl; double ar = pow2(mr + gammaOffset) / vr; double br = (mr + gammaOffset) / vr; - double log2piv = ::log(boost::math::double_constants::two_pi * v); - double log2pis = ::log(boost::math::double_constants::two_pi * s); - double loggn = boost::math::lgamma(a) - a * ::log(b); - double log2pivl = ::log(boost::math::double_constants::two_pi * vl / pow2(wl)); - double log2pivr = ::log(boost::math::double_constants::two_pi * vr / pow2(wr)); - double log2pisl = ::log(boost::math::double_constants::two_pi * sl / pow2(wl)); - double log2pisr = ::log(boost::math::double_constants::two_pi * sr / pow2(wr)); - double loggnl = boost::math::lgamma(al) - al * ::log(bl) - ::log(wl); - double loggnr = boost::math::lgamma(ar) - ar * ::log(br) - ::log(wr); + double log2piv = std::log(boost::math::double_constants::two_pi * v); + double log2pis = std::log(boost::math::double_constants::two_pi * s); + double loggn = boost::math::lgamma(a) - a * std::log(b); + double log2pivl = std::log(boost::math::double_constants::two_pi * vl / pow2(wl)); + double log2pivr = std::log(boost::math::double_constants::two_pi * vr / pow2(wr)); + double log2pisl = std::log(boost::math::double_constants::two_pi * sl / pow2(wl)); + double log2pisr = std::log(boost::math::double_constants::two_pi * sr / pow2(wr)); + double loggnl = boost::math::lgamma(al) - al * std::log(bl) - std::log(wl); + double loggnr = boost::math::lgamma(ar) - ar * std::log(br) - std::log(wr); for (std::size_t i = start; i < split; ++i) { @@ -346,7 +345,7 @@ void BICGain(maths_t::EDataType dataType, if (vi == 0.0) { - double li = ::log(mi + logNormalOffset); + double li = std::log(mi + logNormalOffset); ll1n += ni * ((vi + pow2(mi - m)) / v + log2piv); ll1l += ni * (pow2(li - l) / s + 2.0 * li + log2pis); ll1g += ni * 2.0 * (b * (mi + gammaOffset) - (a - 1.0) * li + loggn); @@ -356,8 +355,8 @@ void BICGain(maths_t::EDataType dataType, } else { - double si = ::log(1.0 + vi / pow2(mi + logNormalOffset)); - double li = ::log(mi + logNormalOffset) - si / 2.0; + double si = std::log(1.0 + vi / pow2(mi + logNormalOffset)); + double li = std::log(mi + logNormalOffset) - si / 2.0; ll1n += ni * ((vi + pow2(mi - m)) / v + log2piv); ll1l += ni * ((si + pow2(li - l)) / s + 2.0 * li + log2pis); ll1g += ni * 2.0 * (b * (mi + gammaOffset) - (a - 1.0) * li + loggn); @@ -375,7 +374,7 @@ void BICGain(maths_t::EDataType dataType, if (vi == 0.0) { - double li = ::log(mi + logNormalOffset); + double li = std::log(mi + logNormalOffset); ll1n += ni * ((vi + pow2(mi - m)) / v + log2piv); ll1l += ni * (pow2(li - l) / s + 2.0 * li + log2pis); ll1g += ni * 2.0 * (b * (mi + gammaOffset) - (a - 1.0) * li + loggn); @@ -385,8 +384,8 @@ void BICGain(maths_t::EDataType dataType, } else { - double si = ::log(1.0 + vi / pow2(mi + logNormalOffset)); - double li = ::log(mi + logNormalOffset) - si / 2.0; + double si = std::log(1.0 + vi / pow2(mi + logNormalOffset)); + double li = std::log(mi + logNormalOffset) - si / 2.0; ll1n += ni * ((vi + pow2(mi - m)) / v + log2piv); ll1l += ni * ((si + pow2(li - l)) / s + 2.0 * li + log2pis); ll1g += ni * 2.0 * (b * (mi + gammaOffset) - (a - 1.0) * li + loggn); @@ -405,7 +404,7 @@ void BICGain(maths_t::EDataType dataType, return; } - double logn = ::log(n); + double logn = std::log(n); double ll1 = min(distributions.haveNormal() ? ll1n : boost::numeric::bounds::highest(), distributions.haveLogNormal() ? ll1l : boost::numeric::bounds::highest(), distributions.haveGamma() ? ll1g : boost::numeric::bounds::highest()) @@ -445,7 +444,7 @@ void winsorise(const TDoubleDoublePr &interval, TTuple &category) double a = interval.first; double b = interval.second; double m = CBasicStatistics::mean(category); - double sigma = ::sqrt(CBasicStatistics::maximumLikelihoodVariance(category)); + double sigma = std::sqrt(CBasicStatistics::maximumLikelihoodVariance(category)); double t = 3.0 * sigma; double xa = m - a; @@ -465,8 +464,8 @@ void winsorise(const TDoubleDoublePr &interval, TTuple &category) xa /= sigma; xb /= sigma; - double ea = xa > t ? 0.0 : ::exp(-xa*xa / 2.0); - double eb = xb > t ? 0.0 : ::exp(-xb*xb / 2.0); + double ea = xa > t ? 0.0 : std::exp(-xa*xa / 2.0); + double eb = xb > t ? 0.0 : std::exp(-xb*xb / 2.0); double km = sigma / boost::math::double_constants::root_two_pi @@ -956,8 +955,8 @@ void CXMeansOnline1d::cluster(const double &point, double likelihoodRight = rightCluster->logLikelihoodFromCluster(m_WeightCalc, point); double renormalizer = std::max(likelihoodLeft, likelihoodRight); - double pLeft = ::exp(likelihoodLeft - renormalizer); - double pRight = ::exp(likelihoodRight - renormalizer); + double pLeft = std::exp(likelihoodLeft - renormalizer); + double pRight = std::exp(likelihoodRight - renormalizer); double normalizer = pLeft + pRight; pLeft /= normalizer; pRight /= normalizer; @@ -1043,8 +1042,8 @@ void CXMeansOnline1d::add(const double &point, // Normalize the likelihood values. double renormalizer = std::max(likelihoodLeft, likelihoodRight); - double pLeft = ::exp(likelihoodLeft - renormalizer); - double pRight = ::exp(likelihoodRight - renormalizer); + double pLeft = std::exp(likelihoodLeft - renormalizer); + double pRight = std::exp(likelihoodRight - renormalizer); double normalizer = pLeft + pRight; pLeft /= normalizer; pRight /= normalizer; @@ -1119,7 +1118,7 @@ void CXMeansOnline1d::propagateForwardsByTime(double time) LOG_ERROR("Can't propagate backwards in time"); return; } - m_HistoryLength *= ::exp(-m_DecayRate * time); + m_HistoryLength *= std::exp(-m_DecayRate * time); for (std::size_t i = 0u; i < m_Clusters.size(); ++i) { m_Clusters[i].propagateForwardsByTime(time); @@ -1253,7 +1252,7 @@ std::string CXMeansOnline1d::printClusters(void) const { likelihood += m_Clusters[j].weight(m_WeightCalc) / weightSum - * ::exp(logLikelihood); + * std::exp(logLikelihood); } } coordinatesStr << x[0] << " "; @@ -1327,7 +1326,7 @@ double CXMeansOnline1d::minimumSplitCount(void) const { count += m_Clusters[i].count(); } - double scale = std::max(m_HistoryLength * (1.0 - ::exp(-m_InitialDecayRate)), 1.0); + double scale = std::max(m_HistoryLength * (1.0 - std::exp(-m_InitialDecayRate)), 1.0); count *= m_MinimumClusterFraction / scale; result = std::max(result, count); } @@ -1562,7 +1561,7 @@ double CXMeansOnline1d::CCluster::centre(void) const double CXMeansOnline1d::CCluster::spread(void) const { - return ::sqrt(m_Prior.marginalLikelihoodVariance()); + return std::sqrt(m_Prior.marginalLikelihoodVariance()); } double CXMeansOnline1d::CCluster::percentile(double p) const diff --git a/lib/maths/ProbabilityAggregators.cc b/lib/maths/ProbabilityAggregators.cc index 49322b5d47..838e09b570 100644 --- a/lib/maths/ProbabilityAggregators.cc +++ b/lib/maths/ProbabilityAggregators.cc @@ -103,7 +103,7 @@ double powOneMinusX(double x, double p) } double y = p * x; - if (::fabs(y) < EPS) + if (std::fabs(y) < EPS) { static const double COEFFS[] = { @@ -127,16 +127,16 @@ double powOneMinusX(double x, double p) } else if (p > 1000.0) { - return ::exp(-y); + return std::exp(-y); } if (x > 1.0) { double sign = static_cast(p) % 2 ? -1.0 : 1.0; - return sign * ::exp(p * ::log(x - 1.0)); + return sign * std::exp(p * std::log(x - 1.0)); } - return ::exp(p * ::log(1.0 - x)); + return std::exp(p * std::log(1.0 - x)); } //! A custom, numerically robust, implementation of \f$1 - (1 - x) ^ p\f$. @@ -168,7 +168,7 @@ double oneMinusPowOneMinusX(double x, double p) } double y = p * x; - if (::fabs(y) < EPS) + if (std::fabs(y) < EPS) { static const double COEFFS[] = { @@ -194,16 +194,16 @@ double oneMinusPowOneMinusX(double x, double p) } else if (p > 1000.0) { - return 1.0 - ::exp(-y); + return 1.0 - std::exp(-y); } if (x > 1.0) { double sign = static_cast(p) % 2 ? -1.0 : 1.0; - return 1.0 - sign * ::exp(p * ::log(x - 1.0)); + return 1.0 - sign * std::exp(p * std::log(x - 1.0)); } - return 1.0 - ::exp(p * ::log(1.0 - x)); + return 1.0 - std::exp(p * std::log(1.0 - x)); } //! A custom implementation of \f$\log(1 - x)\f$ which handles the @@ -212,7 +212,7 @@ double logOneMinusX(double x) { double result = 0.0; - if (::fabs(x) < EPS) + if (std::fabs(x) < EPS) { double xi = -x; for (std::size_t i = 0u; i < 6; ++i, xi *= -x) @@ -222,7 +222,7 @@ double logOneMinusX(double x) } else { - result = ::log(1.0 - x); + result = std::log(1.0 - x); } return result; @@ -317,7 +317,7 @@ class CNumericalLogProbabilityOfMFromNExtremeSamples for (std::size_t i = 1u; i < std::min(p.count(), MAX_DIMENSION); ++i) { m_P.push_back(truncate(p[i], m_P[i-1])); - m_Corrections.push_back(p[i] == p[i-1] ? 0.0 : ::log(p[i] - p[i-1]) - ::log(m_P[i] - m_P[i-1])); + m_Corrections.push_back(p[i] == p[i-1] ? 0.0 : std::log(p[i] - p[i-1]) - std::log(m_P[i] - m_P[i-1])); } } } @@ -557,7 +557,7 @@ bool CJointProbabilityOfLessLikelySamples::averageProbability(double &result) co try { boost::math::normal_distribution<> normal(0.0, 1.0); - result = 2.0 * boost::math::cdf(normal, -::sqrt(m_Distance / m_NumberSamples)); + result = 2.0 * boost::math::cdf(normal, -std::sqrt(m_Distance / m_NumberSamples)); } catch (const std::exception &e) { @@ -649,7 +649,7 @@ bool CLogJointProbabilityOfLessLikelySamples::calculateLowerBound(double &result // This is defined as log(1) = 0 for the case there are no samples. if (this->onlyProbability()) { - result = std::min(::log(*this->onlyProbability()), 0.0); + result = std::min(std::log(*this->onlyProbability()), 0.0); return true; } if (this->numberSamples() == 0.0 || this->distance() == 0.0) @@ -729,12 +729,12 @@ bool CLogJointProbabilityOfLessLikelySamples::calculateLowerBound(double &result if (this->calculate(probability) && probability > 10.0 * boost::numeric::bounds::smallest()) { LOG_TRACE("probability = " << probability); - result = ::log(probability); + result = std::log(probability); return true; } static const double E = boost::math::double_constants::e; - static const double LOG_DOUBLE_MAX = ::log(0.1 * boost::numeric::bounds::highest()); + static const double LOG_DOUBLE_MAX = std::log(0.1 * boost::numeric::bounds::highest()); double s = this->numberSamples() / 2.0; double x = this->distance() / 2.0; @@ -743,11 +743,11 @@ bool CLogJointProbabilityOfLessLikelySamples::calculateLowerBound(double &result try { - double logx = ::log(x); - double p = ::floor(s - 1.0); + double logx = std::log(x); + double p = std::floor(s - 1.0); double logPFactorial = boost::math::lgamma(p + 1.0); - double m = ::floor(std::min(x, p) + 0.5); - double logm = ::log(m); + double m = std::floor(std::min(x, p) + 0.5); + double logm = std::log(m); double b1 = 0.0; @@ -759,21 +759,21 @@ bool CLogJointProbabilityOfLessLikelySamples::calculateLowerBound(double &result else if (E * x / m != 1.0) { double r = 1.0 - E * x / m; - b1 = -1.0 - 0.5 * logm + ::log(oneMinusPowOneMinusX(r, m + 1.0) / r); + b1 = -1.0 - 0.5 * logm + std::log(oneMinusPowOneMinusX(r, m + 1.0) / r); } else { // Use L'Hopital's rule to show that: // lim { (1 - r^(m+1)) / (1 - r) } = m + 1 // r -> 1 - b1 = -1.0 - 0.5 * logm + ::log(m + 1.0); + b1 = -1.0 - 0.5 * logm + std::log(m + 1.0); } if (p > m) { double t = 0.0; - double logp = ::log(p); + double logp = std::log(p); if ((p - m) * (1.0 + logx - logp) >= LOG_DOUBLE_MAX) { // Handle the case that (e*x/p)^(p-m) overflows. @@ -784,24 +784,24 @@ bool CLogJointProbabilityOfLessLikelySamples::calculateLowerBound(double &result { double r = 1.0 - E * x / p; t = m + (m + 1.0) * logx - (m + 1.5) * logp - + ::log(oneMinusPowOneMinusX(r, p - m) / r); + + std::log(oneMinusPowOneMinusX(r, p - m) / r); } else { // Use L'Hopital's rule to show that: // lim { (1 - r^(p - m)) / (1 - r) } = p - m // r -> 1 - t = m + (m + 1.0) * logx - (m + 1.5) * logp + ::log(p - m); + t = m + (m + 1.0) * logx - (m + 1.5) * logp + std::log(p - m); } double normalizer = std::max(b1, t); - b1 = normalizer + ::log(::exp(b1 - normalizer) + ::exp(t - normalizer)); + b1 = normalizer + std::log(std::exp(b1 - normalizer) + std::exp(t - normalizer)); } double b2 = 0.0; - if ((p + 1.0) * ::log(x) < logPFactorial + ::log(p + 1.0)) + if ((p + 1.0) * std::log(x) < logPFactorial + std::log(p + 1.0)) { - b2 = ::log(1.0 - ::exp((p + 1.0) * logx - logPFactorial) / (p + 1.0)) + x; + b2 = std::log(1.0 - std::exp((p + 1.0) * logx - logPFactorial) / (p + 1.0)) + x; } double logSum = logPFactorial - p * logx + std::max(b1, b2); @@ -833,7 +833,7 @@ bool CLogJointProbabilityOfLessLikelySamples::calculateUpperBound(double &result // This is defined as log(1) = 0 for the case there are no samples. if (this->onlyProbability()) { - result = std::min(::log(*this->onlyProbability()), 0.0); + result = std::min(std::log(*this->onlyProbability()), 0.0); return true; } if (this->numberSamples() == 0.0 || this->distance() == 0.0) @@ -893,11 +893,11 @@ bool CLogJointProbabilityOfLessLikelySamples::calculateUpperBound(double &result if (this->calculate(probability) && probability > 10.0 * boost::numeric::bounds::smallest()) { LOG_TRACE("probability = " << probability); - result = ::log(probability); + result = std::log(probability); return true; } - static const double LOG_DOUBLE_MAX = ::log(0.10 * boost::numeric::bounds::highest()); + static const double LOG_DOUBLE_MAX = std::log(0.10 * boost::numeric::bounds::highest()); double s = this->numberSamples() / 2.0; double x = this->distance() / 2.0; @@ -906,34 +906,34 @@ bool CLogJointProbabilityOfLessLikelySamples::calculateUpperBound(double &result try { - double p = ::ceil(s - 1.0); + double p = std::ceil(s - 1.0); double b1 = 0.0; - if ((p + 1.0) * ::log(p / x) >= LOG_DOUBLE_MAX) + if ((p + 1.0) * std::log(p / x) >= LOG_DOUBLE_MAX) { // Handle the case that (p/x)^(p+1) is going to overflow. In this case // (1 - (p/x)^(p+1)) / (1 - p/x) < (p/x)^(p+1) / (p/x - 1) but they are // essentially equal. - b1 = (p + 1.0) * ::log(p / x) - ::log(p / x - 1.0); + b1 = (p + 1.0) * std::log(p / x) - std::log(p / x - 1.0); } else if (p != x) { double r = 1.0 - p / x; - b1 = ::log(oneMinusPowOneMinusX(r, p + 1.0) / r); + b1 = std::log(oneMinusPowOneMinusX(r, p + 1.0) / r); } else { // Use L'Hopital's rule to show that: // lim { (1 - r^(p+1)) / (1 - r) } = p + 1 // r -> 1 - b1 = ::log(p + 1); + b1 = std::log(p + 1); } - double b2 = boost::math::lgamma(p + 1.0) - p * ::log(x) + x; + double b2 = boost::math::lgamma(p + 1.0) - p * std::log(x) + x; double logSum = std::min(b1, b2); - bound = (s - 1.0) * ::log(x) - x + logSum - boost::math::lgamma(s); + bound = (s - 1.0) * std::log(x) - x + logSum - boost::math::lgamma(s); LOG_TRACE("s = " << s << ", x = " << x << ", b1 = " << b1 << ", b2 = " << b2 @@ -1117,7 +1117,7 @@ bool CLogProbabilityOfMFromNExtremeSamples::calculate(double &result) double p = m_MinValues[M - m]; LOG_TRACE("p(" << m << ") = " << p); - logc -= ::log(2.0 * static_cast(N - M + m)); + logc -= std::log(2.0 * static_cast(N - M + m)); // Update the coefficients (they are stored in reverse order). double sum = 0.0; @@ -1136,16 +1136,16 @@ bool CLogProbabilityOfMFromNExtremeSamples::calculate(double &result) // "c" directly because it might be infinite. Instead, we make // use the fact that c * (1 - p)^(N - M + m) won't overflow. double q = CTools::truncate(powOneMinusX(p, static_cast(N - M + m)), 0.0, 1.0); - coeffs.push_back(-sum - q * ::exp(logc - logLargestCoeff)); + coeffs.push_back(-sum - q * std::exp(logc - logLargestCoeff)); LOG_TRACE("c(0) = " << coeffs.back()); // Re-normalize the coefficients if they aren't all identically zero. double cmax = 0.0; for (std::size_t i = 0u; i < coeffs.size(); ++i) { - if (::fabs(coeffs[i]) > 1.0 / boost::numeric::bounds::highest()) + if (std::fabs(coeffs[i]) > 1.0 / boost::numeric::bounds::highest()) { - cmax = std::max(cmax, ::fabs(coeffs[i])); + cmax = std::max(cmax, std::fabs(coeffs[i])); } } if (cmax > 0.0) @@ -1155,7 +1155,7 @@ bool CLogProbabilityOfMFromNExtremeSamples::calculate(double &result) { coeffs[i] /= cmax; } - logLargestCoeff += ::log(cmax); + logLargestCoeff += std::log(cmax); LOG_TRACE("logLargestCoeff = " << logLargestCoeff); } } @@ -1165,11 +1165,11 @@ bool CLogProbabilityOfMFromNExtremeSamples::calculate(double &result) double cmax = 0.0; for (std::size_t i = 0u; i < coeffs.size(); ++i) { - cmax = std::max(cmax, ::fabs(coeffs[i])); + cmax = std::max(cmax, std::fabs(coeffs[i])); } if (cmax > 0.0 && cmax < 1.0 / boost::numeric::bounds::highest()) { - logLargestCoeff = ::log(cmax); + logLargestCoeff = std::log(cmax); for (std::size_t i = 0u; i < coeffs.size(); ++i) { coeffs[i] /= cmax; @@ -1185,7 +1185,7 @@ bool CLogProbabilityOfMFromNExtremeSamples::calculate(double &result) if (M > 1) { - double logScale = static_cast(M) * ::log(2.0) + double logScale = static_cast(M) * std::log(2.0) + boost::math::lgamma(static_cast(N + 1)) - boost::math::lgamma(static_cast(N - M + 1)) + logLargestCoeff; @@ -1205,14 +1205,14 @@ bool CLogProbabilityOfMFromNExtremeSamples::calculate(double &result) << " (c(" << index << ") = " << c << ", 1 - (1 - p(M)/2)^" << index << " = " << p << ")"); terms.push_back(c * p); - sum += ::fabs(c * p); - (c * p < 0.0 ? negative : positive) += ::fabs(c * p); + sum += std::fabs(c * p); + (c * p < 0.0 ? negative : positive) += std::fabs(c * p); } LOG_TRACE("negative = " << negative << ", positive = " << positive); if (sum == 0.0) { - result = ::log(pMin); + result = std::log(pMin); } else { @@ -1224,15 +1224,15 @@ bool CLogProbabilityOfMFromNExtremeSamples::calculate(double &result) result = 0.0; double condition = 0.0; - double logPMin = ::log(pMin); + double logPMin = std::log(pMin); if (logPMin - logScale > core::constants::LOG_MAX_DOUBLE) { for (std::size_t i = 0u; i < terms.size(); ++i) { - LOG_TRACE("remainder(" << i << ") = " << ::fabs(terms[i])); - result += ::fabs(terms[i]); + LOG_TRACE("remainder(" << i << ") = " << std::fabs(terms[i])); + result += std::fabs(terms[i]); } - result = ::log(result * pMin / sum); + result = std::log(result * pMin / sum); } else { @@ -1242,18 +1242,18 @@ bool CLogProbabilityOfMFromNExtremeSamples::calculate(double &result) for (std::size_t i = 0u; i < terms.size(); ++i) { result += terms[i]; - condition = std::max(condition, ::fabs(terms[i])); + condition = std::max(condition, std::fabs(terms[i])); } } else { - pMin /= ::exp(logScale); + pMin /= std::exp(logScale); LOG_TRACE("pMin = " << pMin); for (std::size_t i = 0u; i < terms.size(); ++i) { - double remainder = ::fabs(terms[i]) * pMin / sum + terms[i]; + double remainder = std::fabs(terms[i]) * pMin / sum + terms[i]; result += remainder; - double absTerms[] = { ::fabs(terms[i]), ::fabs(terms[i] * pMin / sum), ::fabs(remainder) }; + double absTerms[] = { std::fabs(terms[i]), std::fabs(terms[i] * pMin / sum), std::fabs(remainder) }; condition = std::max(condition, *std::max_element(absTerms, absTerms + 3)); } } @@ -1271,14 +1271,14 @@ bool CLogProbabilityOfMFromNExtremeSamples::calculate(double &result) } else { - result = logScale + ::log(result); + result = logScale + std::log(result); } } } } else { - result = ::log(pMin); + result = std::log(pMin); } // Numerical error means the probability can be slightly greater @@ -1338,7 +1338,7 @@ bool CLogProbabilityOfMFromNExtremeSamples::calibrated(double &result) { return true; } - result /= 1.0 + ::log(static_cast(n)) / 2.1; + result /= 1.0 + std::log(static_cast(n)) / 2.1; return true; } diff --git a/lib/maths/unittest/CAgglomerativeClustererTest.cc b/lib/maths/unittest/CAgglomerativeClustererTest.cc index 016e7fc25b..95922972f6 100644 --- a/lib/maths/unittest/CAgglomerativeClustererTest.cc +++ b/lib/maths/unittest/CAgglomerativeClustererTest.cc @@ -348,7 +348,7 @@ void CAgglomerativeClustererTest::testSimplePermutations(void) { for (std::size_t j = i; j < n; ++j) { - distanceMatrix[j].push_back(::fabs(x[p[i]] - x[p[j]])); + distanceMatrix[j].push_back(std::fabs(x[p[i]] - x[p[j]])); } LOG_DEBUG("D = " << core::CContainerPrinter::print(distanceMatrix[i])); } @@ -428,7 +428,7 @@ void CAgglomerativeClustererTest::testDegenerate(void) { for (std::size_t j = i; j < n; ++j) { - distanceMatrix[j].push_back(::fabs(x[p[i]] - x[p[j]])); + distanceMatrix[j].push_back(std::fabs(x[p[i]] - x[p[j]])); } if (count % 10 == 0) { diff --git a/lib/maths/unittest/CAssignmentTest.cc b/lib/maths/unittest/CAssignmentTest.cc index 5408878942..771d42d30b 100644 --- a/lib/maths/unittest/CAssignmentTest.cc +++ b/lib/maths/unittest/CAssignmentTest.cc @@ -54,7 +54,7 @@ void fill(const double (&costs)[N][M], TDoubleVecVec &result) void fill(const TDoubleVec &costs, TDoubleVecVec &result) { - std::size_t n = static_cast(::sqrt(static_cast(costs.size()))); + std::size_t n = static_cast(std::sqrt(static_cast(costs.size()))); result.reserve(n); for (std::size_t i = 0u; i < n; ++i) { diff --git a/lib/maths/unittest/CBjkstUniqueValuesTest.cc b/lib/maths/unittest/CBjkstUniqueValuesTest.cc index 774bf232f1..29f0837301 100644 --- a/lib/maths/unittest/CBjkstUniqueValuesTest.cc +++ b/lib/maths/unittest/CBjkstUniqueValuesTest.cc @@ -114,10 +114,10 @@ void CBjkstUniqueValuesTest::testNumber(void) double n = static_cast(uniqueValues.size()); double e5 = static_cast(approxUniqueValues5.number()); - double error5 = ::fabs(e5 - n) / std::max(e5, n); + double error5 = std::fabs(e5 - n) / std::max(e5, n); double e6 = static_cast(approxUniqueValues6.number()); - double error6 = ::fabs(e6 - n) / std::max(e6, n); + double error6 = std::fabs(e6 - n) / std::max(e6, n); LOG_DEBUG("error5 = " << error5 << ", error6 = " << error6); CPPUNIT_ASSERT(error5 < 0.35); @@ -191,7 +191,7 @@ void CBjkstUniqueValuesTest::testRemove(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast(unique.size()), static_cast(sketch.number()), 0.3 * static_cast(unique.size())); - meanRelativeErrorBeforeRemove.add(::fabs( static_cast(unique.size()) + meanRelativeErrorBeforeRemove.add(std::fabs( static_cast(unique.size()) - static_cast(sketch.number())) / static_cast(unique.size())); @@ -208,7 +208,7 @@ void CBjkstUniqueValuesTest::testRemove(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast(unique.size()), static_cast(sketch.number()), 0.25 * static_cast(unique.size())); - meanRelativeErrorAfterRemove.add(::fabs( static_cast(unique.size()) + meanRelativeErrorAfterRemove.add(std::fabs( static_cast(unique.size()) - static_cast(sketch.number())) / static_cast(unique.size())); } @@ -329,7 +329,7 @@ void CBjkstUniqueValuesTest::testSmall(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast(unique.size()), static_cast(sketch.number()), 0.15 * static_cast(unique.size())); - meanRelativeError.add(::fabs( static_cast(unique.size()) + meanRelativeError.add(std::fabs( static_cast(unique.size()) - static_cast(sketch.number())) / static_cast(unique.size())); } diff --git a/lib/maths/unittest/CCalendarComponentAdaptiveBucketingTest.cc b/lib/maths/unittest/CCalendarComponentAdaptiveBucketingTest.cc index 1a05664e1c..4aa0a642cd 100644 --- a/lib/maths/unittest/CCalendarComponentAdaptiveBucketingTest.cc +++ b/lib/maths/unittest/CCalendarComponentAdaptiveBucketingTest.cc @@ -198,8 +198,8 @@ void CCalendarComponentAdaptiveBucketingTest::testRefine(void) double y0{function[j - 1]}; double y1{function[j]}; double y{y0 + (y1 - y0) * (static_cast(t) - x0) / (x1 - x0)}; - meanError1.add(::fabs(values1[i - 1] - y)); - maxError1.add(::fabs(values1[i - 1] - y)); + meanError1.add(std::fabs(values1[i - 1] - y)); + maxError1.add(std::fabs(values1[i - 1] - y)); } TMeanAccumulator meanError2; @@ -218,8 +218,8 @@ void CCalendarComponentAdaptiveBucketingTest::testRefine(void) double y0{function[j - 1]}; double y1{function[j]}; double y{y0 + (y1 - y0) * (static_cast(t) - x0) / (x1 - x0)}; - meanError2.add(::fabs(values2[i - 1] - y)); - maxError2.add(::fabs(values2[i - 1] - y)); + meanError2.add(std::fabs(values2[i - 1] - y)); + maxError2.add(std::fabs(values2[i - 1] - y)); } LOG_DEBUG("mean error = " << maths::CBasicStatistics::mean(meanError1)); @@ -328,7 +328,7 @@ void CCalendarComponentAdaptiveBucketingTest::testMinimumBucketLength(void) double totalError{0.0}; for (std::size_t j = 0u; j < endpoints1.size(); ++j) { - totalError += ::fabs(endpoints2[j] - endpoints1[j]); + totalError += std::fabs(endpoints2[j] - endpoints1[j]); } LOG_DEBUG("minimumTotalError = " << minimumTotalError); @@ -429,8 +429,8 @@ void CCalendarComponentAdaptiveBucketingTest::testKnots(void) * (knots[i] - 43800.0)}; LOG_DEBUG("expected = " << expectedValue << ", value = " << values[i]); CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedValue, values[i], 50000.0); - meanError.add(::fabs(values[i] - expectedValue)); - meanValue.add(::fabs(expectedValue)); + meanError.add(std::fabs(values[i] - expectedValue)); + meanValue.add(std::fabs(expectedValue)); } LOG_DEBUG("meanError = " << maths::CBasicStatistics::mean(meanError)); LOG_DEBUG("meanValue = " << maths::CBasicStatistics::mean(meanValue)); @@ -479,8 +479,8 @@ void CCalendarComponentAdaptiveBucketingTest::testKnots(void) LOG_DEBUG("expected = " << expectedVariance << ", variance = " << variances[i]); CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedVariance, variances[i], 5.0); - meanError.add(::fabs(variances[i] - expectedVariance)); - meanVariance.add(::fabs(expectedVariance)); + meanError.add(std::fabs(variances[i] - expectedVariance)); + meanVariance.add(std::fabs(expectedVariance)); } LOG_DEBUG("meanError = " << maths::CBasicStatistics::mean(meanError)); LOG_DEBUG("meanVariance = " << maths::CBasicStatistics::mean(meanVariance)); diff --git a/lib/maths/unittest/CCategoricalToolsTest.cc b/lib/maths/unittest/CCategoricalToolsTest.cc index 77e28b1d60..c7e56cb13a 100644 --- a/lib/maths/unittest/CCategoricalToolsTest.cc +++ b/lib/maths/unittest/CCategoricalToolsTest.cc @@ -83,7 +83,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) LOG_DEBUG("probabilities = " << core::CContainerPrinter::print(probabilities)); LOG_DEBUG("expectedDistinctCategories = " << maths::CBasicStatistics::mean(expectedDistinctCategories) - << " (deviation = " << ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + << " (deviation = " << std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials)) << ")"); double distinctCategories; @@ -95,7 +95,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedDistinctCategories), distinctCategories, - 2.0 * ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + 2.0 * std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials))); } @@ -119,7 +119,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) LOG_DEBUG("probabilities = " << core::CContainerPrinter::print(probabilities)); LOG_DEBUG("expectedDistinctCategories = " << maths::CBasicStatistics::mean(expectedDistinctCategories) - << " (deviation = " << ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + << " (deviation = " << std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials)) << ")"); double distinctCategories; @@ -131,7 +131,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedDistinctCategories), distinctCategories, - 2.0 * ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + 2.0 * std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials))); } { @@ -154,7 +154,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) LOG_DEBUG("probabilities = " << core::CContainerPrinter::print(probabilities)); LOG_DEBUG("expectedDistinctCategories = " << maths::CBasicStatistics::mean(expectedDistinctCategories) - << " (deviation = " << ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + << " (deviation = " << std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials)) << ")"); double distinctCategories; @@ -166,7 +166,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedDistinctCategories), distinctCategories, - 2.0 * ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + 2.0 * std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials))); } } @@ -193,7 +193,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) LOG_DEBUG("probabilities = " << core::CContainerPrinter::print(probabilities)); LOG_DEBUG("expectedDistinctCategories = " << maths::CBasicStatistics::mean(expectedDistinctCategories) - << " (deviation = " << ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + << " (deviation = " << std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials)) << ")"); double distinctCategories; @@ -205,7 +205,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedDistinctCategories), distinctCategories, - 2.0 * ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + 2.0 * std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials))); } @@ -229,7 +229,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) LOG_DEBUG("probabilities = " << core::CContainerPrinter::print(probabilities)); LOG_DEBUG("expectedDistinctCategories = " << maths::CBasicStatistics::mean(expectedDistinctCategories) - << " (deviation = " << ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + << " (deviation = " << std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials)) << ")"); double distinctCategories; @@ -241,7 +241,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedDistinctCategories), distinctCategories, - 2.0 * ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + 2.0 * std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials))); } { @@ -264,7 +264,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) LOG_DEBUG("probabilities = " << core::CContainerPrinter::print(probabilities)); LOG_DEBUG("expectedDistinctCategories = " << maths::CBasicStatistics::mean(expectedDistinctCategories) - << " (deviation = " << ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + << " (deviation = " << std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials)) << ")"); double distinctCategories; @@ -276,7 +276,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedDistinctCategories), distinctCategories, - 2.0 * ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + 2.0 * std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials))); } } @@ -306,7 +306,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) } LOG_DEBUG("expectedDistinctCategories = " << maths::CBasicStatistics::mean(expectedDistinctCategories) - << " (deviation = " << ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + << " (deviation = " << std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials)) << ")"); double distinctCategories; @@ -317,7 +317,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedDistinctCategories), distinctCategories, - 3.0 * ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + 3.0 * std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials))); } } @@ -343,7 +343,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) } LOG_DEBUG("expectedDistinctCategories = " << maths::CBasicStatistics::mean(expectedDistinctCategories) - << " (deviation = " << ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + << " (deviation = " << std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials)) << ")"); double distinctCategories; @@ -354,7 +354,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedDistinctCategories), distinctCategories, - 3.0 * ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + 3.0 * std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials))); } } @@ -384,7 +384,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) } LOG_DEBUG("expectedDistinctCategories = " << maths::CBasicStatistics::mean(expectedDistinctCategories) - << " (deviation = " << ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + << " (deviation = " << std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials)) << ")"); double distinctCategories; @@ -395,7 +395,7 @@ void CCategoricalToolsTest::testExpectedDistinctCategories(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedDistinctCategories), distinctCategories, - 2.5 * ::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) + 2.5 * std::sqrt(maths::CBasicStatistics::variance(expectedDistinctCategories) / static_cast(nTrials))); } } @@ -424,7 +424,7 @@ void CCategoricalToolsTest::testLogBinomialProbability(void) for (std::size_t f = 1u; f < 10; ++f) { double f_ = static_cast(f) / 10.0; - double m = ::floor(f_ * median); + double m = std::floor(f_ * median); double pdf = boost::math::pdf(binomial, m); double logpdf; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, @@ -433,13 +433,13 @@ void CCategoricalToolsTest::testLogBinomialProbability(void) static_cast(m), logpdf)); LOG_DEBUG("f(" << m << "), expected = " << pdf - << ", actual = " << ::exp(logpdf)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(pdf, ::exp(logpdf), 1e-6 * pdf); + << ", actual = " << std::exp(logpdf)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(pdf, std::exp(logpdf), 1e-6 * pdf); } for (std::size_t f = 1u; f < 10; ++f) { double f_ = static_cast(f) / 10.0; - double m = median + ::floor(f_ * (n[i] - median)); + double m = median + std::floor(f_ * (n[i] - median)); double pdf = boost::math::pdf(binomial, m); double logpdf; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, @@ -448,8 +448,8 @@ void CCategoricalToolsTest::testLogBinomialProbability(void) static_cast(m), logpdf)); LOG_DEBUG("f(" << m << "), expected = " << pdf - << ", actual = " << ::exp(logpdf)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(pdf, ::exp(logpdf), 1e-6 * pdf); + << ", actual = " << std::exp(logpdf)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(pdf, std::exp(logpdf), 1e-6 * pdf); } } } @@ -482,7 +482,7 @@ void CCategoricalToolsTest::testLogMultinomialProbability(void) for (std::size_t f = 1u; f < 10; ++f) { double f_ = static_cast(f) / 10.0; - double m = ::floor(f_ * median); + double m = std::floor(f_ * median); double pdf = boost::math::pdf(binomial, m); double logpdf; TDoubleVec pi; @@ -494,13 +494,13 @@ void CCategoricalToolsTest::testLogMultinomialProbability(void) CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, maths::CCategoricalTools::logMultinomialProbability(pi, ni, logpdf)); LOG_DEBUG("f(" << m << "), expected = " << pdf - << ", actual = " << ::exp(logpdf)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(pdf, ::exp(logpdf), 1e-6 * pdf); + << ", actual = " << std::exp(logpdf)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(pdf, std::exp(logpdf), 1e-6 * pdf); } for (std::size_t f = 1u; f < 10; ++f) { double f_ = static_cast(f) / 10.0; - double m = median + ::floor(f_ * (n[i] - median)); + double m = median + std::floor(f_ * (n[i] - median)); double pdf = boost::math::pdf(binomial, m); double logpdf; TDoubleVec pi; @@ -512,8 +512,8 @@ void CCategoricalToolsTest::testLogMultinomialProbability(void) CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, maths::CCategoricalTools::logMultinomialProbability(pi, ni, logpdf)); LOG_DEBUG("f(" << m << "), expected = " << pdf - << ", actual = " << ::exp(logpdf)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(pdf, ::exp(logpdf), 1e-6 * pdf); + << ", actual = " << std::exp(logpdf)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(pdf, std::exp(logpdf), 1e-6 * pdf); } } } @@ -540,7 +540,7 @@ void CCategoricalToolsTest::testLogMultinomialProbability(void) ni.push_back(n - m - i); CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, maths::CCategoricalTools::logMultinomialProbability(pi, ni, logpdf)); - marginal += ::exp(logpdf); + marginal += std::exp(logpdf); } boost::math::binomial_distribution<> binomial(static_cast(n), pi[0]); diff --git a/lib/maths/unittest/CCountMinSketchTest.cc b/lib/maths/unittest/CCountMinSketchTest.cc index 7b20ee66be..10db347b41 100644 --- a/lib/maths/unittest/CCountMinSketchTest.cc +++ b/lib/maths/unittest/CCountMinSketchTest.cc @@ -56,7 +56,7 @@ void CCountMinSketchTest::testCounts(void) for (std::size_t i = 0u; i < counts.size(); ++i) { - counts[i] = ::floor(counts[i]); + counts[i] = std::floor(counts[i]); sketch.add(static_cast(i), counts[i]); } LOG_DEBUG("error = " << sketch.oneMinusDeltaError()); @@ -74,7 +74,7 @@ void CCountMinSketchTest::testCounts(void) << ", estimated count = " << estimated); } - meanError.add(::fabs(estimated - count)); + meanError.add(std::fabs(estimated - count)); if (count + sketch.oneMinusDeltaError() < estimated) { errorCount += 1.0; @@ -110,12 +110,12 @@ void CCountMinSketchTest::testCounts(void) for (std::size_t i = 0u; i < heavyHitters.size(); ++i) { - heavyHitters[i] = ::floor(heavyHitters[i]); + heavyHitters[i] = std::floor(heavyHitters[i]); sketch.add(static_cast(i), heavyHitters[i]); } for (std::size_t i = 0u; i < counts.size(); ++i) { - counts[i] = ::floor(counts[i]); + counts[i] = std::floor(counts[i]); sketch.add(static_cast(i + heavyHitters.size()), counts[i]); } LOG_DEBUG("error = " << sketch.oneMinusDeltaError()); @@ -129,7 +129,7 @@ void CCountMinSketchTest::testCounts(void) << ", true count = " << count << ", estimated count = " << estimated); - double relativeError = ::fabs(estimated - count) / count; + double relativeError = std::fabs(estimated - count) / count; CPPUNIT_ASSERT(relativeError < 0.01); meanRelativeError.add(relativeError); diff --git a/lib/maths/unittest/CEntropySketchTest.cc b/lib/maths/unittest/CEntropySketchTest.cc index 4f265a1c8a..f15affd993 100644 --- a/lib/maths/unittest/CEntropySketchTest.cc +++ b/lib/maths/unittest/CEntropySketchTest.cc @@ -24,9 +24,9 @@ #include +#include #include #include -#include using namespace ml; @@ -83,18 +83,18 @@ void CEntropySketchTest::testAll(void) double h = 0.0; for (TSizeDoubleUMapCItr j = p.begin(); j != p.end(); ++j) { - h -= j->second * ::log(j->second); + h -= j->second * std::log(j->second); } if (t % 30 == 0) { LOG_DEBUG("H_approx = " << ha << ", H_exact = " << h); } - meanError[i].add(::fabs(ha - h) / h); - maxError[i].add( ::fabs(ha - h) / h); + meanError[i].add(std::fabs(ha - h) / h); + maxError[i].add( std::fabs(ha - h) / h); for (std::size_t k = 0u; k < 3; ++k) { - if (::fabs(ha - h) > eps[k]) + if (std::fabs(ha - h) > eps[k]) { epsDeviations[i][k] += 1.0; } @@ -115,7 +115,7 @@ void CEntropySketchTest::testAll(void) // Test additive approximation bounds. for (std::size_t j = 0u; j < 3; ++j) { - CPPUNIT_ASSERT(epsDeviations[i][j] / 1000.0 < 2.0 * ::exp(-K[i]*eps[j]*eps[j] / 6.0)); + CPPUNIT_ASSERT(epsDeviations[i][j] / 1000.0 < 2.0 * std::exp(-K[i]*eps[j]*eps[j] / 6.0)); } } } diff --git a/lib/maths/unittest/CEqualWithToleranceTest.cc b/lib/maths/unittest/CEqualWithToleranceTest.cc index 7595dc5969..06ecc6b280 100644 --- a/lib/maths/unittest/CEqualWithToleranceTest.cc +++ b/lib/maths/unittest/CEqualWithToleranceTest.cc @@ -102,8 +102,8 @@ void CEqualWithToleranceTest::testVector(void) float c_[] = { 201.1f, 202.2f }; float d_[] = { 202.1f, 203.2f }; - maths::CVector epsAbs(2, 0.15 / ::sqrt(2.0)); - maths::CVector epsRel(2, 0.0062 / ::sqrt(2.0)); + maths::CVector epsAbs(2, 0.15 / std::sqrt(2.0)); + maths::CVector epsRel(2, 0.0062 / std::sqrt(2.0)); maths::CEqualWithTolerance> abs(maths::CToleranceTypes::E_AbsoluteTolerance, epsAbs); maths::CEqualWithTolerance> rel(maths::CToleranceTypes::E_RelativeTolerance, epsRel); diff --git a/lib/maths/unittest/CGammaRateConjugateTest.cc b/lib/maths/unittest/CGammaRateConjugateTest.cc index 1e96c4c50f..627e3a4223 100644 --- a/lib/maths/unittest/CGammaRateConjugateTest.cc +++ b/lib/maths/unittest/CGammaRateConjugateTest.cc @@ -33,13 +33,12 @@ #include #include +#include #include #include #include #include -#include - using namespace ml; using namespace handy_typedefs; @@ -321,7 +320,7 @@ void CGammaRateConjugateTest::testRateEstimation(void) { // The number of errors should be inside the percentile bounds. unsigned int maximumErrors = - static_cast(::ceil((1.0 - testIntervals[j]/100.0) * nTests)); + static_cast(std::ceil((1.0 - testIntervals[j]/100.0) * nTests)); LOG_DEBUG("errors = " << errors[j] << ", maximumErrors = " << maximumErrors); @@ -422,7 +421,7 @@ void CGammaRateConjugateTest::testMarginalLikelihood(void) for (size_t k = 0; k < boost::size(deltas); ++k) { - double x = mean + deltas[k] * ::sqrt(variance); + double x = mean + deltas[k] * std::sqrt(variance); TDouble1Vec sample(1, x); LOG_DEBUG("number = " << numberSamples[i] @@ -431,21 +430,21 @@ void CGammaRateConjugateTest::testMarginalLikelihood(void) double logLikelihood = 0.0; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter.jointLogMarginalLikelihood(sample, logLikelihood)); - double pdf = ::exp(logLikelihood); + double pdf = std::exp(logLikelihood); double lowerBound = 0.0, upperBound = 0.0; sample[0] -= eps; CPPUNIT_ASSERT(filter.minusLogJointCdf(sample, lowerBound, upperBound)); CPPUNIT_ASSERT_EQUAL(lowerBound, upperBound); double minusLogCdf = (lowerBound + upperBound) / 2.0; - double cdfAtMinusEps = ::exp(-minusLogCdf); + double cdfAtMinusEps = std::exp(-minusLogCdf); CPPUNIT_ASSERT(minusLogCdf >= 0.0); sample[0] += 2.0 * eps; CPPUNIT_ASSERT(filter.minusLogJointCdf(sample, lowerBound, upperBound)); CPPUNIT_ASSERT_EQUAL(lowerBound, upperBound); minusLogCdf = (lowerBound + upperBound) / 2.0; - double cdfAtPlusEps = ::exp(-minusLogCdf); + double cdfAtPlusEps = std::exp(-minusLogCdf); CPPUNIT_ASSERT(minusLogCdf >= 0.0); double dcdfdx = (cdfAtPlusEps - cdfAtMinusEps) / 2.0 / eps; @@ -523,8 +522,8 @@ void CGammaRateConjugateTest::testMarginalLikelihood(void) << ", interval = " << core::CContainerPrinter::print(interval)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q1, interval.first, 0.02); CPPUNIT_ASSERT_DOUBLES_EQUAL(q2, interval.second, 0.02); - error.add(::fabs(interval.first - q1)); - error.add(::fabs(interval.second - q2)); + error.add(std::fabs(interval.first - q1)); + error.add(std::fabs(interval.second - q2)); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 4e-3); @@ -550,8 +549,8 @@ void CGammaRateConjugateTest::testMarginalLikelihood(void) << ", interval = " << core::CContainerPrinter::print(interval)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q1, interval.first, 0.4); CPPUNIT_ASSERT_DOUBLES_EQUAL(q2, interval.second, 0.4); - error.add(::fabs(interval.first - q1)); - error.add(::fabs(interval.second - q2)); + error.add(std::fabs(interval.first - q1)); + error.add(std::fabs(interval.second - q2)); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 0.09); @@ -659,7 +658,7 @@ void CGammaRateConjugateTest::testMarginalLikelihoodMode(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedMode, filter.marginalLikelihoodMode(weightStyle, weight), 0.28 * expectedMode + 0.3); - double error = ::fabs(filter.marginalLikelihoodMode(weightStyle, weight) - expectedMode); + double error = std::fabs(filter.marginalLikelihoodMode(weightStyle, weight) - expectedMode); relativeError.add(error == 0.0 ? 0.0 : error / expectedMode); } LOG_DEBUG("relativeError = " << maths::CBasicStatistics::mean(relativeError)); @@ -720,7 +719,7 @@ void CGammaRateConjugateTest::testMarginalLikelihoodVariance(void) filter.marginalLikelihoodVariance(), 0.01 * expectedVariance); - relativeError.add(::fabs(expectedVariance - filter.marginalLikelihoodVariance()) + relativeError.add(std::fabs(expectedVariance - filter.marginalLikelihoodVariance()) / expectedVariance); } @@ -805,7 +804,7 @@ void CGammaRateConjugateTest::testSampleMarginalLikelihood(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(filter.marginalLikelihoodVariance(), maths::CBasicStatistics::variance(sampledMoments), 0.25 * filter.marginalLikelihoodVariance()); - meanVarError.add( ::fabs( filter.marginalLikelihoodVariance() + meanVarError.add( std::fabs( filter.marginalLikelihoodVariance() - maths::CBasicStatistics::variance(sampledMoments)) / filter.marginalLikelihoodVariance()); @@ -868,8 +867,8 @@ void CGammaRateConjugateTest::testCdf(void) double fComplement = (lowerBound + upperBound) / 2.0; LOG_DEBUG("log(F(x)) = " << -f << ", log(1 - F(x)) = " << fComplement); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(std::numeric_limits::min()), -f, 1e-10); - CPPUNIT_ASSERT_EQUAL(1.0, ::exp(-fComplement)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(std::numeric_limits::min()), -f, 1e-10); + CPPUNIT_ASSERT_EQUAL(1.0, std::exp(-fComplement)); for (std::size_t i = 1u; i < 500; ++i) { @@ -882,7 +881,7 @@ void CGammaRateConjugateTest::testCdf(void) LOG_DEBUG("log(F(x)) = " << (f == 0.0 ? f : -f) << ", log(1 - F(x)) = " << (fComplement == 0.0 ? fComplement : -fComplement)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, ::exp(-f) + ::exp(-fComplement), 1e-10); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, std::exp(-f) + std::exp(-fComplement), 1e-10); } } @@ -948,7 +947,7 @@ void CGammaRateConjugateTest::testProbabilityOfLessLikelySamples(void) double lb, ub; filter.probabilityOfLessLikelySamples(maths_t::E_TwoSided, sample, lb, ub); - double ssd = ::sqrt(px * (1.0 - px) / static_cast(samples.size())); + double ssd = std::sqrt(px * (1.0 - px) / static_cast(samples.size())); LOG_DEBUG("expected P(x) = " << px << ", actual P(x) = " << (lb + ub) / 2.0 @@ -956,7 +955,7 @@ void CGammaRateConjugateTest::testProbabilityOfLessLikelySamples(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(px, (lb + ub) / 2.0, 3.0 * ssd); - meanError.add(::fabs(px - (lb + ub) / 2.0)); + meanError.add(std::fabs(px - (lb + ub) / 2.0)); } maths_t::TWeightStyleVec weightStyle(1, maths_t::E_SampleCountVarianceScaleWeight); @@ -1284,7 +1283,7 @@ void CGammaRateConjugateTest::testIntegerData(void) for (std::size_t k = 0u; k < nSamples; ++k) { - double x = ::floor(samples[k]); + double x = std::floor(samples[k]); TDouble1Vec sample(1, x); filter1.addSamples(sample); @@ -1326,7 +1325,7 @@ void CGammaRateConjugateTest::testIntegerData(void) for (std::size_t k = 0u; k < nSamples; ++k) { - double x = ::floor(samples[k]); + double x = std::floor(samples[k]); TDouble1Vec sample(1, x); @@ -1733,9 +1732,9 @@ void CGammaRateConjugateTest::testVarianceScale(void) double estimatedVariance = estimatedMean / filter.likelihoodRate(); double dm = (dataTypes[t] == maths_t::E_IntegerData ? 0.5 : 0.0); double dv = (dataTypes[t] == maths_t::E_IntegerData ? 1.0 / 12.0 : 0.0); - double trialMeanError = ::fabs(estimatedMean - (mean + dm)) + double trialMeanError = std::fabs(estimatedMean - (mean + dm)) / std::max(1.0, mean + dm); - double trialVarianceError = ::fabs(estimatedVariance - (variance + dv)) + double trialVarianceError = std::fabs(estimatedVariance - (variance + dv)) / std::max(1.0, variance + dv); LOG_DEBUG("trial mean error = " << trialMeanError); diff --git a/lib/maths/unittest/CGramSchmidtTest.cc b/lib/maths/unittest/CGramSchmidtTest.cc index b7dbf7d354..c71a9c4790 100644 --- a/lib/maths/unittest/CGramSchmidtTest.cc +++ b/lib/maths/unittest/CGramSchmidtTest.cc @@ -207,7 +207,7 @@ void CGramSchmidtTest::testNormalisation(void) if (t % 10 == 0) debug(x); for (std::size_t i = 0u; i < x.size(); ++i) { - double normxi = ::sqrt(inner(x[i], x[i])); + double normxi = std::sqrt(inner(x[i], x[i])); if (t % 10 == 0) { LOG_DEBUG("|| x(i) || = " << normxi); @@ -283,7 +283,7 @@ void CGramSchmidtTest::testSpan(void) } subtract(r, x[i]); - double normr = ::sqrt(inner(r, r)); + double normr = std::sqrt(inner(r, r)); if (t % 10 == 0) { diff --git a/lib/maths/unittest/CInformationCriteriaTest.cc b/lib/maths/unittest/CInformationCriteriaTest.cc index 8685506813..28c076596b 100644 --- a/lib/maths/unittest/CInformationCriteriaTest.cc +++ b/lib/maths/unittest/CInformationCriteriaTest.cc @@ -50,7 +50,7 @@ double logfSphericalGaussian(const POINT &mean, { double d = static_cast(x.dimension()); double r = (x - mean).euclidean(); - return -0.5 * ( d * ::log(boost::math::double_constants::two_pi * variance) + return -0.5 * ( d * std::log(boost::math::double_constants::two_pi * variance) + r * r / variance); } @@ -100,10 +100,10 @@ void CInformationCriteriaTest::testSphericalGaussian(void) for (std::size_t i = 0u; i < samples.size(); ++i) { likelihood += -2.0 * logfSphericalGaussian(mean, variance, samples[i]) - + 2.0 * ::log(upper); + + 2.0 * std::log(upper); } double expectedAICc = likelihood + 6.0 + 12.0 / (n - 4.0); - double expectedBIC = likelihood + 3.0 * ::log(n); + double expectedBIC = likelihood + 3.0 * std::log(n); maths::CSphericalGaussianInfoCriterion bic; bic.add(samples); @@ -142,10 +142,10 @@ void CInformationCriteriaTest::testSphericalGaussian(void) for (std::size_t i = 0u; i < samples.size(); ++i) { likelihood += -2.0 * logfSphericalGaussian(mean, variance, samples[i]) - + 4.0 * ::log(upper); + + 4.0 * std::log(upper); } double expectedAICc = likelihood + 10.0 + 30.0 / (n - 6.0); - double expectedBIC = likelihood + 5.0 * ::log(n); + double expectedBIC = likelihood + 5.0 * std::log(n); maths::CSphericalGaussianInfoCriterion bic; bic.add(samples); @@ -338,10 +338,10 @@ void CInformationCriteriaTest::testGaussian(void) for (std::size_t i = 0u; i < samples.size(); ++i) { likelihood += -2.0 * logfGaussian(mean, covariance, samples[i]) - + 2.0 * ::log(upper); + + 2.0 * std::log(upper); } double expectedAICc = likelihood + 10.0 + 30.0 / (n - 6.0); - double expectedBIC = likelihood + 5.0 * ::log(n); + double expectedBIC = likelihood + 5.0 * std::log(n); maths::CGaussianInfoCriterion bic; bic.add(samples); @@ -379,10 +379,10 @@ void CInformationCriteriaTest::testGaussian(void) for (std::size_t i = 0u; i < samples.size(); ++i) { likelihood += -2.0 * logfGaussian(mean, covariance, samples[i]) - + 4.0 * ::log(upper); + + 4.0 * std::log(upper); } double expectedAICc = likelihood + 28.0 + 210.0 / (n - 15.0); - double expectedBIC = likelihood + 14.0 * ::log(n); + double expectedBIC = likelihood + 14.0 * std::log(n); maths::CGaussianInfoCriterion bic; bic.add(samples); diff --git a/lib/maths/unittest/CIntegerToolsTest.cc b/lib/maths/unittest/CIntegerToolsTest.cc index 531a9e5e7c..7c6f8e83be 100644 --- a/lib/maths/unittest/CIntegerToolsTest.cc +++ b/lib/maths/unittest/CIntegerToolsTest.cc @@ -26,7 +26,7 @@ #include #include -#include +#include using namespace ml; @@ -238,7 +238,7 @@ void CIntegerToolsTest::testBinomial(void) LOG_DEBUG("j = " << j << ", n = " << n[i] << ", (n j) = " << maths::CIntegerTools::binomial(n[i], j)); - double expected = ::exp( boost::math::lgamma(static_cast(n[i]+1)) + double expected = std::exp( boost::math::lgamma(static_cast(n[i]+1)) - boost::math::lgamma(static_cast(n[i]-j+1)) - boost::math::lgamma(static_cast(j+1))); CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, maths::CIntegerTools::binomial(n[i], j), 1e-10); diff --git a/lib/maths/unittest/CIntegrationTest.cc b/lib/maths/unittest/CIntegrationTest.cc index 86db28473d..d1c7282538 100644 --- a/lib/maths/unittest/CIntegrationTest.cc +++ b/lib/maths/unittest/CIntegrationTest.cc @@ -28,11 +28,10 @@ #include #include +#include #include #include -#include - using namespace ml; using namespace maths; @@ -55,7 +54,7 @@ class CPolynomialFunction : public std::unary_function result = 0.0; for (unsigned int i = 0u; i < ORDER + 1; ++i) { - result += m_Coefficients[i] * ::pow(x, static_cast(i)); + result += m_Coefficients[i] * std::pow(x, static_cast(i)); } return true; } @@ -98,7 +97,7 @@ double integrate(const CPolynomialFunction &f, for (unsigned int i = 0; i < ORDER + 1; ++i) { double n = static_cast(i) + 1.0; - result += f.coefficient(i) / n * (::pow(b, n) - ::pow(a, n)); + result += f.coefficient(i) / n * (std::pow(b, n) - std::pow(a, n)); } return result; } @@ -146,7 +145,7 @@ class CMultivariatePolynomialFunction { if (monomial.s_Powers[j] > 0.0) { - term *= ::pow(x(j), monomial.s_Powers[j]); + term *= std::pow(x(j), monomial.s_Powers[j]); } } result += term; @@ -202,7 +201,7 @@ double integrate(const CMultivariatePolynomialFunction &f, for (unsigned int j = 0; j < DIMENSION; ++j) { double n = (f.terms())[i].s_Powers[j] + 1.0; - term *= (::pow(b[j], n) - ::pow(a[j], n)) / n; + term *= (std::pow(b[j], n) - std::pow(a[j], n)) / n; } result += term; } @@ -272,8 +271,8 @@ class CSmoothHeavySide bool operator()(double x, double &result) const { - result = ::exp(m_Slope * (x - m_Offset)) - / (::exp(m_Slope * (x - m_Offset)) + 1.0); + result = std::exp(m_Slope * (x - m_Offset)) + / (std::exp(m_Slope * (x - m_Offset)) + 1.0); return true; } @@ -1143,7 +1142,7 @@ void CIntegrationTest::testSparseGrid(void) { LOG_DEBUG("weight = " << (sparse.weights())[i]); CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedWeights[i], - (sparse.weights())[i] / ::pow(2.0, 7.0), 1e-6); + (sparse.weights())[i] / std::pow(2.0, 7.0), 1e-6); LOG_DEBUG("point = " << (sparse.points())[i]); for (std::size_t j = 0u; j < expectedPoints[i].size(); ++j) @@ -1179,7 +1178,7 @@ void CIntegrationTest::testSparseGrid(void) LOG_DEBUG("weight = " << (sparse.weights())[i]); } CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedWeights[i], - (sparse.weights())[i] / ::pow(2.0, 7.0), 1e-6); + (sparse.weights())[i] / std::pow(2.0, 7.0), 1e-6); if (i % 10 == 0) { diff --git a/lib/maths/unittest/CKMeansOnlineTest.cc b/lib/maths/unittest/CKMeansOnlineTest.cc index 7cb84b94bb..523207c14e 100644 --- a/lib/maths/unittest/CKMeansOnlineTest.cc +++ b/lib/maths/unittest/CKMeansOnlineTest.cc @@ -345,8 +345,8 @@ void CKMeansOnlineTest::testClustering(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(costOnline), maths::CBasicStatistics::mean(cost), 1e-10); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::sqrt(maths::CBasicStatistics::variance(costOnline)), - ::sqrt(maths::CBasicStatistics::variance(cost)), + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(maths::CBasicStatistics::variance(costOnline)), + std::sqrt(maths::CBasicStatistics::variance(cost)), 1e-10); } @@ -417,8 +417,8 @@ void CKMeansOnlineTest::testClustering(void) CPPUNIT_ASSERT(maths::CBasicStatistics::mean(costOnline) <= 1.01 * maths::CBasicStatistics::mean(cost)); - CPPUNIT_ASSERT(::sqrt(maths::CBasicStatistics::variance(costOnline)) - <= 26.0 * ::sqrt(maths::CBasicStatistics::variance(cost))); + CPPUNIT_ASSERT(std::sqrt(maths::CBasicStatistics::variance(costOnline)) + <= 26.0 * std::sqrt(maths::CBasicStatistics::variance(cost))); } } diff --git a/lib/maths/unittest/CKMostCorrelatedTest.cc b/lib/maths/unittest/CKMostCorrelatedTest.cc index 84d864f586..8720a21290 100644 --- a/lib/maths/unittest/CKMostCorrelatedTest.cc +++ b/lib/maths/unittest/CKMostCorrelatedTest.cc @@ -113,16 +113,16 @@ double mutualInformation(const TDoubleVec &p1, if (f12[i][j] > 0.0) { I += f12[i][j] / static_cast(n) - * ::log(f12[i][j] * static_cast(n) / f1[i] / f2[j]); + * std::log(f12[i][j] * static_cast(n) / f1[i] / f2[j]); } } if (f1[i] > 0.0) { - H1 -= f1[i] / static_cast(n) * ::log(f1[i] / static_cast(n)); + H1 -= f1[i] / static_cast(n) * std::log(f1[i] / static_cast(n)); } if (f2[i] > 0.0) { - H2 -= f2[i] / static_cast(n) * ::log(f2[i] / static_cast(n)); + H2 -= f2[i] / static_cast(n) * std::log(f2[i] / static_cast(n)); } } @@ -177,9 +177,9 @@ void estimateCorrelation(const std::size_t trials, if (maths::CBasicStatistics::count(sampleMoments) > 1.0) { px += projections[i] * (samples[i](0) - maths::CBasicStatistics::mean(sampleMoments)(0)) - / ::sqrt(maths::CBasicStatistics::variance(sampleMoments)(0)); + / std::sqrt(maths::CBasicStatistics::variance(sampleMoments)(0)); py += projections[i] * (samples[i](1) - maths::CBasicStatistics::mean(sampleMoments)(1)) - / ::sqrt(maths::CBasicStatistics::variance(sampleMoments)(1)); + / std::sqrt(maths::CBasicStatistics::variance(sampleMoments)(1)); } } maths::CPackedBitVector ix(50, true); @@ -218,7 +218,7 @@ void CKMostCorrelatedTest::testCorrelation(void) estimateCorrelation(100, mean, covariance, correlationEstimate); LOG_DEBUG("correlationEstimate = " << correlationEstimate); - double sd = ::sqrt(maths::CBasicStatistics::variance(correlationEstimate)); + double sd = std::sqrt(maths::CBasicStatistics::variance(correlationEstimate)); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.2, maths::CBasicStatistics::mean(correlationEstimate), 3.0 * sd / 10.0); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, sd, 0.5); } @@ -234,7 +234,7 @@ void CKMostCorrelatedTest::testCorrelation(void) estimateCorrelation(100, mean, covariance, correlationEstimate); LOG_DEBUG("correlation = " << correlationEstimate); - double sd = ::sqrt(maths::CBasicStatistics::variance(correlationEstimate)); + double sd = std::sqrt(maths::CBasicStatistics::variance(correlationEstimate)); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5, maths::CBasicStatistics::mean(correlationEstimate), 3.0 * sd / 10.0); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, sd, 0.42); } @@ -250,7 +250,7 @@ void CKMostCorrelatedTest::testCorrelation(void) estimateCorrelation(100, mean, covariance, correlationEstimate); LOG_DEBUG("correlation = " << correlationEstimate); - double sd = ::sqrt(maths::CBasicStatistics::variance(correlationEstimate)); + double sd = std::sqrt(maths::CBasicStatistics::variance(correlationEstimate)); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.9, maths::CBasicStatistics::mean(correlationEstimate), 3.0 * sd / 10.0); CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, sd, 0.2); } @@ -905,9 +905,9 @@ void CKMostCorrelatedTest::testScale(void) { slope.add(static_cast(elapsed[i]) / static_cast(elapsed[i-1])); } - double exponent = ::log(maths::CBasicStatistics::mean(slope)) / ::log(2.0); + double exponent = std::log(maths::CBasicStatistics::mean(slope)) / std::log(2.0); LOG_DEBUG("exponent = " << exponent); - double sdRatio = ::sqrt(maths::CBasicStatistics::variance(slope)) + double sdRatio = std::sqrt(maths::CBasicStatistics::variance(slope)) / maths::CBasicStatistics::mean(slope); LOG_DEBUG("sdRatio = " << sdRatio); if (core::CUname::nodeName().compare(0, 3, "vm-") == 0) diff --git a/lib/maths/unittest/CLassoLogisticRegressionTest.cc b/lib/maths/unittest/CLassoLogisticRegressionTest.cc index b0239f161f..f1b087ff66 100644 --- a/lib/maths/unittest/CLassoLogisticRegressionTest.cc +++ b/lib/maths/unittest/CLassoLogisticRegressionTest.cc @@ -25,10 +25,9 @@ #include #include +#include #include -#include - using namespace ml; namespace @@ -91,11 +90,11 @@ double logLikelihood(const TDoubleVecVec &x, { f += beta[j] * x[j][i]; } - result -= ::log(1.0 + ::exp(-f * y[i])); + result -= std::log(1.0 + std::exp(-f * y[i])); } for (std::size_t j = 0u; j < beta.size(); ++j) { - result -= lambda[j] * ::fabs(beta[j]); + result -= lambda[j] * std::fabs(beta[j]); } return result; } @@ -180,7 +179,7 @@ void CLassoLogisticRegressionTest::testCyclicCoordinateDescent(void) betaPlusEps.push_back(beta1[j] + step[j]); length += step[j] * step[j]; } - length = 2.0 * ::sqrt(length); + length = 2.0 * std::sqrt(length); llMinusEps += logLikelihood(x, y, lambda, betaMinusEps); llPlusEps += logLikelihood(x, y, lambda, betaPlusEps); @@ -205,7 +204,7 @@ void CLassoLogisticRegressionTest::testCyclicCoordinateDescent(void) double decision = 1.0; TDoubleVec decisionNormal; rng.generateUniformSamples(0.0, 1.0, 5, decisionNormal); - double length = ::sqrt(inner(decisionNormal, decisionNormal)); + double length = std::sqrt(inner(decisionNormal, decisionNormal)); for (std::size_t j = 0u; j < decisionNormal.size(); ++j) { decisionNormal[j] /= length; @@ -219,7 +218,7 @@ void CLassoLogisticRegressionTest::testCyclicCoordinateDescent(void) { TDoubleVec xi; rng.generateUniformSamples(-20.0, 20.0, 5, xi); - double yi = ::sqrt(inner(decisionNormal, xi)) > decision ? 1.0 : -1.0; + double yi = std::sqrt(inner(decisionNormal, xi)) > decision ? 1.0 : -1.0; for (std::size_t j = 0u; j < xi.size(); ++j) { x_[j][i] = xi[j]; @@ -246,8 +245,8 @@ void CLassoLogisticRegressionTest::testCyclicCoordinateDescent(void) effectiveDecisionNormal.push_back(beta[j]); } - double theta = ::acos(inner(effectiveDecisionNormal, decisionNormal) - / ::sqrt(inner(effectiveDecisionNormal, effectiveDecisionNormal))) + double theta = std::acos(inner(effectiveDecisionNormal, decisionNormal) + / std::sqrt(inner(effectiveDecisionNormal, effectiveDecisionNormal))) * 360.0 / boost::math::double_constants::two_pi; LOG_DEBUG("angular error = " << theta << " deg"); diff --git a/lib/maths/unittest/CLinearAlgebraTest.cc b/lib/maths/unittest/CLinearAlgebraTest.cc index c2b0edfba2..9fc7c5c8be 100644 --- a/lib/maths/unittest/CLinearAlgebraTest.cc +++ b/lib/maths/unittest/CLinearAlgebraTest.cc @@ -770,7 +770,7 @@ void CLinearAlgebraTest::testUtils(void) } { - double expected[] = { 1.0, ::sqrt(3.1), ::sqrt(2.2), ::sqrt(4.9), ::sqrt(12.0) }; + double expected[] = { 1.0, std::sqrt(3.1), std::sqrt(2.2), std::sqrt(4.9), std::sqrt(12.0) }; LOG_DEBUG("sqrt(v1) = " << maths::sqrt(v1)); for (std::size_t i = 0u; i < 5; ++i) { @@ -903,9 +903,9 @@ void CLinearAlgebraTest::testUtils(void) { double expected[][3] = { - { ::sqrt(2.1), ::sqrt(0.3), ::sqrt(0.4) }, - { ::sqrt(0.3), ::sqrt(1.2), ::sqrt(3.8) }, - { ::sqrt(0.4), ::sqrt(3.8), ::sqrt(0.2) } + { std::sqrt(2.1), std::sqrt(0.3), std::sqrt(0.4) }, + { std::sqrt(0.3), std::sqrt(1.2), std::sqrt(3.8) }, + { std::sqrt(0.4), std::sqrt(3.8), std::sqrt(0.2) } }; LOG_DEBUG("sqrt(m1) = " << maths::sqrt(m1)); for (std::size_t i = 0u; i < 3; ++i) @@ -1003,22 +1003,22 @@ void CLinearAlgebraTest::testGaussianLogLikelihood(void) double likelihood; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, maths::gaussianLogLikelihood(covariance, e1, likelihood)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 3.0 * ::log(boost::math::double_constants::two_pi) - + ::log(10.0 * 5.0 * 5.0) + CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 3.0 * std::log(boost::math::double_constants::two_pi) + + std::log(10.0 * 5.0 * 5.0) + 4.0 / 10.0), likelihood, 1e-10); CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, maths::gaussianLogLikelihood(covariance, e2, likelihood)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 3.0 * ::log(boost::math::double_constants::two_pi) - + ::log(10.0 * 5.0 * 5.0) + CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 3.0 * std::log(boost::math::double_constants::two_pi) + + std::log(10.0 * 5.0 * 5.0) + 2.0 / 5.0), likelihood, 1e-10); CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, maths::gaussianLogLikelihood(covariance, e3, likelihood)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 3.0 * ::log(boost::math::double_constants::two_pi) - + ::log(10.0 * 5.0 * 5.0) + CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 3.0 * std::log(boost::math::double_constants::two_pi) + + std::log(10.0 * 5.0 * 5.0) + 6.0 / 5.0), likelihood, 1e-10); @@ -1047,26 +1047,26 @@ void CLinearAlgebraTest::testGaussianLogLikelihood(void) double likelihood; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, maths::gaussianLogLikelihood(covariance, e1, likelihood)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 4.0 * ::log(boost::math::double_constants::two_pi) - + ::log(10.0 * 5.0 * 5.0 * 2.0) + CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 4.0 * std::log(boost::math::double_constants::two_pi) + + std::log(10.0 * 5.0 * 5.0 * 2.0) + 4.0 / 10.0), likelihood, 1e-10); CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, maths::gaussianLogLikelihood(covariance, e2, likelihood)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 4.0 * ::log(boost::math::double_constants::two_pi) - + ::log(10.0 * 5.0 * 5.0 * 2.0) + CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 4.0 * std::log(boost::math::double_constants::two_pi) + + std::log(10.0 * 5.0 * 5.0 * 2.0) + 2.0 / 5.0), likelihood, 1e-10); CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, maths::gaussianLogLikelihood(covariance, e3, likelihood)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 4.0 * ::log(boost::math::double_constants::two_pi) - + ::log(10.0 * 5.0 * 5.0 * 2.0) + CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 4.0 * std::log(boost::math::double_constants::two_pi) + + std::log(10.0 * 5.0 * 5.0 * 2.0) + 6.0 / 5.0), likelihood, 1e-10); CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, maths::gaussianLogLikelihood(covariance, e4, likelihood)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 4.0 * ::log(boost::math::double_constants::two_pi) - + ::log(10.0 * 5.0 * 5.0 * 2.0) + CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5 * ( 4.0 * std::log(boost::math::double_constants::two_pi) + + std::log(10.0 * 5.0 * 5.0 * 2.0) + 12.0 / 2.0), likelihood, 1e-10); @@ -1235,8 +1235,8 @@ void CLinearAlgebraTest::testLogDeterminant(void) double logDeterminant; maths::logDeterminant(M, logDeterminant); LOG_DEBUG("expected |M| = " << expected[i]); - LOG_DEBUG("got |M| = " << ::exp(logDeterminant)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i], ::exp(logDeterminant), 1e-4 * expected[i]); + LOG_DEBUG("got |M| = " << std::exp(logDeterminant)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[i], std::exp(logDeterminant), 1e-4 * expected[i]); } } @@ -1257,7 +1257,7 @@ void CLinearAlgebraTest::testLogDeterminant(void) + 2.0 * maths::CSymmetricMatrixNxN(maths::E_OuterProduct, e4 / e4.euclidean())); double logDeterminant; maths::logDeterminant(M, logDeterminant); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(10.0 * 5.0 * 5.0 * 2.0), logDeterminant, 1e-10); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(10.0 * 5.0 * 5.0 * 2.0), logDeterminant, 1e-10); } } diff --git a/lib/maths/unittest/CLogNormalMeanPrecConjugateTest.cc b/lib/maths/unittest/CLogNormalMeanPrecConjugateTest.cc index 2ed6f64122..31d2652031 100644 --- a/lib/maths/unittest/CLogNormalMeanPrecConjugateTest.cc +++ b/lib/maths/unittest/CLogNormalMeanPrecConjugateTest.cc @@ -35,12 +35,11 @@ #include #include +#include #include #include #include -#include - using namespace ml; using namespace handy_typedefs; @@ -80,7 +79,7 @@ void CLogNormalMeanPrecConjugateTest::testMultipleUpdate(void) maths_t::E_ContinuousData }; - const double location = ::log(10.0); + const double location = std::log(10.0); const double squareScale = 3.0; test::CRandomNumbers rng; @@ -105,14 +104,14 @@ void CLogNormalMeanPrecConjugateTest::testMultipleUpdate(void) // Test with variance scale. - double mean = ::exp(location + squareScale / 2.0); - double variance = mean * mean * (::exp(squareScale) - 1.0); + double mean = std::exp(location + squareScale / 2.0); + double variance = mean * mean * (std::exp(squareScale) - 1.0); LOG_DEBUG("mean = " << mean << " variance = " << variance); - double scaledSquareScale = ::log(1.0 + 2.0 * variance / mean / mean); - double scaledLocation = ::log(mean) - scaledSquareScale / 2.0; - double scaledMean = ::exp(scaledLocation + scaledSquareScale / 2.0); - double scaledVariance = scaledMean * scaledMean * (::exp(scaledSquareScale) - 1.0); + double scaledSquareScale = std::log(1.0 + 2.0 * variance / mean / mean); + double scaledLocation = std::log(mean) - scaledSquareScale / 2.0; + double scaledMean = std::exp(scaledLocation + scaledSquareScale / 2.0); + double scaledVariance = scaledMean * scaledMean * (std::exp(scaledSquareScale) - 1.0); LOG_DEBUG("scaled mean = " << scaledMean << " scaled variance = " << scaledVariance); TDoubleVec scaledSamples; @@ -232,7 +231,7 @@ void CLogNormalMeanPrecConjugateTest::testMeanEstimation(void) for (unsigned int test = 0; test < nTests; ++test) { - double location = ::log(0.5 * (test + 1)); + double location = std::log(0.5 * (test + 1)); double squareScale = 4.0; TDoubleVec samples; @@ -444,7 +443,7 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihood(void) for (size_t k = 0; k < boost::size(deltas); ++k) { - double x = ::exp(location + deltas[k] * ::sqrt(squareScale)); + double x = std::exp(location + deltas[k] * std::sqrt(squareScale)); TDouble1Vec sample(1, x); LOG_DEBUG("number = " << numberSamples[i] @@ -453,21 +452,21 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihood(void) double logLikelihood = 0.0; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter.jointLogMarginalLikelihood(sample, logLikelihood)); - double pdf = ::exp(logLikelihood); + double pdf = std::exp(logLikelihood); double lowerBound = 0.0, upperBound = 0.0; sample[0] -= eps; CPPUNIT_ASSERT(filter.minusLogJointCdf(sample, lowerBound, upperBound)); CPPUNIT_ASSERT_EQUAL(lowerBound, upperBound); double minusLogCdf = (lowerBound + upperBound) / 2.0; - double cdfAtMinusEps = ::exp(-minusLogCdf); + double cdfAtMinusEps = std::exp(-minusLogCdf); CPPUNIT_ASSERT(minusLogCdf >= 0.0); sample[0] += 2.0 * eps; CPPUNIT_ASSERT(filter.minusLogJointCdf(sample, lowerBound, upperBound)); CPPUNIT_ASSERT_EQUAL(lowerBound, upperBound); minusLogCdf = (lowerBound + upperBound) / 2.0; - double cdfAtPlusEps = ::exp(-minusLogCdf); + double cdfAtPlusEps = std::exp(-minusLogCdf); CPPUNIT_ASSERT(minusLogCdf >= 0.0); double dcdfdx = (cdfAtPlusEps - cdfAtMinusEps) / 2.0 / eps; @@ -485,7 +484,7 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihood(void) // law of large numbers), which is just the differential entropy // of a log-normal R.V. - boost::math::lognormal_distribution<> logNormal(location, ::sqrt(squareScale)); + boost::math::lognormal_distribution<> logNormal(location, std::sqrt(squareScale)); double expectedDifferentialEntropy = maths::CTools::differentialEntropy(logNormal); CLogNormalMeanPrecConjugate filter(makePrior()); @@ -524,7 +523,7 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihood(void) 1.2, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0 }; - boost::math::lognormal_distribution<> logNormal(location, ::sqrt(squareScale)); + boost::math::lognormal_distribution<> logNormal(location, std::sqrt(squareScale)); CLogNormalMeanPrecConjugate filter(makePrior()); TDoubleVec samples; @@ -551,8 +550,8 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihood(void) << ", interval = " << core::CContainerPrinter::print(interval)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q1, interval.first, 1e-3); CPPUNIT_ASSERT_DOUBLES_EQUAL(q2, interval.second, 1e-3); - error.add(::fabs(interval.first - q1)); - error.add(::fabs(interval.second - q2)); + error.add(std::fabs(interval.first - q1)); + error.add(std::fabs(interval.second - q2)); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 1e-3); @@ -563,11 +562,11 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihood(void) { TMeanAccumulator error; double vs = varianceScales[i]; - double shift = ::log(1.0 + vs * (::exp(squareScale) - 1.0)) - squareScale; + double shift = std::log(1.0 + vs * (std::exp(squareScale) - 1.0)) - squareScale; double shiftedLocation = location - 0.5 * shift; double shiftedSquareScale = squareScale + shift; boost::math::lognormal_distribution<> scaledLogNormal(shiftedLocation, - ::sqrt(shiftedSquareScale)); + std::sqrt(shiftedSquareScale)); LOG_DEBUG("*** vs = " << boost::math::variance(scaledLogNormal) / boost::math::variance(logNormal) << " ***"); for (std::size_t j = 0u; j < boost::size(percentages); ++j) @@ -582,8 +581,8 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihood(void) << ", interval = " << core::CContainerPrinter::print(interval)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q1, interval.first, std::max(0.5, 0.2 * q1)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q2, interval.second, 0.1 * q2); - error.add(::fabs(interval.first - q1) / q1); - error.add(::fabs(interval.second - q2) / q2); + error.add(std::fabs(interval.first - q1) / q1); + error.add(std::fabs(interval.second - q2) / q2); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 0.07); @@ -644,7 +643,7 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihoodMean(void) filter.marginalLikelihoodMean(), 0.35 * expectedMean); - relativeError.add(::fabs(filter.marginalLikelihoodMean() - expectedMean) + relativeError.add(std::fabs(filter.marginalLikelihoodMean() - expectedMean) / expectedMean); } @@ -680,7 +679,7 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihoodMode(void) << ", squareScale = " << squareScales[j] << " ***"); boost::math::lognormal_distribution<> logNormal(locations[i], - ::sqrt(squareScales[j])); + std::sqrt(squareScales[j])); CLogNormalMeanPrecConjugate filter(makePrior()); TDoubleVec samples; @@ -694,11 +693,11 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihoodMode(void) { double vs = varianceScales[k]; weight[0] = vs; - double shift = ::log(1.0 + vs * (::exp(squareScales[j]) - 1.0)) - squareScales[j]; + double shift = std::log(1.0 + vs * (std::exp(squareScales[j]) - 1.0)) - squareScales[j]; double shiftedLocation = locations[i] - 0.5 * shift; double shiftedSquareScale = squareScales[j] + shift; boost::math::lognormal_distribution<> scaledLogNormal(shiftedLocation, - ::sqrt(shiftedSquareScale)); + std::sqrt(shiftedSquareScale)); double expectedMode = boost::math::mode(scaledLogNormal); LOG_DEBUG("dm = " << boost::math::mean(scaledLogNormal) - boost::math::mean(logNormal) @@ -709,7 +708,7 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihoodMode(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedMode, filter.marginalLikelihoodMode(weightStyle, weight), 1.0); - error.add(::fabs(filter.marginalLikelihoodMode(weightStyle, weight) - expectedMode)); + error.add(std::fabs(filter.marginalLikelihoodMode(weightStyle, weight) - expectedMode)); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 0.26); @@ -763,7 +762,7 @@ void CLogNormalMeanPrecConjugateTest::testMarginalLikelihoodVariance(void) << ", expectedVariance = " << expectedVariance); } - relativeError.add(::fabs(filter.marginalLikelihoodVariance() - expectedVariance) + relativeError.add(std::fabs(filter.marginalLikelihoodVariance() - expectedVariance) / expectedVariance); } @@ -837,7 +836,7 @@ void CLogNormalMeanPrecConjugateTest::testSampleMarginalLikelihood(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(filter.marginalLikelihoodMean(), maths::CBasicStatistics::mean(sampledMoments), 0.8); - meanMeanError.add(::fabs( filter.marginalLikelihoodMean() + meanMeanError.add(std::fabs( filter.marginalLikelihoodMean() - maths::CBasicStatistics::mean(sampledMoments))); } @@ -900,8 +899,8 @@ void CLogNormalMeanPrecConjugateTest::testCdf(void) double fComplement = (lowerBound + upperBound) / 2.0; LOG_DEBUG("log(F(x)) = " << -f << ", log(1 - F(x)) = " << fComplement); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(std::numeric_limits::min()), -f, 1e-10); - CPPUNIT_ASSERT_EQUAL(1.0, ::exp(-fComplement)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(std::numeric_limits::min()), -f, 1e-10); + CPPUNIT_ASSERT_EQUAL(1.0, std::exp(-fComplement)); for (std::size_t j = 1u; j < 500; ++j) { @@ -913,7 +912,7 @@ void CLogNormalMeanPrecConjugateTest::testCdf(void) fComplement = (lowerBound + upperBound) / 2.0; LOG_DEBUG("log(F(x)) = " << (f == 0.0 ? f : -f) << ", log(1 - F(x)) = " << (fComplement == 0.0 ? fComplement : -fComplement)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, ::exp(-f) + ::exp(-fComplement), 1e-10); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, std::exp(-f) + std::exp(-fComplement), 1e-10); } } } @@ -944,7 +943,7 @@ void CLogNormalMeanPrecConjugateTest::testProbabilityOfLessLikelySamples(void) for (size_t j = 0; j < boost::size(squareScales); ++j) { LOG_DEBUG("means = " << means[i] - << ", scale = " << ::sqrt(squareScales[j])); + << ", scale = " << std::sqrt(squareScales[j])); TDoubleVec samples; rng.generateLogNormalSamples(means[i], squareScales[j], 1000, samples); @@ -953,7 +952,7 @@ void CLogNormalMeanPrecConjugateTest::testProbabilityOfLessLikelySamples(void) filter.addSamples(samples); double location = filter.normalMean(); - double scale = ::sqrt(1.0 / filter.normalPrecision()); + double scale = std::sqrt(1.0 / filter.normalPrecision()); TDoubleVec likelihoods; for (std::size_t k = 0u; k < samples.size(); ++k) @@ -981,7 +980,7 @@ void CLogNormalMeanPrecConjugateTest::testProbabilityOfLessLikelySamples(void) double lb, ub; filter.probabilityOfLessLikelySamples(maths_t::E_TwoSided, sample, lb, ub); - double ssd = ::sqrt(px * (1.0 - px) / static_cast(samples.size())); + double ssd = std::sqrt(px * (1.0 - px) / static_cast(samples.size())); LOG_DEBUG("expected P(x) = " << px << ", actual P(x) = " << (lb + ub) / 2.0 @@ -989,7 +988,7 @@ void CLogNormalMeanPrecConjugateTest::testProbabilityOfLessLikelySamples(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(px, (lb + ub) / 2.0, 3.0 * ssd); - meanError.add(::fabs(px - (lb + ub) / 2.0)); + meanError.add(std::fabs(px - (lb + ub) / 2.0)); } maths_t::TWeightStyleVec weightStyle(1, maths_t::E_SampleCountVarianceScaleWeight); @@ -1108,9 +1107,9 @@ void CLogNormalMeanPrecConjugateTest::testAnomalyScore(void) { for (size_t j = 0; j < boost::size(squareScales); ++j) { - LOG_DEBUG("mean = " << means[i] << ", scale = " << ::sqrt(squareScales[j])); + LOG_DEBUG("mean = " << means[i] << ", scale = " << std::sqrt(squareScales[j])); - boost::math::lognormal_distribution<> logNormal(means[i], ::sqrt(squareScales[j])); + boost::math::lognormal_distribution<> logNormal(means[i], std::sqrt(squareScales[j])); TDoubleVec samples; rng.generateLogNormalSamples(means[i], squareScales[j], 500, samples); @@ -1317,7 +1316,7 @@ void CLogNormalMeanPrecConjugateTest::testIntegerData(void) for (std::size_t k = 0; k < nSamples; ++k) { - double x = ::floor(samples[k]); + double x = std::floor(samples[k]); TDouble1Vec sample(1, x); filter1.addSamples(sample); @@ -1334,7 +1333,7 @@ void CLogNormalMeanPrecConjugateTest::testIntegerData(void) TMeanAccumulator meanLogLikelihood2; for (std::size_t k = 0u; k < nSamples; ++k) { - double x = ::floor(samples[k]); + double x = std::floor(samples[k]); TDouble1Vec sample(1, x); double logLikelihood1; @@ -1383,7 +1382,7 @@ void CLogNormalMeanPrecConjugateTest::testIntegerData(void) for (std::size_t k = 0; k < nSamples; ++k) { - double x = ::floor(samples[k]); + double x = std::floor(samples[k]); TDouble1Vec sample(1, x); @@ -1460,7 +1459,7 @@ void CLogNormalMeanPrecConjugateTest::testPersist(void) LOG_DEBUG("| CLogNormalMeanPrecConjugateTest::testPersist |"); LOG_DEBUG("+------------------------------------------------+"); - const double location = ::log(10.0); + const double location = std::log(10.0); const double squareScale = 3.0; test::CRandomNumbers rng; @@ -1548,7 +1547,7 @@ void CLogNormalMeanPrecConjugateTest::testVarianceScale(void) const double location = 2.0; const double squareScale = 1.5; { - boost::math::lognormal_distribution<> logNormal(location, ::sqrt(squareScale)); + boost::math::lognormal_distribution<> logNormal(location, std::sqrt(squareScale)); LOG_DEBUG("mean = " << boost::math::mean(logNormal) << ", variance = " << boost::math::variance(logNormal)); } @@ -1616,7 +1615,7 @@ void CLogNormalMeanPrecConjugateTest::testVarianceScale(void) { std::size_t index = static_cast( static_cast(nScaledSamples) * percentiles[j]/100.0); - double error = ::fabs(probabilities[index] - percentiles[j]/100.0); + double error = std::fabs(probabilities[index] - percentiles[j]/100.0); unscaledPercentileErrors.push_back(error); unscaledMeanPercentileError += error; } @@ -1627,10 +1626,10 @@ void CLogNormalMeanPrecConjugateTest::testVarianceScale(void) { LOG_DEBUG("**** variance scale = " << varianceScales[j] << " ****"); - double ss = ::log(1.0 + varianceScales[j] * (::exp(squareScale) - 1.0)); + double ss = std::log(1.0 + varianceScales[j] * (std::exp(squareScale) - 1.0)); double shiftedLocation = location + (squareScale - ss) / 2.0; { - boost::math::lognormal_distribution<> logNormal(shiftedLocation, ::sqrt(ss)); + boost::math::lognormal_distribution<> logNormal(shiftedLocation, std::sqrt(ss)); LOG_DEBUG("mean = " << boost::math::mean(logNormal) << ", variance = " << boost::math::variance(logNormal)); } @@ -1663,7 +1662,7 @@ void CLogNormalMeanPrecConjugateTest::testVarianceScale(void) { std::size_t index = static_cast( static_cast(nScaledSamples) * percentiles[k]/100.0); - double error = ::fabs(probabilities[index] - percentiles[k]/100.0); + double error = std::fabs(probabilities[index] - percentiles[k]/100.0); meanPercentileError += error; double threshold = percentileErrorTolerance + unscaledPercentileErrors[k]; @@ -1708,9 +1707,9 @@ void CLogNormalMeanPrecConjugateTest::testVarianceScale(void) { LOG_DEBUG("**** variance scale = " << varianceScales[i] << " ****"); - double ss = ::log(1.0 + varianceScales[i] * (::exp(squareScale) - 1.0)); + double ss = std::log(1.0 + varianceScales[i] * (std::exp(squareScale) - 1.0)); double shiftedLocation = location + (squareScale - ss) / 2.0; - boost::math::lognormal_distribution<> logNormal(shiftedLocation, ::sqrt(ss)); + boost::math::lognormal_distribution<> logNormal(shiftedLocation, std::sqrt(ss)); { LOG_DEBUG("mean = " << boost::math::mean(logNormal) << ", variance = " << boost::math::variance(logNormal)); @@ -1793,16 +1792,16 @@ void CLogNormalMeanPrecConjugateTest::testVarianceScale(void) } // We purposely don't estimate true variance in this case. - if (::sqrt(variance) < mean * maths::MINIMUM_COEFFICIENT_OF_VARIATION) + if (std::sqrt(variance) < mean * maths::MINIMUM_COEFFICIENT_OF_VARIATION) { continue; } - double squareScale = ::log(1.0 + variance / (mean * mean)); - double location = ::log(mean) - squareScale / 2.0; + double squareScale = std::log(1.0 + variance / (mean * mean)); + double location = std::log(mean) - squareScale / 2.0; double precision = 1.0 / squareScale; { - boost::math::lognormal_distribution<> logNormal(location, ::sqrt(squareScale)); + boost::math::lognormal_distribution<> logNormal(location, std::sqrt(squareScale)); LOG_DEBUG(""); LOG_DEBUG("****** mean = " << boost::math::mean(logNormal) << ", variance = " << boost::math::variance(logNormal) << " ******"); @@ -1819,11 +1818,11 @@ void CLogNormalMeanPrecConjugateTest::testVarianceScale(void) } LOG_DEBUG("*** scale = " << scale << " ***"); - double scaledSquareScale = ::log(1.0 + variance * scale / (mean * mean)); - double scaledLocation = ::log(mean) - scaledSquareScale / 2.0; + double scaledSquareScale = std::log(1.0 + variance * scale / (mean * mean)); + double scaledLocation = std::log(mean) - scaledSquareScale / 2.0; double scaledPrecision = 1.0 / scaledSquareScale; { - boost::math::lognormal_distribution<> logNormal(scaledLocation, ::sqrt(scaledSquareScale)); + boost::math::lognormal_distribution<> logNormal(scaledLocation, std::sqrt(scaledSquareScale)); LOG_DEBUG("scaled mean = " << boost::math::mean(logNormal) << ", scaled variance = " << boost::math::variance(logNormal)); LOG_DEBUG("scaled location = " << scaledLocation @@ -1846,12 +1845,12 @@ void CLogNormalMeanPrecConjugateTest::testVarianceScale(void) filter.addSamples(weightStyle, samples, weights); boost::math::lognormal_distribution<> logNormal(filter.normalMean(), - ::sqrt(1.0 / filter.normalPrecision())); + std::sqrt(1.0 / filter.normalPrecision())); double dm = (dataTypes[t] == maths_t::E_IntegerData ? 0.5 : 0.0); double dv = (dataTypes[t] == maths_t::E_IntegerData ? 1.0 / 12.0 : 0.0); - double trialMeanError = ::fabs(boost::math::mean(logNormal) - (mean + dm)) + double trialMeanError = std::fabs(boost::math::mean(logNormal) - (mean + dm)) / std::max(1.0, mean); - double trialVarianceError = ::fabs(boost::math::variance(logNormal) - (variance + dv)) + double trialVarianceError = std::fabs(boost::math::variance(logNormal) - (variance + dv)) / std::max(1.0, variance); LOG_DEBUG("trial mean error = " << trialMeanError); @@ -1898,7 +1897,7 @@ void CLogNormalMeanPrecConjugateTest::testNegativeSample(void) // offset and the other which will adjust and check that we get broadly // similar distributions at the end. - const double location = ::log(2.0); + const double location = std::log(2.0); const double squareScale = 1.0; test::CRandomNumbers rng; diff --git a/lib/maths/unittest/CLogTDistributionTest.cc b/lib/maths/unittest/CLogTDistributionTest.cc index 8591cb72dd..9584d1e4bd 100644 --- a/lib/maths/unittest/CLogTDistributionTest.cc +++ b/lib/maths/unittest/CLogTDistributionTest.cc @@ -23,7 +23,7 @@ #include -#include +#include using namespace ml; using namespace maths; @@ -57,11 +57,11 @@ void CLogTDistributionTest::testMode(void) { LOG_DEBUG("degrees freedom = " << degreesFreedoms[i] << ", location = " << locations[j] - << ", scale = " << ::sqrt(squareScales[k])); + << ", scale = " << std::sqrt(squareScales[k])); CLogTDistribution logt(degreesFreedoms[i], locations[j], - ::sqrt(squareScales[k])); + std::sqrt(squareScales[k])); double x = mode(logt); @@ -105,7 +105,7 @@ void CLogTDistributionTest::testPdf(void) { CLogTDistribution logt(degreesFreedom[test], locations[test], - ::sqrt(squareScales[test])); + std::sqrt(squareScales[test])); for (unsigned int p = 1; p < 100; ++p) { @@ -153,13 +153,13 @@ void CLogTDistributionTest::testCdf(void) sampleItr != samples.end(); ++sampleItr) { - *sampleItr = ::exp(*sampleItr * ::sqrt(squareScales[test]) + locations[test]); + *sampleItr = std::exp(*sampleItr * std::sqrt(squareScales[test]) + locations[test]); } // Check the data percentiles. CLogTDistribution logt(degreesFreedom[test], locations[test], - ::sqrt(squareScales[test])); + std::sqrt(squareScales[test])); std::sort(samples.begin(), samples.end()); for (unsigned int p = 1; p < 100; ++p) @@ -197,7 +197,7 @@ void CLogTDistributionTest::testQuantile(void) { CLogTDistribution logt(degreesFreedom[test], locations[test], - ::sqrt(squareScales[test])); + std::sqrt(squareScales[test])); for (unsigned int p = 1; p < 100; ++p) { diff --git a/lib/maths/unittest/CMathsFuncsTest.cc b/lib/maths/unittest/CMathsFuncsTest.cc index f0fbe936aa..5a8ec6b48c 100644 --- a/lib/maths/unittest/CMathsFuncsTest.cc +++ b/lib/maths/unittest/CMathsFuncsTest.cc @@ -17,11 +17,10 @@ #include +#include #include #include -#include - using namespace ml; namespace @@ -53,8 +52,8 @@ void CMathsFuncsTest::testIsInf(void) CPPUNIT_ASSERT(!maths::CMathsFuncs::isInf(-std::numeric_limits::min())); CPPUNIT_ASSERT(maths::CMathsFuncs::isInf(1.0 / zero())); CPPUNIT_ASSERT(maths::CMathsFuncs::isInf(2.0 / zero())); - CPPUNIT_ASSERT(maths::CMathsFuncs::isInf(::log(zero()))); - CPPUNIT_ASSERT(maths::CMathsFuncs::isInf(::exp(1.0 / zero()))); + CPPUNIT_ASSERT(maths::CMathsFuncs::isInf(std::log(zero()))); + CPPUNIT_ASSERT(maths::CMathsFuncs::isInf(std::exp(1.0 / zero()))); } void CMathsFuncsTest::testIsFinite(void) @@ -70,7 +69,7 @@ void CMathsFuncsTest::testIsFinite(void) CPPUNIT_ASSERT(maths::CMathsFuncs::isFinite(-std::numeric_limits::min())); CPPUNIT_ASSERT(!maths::CMathsFuncs::isFinite(1.0 / zero())); CPPUNIT_ASSERT(!maths::CMathsFuncs::isFinite(2.0 / zero())); - CPPUNIT_ASSERT(!maths::CMathsFuncs::isFinite(::log(zero()))); + CPPUNIT_ASSERT(!maths::CMathsFuncs::isFinite(std::log(zero()))); CPPUNIT_ASSERT(!maths::CMathsFuncs::isFinite(zero() / zero())); CPPUNIT_ASSERT(!maths::CMathsFuncs::isFinite(1.0 / zero() - 2.0 / zero())); diff --git a/lib/maths/unittest/CMixtureDistributionTest.cc b/lib/maths/unittest/CMixtureDistributionTest.cc index 24e6a276cb..9c9b2451e1 100644 --- a/lib/maths/unittest/CMixtureDistributionTest.cc +++ b/lib/maths/unittest/CMixtureDistributionTest.cc @@ -424,7 +424,7 @@ void CMixtureDistributionTest::testQuantile(void) { double q = static_cast(p) / 100.0; double f = cdf(mixture, quantile(mixture, q)); - LOG_DEBUG("Error = " << ::fabs(q - f)); + LOG_DEBUG("Error = " << std::fabs(q - f)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q, f, 1e-10); } } diff --git a/lib/maths/unittest/CMultimodalPriorTest.cc b/lib/maths/unittest/CMultimodalPriorTest.cc index 0f7bce35ea..7117deae7b 100644 --- a/lib/maths/unittest/CMultimodalPriorTest.cc +++ b/lib/maths/unittest/CMultimodalPriorTest.cc @@ -173,7 +173,7 @@ void probabilityOfLessLikelySample(const maths::CMixtureDistribution &mixture // For a discussion of the deviation see the paper: // "Anomaly Detection in Application Performance Monitoring Data" - deviation = ::sqrt(probability * (1.0 - probability) / NUMBER_SAMPLES); + deviation = std::sqrt(probability * (1.0 - probability) / NUMBER_SAMPLES); } } @@ -323,7 +323,7 @@ void CMultimodalPriorTest::testSingleMode(void) const double variance = 2.0; TDoubleVec samples; - rng.generateNormalSamples(mean, ::sqrt(variance), 1000, samples); + rng.generateNormalSamples(mean, std::sqrt(variance), 1000, samples); for (std::size_t i = 0u; i < samples.size(); ++i) { @@ -337,7 +337,7 @@ void CMultimodalPriorTest::testSingleMode(void) TMeanAccumulator L12; TMeanAccumulator differentialEntropy; - boost::math::normal_distribution<> f(mean, ::sqrt(variance)); + boost::math::normal_distribution<> f(mean, std::sqrt(variance)); for (std::size_t i = 0u; i < samples.size(); ++i) { double fx = boost::math::pdf(f, samples[i]); @@ -345,12 +345,12 @@ void CMultimodalPriorTest::testSingleMode(void) double l1; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter1.jointLogMarginalLikelihood(sample, l1)); - L1G.add(::log(fx) - l1); + L1G.add(std::log(fx) - l1); double l2; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter2.jointLogMarginalLikelihood(sample, l2)); L12.add(l2 - l1); - differentialEntropy.add(-::log(fx)); + differentialEntropy.add(-std::log(fx)); } LOG_DEBUG("L1G = " << maths::CBasicStatistics::mean(L1G) @@ -384,7 +384,7 @@ void CMultimodalPriorTest::testSingleMode(void) TMeanAccumulator L12; TMeanAccumulator differentialEntropy; - boost::math::lognormal_distribution<> f(location, ::sqrt(squareScale)); + boost::math::lognormal_distribution<> f(location, std::sqrt(squareScale)); for (std::size_t i = 0u; i < samples.size(); ++i) { @@ -393,12 +393,12 @@ void CMultimodalPriorTest::testSingleMode(void) double l1; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter1.jointLogMarginalLikelihood(sample, l1)); - L1G.add(::log(fx) - l1); + L1G.add(std::log(fx) - l1); double l2; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter2.jointLogMarginalLikelihood(sample, l2)); L12.add(l2 - l1); - differentialEntropy.add(-::log(fx)); + differentialEntropy.add(-std::log(fx)); } LOG_DEBUG("L1G = " << maths::CBasicStatistics::mean(L1G) @@ -441,12 +441,12 @@ void CMultimodalPriorTest::testSingleMode(void) double l1; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter1.jointLogMarginalLikelihood(sample, l1)); - L1G.add(::log(fx) - l1); + L1G.add(std::log(fx) - l1); double l2; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter2.jointLogMarginalLikelihood(sample, l2)); L12.add(l2 - l1); - differentialEntropy.add(-::log(fx)); + differentialEntropy.add(-std::log(fx)); } LOG_DEBUG("L1G = " << maths::CBasicStatistics::mean(L1G) @@ -501,8 +501,8 @@ void CMultimodalPriorTest::testMultipleModes(void) double w1 = n1 / static_cast(n1 + n2); double w2 = n2 / static_cast(n1 + n2); - boost::math::normal_distribution<> mode1Distribution(mean1, ::sqrt(variance1)); - boost::math::normal_distribution<> mode2Distribution(mean2, ::sqrt(variance2)); + boost::math::normal_distribution<> mode1Distribution(mean1, std::sqrt(variance1)); + boost::math::normal_distribution<> mode2Distribution(mean2, std::sqrt(variance2)); double loss = 0.0; TMeanAccumulator differentialEntropy_; @@ -510,7 +510,7 @@ void CMultimodalPriorTest::testMultipleModes(void) { double fx = w1 * boost::math::pdf(mode1Distribution, samples[j]) + w2 * boost::math::pdf(mode2Distribution, samples[j]); - differentialEntropy_.add(-::log(fx)); + differentialEntropy_.add(-std::log(fx)); } double differentialEntropy = maths::CBasicStatistics::mean(differentialEntropy_); @@ -543,7 +543,7 @@ void CMultimodalPriorTest::testMultipleModes(void) double l1; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter1.jointLogMarginalLikelihood(sample, l1)); - loss1G.add(::log(fx) - l1); + loss1G.add(std::log(fx) - l1); double l2; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter2.jointLogMarginalLikelihood(sample, l2)); @@ -596,9 +596,9 @@ void CMultimodalPriorTest::testMultipleModes(void) double w1 = n1 / static_cast(n1 + n2 + n3); double w2 = n2 / static_cast(n1 + n2 + n3); double w3 = n3 / static_cast(n1 + n2 + n3); - boost::math::lognormal_distribution<> mode1Distribution(location1, ::sqrt(squareScale1)); - boost::math::lognormal_distribution<> mode2Distribution(location2, ::sqrt(squareScale2)); - boost::math::lognormal_distribution<> mode3Distribution(location3, ::sqrt(squareScale3)); + boost::math::lognormal_distribution<> mode1Distribution(location1, std::sqrt(squareScale1)); + boost::math::lognormal_distribution<> mode2Distribution(location2, std::sqrt(squareScale2)); + boost::math::lognormal_distribution<> mode3Distribution(location3, std::sqrt(squareScale3)); double loss = 0.0; TMeanAccumulator differentialEntropy_; @@ -607,7 +607,7 @@ void CMultimodalPriorTest::testMultipleModes(void) double fx = w1 * boost::math::pdf(mode1Distribution, samples[j]) + w2 * boost::math::pdf(mode2Distribution, samples[j]) + w3 * boost::math::pdf(mode3Distribution, samples[j]); - differentialEntropy_.add(-::log(fx)); + differentialEntropy_.add(-std::log(fx)); } double differentialEntropy = maths::CBasicStatistics::mean(differentialEntropy_); @@ -641,7 +641,7 @@ void CMultimodalPriorTest::testMultipleModes(void) double l1; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter1.jointLogMarginalLikelihood(sample, l1)); - loss1G.add(::log(fx) - l1); + loss1G.add(std::log(fx) - l1); double l2; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter2.jointLogMarginalLikelihood(sample, l2)); @@ -694,8 +694,8 @@ void CMultimodalPriorTest::testMultipleModes(void) double w1 = n1 / static_cast(n1 + n2 + n3); double w2 = n2 / static_cast(n1 + n2 + n3); double w3 = n3 / static_cast(n1 + n2 + n3); - boost::math::normal_distribution<> mode1Distribution(mean1, ::sqrt(variance1)); - boost::math::lognormal_distribution<> mode2Distribution(location2, ::sqrt(squareScale2)); + boost::math::normal_distribution<> mode1Distribution(mean1, std::sqrt(variance1)); + boost::math::lognormal_distribution<> mode2Distribution(location2, std::sqrt(squareScale2)); boost::math::gamma_distribution<> mode3Distribution(shape3, scale3); double loss = 0.0; @@ -705,7 +705,7 @@ void CMultimodalPriorTest::testMultipleModes(void) double fx = w1 * boost::math::pdf(mode1Distribution, samples[j]) + w2 * boost::math::pdf(mode2Distribution, samples[j]) + w3 * boost::math::pdf(mode3Distribution, samples[j]); - differentialEntropy_.add(-::log(fx)); + differentialEntropy_.add(-std::log(fx)); } double differentialEntropy = maths::CBasicStatistics::mean(differentialEntropy_); @@ -739,7 +739,7 @@ void CMultimodalPriorTest::testMultipleModes(void) double l1; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter1.jointLogMarginalLikelihood(sample, l1)); - loss1G.add(::log(fx) - l1); + loss1G.add(std::log(fx) - l1); double l2; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter2.jointLogMarginalLikelihood(sample, l2)); @@ -878,21 +878,21 @@ void CMultimodalPriorTest::testMarginalLikelihood(void) double logLikelihood = 0.0; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter.jointLogMarginalLikelihood(sample, logLikelihood)); - double pdf = ::exp(logLikelihood); + double pdf = std::exp(logLikelihood); double lowerBound = 0.0, upperBound = 0.0; sample[0] -= eps; CPPUNIT_ASSERT(filter.minusLogJointCdf(sample, lowerBound, upperBound)); CPPUNIT_ASSERT_DOUBLES_EQUAL(lowerBound, upperBound, 1e-3); double minusLogCdf = (lowerBound + upperBound) / 2.0; - double cdfAtMinusEps = ::exp(-minusLogCdf); + double cdfAtMinusEps = std::exp(-minusLogCdf); CPPUNIT_ASSERT(minusLogCdf >= 0.0); sample[0] += 2.0 * eps; CPPUNIT_ASSERT(filter.minusLogJointCdf(sample, lowerBound, upperBound)); CPPUNIT_ASSERT_DOUBLES_EQUAL(lowerBound, upperBound, 1e-3); minusLogCdf = (lowerBound + upperBound) / 2.0; - double cdfAtPlusEps = ::exp(-minusLogCdf); + double cdfAtPlusEps = std::exp(-minusLogCdf); CPPUNIT_ASSERT(minusLogCdf >= 0.0); double dcdfdx = (cdfAtPlusEps - cdfAtMinusEps) / 2.0 / eps; @@ -1043,15 +1043,15 @@ void CMultimodalPriorTest::testMarginalLikelihoodMode(void) TDouble1Vec(1, modePlusEps), weights, fModePlusEps); - fMode = ::exp(fMode); - fModeMinusEps = ::exp(fModeMinusEps); - fModePlusEps = ::exp(fModePlusEps); + fMode = std::exp(fMode); + fModeMinusEps = std::exp(fModeMinusEps); + fModePlusEps = std::exp(fModePlusEps); double gradient = (fModePlusEps - fModeMinusEps) / 2.0 / eps; LOG_DEBUG("f(mode) = " << fMode << ", f(mode-eps) = " << fModeMinusEps << ", f(mode + eps) = " << fModePlusEps); LOG_DEBUG("gradient = " << gradient); - CPPUNIT_ASSERT(::fabs(gradient) < 0.05); + CPPUNIT_ASSERT(std::fabs(gradient) < 0.05); CPPUNIT_ASSERT(fMode > 0.999 * fModeMinusEps); CPPUNIT_ASSERT(fMode > 0.999 * fModePlusEps); TDoubleVec trials; @@ -1065,7 +1065,7 @@ void CMultimodalPriorTest::testMarginalLikelihoodMode(void) TDouble1Vec(1, trials[j]), weights, fTrial); - fTrial = ::exp(fTrial); + fTrial = std::exp(fTrial); if (fTrial > fMode) { LOG_DEBUG("f(" << trials[j] << ") = " << fTrial << " > " << fMode); @@ -1147,8 +1147,8 @@ void CMultimodalPriorTest::testMarginalLikelihoodConfidenceInterval(void) << ", interval = " << core::CContainerPrinter::print(interval)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q1, interval.first, 0.1); CPPUNIT_ASSERT_DOUBLES_EQUAL(q2, interval.second, 0.05); - error.add(::fabs(interval.first - q1)); - error.add(::fabs(interval.second - q2)); + error.add(std::fabs(interval.first - q1)); + error.add(std::fabs(interval.second - q2)); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 5e-3); @@ -1172,8 +1172,8 @@ void CMultimodalPriorTest::testMarginalLikelihoodConfidenceInterval(void) << ", interval = " << core::CContainerPrinter::print(interval)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q1, interval.first, std::max(0.1 * q1, 0.15)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q2, interval.second, 0.1 * q2); - error.add(::fabs(interval.first - q1) / q1); - error.add(::fabs(interval.second - q2) / q2); + error.add(std::fabs(interval.first - q1) / q1); + error.add(std::fabs(interval.second - q2) / q2); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 0.05); @@ -1294,10 +1294,10 @@ void CMultimodalPriorTest::testSampleMarginalLikelihood(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(filter.marginalLikelihoodVariance(), maths::CBasicStatistics::variance(sampledMoments), 0.2 * filter.marginalLikelihoodVariance()); - meanMeanError.add( ::fabs( filter.marginalLikelihoodMean() + meanMeanError.add( std::fabs( filter.marginalLikelihoodMean() - maths::CBasicStatistics::mean(sampledMoments)) / filter.marginalLikelihoodMean()); - meanVarError.add(::fabs( filter.marginalLikelihoodVariance() + meanVarError.add(std::fabs( filter.marginalLikelihoodVariance() - maths::CBasicStatistics::variance(sampledMoments)) / filter.marginalLikelihoodVariance()); } @@ -1392,8 +1392,8 @@ void CMultimodalPriorTest::testCdf(void) double fComplement = (lowerBound + upperBound) / 2.0; LOG_DEBUG("log(F(x)) = " << -f << ", log(1 - F(x)) = " << fComplement); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(std::numeric_limits::min()), -f, 1e-8); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, ::exp(-fComplement), 1e-8); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(std::numeric_limits::min()), -f, 1e-8); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, std::exp(-fComplement), 1e-8); for (std::size_t j = 1u; j < 1000; ++j) { @@ -1406,7 +1406,7 @@ void CMultimodalPriorTest::testCdf(void) LOG_DEBUG("log(F(x)) = " << (f == 0.0 ? f : -f) << ", log(1 - F(x)) = " << (fComplement == 0.0 ? fComplement : -fComplement)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, ::exp(-f) + ::exp(-fComplement), 1e-8); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, std::exp(-f) + std::exp(-fComplement), 1e-8); } } @@ -1530,9 +1530,9 @@ void CMultimodalPriorTest::testProbabilityOfLessLikelySamples(void) TDoubleVec mixtureWeights(boost::begin(weights), boost::end(weights)); TLogNormalVec modes; - modes.push_back(boost::math::lognormal_distribution<>(locations[0], ::sqrt(squareScales[0]))); - modes.push_back(boost::math::lognormal_distribution<>(locations[1], ::sqrt(squareScales[1]))); - modes.push_back(boost::math::lognormal_distribution<>(locations[2], ::sqrt(squareScales[2]))); + modes.push_back(boost::math::lognormal_distribution<>(locations[0], std::sqrt(squareScales[0]))); + modes.push_back(boost::math::lognormal_distribution<>(locations[1], std::sqrt(squareScales[1]))); + modes.push_back(boost::math::lognormal_distribution<>(locations[2], std::sqrt(squareScales[2]))); maths::CMixtureDistribution> mixture(mixtureWeights, modes); CMultimodalPrior filter(makePrior()); @@ -1882,15 +1882,15 @@ void CMultimodalPriorTest::testSeasonalVarianceScale(void) TDouble1Vec xPlusEps(1, points[j] + 1e-3); double lb, ub; filter.minusLogJointCdf(weightStyle, xPlusEps, weights, lb, ub); - double FxPlusEps = ::exp(-(lb + ub) / 2.0); + double FxPlusEps = std::exp(-(lb + ub) / 2.0); filter.minusLogJointCdf(weightStyle, xMinusEps, weights, lb, ub); - double FxMinusEps = ::exp(-(lb + ub) / 2.0); + double FxMinusEps = std::exp(-(lb + ub) / 2.0); LOG_DEBUG("x = " << points[j] << ", log(f(x)) = " << fx - << ", log(dF/dx)) = " << ::log((FxPlusEps - FxMinusEps) / 2e-3)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(fx, ::log((FxPlusEps - FxMinusEps) / 2e-3), 0.05 * ::fabs(fx)); + << ", log(dF/dx)) = " << std::log((FxPlusEps - FxMinusEps) / 2e-3)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(fx, std::log((FxPlusEps - FxMinusEps) / 2e-3), 0.05 * std::fabs(fx)); - sample[0] = m + (points[j] - m) / ::sqrt(vs); + sample[0] = m + (points[j] - m) / std::sqrt(vs); weights[0][0] = 1.0; double expectedLowerBound; double expectedUpperBound; @@ -1921,12 +1921,12 @@ void CMultimodalPriorTest::testSeasonalVarianceScale(void) if ((expectedLowerBound + expectedUpperBound) < 0.02) { - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(expectedLowerBound), - ::log(lowerBound), - 0.1 * ::fabs(::log(expectedLowerBound))); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(expectedUpperBound), - ::log(upperBound), - 0.1 * ::fabs(::log(expectedUpperBound))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(expectedLowerBound), + std::log(lowerBound), + 0.1 * std::fabs(std::log(expectedLowerBound))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(expectedUpperBound), + std::log(upperBound), + 0.1 * std::fabs(std::log(expectedUpperBound))); } else { diff --git a/lib/maths/unittest/CMultinomialConjugateTest.cc b/lib/maths/unittest/CMultinomialConjugateTest.cc index 3f0f859e7d..f3e8a15537 100644 --- a/lib/maths/unittest/CMultinomialConjugateTest.cc +++ b/lib/maths/unittest/CMultinomialConjugateTest.cc @@ -216,7 +216,7 @@ void CMultinomialConjugateTest::testProbabilityEstimation(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(intervals[k], 100.0 - testIntervals[j], std::min(5.0, 0.4 * (100.0 - testIntervals[j]))); - meanError += ::fabs(intervals[k] - (100.0 - testIntervals[j])); + meanError += std::fabs(intervals[k] - (100.0 - testIntervals[j])); } else { @@ -283,9 +283,9 @@ void CMultinomialConjugateTest::testMarginalLikelihood(void) LOG_DEBUG("sample = " << samples[j] << ", expected likelihood = " << p - << ", likelihood = " << ::exp(logp)); + << ", likelihood = " << std::exp(logp)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(p, ::exp(logp), 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(p, std::exp(logp), 1e-12); } } } @@ -350,7 +350,7 @@ void CMultinomialConjugateTest::testMarginalLikelihood(void) double p; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter.jointLogMarginalLikelihood(o2[i], p)); - p = ::exp(p); + p = std::exp(p); p2.push_back(p); LOG_DEBUG("categories = " << core::CContainerPrinter::print(o2[i]) << ", p = " << p); @@ -393,7 +393,7 @@ void CMultinomialConjugateTest::testMarginalLikelihood(void) double p; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter.jointLogMarginalLikelihood(o3[i], p)); - p = ::exp(p); + p = std::exp(p); p3.push_back(p); LOG_DEBUG("categories = " << core::CContainerPrinter::print(o3[i]) << ", p = " << p); @@ -918,7 +918,7 @@ void CMultinomialConjugateTest::testProbabilityOfLessLikelySamples(void) for (std::size_t i = 0u; i < lowerBounds.size(); ++i) { CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedProbabilities[i], lowerBounds[i], 0.1); - totalError += ::fabs(lowerBounds[i] - expectedProbabilities[i]); + totalError += std::fabs(lowerBounds[i] - expectedProbabilities[i]); } LOG_DEBUG("totalError = " << totalError); CPPUNIT_ASSERT(totalError < 0.7); diff --git a/lib/maths/unittest/CMultivariateConstantPriorTest.cc b/lib/maths/unittest/CMultivariateConstantPriorTest.cc index 328bcdc752..54bd569d9f 100644 --- a/lib/maths/unittest/CMultivariateConstantPriorTest.cc +++ b/lib/maths/unittest/CMultivariateConstantPriorTest.cc @@ -126,7 +126,7 @@ void CMultivariateConstantPriorTest::testMarginalLikelihood(void) TDouble10Vec1Vec(1, TDouble10Vec(boost::begin(constant), boost::end(constant))), singleUnitWeight(2), likelihood)); - CPPUNIT_ASSERT_EQUAL(::log(boost::numeric::bounds::highest()), likelihood); + CPPUNIT_ASSERT_EQUAL(std::log(boost::numeric::bounds::highest()), likelihood); CPPUNIT_ASSERT_EQUAL(maths_t::E_FpOverflowed, filter.jointLogMarginalLikelihood(COUNT_WEIGHT, diff --git a/lib/maths/unittest/CMultivariateMultimodalPriorTest.cc b/lib/maths/unittest/CMultivariateMultimodalPriorTest.cc index 330e31d407..9e8e8d20c1 100644 --- a/lib/maths/unittest/CMultivariateMultimodalPriorTest.cc +++ b/lib/maths/unittest/CMultivariateMultimodalPriorTest.cc @@ -122,9 +122,9 @@ double logLikelihood(const double w[N], TMatrix2 covariance(covariances[i], covariances[i] + 3); double ll; maths::gaussianLogLikelihood(covariance, TVector2(x) - mean, ll); - lx += w[i] * ::exp(ll); + lx += w[i] * std::exp(ll); } - return ::log(lx); + return std::log(lx); } double logLikelihood(const TDoubleVec &w, @@ -139,9 +139,9 @@ double logLikelihood(const TDoubleVec &w, maths::gaussianLogLikelihood(TMatrix2(covariances[i]), TVector2(x) - TVector2(means[i]), ll); - lx += w[i] * ::exp(ll); + lx += w[i] * std::exp(ll); } - return ::log(lx); + return std::log(lx); } void empiricalProbabilityOfLessLikelySamples(const TDoubleVec &w, @@ -696,15 +696,15 @@ void CMultivariateMultimodalPriorTest::testMarginalLikelihood(void) double intervals[][2] = { - { means[i](0) - 3.0 * ::sqrt(trace), means[i](1) - 3.0 * ::sqrt(trace) }, - { means[i](0) - 3.0 * ::sqrt(trace), means[i](1) - 1.0 * ::sqrt(trace) }, - { means[i](0) - 3.0 * ::sqrt(trace), means[i](1) + 1.0 * ::sqrt(trace) }, - { means[i](0) - 1.0 * ::sqrt(trace), means[i](1) - 3.0 * ::sqrt(trace) }, - { means[i](0) - 1.0 * ::sqrt(trace), means[i](1) - 1.0 * ::sqrt(trace) }, - { means[i](0) - 1.0 * ::sqrt(trace), means[i](1) + 1.0 * ::sqrt(trace) }, - { means[i](0) + 1.0 * ::sqrt(trace), means[i](1) - 3.0 * ::sqrt(trace) }, - { means[i](0) + 1.0 * ::sqrt(trace), means[i](1) - 1.0 * ::sqrt(trace) }, - { means[i](0) + 1.0 * ::sqrt(trace), means[i](1) + 1.0 * ::sqrt(trace) } + { means[i](0) - 3.0 * std::sqrt(trace), means[i](1) - 3.0 * std::sqrt(trace) }, + { means[i](0) - 3.0 * std::sqrt(trace), means[i](1) - 1.0 * std::sqrt(trace) }, + { means[i](0) - 3.0 * std::sqrt(trace), means[i](1) + 1.0 * std::sqrt(trace) }, + { means[i](0) - 1.0 * std::sqrt(trace), means[i](1) - 3.0 * std::sqrt(trace) }, + { means[i](0) - 1.0 * std::sqrt(trace), means[i](1) - 1.0 * std::sqrt(trace) }, + { means[i](0) - 1.0 * std::sqrt(trace), means[i](1) + 1.0 * std::sqrt(trace) }, + { means[i](0) + 1.0 * std::sqrt(trace), means[i](1) - 3.0 * std::sqrt(trace) }, + { means[i](0) + 1.0 * std::sqrt(trace), means[i](1) - 1.0 * std::sqrt(trace) }, + { means[i](0) + 1.0 * std::sqrt(trace), means[i](1) + 1.0 * std::sqrt(trace) } }; CUnitKernel<2> likelihoodKernel(filter); CMeanKernel<2> meanKernel(filter); @@ -714,8 +714,8 @@ void CMultivariateMultimodalPriorTest::testMarginalLikelihood(void) { TDoubleVec a(boost::begin(intervals[j]), boost::end(intervals[j])); TDoubleVec b(a); - b[0] += 2.0 * ::sqrt(trace); - b[1] += 2.0 * ::sqrt(trace); + b[0] += 2.0 * std::sqrt(trace); + b[1] += 2.0 * std::sqrt(trace); double zj; maths::CIntegration::sparseGaussLegendre #include -#include - using namespace ml; using namespace handy_typedefs; @@ -299,14 +298,14 @@ void CMultivariateOneOfNPriorTest::testPropagation(void) double numberSamples = filter.numberSamples(); TDouble10Vec mean = filter.marginalLikelihoodMean(); TDouble10Vec10Vec covariance = filter.marginalLikelihoodCovariance(); - double logWeightRatio = ::fabs(filter.logWeights()[0] - filter.logWeights()[1]); + double logWeightRatio = std::fabs(filter.logWeights()[0] - filter.logWeights()[1]); filter.propagateForwardsByTime(40.0); double propagatedNumberSamples = filter.numberSamples(); TDouble10Vec propagatedMean = filter.marginalLikelihoodMean(); TDouble10Vec10Vec propagatedCovariance = filter.marginalLikelihoodCovariance(); - double propagatedLogWeightRatio = ::fabs(filter.logWeights()[0] - filter.logWeights()[1]); + double propagatedLogWeightRatio = std::fabs(filter.logWeights()[0] - filter.logWeights()[1]); LOG_DEBUG("numberSamples = " << numberSamples); LOG_DEBUG("propagatedNumberSamples = " << propagatedNumberSamples); @@ -547,15 +546,15 @@ void CMultivariateOneOfNPriorTest::testMarginalLikelihood(void) } double intervals[][2] = { - { m[0] - 3.0 * ::sqrt(trace), m[1] - 3.0 * ::sqrt(trace) }, - { m[0] - 3.0 * ::sqrt(trace), m[1] - 1.0 * ::sqrt(trace) }, - { m[0] - 3.0 * ::sqrt(trace), m[1] + 1.0 * ::sqrt(trace) }, - { m[0] - 1.0 * ::sqrt(trace), m[1] - 3.0 * ::sqrt(trace) }, - { m[0] - 1.0 * ::sqrt(trace), m[1] - 1.0 * ::sqrt(trace) }, - { m[0] - 1.0 * ::sqrt(trace), m[1] + 1.0 * ::sqrt(trace) }, - { m[0] + 1.0 * ::sqrt(trace), m[1] - 3.0 * ::sqrt(trace) }, - { m[0] + 1.0 * ::sqrt(trace), m[1] - 1.0 * ::sqrt(trace) }, - { m[0] + 1.0 * ::sqrt(trace), m[1] + 1.0 * ::sqrt(trace) } + { m[0] - 3.0 * std::sqrt(trace), m[1] - 3.0 * std::sqrt(trace) }, + { m[0] - 3.0 * std::sqrt(trace), m[1] - 1.0 * std::sqrt(trace) }, + { m[0] - 3.0 * std::sqrt(trace), m[1] + 1.0 * std::sqrt(trace) }, + { m[0] - 1.0 * std::sqrt(trace), m[1] - 3.0 * std::sqrt(trace) }, + { m[0] - 1.0 * std::sqrt(trace), m[1] - 1.0 * std::sqrt(trace) }, + { m[0] - 1.0 * std::sqrt(trace), m[1] + 1.0 * std::sqrt(trace) }, + { m[0] + 1.0 * std::sqrt(trace), m[1] - 3.0 * std::sqrt(trace) }, + { m[0] + 1.0 * std::sqrt(trace), m[1] - 1.0 * std::sqrt(trace) }, + { m[0] + 1.0 * std::sqrt(trace), m[1] + 1.0 * std::sqrt(trace) } }; TVector2 expectedMean(m.begin(), m.end()); @@ -573,8 +572,8 @@ void CMultivariateOneOfNPriorTest::testMarginalLikelihood(void) { TDoubleVec a(boost::begin(intervals[j]), boost::end(intervals[j])); TDoubleVec b(a); - b[0] += 2.0 * ::sqrt(trace); - b[1] += 2.0 * ::sqrt(trace); + b[0] += 2.0 * std::sqrt(trace); + b[1] += 2.0 * std::sqrt(trace); double zj; maths::CIntegration::sparseGaussLegendre likelihoodKernel(filter); CMeanKernel<2> meanKernel(filter); @@ -685,8 +684,8 @@ void CMultivariateOneOfNPriorTest::testMarginalLikelihood(void) { TDoubleVec a(boost::begin(intervals[j]), boost::end(intervals[j])); TDoubleVec b(a); - b[0] += 2.0 * ::sqrt(trace); - b[1] += 2.0 * ::sqrt(trace); + b[0] += 2.0 * std::sqrt(trace); + b[1] += 2.0 * std::sqrt(trace); double zj; maths::CIntegration::sparseGaussLegendre(n1)) / static_cast(n1) < 0.33); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::mean(twoSplit[1]) - mean2) < 0.4); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::variance(twoSplit[1]) - var2) < 0.63); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::count(twoSplit[1]) + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::mean(twoSplit[1]) - mean2) < 0.4); + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::variance(twoSplit[1]) - var2) < 0.63); + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::count(twoSplit[1]) - static_cast(n2)) / static_cast(n2) < 0.11); } @@ -383,22 +383,22 @@ void CNaturalBreaksClassifierTest::testCategories(void) LOG_DEBUG("split 1 = " << CBasicStatistics::print(twoSplit[0]) << ", split 2 = " << CBasicStatistics::print(twoSplit[1])); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::mean(twoSplit[0]) - mean1) < 0.7); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::variance(twoSplit[0]) - var1) < 0.4); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::count(twoSplit[0]) + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::mean(twoSplit[0]) - mean1) < 0.7); + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::variance(twoSplit[0]) - var1) < 0.4); + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::count(twoSplit[0]) - static_cast(n1)) / static_cast(n1) < 0.7); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::mean(twoSplit[1]) - mean2) < 0.6); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::variance(twoSplit[1]) - var2) < 1.0); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::count(twoSplit[1]) + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::mean(twoSplit[1]) - mean2) < 0.6); + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::variance(twoSplit[1]) - var2) < 1.0); + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::count(twoSplit[1]) - static_cast(n2)) / static_cast(n2) < 0.3); - totalMeanError1 += ::fabs(CBasicStatistics::mean(twoSplit[0]) - mean1); - totalVarError1 += ::fabs(CBasicStatistics::variance(twoSplit[0]) - var1); - totalCountError1 += ::fabs(CBasicStatistics::count(twoSplit[0]) + totalMeanError1 += std::fabs(CBasicStatistics::mean(twoSplit[0]) - mean1); + totalVarError1 += std::fabs(CBasicStatistics::variance(twoSplit[0]) - var1); + totalCountError1 += std::fabs(CBasicStatistics::count(twoSplit[0]) - static_cast(n1)) / static_cast(n1); - totalMeanError2 += ::fabs(CBasicStatistics::mean(twoSplit[1]) - mean2); - totalVarError2 += ::fabs(CBasicStatistics::variance(twoSplit[1]) - var2); - totalCountError2 += ::fabs(CBasicStatistics::count(twoSplit[1]) + totalMeanError2 += std::fabs(CBasicStatistics::mean(twoSplit[1]) - mean2); + totalVarError2 += std::fabs(CBasicStatistics::variance(twoSplit[1]) - var2); + totalCountError2 += std::fabs(CBasicStatistics::count(twoSplit[1]) - static_cast(n2)) / static_cast(n2); } @@ -479,22 +479,22 @@ void CNaturalBreaksClassifierTest::testCategories(void) << ", split 2 = " << CBasicStatistics::print(twoSplit[1]) << ", split 3 = " << CBasicStatistics::print(twoSplit[2])); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::mean(twoSplit[0]) - mean1) < 0.15); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::variance(twoSplit[0]) - var1) < 0.4); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::count(twoSplit[0]) + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::mean(twoSplit[0]) - mean1) < 0.15); + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::variance(twoSplit[0]) - var1) < 0.4); + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::count(twoSplit[0]) - static_cast(n1)) / static_cast(n1) < 0.05); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::mean(twoSplit[1]) - mean2) < 0.5); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::variance(twoSplit[1]) - var2) < 2.5); - CPPUNIT_ASSERT(::fabs(CBasicStatistics::count(twoSplit[1]) + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::mean(twoSplit[1]) - mean2) < 0.5); + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::variance(twoSplit[1]) - var2) < 2.5); + CPPUNIT_ASSERT(std::fabs(CBasicStatistics::count(twoSplit[1]) - static_cast(n2)) / static_cast(n2) < 0.15); - totalMeanError1 += ::fabs(CBasicStatistics::mean(twoSplit[0]) - mean1); - totalVarError1 += ::fabs(CBasicStatistics::variance(twoSplit[0]) - var1); - totalCountError1 += ::fabs(CBasicStatistics::count(twoSplit[0]) + totalMeanError1 += std::fabs(CBasicStatistics::mean(twoSplit[0]) - mean1); + totalVarError1 += std::fabs(CBasicStatistics::variance(twoSplit[0]) - var1); + totalCountError1 += std::fabs(CBasicStatistics::count(twoSplit[0]) - static_cast(n1)) / static_cast(n1); - totalMeanError2 += ::fabs(CBasicStatistics::mean(twoSplit[1]) - mean2); - totalVarError2 += ::fabs(CBasicStatistics::variance(twoSplit[1]) - var2); - totalCountError2 += ::fabs(CBasicStatistics::count(twoSplit[1]) + totalMeanError2 += std::fabs(CBasicStatistics::mean(twoSplit[1]) - mean2); + totalVarError2 += std::fabs(CBasicStatistics::variance(twoSplit[1]) - var2); + totalCountError2 += std::fabs(CBasicStatistics::count(twoSplit[1]) - static_cast(n2)) / static_cast(n2); } @@ -619,7 +619,7 @@ void CNaturalBreaksClassifierTest::testSample(void) double error = 0.0; for (std::size_t i = 0u; i < expectedSampled.size(); ++i) { - error += ::fabs(expectedSampled[i] - sampled[i]); + error += std::fabs(expectedSampled[i] - sampled[i]); } CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, error, 2e-6); diff --git a/lib/maths/unittest/CNormalMeanPrecConjugateTest.cc b/lib/maths/unittest/CNormalMeanPrecConjugateTest.cc index 8faf155824..6731ad5e8c 100644 --- a/lib/maths/unittest/CNormalMeanPrecConjugateTest.cc +++ b/lib/maths/unittest/CNormalMeanPrecConjugateTest.cc @@ -35,12 +35,11 @@ #include #include +#include #include #include #include -#include - using namespace ml; using namespace handy_typedefs; @@ -423,7 +422,7 @@ void CNormalMeanPrecConjugateTest::testMarginalLikelihood(void) for (std::size_t k = 0; k < boost::size(deltas); ++k) { - double x = mean + deltas[k] * ::sqrt(variance); + double x = mean + deltas[k] * std::sqrt(variance); TDouble1Vec sample(1, x); LOG_DEBUG("number = " << numberSamples[i] @@ -432,21 +431,21 @@ void CNormalMeanPrecConjugateTest::testMarginalLikelihood(void) double logLikelihood = 0.0; CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter.jointLogMarginalLikelihood(sample, logLikelihood)); - double pdf = ::exp(logLikelihood); + double pdf = std::exp(logLikelihood); double lowerBound = 0.0, upperBound = 0.0; sample[0] -= eps; CPPUNIT_ASSERT(filter.minusLogJointCdf(sample, lowerBound, upperBound)); CPPUNIT_ASSERT_EQUAL(lowerBound, upperBound); double minusLogCdf = (lowerBound + upperBound) / 2.0; - double cdfAtMinusEps = ::exp(-minusLogCdf); + double cdfAtMinusEps = std::exp(-minusLogCdf); CPPUNIT_ASSERT(minusLogCdf >= 0.0); sample[0] += 2.0 * eps; CPPUNIT_ASSERT(filter.minusLogJointCdf(sample, lowerBound, upperBound)); CPPUNIT_ASSERT_EQUAL(lowerBound, upperBound); minusLogCdf = (lowerBound + upperBound) / 2.0; - double cdfAtPlusEps = ::exp(-minusLogCdf); + double cdfAtPlusEps = std::exp(-minusLogCdf); CPPUNIT_ASSERT(minusLogCdf >= 0.0); double dcdfdx = (cdfAtPlusEps - cdfAtMinusEps) / 2.0 / eps; @@ -464,7 +463,7 @@ void CNormalMeanPrecConjugateTest::testMarginalLikelihood(void) // of large numbers), which is just the differential entropy of // a normal R.V. - boost::math::normal_distribution<> normal(mean, ::sqrt(variance)); + boost::math::normal_distribution<> normal(mean, std::sqrt(variance)); double expectedDifferentialEntropy = maths::CTools::differentialEntropy(normal); CNormalMeanPrecConjugate filter(makePrior()); @@ -496,7 +495,7 @@ void CNormalMeanPrecConjugateTest::testMarginalLikelihood(void) } { - boost::math::normal_distribution<> normal(mean, ::sqrt(variance)); + boost::math::normal_distribution<> normal(mean, std::sqrt(variance)); const double varianceScales[] = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0 @@ -527,8 +526,8 @@ void CNormalMeanPrecConjugateTest::testMarginalLikelihood(void) << ", interval = " << core::CContainerPrinter::print(interval)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q1, interval.first, 0.005); CPPUNIT_ASSERT_DOUBLES_EQUAL(q2, interval.second, 0.005); - error.add(::fabs(interval.first - q1)); - error.add(::fabs(interval.second - q2)); + error.add(std::fabs(interval.first - q1)); + error.add(std::fabs(interval.second - q2)); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 1e-3); @@ -539,7 +538,7 @@ void CNormalMeanPrecConjugateTest::testMarginalLikelihood(void) { TMeanAccumulator error; double vs = varianceScales[i]; - boost::math::normal_distribution<> scaledNormal(mean, ::sqrt(vs * variance)); + boost::math::normal_distribution<> scaledNormal(mean, std::sqrt(vs * variance)); LOG_DEBUG("*** vs = " << vs << " ***"); for (std::size_t j = 0u; j < boost::size(percentages); ++j) { @@ -553,8 +552,8 @@ void CNormalMeanPrecConjugateTest::testMarginalLikelihood(void) << ", interval = " << core::CContainerPrinter::print(interval)); CPPUNIT_ASSERT_DOUBLES_EQUAL(q1, interval.first, 0.3); CPPUNIT_ASSERT_DOUBLES_EQUAL(q2, interval.second, 0.3); - error.add(::fabs(interval.first - q1)); - error.add(::fabs(interval.second - q2)); + error.add(std::fabs(interval.first - q1)); + error.add(std::fabs(interval.second - q2)); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 0.1); @@ -615,7 +614,7 @@ void CNormalMeanPrecConjugateTest::testMarginalLikelihoodMean(void) filter.marginalLikelihoodMean(), 0.01); - relativeError.add(::fabs(expectedMean - filter.marginalLikelihoodMean()) + relativeError.add(std::fabs(expectedMean - filter.marginalLikelihoodMean()) / expectedMean); } @@ -663,13 +662,13 @@ void CNormalMeanPrecConjugateTest::testMarginalLikelihoodMode(void) { double vs = varianceScales[i]; weight[0] = vs; - boost::math::normal_distribution<> scaledNormal(means[i], ::sqrt(vs * variances[j])); + boost::math::normal_distribution<> scaledNormal(means[i], std::sqrt(vs * variances[j])); double expectedMode = boost::math::mode(scaledNormal); LOG_DEBUG("marginalLikelihoodMode = " << filter.marginalLikelihoodMode(weightStyle, weight) << ", expectedMode = " << expectedMode); CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedMode, filter.marginalLikelihoodMode(weightStyle, weight), - 0.12 * ::sqrt(variances[j])); + 0.12 * std::sqrt(variances[j])); } } } @@ -724,7 +723,7 @@ void CNormalMeanPrecConjugateTest::testMarginalLikelihoodVariance(void) filter.marginalLikelihoodVariance(), 0.2); - relativeError.add(::fabs(expectedVariance - filter.marginalLikelihoodVariance()) + relativeError.add(std::fabs(expectedVariance - filter.marginalLikelihoodVariance()) / expectedVariance); } @@ -799,7 +798,7 @@ void CNormalMeanPrecConjugateTest::testSampleMarginalLikelihood(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(filter.marginalLikelihoodVariance(), maths::CBasicStatistics::variance(sampledMoments), 0.2 * filter.marginalLikelihoodVariance()); - meanVarError.add(::fabs( filter.marginalLikelihoodVariance() + meanVarError.add(std::fabs( filter.marginalLikelihoodVariance() - maths::CBasicStatistics::variance(sampledMoments)) / filter.marginalLikelihoodVariance()); @@ -867,7 +866,7 @@ void CNormalMeanPrecConjugateTest::testCdf(void) LOG_DEBUG("log(F(x)) = " << (f == 0.0 ? f : -f) << ", log(1 - F(x)) = " << (fComplement == 0.0 ? fComplement : -fComplement)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, ::exp(-f) + ::exp(-fComplement), 1e-10); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, std::exp(-f) + std::exp(-fComplement), 1e-10); } } } @@ -907,7 +906,7 @@ void CNormalMeanPrecConjugateTest::testProbabilityOfLessLikelySamples(void) filter.addSamples(samples); double mean = filter.mean(); - double sd = ::sqrt(1.0 / filter.precision()); + double sd = std::sqrt(1.0 / filter.precision()); TDoubleVec likelihoods; for (std::size_t k = 0u; k < samples.size(); ++k) @@ -935,7 +934,7 @@ void CNormalMeanPrecConjugateTest::testProbabilityOfLessLikelySamples(void) double lb, ub; filter.probabilityOfLessLikelySamples(maths_t::E_TwoSided, sample, lb, ub); - double ssd = ::sqrt(px * (1.0 - px) / static_cast(samples.size())); + double ssd = std::sqrt(px * (1.0 - px) / static_cast(samples.size())); LOG_DEBUG("expected P(x) = " << px << ", actual P(x) = " << (lb + ub) / 2.0 @@ -943,7 +942,7 @@ void CNormalMeanPrecConjugateTest::testProbabilityOfLessLikelySamples(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(px, (lb + ub) / 2.0, 3.0 * ssd); - meanError.add(::fabs(px - (lb + ub) / 2.0)); + meanError.add(std::fabs(px - (lb + ub) / 2.0)); } maths_t::TWeightStyleVec weightStyle(1, maths_t::E_SampleCountVarianceScaleWeight); @@ -1064,7 +1063,7 @@ void CNormalMeanPrecConjugateTest::testAnomalyScore(void) { LOG_DEBUG("mean = " << means[i] << ", variance = " << variances[j]); - boost::math::normal_distribution<> normal(means[i], ::sqrt(variances[j])); + boost::math::normal_distribution<> normal(means[i], std::sqrt(variances[j])); TDoubleVec samples; rng.generateNormalSamples(means[i], variances[j], 500, samples); @@ -1207,7 +1206,7 @@ void CNormalMeanPrecConjugateTest::testIntegerData(void) TMeanAccumulator meanLogLikelihood2; for (std::size_t j = 0u; j < nSamples; ++j) { - double x = ::floor(samples[j]); + double x = std::floor(samples[j]); TDouble1Vec sample(1, x); double logLikelihood1; @@ -1242,7 +1241,7 @@ void CNormalMeanPrecConjugateTest::testIntegerData(void) for (std::size_t i = 0; i < nSamples; ++i) { - double x = ::floor(samples[i]); + double x = std::floor(samples[i]); TDouble1Vec sample(1, x); @@ -1410,7 +1409,7 @@ void CNormalMeanPrecConjugateTest::testSeasonalVarianceScale(void) m = filter.marginalLikelihoodMean(); v = filter.marginalLikelihoodVariance(); - double s = ::sqrt(v); + double s = std::sqrt(v); LOG_DEBUG("m = " << m << ", v = " << v); double points[] = { m - 3.0 * s, m - s, m, m + s, m + 3.0 * s }; @@ -1459,7 +1458,7 @@ void CNormalMeanPrecConjugateTest::testSeasonalVarianceScale(void) << ", log(f(mode + eps)) = " << fmPlusEps); CPPUNIT_ASSERT(fm > fmMinusEps); CPPUNIT_ASSERT(fm > fmPlusEps); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, (::exp(fmPlusEps) - ::exp(fmMinusEps)) / 2e-3, 1e-6); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, (std::exp(fmPlusEps) - std::exp(fmMinusEps)) / 2e-3, 1e-6); TDouble1Vec sample(1, 0.0); for (std::size_t l = 0u; l < boost::size(points); ++l) { @@ -1470,17 +1469,17 @@ void CNormalMeanPrecConjugateTest::testSeasonalVarianceScale(void) TDouble1Vec xPlusEps(1, points[l] + 1e-3); double lb, ub; filter.minusLogJointCdf(weightStyle, xPlusEps, weights, lb, ub); - double FxPlusEps = ::exp(-(lb + ub) / 2.0); + double FxPlusEps = std::exp(-(lb + ub) / 2.0); filter.minusLogJointCdf(weightStyle, xMinusEps, weights, lb, ub); - double FxMinusEps = ::exp(-(lb + ub) / 2.0); + double FxMinusEps = std::exp(-(lb + ub) / 2.0); LOG_DEBUG("x = " << points[l] << ", log(f(x)) = " << fx << ", F(x - eps) = " << FxMinusEps << ", F(x + eps) = " << FxPlusEps - << ", log(dF/dx)) = " << ::log((FxPlusEps - FxMinusEps) / 2e-3)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(fx, ::log((FxPlusEps - FxMinusEps) / 2e-3), 0.05 * ::fabs(fx)); + << ", log(dF/dx)) = " << std::log((FxPlusEps - FxMinusEps) / 2e-3)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(fx, std::log((FxPlusEps - FxMinusEps) / 2e-3), 0.05 * std::fabs(fx)); - sample[0] = m + (points[l] - m) / ::sqrt(vs); + sample[0] = m + (points[l] - m) / std::sqrt(vs); weights[0][0] = 1.0; double expectedLowerBound; double expectedUpperBound; @@ -1511,12 +1510,12 @@ void CNormalMeanPrecConjugateTest::testSeasonalVarianceScale(void) if ((expectedLowerBound + expectedUpperBound) < 0.02) { - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(expectedLowerBound), - ::log(lowerBound), - 0.1 * ::fabs(::log(expectedLowerBound))); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(expectedUpperBound), - ::log(upperBound), - 0.1 * ::fabs(::log(expectedUpperBound))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(expectedLowerBound), + std::log(lowerBound), + 0.1 * std::fabs(std::log(expectedLowerBound))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(expectedUpperBound), + std::log(upperBound), + 0.1 * std::fabs(std::log(expectedUpperBound))); } else { @@ -1549,7 +1548,7 @@ void CNormalMeanPrecConjugateTest::testSeasonalVarianceScale(void) LOG_DEBUG("m = " << m << ", v = " << v); LOG_DEBUG("sm = " << sm << ", sv = " << sv); - CPPUNIT_ASSERT_DOUBLES_EQUAL(m, sm, ::fabs(0.25 * m)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(m, sm, std::fabs(0.25 * m)); CPPUNIT_ASSERT_DOUBLES_EQUAL(v / vs, sv, 0.05 * v / vs); } } @@ -1641,7 +1640,7 @@ void CNormalMeanPrecConjugateTest::testCountVarianceScale(void) { std::size_t index = static_cast( static_cast(nScaledSamples) * percentiles[j]/100.0); - double error = ::fabs(probabilities[index] - percentiles[j]/100.0); + double error = std::fabs(probabilities[index] - percentiles[j]/100.0); expectedPercentileErrors.push_back(error); expectedTotalError += error; } @@ -1714,7 +1713,7 @@ void CNormalMeanPrecConjugateTest::testCountVarianceScale(void) { LOG_DEBUG("**** variance scale = " << varianceScales[i] << " ****"); - boost::math::normal_distribution<> normal(mean, ::sqrt(varianceScales[i] * variance)); + boost::math::normal_distribution<> normal(mean, std::sqrt(varianceScales[i] * variance)); double expectedDifferentialEntropy = maths::CTools::differentialEntropy(normal); CNormalMeanPrecConjugate filter(makePrior()); diff --git a/lib/maths/unittest/COneOfNPriorTest.cc b/lib/maths/unittest/COneOfNPriorTest.cc index fa321b2dd8..01386e821d 100644 --- a/lib/maths/unittest/COneOfNPriorTest.cc +++ b/lib/maths/unittest/COneOfNPriorTest.cc @@ -369,9 +369,9 @@ void COneOfNPriorTest::testModels(void) << ", precision = " << normalModel->precision() << ", expectedPrecision " << (1.0 / variance)); - CPPUNIT_ASSERT(::fabs(poissonModel->priorMean() - rate) / rate < 0.01); - CPPUNIT_ASSERT(::fabs(normalModel->mean() - mean) / mean < 0.01); - CPPUNIT_ASSERT(::fabs(normalModel->precision() - 1.0 / variance) * variance < 0.06); + CPPUNIT_ASSERT(std::fabs(poissonModel->priorMean() - rate) / rate < 0.01); + CPPUNIT_ASSERT(std::fabs(normalModel->mean() - mean) / mean < 0.01); + CPPUNIT_ASSERT(std::fabs(normalModel->precision() - 1.0 / variance) * variance < 0.06); } { @@ -443,7 +443,7 @@ void COneOfNPriorTest::testModelSelection(void) const double variance = rate; boost::math::poisson_distribution<> poisson(rate); - boost::math::normal_distribution<> normal(mean, ::sqrt(variance)); + boost::math::normal_distribution<> normal(mean, std::sqrt(variance)); double poissonExpectedLogWeight = -maths::CTools::differentialEntropy(poisson); double normalExpectedLogWeight = -maths::CTools::differentialEntropy(normal); @@ -497,8 +497,8 @@ void COneOfNPriorTest::testModelSelection(void) const double mean = 100.0; const double variance = 5.0; - boost::math::normal_distribution<> poissonApprox(mean, ::sqrt(mean)); - boost::math::normal_distribution<> normal(mean, ::sqrt(variance)); + boost::math::normal_distribution<> poissonApprox(mean, std::sqrt(mean)); + boost::math::normal_distribution<> normal(mean, std::sqrt(variance)); double poissonExpectedLogWeight = -maths::CTools::differentialEntropy(poissonApprox); double normalExpectedLogWeight = -maths::CTools::differentialEntropy(normal); @@ -567,7 +567,7 @@ void COneOfNPriorTest::testModelSelection(void) double logWeightRatio = logWeights[0] - logWeights[1]; LOG_DEBUG("logWeightRatio = " << logWeightRatio); - CPPUNIT_ASSERT(::exp(logWeightRatio) < 1e-6); + CPPUNIT_ASSERT(std::exp(logWeightRatio) < 1e-6); } } @@ -656,15 +656,15 @@ void COneOfNPriorTest::testMarginalLikelihood(void) double fx; CPPUNIT_ASSERT(filter.jointLogMarginalLikelihood(TDouble1Vec(1, x), fx) == maths_t::E_FpNoErrors); - fx = ::exp(fx); + fx = std::exp(fx); double lb; double ub; CPPUNIT_ASSERT(filter.minusLogJointCdf(TDouble1Vec(1, x + EPS), lb, ub)); - double FxPlusEps = ::exp(-(lb + ub) / 2.0); + double FxPlusEps = std::exp(-(lb + ub) / 2.0); CPPUNIT_ASSERT(filter.minusLogJointCdf(TDouble1Vec(1, x - EPS), lb, ub)); - double FxMinusEps = ::exp(-(lb + ub) / 2.0); + double FxMinusEps = std::exp(-(lb + ub) / 2.0); double dFdx = (FxPlusEps - FxMinusEps) / (2.0 * EPS); @@ -673,10 +673,10 @@ void COneOfNPriorTest::testMarginalLikelihood(void) CPPUNIT_ASSERT(filter.minusLogJointCdf(TDouble1Vec(1, x), lb, ub)); - double Fx = ::exp(-(lb + ub) / 2.0); + double Fx = std::exp(-(lb + ub) / 2.0); CPPUNIT_ASSERT(filter.minusLogJointCdfComplement(TDouble1Vec(1, x), lb, ub)); - double FxComplement = ::exp(-(lb + ub) / 2.0); + double FxComplement = std::exp(-(lb + ub) / 2.0); LOG_DEBUG("F(x) = " << Fx << " 1 - F(x) = " << FxComplement); CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, Fx + FxComplement, 1e-3); @@ -787,7 +787,7 @@ void COneOfNPriorTest::testMarginalLikelihoodMean(void) filter.marginalLikelihoodMean(), 0.2 * expectedMean); - relativeError.add(::fabs(filter.marginalLikelihoodMean() - expectedMean) / expectedMean); + relativeError.add(std::fabs(filter.marginalLikelihoodMean() - expectedMean) / expectedMean); } LOG_DEBUG("relativeError = " << maths::CBasicStatistics::mean(relativeError)); @@ -837,8 +837,8 @@ void COneOfNPriorTest::testMarginalLikelihoodMode(void) double mode; double fmode; maths::CCompositeFunctions::CExp likelihood(filter); - double a = means[i] - 2.0 * ::sqrt(variances[j]); - double b = means[i] + 2.0 * ::sqrt(variances[j]); + double a = means[i] - 2.0 * std::sqrt(variances[j]); + double b = means[i] + 2.0 * std::sqrt(variances[j]); maths::CSolvers::maximize(a, b, likelihood(a), likelihood(b), likelihood, 0.0, iterations, mode, fmode); LOG_DEBUG("marginalLikelihoodMode = " << filter.marginalLikelihoodMode() @@ -879,7 +879,7 @@ void COneOfNPriorTest::testMarginalLikelihoodMode(void) double mode; double fmode; maths::CCompositeFunctions::CExp likelihood(filter); - boost::math::lognormal_distribution<> logNormal(locations[i], ::sqrt(squareScales[j])); + boost::math::lognormal_distribution<> logNormal(locations[i], std::sqrt(squareScales[j])); double a = 0.01; double b = boost::math::mode(logNormal) + 1.0 * boost::math::standard_deviation(logNormal); maths::CSolvers::maximize(a, b, likelihood(a), likelihood(b), likelihood, 0.0, iterations, mode, fmode); @@ -948,7 +948,7 @@ void COneOfNPriorTest::testMarginalLikelihoodVariance(void) filter.marginalLikelihoodVariance(), 0.02 * expectedVariance); - relativeError.add(::fabs(expectedVariance - filter.marginalLikelihoodVariance()) + relativeError.add(std::fabs(expectedVariance - filter.marginalLikelihoodVariance()) / expectedVariance); } @@ -1005,7 +1005,7 @@ void COneOfNPriorTest::testMarginalLikelihoodVariance(void) filter.marginalLikelihoodVariance(), 0.01 * expectedVariance); - relativeError.add(::fabs(expectedVariance - filter.marginalLikelihoodVariance()) + relativeError.add(std::fabs(expectedVariance - filter.marginalLikelihoodVariance()) / expectedVariance); } @@ -1141,7 +1141,7 @@ void COneOfNPriorTest::testCdf(void) LOG_DEBUG("log(F(x)) = " << (f == 0.0 ? f : -f) << ", log(1 - F(x)) = " << (fComplement == 0.0 ? fComplement : -fComplement)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, ::exp(-f) + ::exp(-fComplement), 1e-10); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, std::exp(-f) + std::exp(-fComplement), 1e-10); } } } diff --git a/lib/maths/unittest/COrdinalTest.cc b/lib/maths/unittest/COrdinalTest.cc index de8f918c6e..e2b0bd9392 100644 --- a/lib/maths/unittest/COrdinalTest.cc +++ b/lib/maths/unittest/COrdinalTest.cc @@ -67,20 +67,20 @@ void COrdinalTest::testEqual(void) CPPUNIT_ASSERT_EQUAL(true, equal); if (sample[0] >= 0.0) { - equal = maths::COrdinal(static_cast(sample[0])) == maths::COrdinal(::floor(sample[0])); + equal = maths::COrdinal(static_cast(sample[0])) == maths::COrdinal(std::floor(sample[0])); CPPUNIT_ASSERT_EQUAL(true, equal); - equal = maths::COrdinal(::floor(sample[0])) == maths::COrdinal(static_cast(sample[0])); + equal = maths::COrdinal(std::floor(sample[0])) == maths::COrdinal(static_cast(sample[0])); CPPUNIT_ASSERT_EQUAL(true, equal); - equal = maths::COrdinal(static_cast(sample[0])) == maths::COrdinal(::floor(sample[0])); + equal = maths::COrdinal(static_cast(sample[0])) == maths::COrdinal(std::floor(sample[0])); CPPUNIT_ASSERT_EQUAL(true, equal); - equal = maths::COrdinal(::floor(sample[0])) == maths::COrdinal(static_cast(sample[0])); + equal = maths::COrdinal(std::floor(sample[0])) == maths::COrdinal(static_cast(sample[0])); CPPUNIT_ASSERT_EQUAL(true, equal); } else { - equal = maths::COrdinal(static_cast(sample[0])) == maths::COrdinal(::ceil(sample[0])); + equal = maths::COrdinal(static_cast(sample[0])) == maths::COrdinal(std::ceil(sample[0])); CPPUNIT_ASSERT_EQUAL(true, equal); - equal = maths::COrdinal(::ceil(sample[0])) == maths::COrdinal(static_cast(sample[0])); + equal = maths::COrdinal(std::ceil(sample[0])) == maths::COrdinal(static_cast(sample[0])); CPPUNIT_ASSERT_EQUAL(true, equal); } } @@ -281,11 +281,11 @@ void COrdinalTest::testAsDouble(void) TDoubleVec sample; rng.generateUniformSamples(-20000.0, 0.0, 1, sample); maths::COrdinal signedOrdinal(static_cast(sample[0])); - CPPUNIT_ASSERT_EQUAL(::ceil(sample[0]), signedOrdinal.asDouble()); + CPPUNIT_ASSERT_EQUAL(std::ceil(sample[0]), signedOrdinal.asDouble()); rng.generateUniformSamples(0.0, 20000.0, 1, sample); maths::COrdinal unsignedOrdinal(static_cast(sample[0])); - CPPUNIT_ASSERT_EQUAL(::floor(sample[0]), unsignedOrdinal.asDouble()); + CPPUNIT_ASSERT_EQUAL(std::floor(sample[0]), unsignedOrdinal.asDouble()); rng.generateUniformSamples(-1.0, 1.0, 1, sample); maths::COrdinal doubleOrdinal(sample[0]); diff --git a/lib/maths/unittest/CPoissonMeanConjugateTest.cc b/lib/maths/unittest/CPoissonMeanConjugateTest.cc index 4e0c3ab67d..c4d3278c28 100644 --- a/lib/maths/unittest/CPoissonMeanConjugateTest.cc +++ b/lib/maths/unittest/CPoissonMeanConjugateTest.cc @@ -33,13 +33,12 @@ #include #include +#include #include #include #include #include -#include - using namespace ml; using namespace handy_typedefs; @@ -284,7 +283,7 @@ void CPoissonMeanConjugateTest::testMarginalLikelihood(void) TDouble1Vec sample(1, static_cast(x)); CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter.jointLogMarginalLikelihood(sample, logLikelihood)); - cdf += ::exp(logLikelihood); + cdf += std::exp(logLikelihood); double lb, ub; CPPUNIT_ASSERT(filter.minusLogJointCdf(sample, lb, ub)); @@ -292,10 +291,10 @@ void CPoissonMeanConjugateTest::testMarginalLikelihood(void) double minusLogCdf = (lb + ub) / 2.0; LOG_DEBUG("sample = " << x - << ", -log(cdf) = " << (-::log(cdf)) + << ", -log(cdf) = " << (-std::log(cdf)) << ", minusLogCdf = " << minusLogCdf); - CPPUNIT_ASSERT_DOUBLES_EQUAL(minusLogCdf, -::log(cdf), epsilon); + CPPUNIT_ASSERT_DOUBLES_EQUAL(minusLogCdf, -std::log(cdf), epsilon); CPPUNIT_ASSERT(minusLogCdf >= 0.0); } } @@ -318,7 +317,7 @@ void CPoissonMeanConjugateTest::testMarginalLikelihood(void) for (std::size_t j = 0; j < boost::size(sampleStds); ++j) { double mean = filter.marginalLikelihoodMean(); - unsigned int sample = static_cast(mean + sampleStds[j] * ::sqrt(mean)); + unsigned int sample = static_cast(mean + sampleStds[j] * std::sqrt(mean)); double lb = 0.0, ub = 0.0; CPPUNIT_ASSERT(filter.minusLogJointCdf(TDouble1Vec(1, static_cast(sample)), lb, ub)); @@ -333,16 +332,16 @@ void CPoissonMeanConjugateTest::testMarginalLikelihood(void) CPPUNIT_ASSERT_EQUAL(maths_t::E_FpNoErrors, filter.jointLogMarginalLikelihood(TDouble1Vec(1, static_cast(x)), logLikelihood)); - cdf += ::exp(logLikelihood); + cdf += std::exp(logLikelihood); cdf = std::min(cdf, 1.0); } - LOG_DEBUG("-log(cdf) = " << -::log(cdf) + LOG_DEBUG("-log(cdf) = " << -std::log(cdf) << ", minusLogCdf = " << minusLogCdf); // We'll tolerate a 5% error in the -log(c.d.f.) since // we're approximating for large mean. - CPPUNIT_ASSERT_DOUBLES_EQUAL(minusLogCdf, -::log(cdf), -0.05 * ::log(cdf)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(minusLogCdf, -std::log(cdf), -0.05 * std::log(cdf)); } } } @@ -388,7 +387,7 @@ void CPoissonMeanConjugateTest::testMarginalLikelihood(void) LOG_DEBUG("differentialEntropy = " << differentialEntropy << ", expectedDifferentialEntropy = " << expectedDifferentialEntropy); - CPPUNIT_ASSERT(::fabs(differentialEntropy - expectedDifferentialEntropy) < 0.01); + CPPUNIT_ASSERT(std::fabs(differentialEntropy - expectedDifferentialEntropy) < 0.01); } } @@ -482,7 +481,7 @@ void CPoissonMeanConjugateTest::testMarginalLikelihoodVariance(void) filter.marginalLikelihoodVariance(), 0.3 * expectedVariance); - relativeError.add(::fabs(expectedVariance - filter.marginalLikelihoodVariance()) + relativeError.add(std::fabs(expectedVariance - filter.marginalLikelihoodVariance()) / expectedVariance); } @@ -546,7 +545,7 @@ void CPoissonMeanConjugateTest::testSampleMarginalLikelihood(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(filter.marginalLikelihoodVariance(), maths::CBasicStatistics::variance(sampledMomemts), 0.15 * filter.marginalLikelihoodVariance()); - meanVarError.add( ::fabs( filter.marginalLikelihoodVariance() + meanVarError.add( std::fabs( filter.marginalLikelihoodVariance() - maths::CBasicStatistics::variance(sampledMomemts)) / filter.marginalLikelihoodVariance()); @@ -620,8 +619,8 @@ void CPoissonMeanConjugateTest::testCdf(void) double fComplement = (lb + ub) / 2.0; LOG_DEBUG("log(F(x)) = " << -f << ", log(1 - F(x)) = " << fComplement); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(std::numeric_limits::min()), -f, 1e-10); - CPPUNIT_ASSERT_EQUAL(1.0, ::exp(-fComplement)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(std::numeric_limits::min()), -f, 1e-10); + CPPUNIT_ASSERT_EQUAL(1.0, std::exp(-fComplement)); for (std::size_t j = 1u; j < 500; ++j) { @@ -634,7 +633,7 @@ void CPoissonMeanConjugateTest::testCdf(void) LOG_DEBUG("log(F(x)) = " << (f == 0.0 ? f : -f) << ", log(1 - F(x)) = " << (fComplement == 0.0 ? fComplement : -fComplement)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, ::exp(-f) + ::exp(-fComplement), 1e-10); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, std::exp(-f) + std::exp(-fComplement), 1e-10); } } } @@ -700,7 +699,7 @@ void CPoissonMeanConjugateTest::testProbabilityOfLessLikelySamples(void) double lb, ub; filter.probabilityOfLessLikelySamples(maths_t::E_TwoSided, sample, lb, ub); - double ssd = ::sqrt(px * (1.0 - px) / static_cast(samples.size())); + double ssd = std::sqrt(px * (1.0 - px) / static_cast(samples.size())); LOG_DEBUG("x = " << x << ", expected P(x) = " << px @@ -709,7 +708,7 @@ void CPoissonMeanConjugateTest::testProbabilityOfLessLikelySamples(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(px, (lb + ub) / 2.0, 8.0 * ssd); - meanError.add(::fabs(px - (lb + ub) / 2.0)); + meanError.add(std::fabs(px - (lb + ub) / 2.0)); } maths_t::TWeightStyleVec weightStyle(1, maths_t::E_SampleCountVarianceScaleWeight); diff --git a/lib/maths/unittest/CPriorTest.cc b/lib/maths/unittest/CPriorTest.cc index de4eb24ce9..f6e6a4f4e1 100644 --- a/lib/maths/unittest/CPriorTest.cc +++ b/lib/maths/unittest/CPriorTest.cc @@ -128,7 +128,7 @@ void CPriorTest::testExpectation(void) CPPUNIT_ASSERT(prior.expectation(CX(), n, mean)); LOG_DEBUG("n = " << n << ", mean = " << mean - << ", error = " << ::fabs(mean - trueMean)); + << ", error = " << std::fabs(mean - trueMean)); CPPUNIT_ASSERT_DOUBLES_EQUAL(trueMean, mean, 1e-10); } @@ -144,7 +144,7 @@ void CPriorTest::testExpectation(void) CPPUNIT_ASSERT(prior.expectation(CVariance(prior.mean()), n, variance)); LOG_DEBUG("n = " << n << ", variance = " << variance - << ", error = " << ::fabs(variance - trueVariance)); + << ", error = " << std::fabs(variance - trueVariance)); CPPUNIT_ASSERT_DOUBLES_EQUAL(trueVariance, variance, varianceErrors[n - 1]); } @@ -152,7 +152,7 @@ void CPriorTest::testExpectation(void) { 0.5, 0.05, 0.01, 0.005, 0.001, 0.0003, 0.0003, 0.0002, 0.0002 }; - boost::math::normal_distribution<> normal(trueMean, ::sqrt(trueVariance)); + boost::math::normal_distribution<> normal(trueMean, std::sqrt(trueVariance)); double trueEntropy = maths::CTools::differentialEntropy(normal); LOG_DEBUG("true differential entropy = " << trueEntropy); for (std::size_t n = 1; n < 10; ++n) @@ -161,7 +161,7 @@ void CPriorTest::testExpectation(void) CPPUNIT_ASSERT(prior.expectation(CMinusLogLikelihood(prior), n, entropy)); LOG_DEBUG("n = " << n << ", differential entropy = " << entropy - << ", error = " << ::fabs(entropy - trueEntropy)); + << ", error = " << std::fabs(entropy - trueEntropy)); CPPUNIT_ASSERT_DOUBLES_EQUAL(trueEntropy, entropy, entropyErrors[n - 1]); } } diff --git a/lib/maths/unittest/CProbabilityAggregatorsTest.cc b/lib/maths/unittest/CProbabilityAggregatorsTest.cc index 27a6d10c74..aeb922b1eb 100644 --- a/lib/maths/unittest/CProbabilityAggregatorsTest.cc +++ b/lib/maths/unittest/CProbabilityAggregatorsTest.cc @@ -47,7 +47,7 @@ class CGammaKernel bool operator()(const double &u, double &result) const { - result = ::pow(m_X - ::log(1.0 - u/m_S), m_S - 1.0); + result = std::pow(m_X - std::log(1.0 - u/m_S), m_S - 1.0); return true; } @@ -84,17 +84,17 @@ double logUpperIncompleteGamma(double s, double x) remainder += partialRemainder; } - return -x - ::log(s) + ::log(remainder); + return -x - std::log(s) + std::log(remainder); } // This uses the standard recurrence relation for the upper incomplete // gamma function, // g(s,x) = (s - 1) * g(s-1,x) + x^(s-1) * exp(x) - double t1 = logUpperIncompleteGamma(s - 1.0, x) + ::log(s - 1.0); - double t2 = (s - 1.0) * ::log(x) - x; + double t1 = logUpperIncompleteGamma(s - 1.0, x) + std::log(s - 1.0); + double t2 = (s - 1.0) * std::log(x) - x; double normalizer = std::max(t1, t2); - return normalizer + ::log(::exp(t1 - normalizer) + ::exp(t2 - normalizer)); + return normalizer + std::log(std::exp(t1 - normalizer) + std::exp(t2 - normalizer)); } class CExpectedLogProbabilityOfMFromNExtremeSamples @@ -124,7 +124,7 @@ class CExpectedLogProbabilityOfMFromNExtremeSamples { if (m_I == m_M) { - return static_cast(m_N - m_M) * ::log(1.0 - x); + return static_cast(m_N - m_M) * std::log(1.0 - x); } double result; CLogIntegrand f(m_Limits, m_N, m_M, m_I + 1u); @@ -202,15 +202,15 @@ void CProbabilityAggregatorsTest::testJointProbabilityOfLessLikelySamples(void) TDoubleVec samples1; rng.generateNormalSamples(1.0, 3.0, numberSamples, samples1); - boost::math::normal_distribution<> normal1(1.0, ::sqrt(3.0)); + boost::math::normal_distribution<> normal1(1.0, std::sqrt(3.0)); TDoubleVec samples2; rng.generateNormalSamples(10.0, 15.0, numberSamples, samples2); - boost::math::normal_distribution<> normal2(10.0, ::sqrt(15.0)); + boost::math::normal_distribution<> normal2(10.0, std::sqrt(15.0)); TDoubleVec samples3; rng.generateNormalSamples(0.0, 1.0, numberSamples, samples3); - boost::math::normal_distribution<> normal3(0.0, ::sqrt(1.0)); + boost::math::normal_distribution<> normal3(0.0, std::sqrt(1.0)); double totalExpectedCount = 0.0; double totalCount = 0.0; @@ -265,7 +265,7 @@ void CProbabilityAggregatorsTest::testJointProbabilityOfLessLikelySamples(void) LOG_DEBUG("count = " << count << ", expectedCount = " << expectedCount); - double error = ::fabs(count - expectedCount) / std::max(count, expectedCount); + double error = std::fabs(count - expectedCount) / std::max(count, expectedCount); CPPUNIT_ASSERT(error < 0.2); totalExpectedCount += expectedCount; @@ -274,7 +274,7 @@ void CProbabilityAggregatorsTest::testJointProbabilityOfLessLikelySamples(void) } } - double totalError = ::fabs(totalCount - totalExpectedCount) + double totalError = std::fabs(totalCount - totalExpectedCount) / std::max(totalCount, totalExpectedCount); LOG_DEBUG("totalError = " << totalError); CPPUNIT_ASSERT(totalError < 0.01); @@ -349,7 +349,7 @@ void CProbabilityAggregatorsTest::testLogJointProbabilityOfLessLikelySamples(voi CPPUNIT_ASSERT(logP < upperBound); CPPUNIT_ASSERT(logP > lowerBound); - CPPUNIT_ASSERT_DOUBLES_EQUAL(upperBound, lowerBound, ::fabs(5e-6 * upperBound)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(upperBound, lowerBound, std::fabs(5e-6 * upperBound)); } // Now test the quality of bounds near underflow. @@ -399,9 +399,9 @@ void CProbabilityAggregatorsTest::testLogJointProbabilityOfLessLikelySamples(voi CPPUNIT_ASSERT(logP < upperBound); CPPUNIT_ASSERT(logP > lowerBound); - CPPUNIT_ASSERT_DOUBLES_EQUAL(upperBound, lowerBound, ::fabs(8e-4 * upperBound)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(upperBound, lowerBound, std::fabs(8e-4 * upperBound)); - error += (upperBound - lowerBound) / ::fabs(upperBound); + error += (upperBound - lowerBound) / std::fabs(upperBound); } else if (jointProbability.numberSamples() > 1.0) { @@ -415,10 +415,10 @@ void CProbabilityAggregatorsTest::testLogJointProbabilityOfLessLikelySamples(voi CPPUNIT_ASSERT(logJointProbability.calculateUpperBound(upperBound)); // Test the test function. - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(probability), logP, 2e-5); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(probability), logP, 2e-5); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(probability), upperBound, 1e-6); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(probability), lowerBound, 1e-6); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(probability), upperBound, 1e-6); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(probability), lowerBound, 1e-6); } } @@ -486,14 +486,14 @@ void CProbabilityAggregatorsTest::testProbabilityOfExtremeSample(void) { TDoubleVec samples; rng.generateNormalSamples(0.0, 1.0, sampleSizes[i], samples); - boost::math::normal_distribution<> normal(0.0, ::sqrt(1.0)); + boost::math::normal_distribution<> normal(0.0, std::sqrt(1.0)); using TMinValue = CBasicStatistics::COrderStatisticsStack; TMinValue minValue; for (std::size_t l = 0u; l < samples.size(); ++l) { - double p = 2.0 * boost::math::cdf(normal, -::fabs(samples[l])); + double p = 2.0 * boost::math::cdf(normal, -std::fabs(samples[l])); minValue.add(p); } @@ -507,11 +507,11 @@ void CProbabilityAggregatorsTest::testProbabilityOfExtremeSample(void) / static_cast(nTrials); LOG_DEBUG("count = " << count << ", expectedProbability = " << expectedProbability - << ", error = " << ::fabs(probability - expectedProbability)); + << ", error = " << std::fabs(probability - expectedProbability)); CPPUNIT_ASSERT_DOUBLES_EQUAL(probability, expectedProbability, 0.012); - totalError += ::fabs(probability - expectedProbability); + totalError += std::fabs(probability - expectedProbability); totalProbability += std::max(probability, expectedProbability); } } @@ -565,7 +565,7 @@ void CProbabilityAggregatorsTest::testProbabilityOfMFromNExtremeSamples(void) LOG_DEBUG("log(probability) = " << p2 << ", expected log(probability) = " << p1); - CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-8 * ::fabs(std::max(p1, p2))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-8 * std::fabs(std::max(p1, p2))); } } @@ -624,7 +624,7 @@ void CProbabilityAggregatorsTest::testProbabilityOfMFromNExtremeSamples(void) double p; CPPUNIT_ASSERT(probabilityCalculator.calculate(p)); - p = ::exp(p); + p = std::exp(p); unsigned int nTrials = 50000u; unsigned int count = 0; @@ -633,14 +633,14 @@ void CProbabilityAggregatorsTest::testProbabilityOfMFromNExtremeSamples(void) { TDoubleVec samples; rng.generateNormalSamples(0.0, 1.0, numberSamples, samples); - boost::math::normal_distribution<> normal(0.0, ::sqrt(1.0)); + boost::math::normal_distribution<> normal(0.0, std::sqrt(1.0)); using TMinValues = CBasicStatistics::COrderStatisticsHeap; TMinValues minValues(i); for (std::size_t k = 0u; k < samples.size(); ++k) { - double p1 = 2.0 * boost::math::cdf(normal, -::fabs(samples[k])); + double p1 = 2.0 * boost::math::cdf(normal, -std::fabs(samples[k])); minValues.add(p1); } @@ -660,7 +660,7 @@ void CProbabilityAggregatorsTest::testProbabilityOfMFromNExtremeSamples(void) double expectedProbability = static_cast(count) / static_cast(nTrials); - double error = ::fabs(p - expectedProbability); + double error = std::fabs(p - expectedProbability); double relativeError = error / std::max(p, expectedProbability); LOG_DEBUG("probability = " << p @@ -734,7 +734,7 @@ void CProbabilityAggregatorsTest::testProbabilityOfMFromNExtremeSamples(void) LOG_DEBUG("log(probability) = " << p2 << ", expected log(probability) = " << p1); - CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-4 * ::fabs(std::max(p1, p2))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-4 * std::fabs(std::max(p1, p2))); } } } @@ -805,7 +805,7 @@ void CProbabilityAggregatorsTest::testProbabilityOfMFromNExtremeSamples(void) double p2; CPPUNIT_ASSERT(probabilityCalculator.calculate(p2)); LOG_DEBUG("probability = " << p2 << ", expectedProbability = " << p1); - CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-8 * ::fabs(std::max(p1, p2))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-8 * std::fabs(std::max(p1, p2))); } { @@ -838,7 +838,7 @@ void CProbabilityAggregatorsTest::testProbabilityOfMFromNExtremeSamples(void) double p2; CPPUNIT_ASSERT(probabilityCalculator.calculate(p2)); LOG_DEBUG("probability = " << p2 << ", expectedProbability = " << p1); - CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-8 * ::fabs(std::max(p1, p2))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-8 * std::fabs(std::max(p1, p2))); } { @@ -864,7 +864,7 @@ void CProbabilityAggregatorsTest::testProbabilityOfMFromNExtremeSamples(void) double p2; probabilityCalculator.calculate(p2); LOG_DEBUG("probability = " << p2 << ", expectedProbability = " << p1); - CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-8 * ::fabs(std::max(p1, p2))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-8 * std::fabs(std::max(p1, p2))); } { @@ -891,7 +891,7 @@ void CProbabilityAggregatorsTest::testProbabilityOfMFromNExtremeSamples(void) double p2; probabilityCalculator.calculate(p2); LOG_DEBUG("probability = " << p2 << ", expectedProbability = " << p1); - CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-8 * ::fabs(std::max(p1, p2))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 1e-8 * std::fabs(std::max(p1, p2))); } { diff --git a/lib/maths/unittest/CProbabilityCalibratorTest.cc b/lib/maths/unittest/CProbabilityCalibratorTest.cc index 22a93dc05f..0c2c36f6bc 100644 --- a/lib/maths/unittest/CProbabilityCalibratorTest.cc +++ b/lib/maths/unittest/CProbabilityCalibratorTest.cc @@ -106,8 +106,8 @@ void CProbabilityCalibratorTest::testCalibration(void) trueProbability = (lowerBound + upperBound) / 2.0; } - double raw = ::fabs(::log(rawProbability) - ::log(trueProbability)); - double calibrated = ::fabs(::log(calibratedProbability) - ::log(trueProbability)); + double raw = std::fabs(std::log(rawProbability) - std::log(trueProbability)); + double calibrated = std::fabs(std::log(calibratedProbability) - std::log(trueProbability)); rawError += raw; calibratedError += calibrated; @@ -186,8 +186,8 @@ void CProbabilityCalibratorTest::testCalibration(void) trueProbability = (lowerBound + upperBound) / 2.0; } - double raw = ::fabs(::log(rawProbability) - ::log(trueProbability)); - double calibrated = ::fabs(::log(calibratedProbability) - ::log(trueProbability)); + double raw = std::fabs(std::log(rawProbability) - std::log(trueProbability)); + double calibrated = std::fabs(std::log(calibratedProbability) - std::log(trueProbability)); rawError += raw; calibratedError += calibrated; diff --git a/lib/maths/unittest/CQDigestTest.cc b/lib/maths/unittest/CQDigestTest.cc index cf6c8e58f1..8af51d23be 100644 --- a/lib/maths/unittest/CQDigestTest.cc +++ b/lib/maths/unittest/CQDigestTest.cc @@ -107,7 +107,7 @@ void CQDigestTest::testAdd(void) TUInt64Set orderedSamples; for (std::size_t i = 0u; i < samples.size(); ++i) { - uint32_t sample = static_cast(::floor(samples[i])); + uint32_t sample = static_cast(std::floor(samples[i])); qDigest.add(sample); orderedSamples.insert(sample); @@ -139,7 +139,7 @@ void CQDigestTest::testAdd(void) << ", error " << error); } - CPPUNIT_ASSERT(::fabs(error) < 0.06); + CPPUNIT_ASSERT(std::fabs(error) < 0.06); totalErrors[j - 1u] += error; } @@ -186,7 +186,7 @@ void CQDigestTest::testCdf(void) std::size_t s = 0u; for (/**/; s < std::min(k, samples.size()); ++s) { - uint32_t sample = static_cast(::floor(samples[s])); + uint32_t sample = static_cast(std::floor(samples[s])); qDigest.add(sample); } @@ -211,7 +211,7 @@ void CQDigestTest::testCdf(void) for (/**/; s < samples.size(); ++s) { - uint32_t sample = static_cast(::floor(samples[s])); + uint32_t sample = static_cast(std::floor(samples[s])); qDigest.add(sample); } @@ -257,7 +257,7 @@ void CQDigestTest::testSummary(void) for (std::size_t i = 0u; i < samples.size(); ++i) { - uint32_t sample = static_cast(::floor(samples[i])); + uint32_t sample = static_cast(std::floor(samples[i])); qDigest.add(sample); } @@ -340,7 +340,7 @@ void CQDigestTest::testPropagateForwardByTime(void) } LOG_DEBUG("Before propagation " << qDigest.print()); - qDigest.propagateForwardsByTime(-::log(0.9)); + qDigest.propagateForwardsByTime(-std::log(0.9)); LOG_DEBUG("After propagation " << qDigest.print()); CPPUNIT_ASSERT(qDigest.checkInvariants()); @@ -384,7 +384,7 @@ void CQDigestTest::testPropagateForwardByTime(void) cdfLower.push_back(lb); double f = boost::math::cdf(normal, x); cdfUpper.push_back(ub); - error.add(::fabs(f - (lb + ub) / 2.0)); + error.add(std::fabs(f - (lb + ub) / 2.0)); } LOG_DEBUG("error = " << CBasicStatistics::mean(error)); intrinsicError = CBasicStatistics::mean(error); @@ -416,8 +416,8 @@ void CQDigestTest::testPropagateForwardByTime(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(cdfUpper[i], cdfUpperAged[i], std::min(5e-5, 2e-3 * cdfUpper[i])); - diff.add(::fabs(cdfLower[i] - cdfLowerAged[i])); - diff.add(::fabs(cdfUpper[i] - cdfUpperAged[i])); + diff.add(std::fabs(cdfLower[i] - cdfLowerAged[i])); + diff.add(std::fabs(cdfUpper[i] - cdfUpperAged[i])); } LOG_DEBUG("diff = " << CBasicStatistics::mean(diff)); CPPUNIT_ASSERT(CBasicStatistics::mean(diff) < 1e-5); @@ -460,7 +460,7 @@ void CQDigestTest::testPropagateForwardByTime(void) CPPUNIT_ASSERT(lb <= f); CPPUNIT_ASSERT(ub >= f); CPPUNIT_ASSERT_DOUBLES_EQUAL(f, (lb + ub) / 2.0, 0.015); - error.add(::fabs(f - (lb + ub) / 2.0)); + error.add(std::fabs(f - (lb + ub) / 2.0)); } LOG_DEBUG("error = " << CBasicStatistics::mean(error)); CPPUNIT_ASSERT(CBasicStatistics::mean(error) < 0.006); @@ -569,8 +569,8 @@ void CQDigestTest::testScale(void) double lowerBound; double upperBound; qDigest.cdf(j, 0.0, lowerBound, upperBound); - double type1 = ::fabs(expectedLowerBound - lowerBound) - + ::fabs(expectedUpperBound - upperBound); + double type1 = std::fabs(expectedLowerBound - lowerBound) + + std::fabs(expectedUpperBound - upperBound); double type2 = std::max(lowerBound - expectedLowerBound, 0.0) + std::max(expectedUpperBound - upperBound, 0.0); maxType1 = std::max(maxType1, type1); @@ -606,7 +606,7 @@ void CQDigestTest::testPersist(void) for (std::size_t i = 0u; i < samples.size(); ++i) { - uint32_t sample = static_cast(::floor(samples[i])); + uint32_t sample = static_cast(std::floor(samples[i])); origQDigest.add(sample); } diff --git a/lib/maths/unittest/CQuantileSketchTest.cc b/lib/maths/unittest/CQuantileSketchTest.cc index 5ec7e96309..390d78e61c 100644 --- a/lib/maths/unittest/CQuantileSketchTest.cc +++ b/lib/maths/unittest/CQuantileSketchTest.cc @@ -63,7 +63,7 @@ void testSketch(maths::CQuantileSketch::EInterpolation interpolation, double sq; CPPUNIT_ASSERT(sketch.quantile(100.0 * q, sq)); bias.add(xq - sq); - error.add(::fabs(xq - sq)); + error.add(std::fabs(xq - sq)); } double min, max; @@ -73,7 +73,7 @@ void testSketch(maths::CQuantileSketch::EInterpolation interpolation, LOG_DEBUG("bias = " << maths::CBasicStatistics::mean(bias) << ", error " << maths::CBasicStatistics::mean(error)); - CPPUNIT_ASSERT(::fabs(maths::CBasicStatistics::mean(bias)) < maxBias); + CPPUNIT_ASSERT(std::fabs(maths::CBasicStatistics::mean(bias)) < maxBias); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < maxError); meanBias += maths::CBasicStatistics::accumulator(maths::CBasicStatistics::count(bias), @@ -204,7 +204,7 @@ void CQuantileSketchTest::testReduce(void) CPPUNIT_ASSERT(sketch.quantile(cdf[i], x)); LOG_DEBUG("expected quantile = " << points[i] << ", actual quantile = " << x); CPPUNIT_ASSERT_DOUBLES_EQUAL(points[i], x, 10.0); - error.add(::fabs(points[i] - x)); + error.add(std::fabs(points[i] - x)); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 1.5); @@ -297,7 +297,7 @@ void CQuantileSketchTest::testReduce(void) CPPUNIT_ASSERT(sketch.quantile(cdf[i], x)); LOG_DEBUG("expected quantile = " << points[i] << ", actual quantile = " << x); CPPUNIT_ASSERT_DOUBLES_EQUAL(points[i], x, 10.0); - error.add(::fabs(points[i] - x)); + error.add(std::fabs(points[i] - x)); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 1.8); @@ -367,7 +367,7 @@ void CQuantileSketchTest::testMerge(void) CPPUNIT_ASSERT(sketch3.quantile(cdf[i], x)); LOG_DEBUG("expected quantile = " << points[i] << ", actual quantile = " << x); CPPUNIT_ASSERT_DOUBLES_EQUAL(points[i], x, 10.0); - error.add(::fabs(points[i] - x)); + error.add(std::fabs(points[i] - x)); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 1.8); @@ -428,14 +428,14 @@ void CQuantileSketchTest::testMedian(void) double expectedMedian = samples[250]; double actualMedian; sketch.quantile(50.0, actualMedian); - CPPUNIT_ASSERT(::fabs(actualMedian - expectedMedian) < 6.7); + CPPUNIT_ASSERT(std::fabs(actualMedian - expectedMedian) < 6.7); bias.add(actualMedian - expectedMedian); - error.add(::fabs(actualMedian - expectedMedian)); + error.add(std::fabs(actualMedian - expectedMedian)); } LOG_DEBUG("bias = " << maths::CBasicStatistics::mean(bias)); LOG_DEBUG("error = " << maths::CBasicStatistics::mean(error)); - CPPUNIT_ASSERT(::fabs(maths::CBasicStatistics::mean(bias)) < 0.2); + CPPUNIT_ASSERT(std::fabs(maths::CBasicStatistics::mean(bias)) < 0.2); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(error) < 1.6); } @@ -481,9 +481,9 @@ void CQuantileSketchTest::testQuantileAccuracy(void) rng.generateUniformSamples(0.0, 20.0 * static_cast(t + 1), 1000, samples); testSketch(maths::CQuantileSketch::E_Linear, 20, samples, 0.15, 0.3, meanBias, meanError); } - LOG_DEBUG("mean bias = " << ::fabs(maths::CBasicStatistics::mean(meanBias)) + LOG_DEBUG("mean bias = " << std::fabs(maths::CBasicStatistics::mean(meanBias)) << ", mean error " << maths::CBasicStatistics::mean(meanError)); - CPPUNIT_ASSERT(::fabs(maths::CBasicStatistics::mean(meanBias)) < 0.0007); + CPPUNIT_ASSERT(std::fabs(maths::CBasicStatistics::mean(meanBias)) < 0.0007); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(meanError) < 0.003); } @@ -501,7 +501,7 @@ void CQuantileSketchTest::testQuantileAccuracy(void) } LOG_DEBUG("mean bias = " << maths::CBasicStatistics::mean(meanBias) << ", mean error " << maths::CBasicStatistics::mean(meanError)); - CPPUNIT_ASSERT(::fabs(maths::CBasicStatistics::mean(meanBias)) < 0.002); + CPPUNIT_ASSERT(std::fabs(maths::CBasicStatistics::mean(meanBias)) < 0.002); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(meanError) < 0.003); } @@ -519,7 +519,7 @@ void CQuantileSketchTest::testQuantileAccuracy(void) } LOG_DEBUG("mean bias = " << maths::CBasicStatistics::mean(meanBias) << ", mean error " << maths::CBasicStatistics::mean(meanError)); - CPPUNIT_ASSERT(::fabs(maths::CBasicStatistics::mean(meanBias)) < 0.0006); + CPPUNIT_ASSERT(std::fabs(maths::CBasicStatistics::mean(meanBias)) < 0.0006); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(meanError) < 0.0009); } LOG_DEBUG("*** Mixture ***"); @@ -556,11 +556,11 @@ void CQuantileSketchTest::testQuantileAccuracy(void) } LOG_DEBUG("linear mean bias = " << maths::CBasicStatistics::mean(meanBiasLinear) << ", mean error " << maths::CBasicStatistics::mean(meanErrorLinear)); - CPPUNIT_ASSERT(::fabs(maths::CBasicStatistics::mean(meanBiasLinear)) < 0.012); + CPPUNIT_ASSERT(std::fabs(maths::CBasicStatistics::mean(meanBiasLinear)) < 0.012); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(meanErrorLinear) < 0.013); LOG_DEBUG("piecewise mean bias = " << maths::CBasicStatistics::mean(meanBiasPiecewise) << ", mean error " << maths::CBasicStatistics::mean(meanErrorPiecewise)); - CPPUNIT_ASSERT(::fabs(maths::CBasicStatistics::mean(meanBiasPiecewise)) < 0.015); + CPPUNIT_ASSERT(std::fabs(maths::CBasicStatistics::mean(meanBiasPiecewise)) < 0.015); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(meanErrorPiecewise) < 0.015); } } diff --git a/lib/maths/unittest/CRandomProjectionClustererTest.cc b/lib/maths/unittest/CRandomProjectionClustererTest.cc index a6644d7d72..1d89178ad0 100644 --- a/lib/maths/unittest/CRandomProjectionClustererTest.cc +++ b/lib/maths/unittest/CRandomProjectionClustererTest.cc @@ -180,7 +180,7 @@ void CRandomProjectionClustererTest::testGenerateProjections(void) maths::CBasicStatistics::variance(moments), 0.2 / static_cast(t)); - error.add(static_cast(t) * ::fabs(maths::CBasicStatistics::variance(moments) - 1.0 / static_cast(t))); + error.add(static_cast(t) * std::fabs(maths::CBasicStatistics::variance(moments) - 1.0 / static_cast(t))); } LOG_DEBUG("Relative error = " << 100.0 * maths::CBasicStatistics::mean(error) << "%"); diff --git a/lib/maths/unittest/CRegressionTest.cc b/lib/maths/unittest/CRegressionTest.cc index e9e3032cc7..12bc64b51d 100644 --- a/lib/maths/unittest/CRegressionTest.cc +++ b/lib/maths/unittest/CRegressionTest.cc @@ -186,8 +186,8 @@ void CRegressionTest::testFit(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(intercept, params[0], 1.3); CPPUNIT_ASSERT_DOUBLES_EQUAL(slope, params[1], 0.015); - interceptError.add(::fabs(params[0] - intercept)); - slopeError.add(::fabs(params[1] - slope)); + interceptError.add(std::fabs(params[0] - intercept)); + slopeError.add(std::fabs(params[1] - slope)); } LOG_DEBUG("intercept error = " << interceptError); @@ -340,10 +340,10 @@ void CRegressionTest::testShiftOrdinate(void) LOG_DEBUG("parameters 1 = " << core::CContainerPrinter::print(params1)); LOG_DEBUG("parameters 2 = " << core::CContainerPrinter::print(params2)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1000.0 + params1[0], params2[0], 1e-6 * ::fabs(params1[0])); - CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[1], params2[1], 1e-6 * ::fabs(params1[1])); - CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[2], params2[2], 1e-6 * ::fabs(params1[2])); - CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[3], params2[3], 1e-6 * ::fabs(params1[3])); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1000.0 + params1[0], params2[0], 1e-6 * std::fabs(params1[0])); + CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[1], params2[1], 1e-6 * std::fabs(params1[1])); + CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[2], params2[2], 1e-6 * std::fabs(params1[2])); + CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[3], params2[3], 1e-6 * std::fabs(params1[3])); } void CRegressionTest::testShiftGradient(void) @@ -373,10 +373,10 @@ void CRegressionTest::testShiftGradient(void) LOG_DEBUG("parameters 1 = " << core::CContainerPrinter::print(params1)); LOG_DEBUG("parameters 2 = " << core::CContainerPrinter::print(params2)); - CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[0], params2[0], 1e-6 * ::fabs(params1[0])); - CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0 + params1[1], params2[1], 1e-6 * ::fabs(params1[1])); - CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[2], params2[2], 1e-6 * ::fabs(params1[2])); - CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[3], params2[3], 1e-6 * ::fabs(params1[3])); + CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[0], params2[0], 1e-6 * std::fabs(params1[0])); + CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0 + params1[1], params2[1], 1e-6 * std::fabs(params1[1])); + CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[2], params2[2], 1e-6 * std::fabs(params1[2])); + CPPUNIT_ASSERT_DOUBLES_EQUAL( params1[3], params2[3], 1e-6 * std::fabs(params1[3])); } void CRegressionTest::testAge(void) @@ -530,7 +530,7 @@ void CRegressionTest::testPrediction(void) for (std::size_t i = 0u; i <= 400; ++i) { double x = 0.005 * pi * static_cast(i); - double y = ::sin(x); + double y = std::sin(x); m.add(y); m.age(0.95); @@ -651,7 +651,7 @@ void CRegressionTest::testCombination(void) for (std::size_t i = 0u; i < params.size(); ++i) { - CPPUNIT_ASSERT_DOUBLES_EQUAL(params[i], paramsAPlusB[i], 5e-3 * ::fabs(params[i])); + CPPUNIT_ASSERT_DOUBLES_EQUAL(params[i], paramsAPlusB[i], 5e-3 * std::fabs(params[i])); } } diff --git a/lib/maths/unittest/CSamplingTest.cc b/lib/maths/unittest/CSamplingTest.cc index b17d0ef2f9..9176fa8a2b 100644 --- a/lib/maths/unittest/CSamplingTest.cc +++ b/lib/maths/unittest/CSamplingTest.cc @@ -46,10 +46,10 @@ double multinomialProbability(const TDoubleVec &probabilities, double ni = static_cast(counts[i]); if (ni > 0.0) { - logP += ni * ::log(probabilities[i]) - boost::math::lgamma(ni + 1.0); + logP += ni * std::log(probabilities[i]) - boost::math::lgamma(ni + 1.0); } } - return ::exp(logP); + return std::exp(logP); } namespace test_detail @@ -131,7 +131,7 @@ double euclidean(const TDoubleVec &v) { result += v[i] * v[i]; } - return ::sqrt(result); + return std::sqrt(result); } //! Frobenius norm of a matrix. @@ -145,7 +145,7 @@ double frobenius(const TDoubleVecVec &m) result += m[i][j] * m[i][j]; } } - return ::sqrt(result); + return std::sqrt(result); } } @@ -193,8 +193,8 @@ void CSamplingTest::testMultinomialSample(void) double p = multinomialProbability(probabilities, pItr->first); double pe = pItr->second; LOG_DEBUG("p = " << p << ", pe = " << pe); - CPPUNIT_ASSERT(::fabs(pe - p) < std::max(0.27 * p, 3e-5)); - error += ::fabs(pe - p); + CPPUNIT_ASSERT(std::fabs(pe - p) < std::max(0.27 * p, 3e-5)); + error += std::fabs(pe - p); pTotal += p; } diff --git a/lib/maths/unittest/CSeasonalComponentAdaptiveBucketingTest.cc b/lib/maths/unittest/CSeasonalComponentAdaptiveBucketingTest.cc index 104f26d80e..f807901607 100644 --- a/lib/maths/unittest/CSeasonalComponentAdaptiveBucketingTest.cc +++ b/lib/maths/unittest/CSeasonalComponentAdaptiveBucketingTest.cc @@ -186,8 +186,8 @@ void CSeasonalComponentAdaptiveBucketingTest::testRefine(void) double y0 = function[j - 1]; double y1 = function[j]; double y = y0 + (y1 - y0) * (static_cast(t) - x0) / (x1 - x0); - meanError1.add(::fabs(values1[i - 1] - y)); - maxError1.add(::fabs(values1[i - 1] - y)); + meanError1.add(std::fabs(values1[i - 1] - y)); + maxError1.add(std::fabs(values1[i - 1] - y)); } TMeanAccumulator meanError2; @@ -206,8 +206,8 @@ void CSeasonalComponentAdaptiveBucketingTest::testRefine(void) double y0 = function[j - 1]; double y1 = function[j]; double y = y0 + (y1 - y0) * (static_cast(t) - x0) / (x1 - x0); - meanError2.add(::fabs(values2[i - 1] - y)); - maxError2.add(::fabs(values2[i - 1] - y)); + meanError2.add(std::fabs(values2[i - 1] - y)); + maxError2.add(std::fabs(values2[i - 1] - y)); } LOG_DEBUG("mean error = " << maths::CBasicStatistics::mean(meanError1)); @@ -266,23 +266,23 @@ void CSeasonalComponentAdaptiveBucketingTest::testRefine(void) double v = variances[i-1]; // Function mean and variance. - double m_ = ::fabs(a) < ::fabs(b) ? - 0.02 / 3.0 * ::pow(b, 3.0) - * (1.0 - ::pow(a/b, 3.0)) / (b-a) : - 0.02 / 3.0 * ::pow(a, 3.0) - * (::pow(b/a, 3.0) - 1.0) / (b-a); + double m_ = std::fabs(a) < std::fabs(b) ? + 0.02 / 3.0 * std::pow(b, 3.0) + * (1.0 - std::pow(a/b, 3.0)) / (b-a) : + 0.02 / 3.0 * std::pow(a, 3.0) + * (std::pow(b/a, 3.0) - 1.0) / (b-a); double v_ = 9.0; LOG_DEBUG("m = " << m << ", m_ = " << m_ - << ", absolute error = " << ::fabs(m - m_)); + << ", absolute error = " << std::fabs(m - m_)); LOG_DEBUG("v = " << v << ", v_ = " << v_ - << ", relative error = " << ::fabs(v - v_) / v_); + << ", relative error = " << std::fabs(v - v_) / v_); CPPUNIT_ASSERT_DOUBLES_EQUAL(m_, m, 0.7); CPPUNIT_ASSERT_DOUBLES_EQUAL(v_, v, 0.4 * v_); - meanError.add(::fabs(m_ - m) / m_); - varianceError.add(::fabs(v_ - v) / v_); + meanError.add(std::fabs(m_ - m) / m_); + varianceError.add(std::fabs(v_ - v) / v_); if (i == 1 || i == endpoints.size() - 1) { @@ -291,26 +291,26 @@ void CSeasonalComponentAdaptiveBucketingTest::testRefine(void) if ((b * b / 50.0 - m) * (a * a / 50.0 - m) < 0.0) { // Root. - double c = b < 0.0 ? -::sqrt(50.0 * m) : +::sqrt(50.0 * m); + double c = b < 0.0 ? -std::sqrt(50.0 * m) : +::sqrt(50.0 * m); // Left and right partial averaging errors. - double l = ::fabs(c) < ::fabs(a) ? + double l = std::fabs(c) < std::fabs(a) ? 0.02 / 3.0 * a * a * a * ((c/a) * (c/a) * (c/a) - 1.0) - m * (c-a) : 0.02 / 3.0 * c * c * c * (1.0 - (a/c) * (a/c) * (a/c)) - m * (c-a); - double r = ::fabs(c) < ::fabs(b) ? + double r = std::fabs(c) < std::fabs(b) ? 0.02 / 3.0 * b * b * b * (1.0 - (c/b) * (c/b) * (c/b)) - m * (b-c) : 0.02 / 3.0 * c * c * c * ((b/c) * (b/c) * (b/c) - 1.0) - m * (b-c); LOG_DEBUG("c = " << c << ", l = " << l << " r = " << r - << ", error = " << ::fabs(l) + ::fabs(r)); - avgError.add(::fabs(l) + ::fabs(r)); + << ", error = " << std::fabs(l) + std::fabs(r)); + avgError.add(std::fabs(l) + std::fabs(r)); } else { - avgError.add(::fabs((m_ - m) * (b - a))); + avgError.add(std::fabs((m_ - m) * (b - a))); } } @@ -323,7 +323,7 @@ void CSeasonalComponentAdaptiveBucketingTest::testRefine(void) CPPUNIT_ASSERT(varianceError_ < 0.21); double avgErrorMean = maths::CBasicStatistics::mean(avgError); - double avgErrorStd = ::sqrt(maths::CBasicStatistics::variance(avgError)); + double avgErrorStd = std::sqrt(maths::CBasicStatistics::variance(avgError)); LOG_DEBUG("avgErrorMean = " << avgErrorMean << ", avgErrorStd = " << avgErrorStd); @@ -436,7 +436,7 @@ void CSeasonalComponentAdaptiveBucketingTest::testMinimumBucketLength(void) double totalError = 0.0; for (std::size_t j = 1u; j+1 < endpoints1.size(); ++j) { - totalError += ::fabs(endpoints2[j] - endpoints1[j]); + totalError += std::fabs(endpoints2[j] - endpoints1[j]); } LOG_DEBUG("minimumTotalError = " << minimumTotalError); LOG_DEBUG("totalError = " << totalError); @@ -543,14 +543,14 @@ void CSeasonalComponentAdaptiveBucketingTest::testKnots(void) LOG_DEBUG("expected = " << expectedValue << ", value = " << values[i]); CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedValue, values[i], 15.0); - meanError.add(::fabs(values[i] - expectedValue)); - meanValue.add(::fabs(expectedValue)); + meanError.add(std::fabs(values[i] - expectedValue)); + meanValue.add(std::fabs(expectedValue)); } LOG_DEBUG("meanError = " << maths::CBasicStatistics::mean(meanError)); LOG_DEBUG("meanValue = " << maths::CBasicStatistics::mean(meanValue)); CPPUNIT_ASSERT( maths::CBasicStatistics::mean(meanError) / maths::CBasicStatistics::mean(meanValue) - < 0.1 / ::sqrt(static_cast(p+1))); + < 0.1 / std::sqrt(static_cast(p+1))); } } LOG_DEBUG("*** Variances ***"); @@ -595,8 +595,8 @@ void CSeasonalComponentAdaptiveBucketingTest::testKnots(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedVariance, variances[i], 15.0); - meanError.add(::fabs(variances[i] - expectedVariance)); - meanVariance.add(::fabs(expectedVariance)); + meanError.add(std::fabs(variances[i] - expectedVariance)); + meanVariance.add(std::fabs(expectedVariance)); } LOG_DEBUG("meanError = " << maths::CBasicStatistics::mean(meanError)); LOG_DEBUG("meanVariance = " << maths::CBasicStatistics::mean(meanVariance)); @@ -634,7 +634,7 @@ void CSeasonalComponentAdaptiveBucketingTest::testLongTermTrendKnots(void) double x = static_cast(i) / 144.0; double y = 10.0 * ( std::min(static_cast(p+1) + x, 50.0) - std::max(static_cast(p+1) + x - 50.0, 0.0) - + 10.0 * ::sin(boost::math::double_constants::two_pi * x)); + + 10.0 * std::sin(boost::math::double_constants::two_pi * x)); bucketing.add(static_cast(86400 * p + 600 * i), y + noise[i], y); } bucketing.refine(static_cast(86400 * (p + 1))); @@ -659,11 +659,11 @@ void CSeasonalComponentAdaptiveBucketingTest::testLongTermTrendKnots(void) double x = knots[i] / 86400.0; double expectedValue = 10.0 * ( std::min(static_cast(p+1) + x, 50.0) - std::max(static_cast(p+1) + x - 50.0, 0.0) - + 10.0 * ::sin(boost::math::double_constants::two_pi * x)); + + 10.0 * std::sin(boost::math::double_constants::two_pi * x)); LOG_DEBUG("expected = " << expectedValue << ", value = " << values[i]); CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedValue, values[i], 70.0); - meanError.add(::fabs(values[i] - expectedValue)); - meanValue.add(::fabs(expectedValue)); + meanError.add(std::fabs(values[i] - expectedValue)); + meanValue.add(std::fabs(expectedValue)); } LOG_DEBUG("meanError = " << maths::CBasicStatistics::mean(meanError)); LOG_DEBUG("meanValue = " << maths::CBasicStatistics::mean(meanValue)); @@ -693,7 +693,7 @@ void CSeasonalComponentAdaptiveBucketingTest::testShiftValue(void) for (/**/; t < 40 * 86400; t += 600) { double x = static_cast(t) / 86400.0; - double y = x + 20.0 + 20.0 * ::sin(boost::math::double_constants::two_pi * x); + double y = x + 20.0 + 20.0 * std::sin(boost::math::double_constants::two_pi * x); bucketing.add(t, y, y); if (t % 86400 == 0) { @@ -743,7 +743,7 @@ void CSeasonalComponentAdaptiveBucketingTest::testSlope(void) for (/**/; t < 60 * 86400; t += 600) { double x = static_cast(t) / 86400.0; - double y = x + 20.0 + 20.0 * ::sin(boost::math::double_constants::two_pi * x); + double y = x + 20.0 + 20.0 * std::sin(boost::math::double_constants::two_pi * x); bucketing.add(t, y, y); if (t % 86400 == 0) { diff --git a/lib/maths/unittest/CSeasonalComponentTest.cc b/lib/maths/unittest/CSeasonalComponentTest.cc index 9fde7a1f02..9283ff77c3 100644 --- a/lib/maths/unittest/CSeasonalComponentTest.cc +++ b/lib/maths/unittest/CSeasonalComponentTest.cc @@ -203,7 +203,7 @@ void CSeasonalComponentTest::testNoPeriodicity(void) double f = function[j].second + residualMean; double e = mean(interval) - f; - error1 += ::fabs(e); + error1 += std::fabs(e); error2 += std::max(std::max(interval.first - f, f - interval.second), 0.0); } //t << "];\n"; @@ -259,7 +259,7 @@ void CSeasonalComponentTest::testConstantPeriodic(void) for (core_t::TTime i = 0u; i < 49; ++i) { core_t::TTime t = (i * core::constants::DAY) / 48; - double ft = 100.0 + 40.0 * ::sin(boost::math::double_constants::two_pi + double ft = 100.0 + 40.0 * std::sin(boost::math::double_constants::two_pi * static_cast(i) / 48.0); function.push_back(TTimeDoublePr(t, ft)); } @@ -310,7 +310,7 @@ void CSeasonalComponentTest::testConstantPeriodic(void) TDoubleDoublePr interval = seasonal.value(time + function[j].first, 70.0); double f = residualMean + function[j].second; double e = mean(interval) - f; - error1 += ::fabs(e); + error1 += std::fabs(e); error2 += std::max(std::max(interval.first - f, f - interval.second), 0.0); } //t << "];\n"; @@ -457,7 +457,7 @@ void CSeasonalComponentTest::testConstantPeriodic(void) double f = residualMean + function[j].second; double e = mean(interval) - f; - error1 += ::fabs(e); + error1 += std::fabs(e); error2 += std::max(std::max(interval.first - f, f - interval.second), 0.0); } //t << "];\n"; @@ -578,7 +578,7 @@ void CSeasonalComponentTest::testTimeVaryingPeriodic(void) for (std::size_t d = 0u; d < 365; ++d) { - double scale = 2.0 + 2.0 * ::sin(3.14159265358979 * static_cast(d) / 365.0); + double scale = 2.0 + 2.0 * std::sin(3.14159265358979 * static_cast(d) / 365.0); TTimeDoublePrVec samples; generateSeasonalValues(rng, @@ -618,7 +618,7 @@ void CSeasonalComponentTest::testTimeVaryingPeriodic(void) double f = residualMean + scale * function[j].second; double e = mean(interval) - f; - error1 += ::fabs(e); + error1 += std::fabs(e); error2 += std::max(std::max(interval.first - f, f - interval.second), 0.0); } //t << "];\n"; @@ -689,7 +689,7 @@ void CSeasonalComponentTest::testVeryLowVariation(void) rng.generateNormalSamples(0.0, 1e-3, n, residuals); double residualMean = maths::CBasicStatistics::mean(residuals); - double deviation = ::sqrt(1e-3); + double deviation = std::sqrt(1e-3); CTestSeasonalComponent seasonal(startTime, core::constants::DAY, core::constants::DAY, 24); seasonal.initialize(startTime); @@ -725,7 +725,7 @@ void CSeasonalComponentTest::testVeryLowVariation(void) double f = residualMean + function[j].second; double e = mean(interval) - f; - error1 += ::fabs(e); + error1 += std::fabs(e); error2 += std::max(std::max(interval.first - f, f - interval.second), 0.0); } //t << "];\n"; @@ -779,7 +779,7 @@ void CSeasonalComponentTest::testVariance(void) for (core_t::TTime i = 0u; i < 481; ++i) { core_t::TTime t = (i * core::constants::DAY) / 48; - double vt = 80.0 + 20.0 * ::sin(boost::math::double_constants::two_pi + double vt = 80.0 + 20.0 * std::sin(boost::math::double_constants::two_pi * static_cast(i % 48) / 48.0); TDoubleVec sample; rng.generateNormalSamples(0.0, vt, 10, sample); @@ -801,17 +801,17 @@ void CSeasonalComponentTest::testVariance(void) for (core_t::TTime i = 0u; i < 48; ++i) { core_t::TTime t = (i * core::constants::DAY) / 48; - double v_ = 80.0 + 20.0 * ::sin(boost::math::double_constants::two_pi + double v_ = 80.0 + 20.0 * std::sin(boost::math::double_constants::two_pi * static_cast(i) / 48.0); TDoubleDoublePr vv = seasonal.variance(t, 98.0); double v = (vv.first + vv.second) / 2.0; LOG_DEBUG("v_ = " << v_ << ", v = " << core::CContainerPrinter::print(vv) - << ", relative error = " << ::fabs(v - v_) / v_); + << ", relative error = " << std::fabs(v - v_) / v_); CPPUNIT_ASSERT_DOUBLES_EQUAL(v_, v, 0.4 * v_); CPPUNIT_ASSERT(v_ > vv.first && v_ < vv.second); - error.add(::fabs(v - v_) / v_); + error.add(std::fabs(v - v_) / v_); } LOG_DEBUG("mean relative error = " << maths::CBasicStatistics::mean(error)); @@ -837,7 +837,7 @@ void CSeasonalComponentTest::testPersist(void) for (core_t::TTime i = 0u; i < 49; ++i) { core_t::TTime t = (i * core::constants::DAY) / 48; - double ft = 100.0 + 40.0 * ::sin(boost::math::double_constants::two_pi + double ft = 100.0 + 40.0 * std::sin(boost::math::double_constants::two_pi * static_cast(i) / 48.0); function.push_back(TTimeDoublePr(t, ft)); } diff --git a/lib/maths/unittest/CSignalTest.cc b/lib/maths/unittest/CSignalTest.cc index bb2a84df49..dd0a43feb0 100644 --- a/lib/maths/unittest/CSignalTest.cc +++ b/lib/maths/unittest/CSignalTest.cc @@ -51,7 +51,7 @@ void bruteForceDft(maths::CSignal::TComplexVec &f, double sign) { double t = -sign * boost::math::double_constants::two_pi * static_cast(k * n) / static_cast(f.size()); - result[k] += maths::CSignal::TComplex(::cos(t), ::sin(t)) * f[n]; + result[k] += maths::CSignal::TComplex(std::cos(t), std::sin(t)) * f[n]; } if (sign < 0.0) { diff --git a/lib/maths/unittest/CSolversTest.cc b/lib/maths/unittest/CSolversTest.cc index da14b90bab..517ca44221 100644 --- a/lib/maths/unittest/CSolversTest.cc +++ b/lib/maths/unittest/CSolversTest.cc @@ -22,10 +22,9 @@ #include #include +#include #include -#include - using namespace ml; using namespace maths; @@ -50,30 +49,30 @@ double f2(const double &x) //! [0.739085133215160, 0.739085133215161] double f3(const double &x) { - return ::cos(x) - x; + return std::cos(x) - x; } //! Root at x = 2/3. double f4(const double &x) { return x <= 2.0/3.0 ? - ::pow(::fabs(x - 2.0/3.0), 0.2) : - -::pow(::fabs(x - 2.0/3.0), 0.2); + std::pow(std::fabs(x - 2.0/3.0), 0.2) : + -std::pow(std::fabs(x - 2.0/3.0), 0.2); } //! This has local maxima at 4 and 10. double f5(const double &x) { - return 1.1 * ::exp(-(x-4.0) * (x-4.0)) - + 0.4 * ::exp(-(x-10.0) * (x-10.0) / 4.0); + return 1.1 * std::exp(-(x-4.0) * (x-4.0)) + + 0.4 * std::exp(-(x-10.0) * (x-10.0) / 4.0); } //! This has local maxima at 4, 6 and 10. double f6(const double &x) { - return 1.1 * ::exp(-2.0 * (x-4.0) * (x-4.0)) - + 0.1 * ::exp(-(x-6.0) * (x-6.0)) - + 0.4 * ::exp(-(x-10.0) * (x-10.0) / 2.0); + return 1.1 * std::exp(-2.0 * (x-4.0) * (x-4.0)) + + 0.1 * std::exp(-(x-6.0) * (x-6.0)) + + 0.4 * std::exp(-(x-10.0) * (x-10.0) / 2.0); } class CLog @@ -89,7 +88,7 @@ class CLog throw std::range_error("Bad value to log " + core::CStringUtils::typeToString(x)); } - return ::log(x); + return std::log(x); } }; @@ -234,11 +233,11 @@ void CSolversTest::testBisection(void) << ", f(a) = " << f3(a) << ", f(b) = " << f3(b)); CPPUNIT_ASSERT(f3(a) * f3(b) <= 0.0); - double error = ::fabs(bestGuess - 0.7390851332151607); + double error = std::fabs(bestGuess - 0.7390851332151607); LOG_DEBUG("bestGuess = " << bestGuess << ", f(bestGuess) = " << f3(bestGuess) << ", error = " << error); - CPPUNIT_ASSERT(error < ::fabs((a + b)/2.0 - 0.7390851332151607)); + CPPUNIT_ASSERT(error < std::fabs((a + b)/2.0 - 0.7390851332151607)); double convergenceFactor = error / lastError; lastError = error; if (i != 3) @@ -248,7 +247,7 @@ void CSolversTest::testBisection(void) LOG_DEBUG("-") } - double meanConvergenceFactor = ::pow(lastError / 0.7390851332151607, 1.0/20.0); + double meanConvergenceFactor = std::pow(lastError / 0.7390851332151607, 1.0/20.0); LOG_DEBUG("mean convergence factor = " << meanConvergenceFactor); CPPUNIT_ASSERT(meanConvergenceFactor < 0.4); } @@ -283,17 +282,17 @@ void CSolversTest::testBisection(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5 * lastInterval, b - a, 1e-5); lastInterval = b - a; - double error = ::fabs(bestGuess - 2.0/3.0); + double error = std::fabs(bestGuess - 2.0/3.0); LOG_DEBUG("bestGuess = " << bestGuess << ", f(bestGuess) = " << f4(bestGuess) << ", error = " << error); - CPPUNIT_ASSERT(error < ::fabs((a + b)/2.0 - 2.0/3.0)); + CPPUNIT_ASSERT(error < std::fabs((a + b)/2.0 - 2.0/3.0)); convergenceFactor *= (error / lastError); lastError = error; if ((i - 2) % 4 == 0) { - convergenceFactor = ::pow(convergenceFactor, 0.25); + convergenceFactor = std::pow(convergenceFactor, 0.25); LOG_DEBUG("convergence factor = " << convergenceFactor); if (i - 2 != 4) { @@ -304,7 +303,7 @@ void CSolversTest::testBisection(void) LOG_DEBUG("-") } - double meanConvergenceFactor = ::pow(lastError / (2.0/3.0), 1.0/40.0); + double meanConvergenceFactor = std::pow(lastError / (2.0/3.0), 1.0/40.0); LOG_DEBUG("mean convergence factor = " << meanConvergenceFactor); CPPUNIT_ASSERT(meanConvergenceFactor < 0.56); } @@ -375,11 +374,11 @@ void CSolversTest::testBrent(void) << ", f(a) = " << f3(a) << ", f(b) = " << f3(b)); CPPUNIT_ASSERT(f3(a) * f3(b) <= 0.0); - double error = ::fabs(bestGuess - 0.7390851332151607); + double error = std::fabs(bestGuess - 0.7390851332151607); LOG_DEBUG("bestGuess = " << bestGuess << ", f(bestGuess) = " << f3(bestGuess) << ", error = " << error); - CPPUNIT_ASSERT(error < ::fabs((a + b)/2.0 - 0.7390851332151607)); + CPPUNIT_ASSERT(error < std::fabs((a + b)/2.0 - 0.7390851332151607)); double convergenceFactor = error / lastError; lastError = error; if (i != 3) @@ -415,17 +414,17 @@ void CSolversTest::testBrent(void) << ", f(a) = " << f4(a) << ", f(b) = " << f4(b)); CPPUNIT_ASSERT(f4(a) * f4(b) <= 0.0); - double error = ::fabs(bestGuess - 2.0/3.0); + double error = std::fabs(bestGuess - 2.0/3.0); LOG_DEBUG("bestGuess = " << bestGuess << ", f(bestGuess) = " << f4(bestGuess) << ", error = " << error); - CPPUNIT_ASSERT(error < ::fabs((a + b)/2.0 - 2.0/3.0)); + CPPUNIT_ASSERT(error < std::fabs((a + b)/2.0 - 2.0/3.0)); double convergenceFactor = error / lastError; lastError = error; LOG_DEBUG("convergence factor = " << convergenceFactor); } - double meanConvergenceFactor = ::pow(lastError / (2.0/3.0), 1.0/40.0); + double meanConvergenceFactor = std::pow(lastError / (2.0/3.0), 1.0/40.0); LOG_DEBUG("mean convergence factor = " << meanConvergenceFactor); CPPUNIT_ASSERT(meanConvergenceFactor < 0.505); } diff --git a/lib/maths/unittest/CSplineTest.cc b/lib/maths/unittest/CSplineTest.cc index 5391b279d5..0369aeb9eb 100644 --- a/lib/maths/unittest/CSplineTest.cc +++ b/lib/maths/unittest/CSplineTest.cc @@ -91,12 +91,12 @@ void CSplineTest::testNatural(void) CPPUNIT_ASSERT_EQUAL(y[i], yy); double ym = spline.value(x[i] - 1e-3); - CPPUNIT_ASSERT(::fabs(yy - ym) < 1e-2); + CPPUNIT_ASSERT(std::fabs(yy - ym) < 1e-2); LOG_DEBUG("f(x[" << i << " - eps]) = " << ym); double yp = spline.value(x[i] + 1e-3); LOG_DEBUG("f(x[" << i << " + eps]) = " << yp); - CPPUNIT_ASSERT(::fabs(yp - yy) < 1e-2); + CPPUNIT_ASSERT(std::fabs(yp - yy) < 1e-2); } const TDoubleVec &curvatures = spline.curvatures(); @@ -116,7 +116,7 @@ void CSplineTest::testNatural(void) for (std::size_t i = 0u; i < x.size(); ++i) { x[i] *= boost::math::double_constants::two_pi; - y.push_back(::sin(x[i])); + y.push_back(std::sin(x[i])); } maths::CSpline<> spline(maths::CSplineTypes::E_Cubic); @@ -128,8 +128,8 @@ void CSplineTest::testNatural(void) * static_cast(i) / 20.0; double yy = spline.value(xx); LOG_DEBUG("spline(" << xx << ") = " << yy - << ", f(" << xx << ") = " << ::sin(xx)); - CPPUNIT_ASSERT(::fabs(::sin(xx) - yy) < 0.02); + << ", f(" << xx << ") = " << std::sin(xx)); + CPPUNIT_ASSERT(std::fabs(std::sin(xx) - yy) < 0.02); } const TDoubleVec &curvatures = spline.curvatures(); @@ -164,12 +164,12 @@ void CSplineTest::testParabolicRunout(void) CPPUNIT_ASSERT_EQUAL(y[i], yy); double ym = spline.value(x[i] - 1e-3); - CPPUNIT_ASSERT(::fabs(yy - ym) < 1e-2); + CPPUNIT_ASSERT(std::fabs(yy - ym) < 1e-2); LOG_DEBUG("f(x[" << i << " - eps]) = " << ym); double yp = spline.value(x[i] + 1e-3); LOG_DEBUG("f(x[" << i << " + eps]) = " << yp); - CPPUNIT_ASSERT(::fabs(yp - yy) < 1e-2); + CPPUNIT_ASSERT(std::fabs(yp - yy) < 1e-2); } const TDoubleVec &curvatures = spline.curvatures(); @@ -193,7 +193,7 @@ void CSplineTest::testParabolicRunout(void) for (std::size_t i = 0u; i < x.size(); ++i) { x[i] *= boost::math::double_constants::two_pi; - y.push_back(::sin(x[i])); + y.push_back(std::sin(x[i])); } @@ -206,8 +206,8 @@ void CSplineTest::testParabolicRunout(void) * static_cast(i) / 20.0; double yy = spline.value(xx); LOG_DEBUG("spline(" << xx << ") = " << yy - << ", f(" << xx << ") = " << ::sin(xx)); - CPPUNIT_ASSERT(::fabs(::sin(xx) - yy) < 0.04); + << ", f(" << xx << ") = " << std::sin(xx)); + CPPUNIT_ASSERT(std::fabs(std::sin(xx) - yy) < 0.04); } const TDoubleVec &curvatures = spline.curvatures(); @@ -238,7 +238,7 @@ void CSplineTest::testPeriodic(void) for (std::size_t i = 0u; i < x.size(); ++i) { x[i] *= boost::math::double_constants::two_pi; - y.push_back(::cos(x[i])); + y.push_back(std::cos(x[i])); } maths::CSpline<> spline(maths::CSplineTypes::E_Cubic); @@ -250,8 +250,8 @@ void CSplineTest::testPeriodic(void) * static_cast(i) / 20.0; double yy = spline.value(xx); LOG_DEBUG("spline(" << xx << ") = " << yy - << ", f(" << xx << ") = " << ::cos(xx)); - CPPUNIT_ASSERT(::fabs(::cos(xx) - yy) < 0.02); + << ", f(" << xx << ") = " << std::cos(xx)); + CPPUNIT_ASSERT(std::fabs(std::cos(xx) - yy) < 0.02); } } @@ -388,7 +388,7 @@ void CSplineTest::testMean(void) for (std::size_t i = 0u; i < 21; ++i) { x.push_back(static_cast(20 * i)); - y.push_back(::cos(boost::math::double_constants::two_pi + y.push_back(std::cos(boost::math::double_constants::two_pi * static_cast(i) / 10.0)); } @@ -439,7 +439,7 @@ void CSplineTest::testIllposed(void) << core::CContainerPrinter::print(curvatures)); for (std::size_t i = 0u; i < curvatures.size(); ++i) { - CPPUNIT_ASSERT(::fabs(curvatures[i]) < 2e-7); + CPPUNIT_ASSERT(std::fabs(curvatures[i]) < 2e-7); } for (std::size_t i = 0u; i <= 30; ++i) @@ -543,7 +543,7 @@ void CSplineTest::testSlope(void) } CPPUNIT_ASSERT_DOUBLES_EQUAL(numericalSlope, slope, - 1e-3 * ::fabs(numericalSlope)); + 1e-3 * std::fabs(numericalSlope)); } } } @@ -555,7 +555,7 @@ void CSplineTest::testSlope(void) for (std::size_t i = 0u; i < 21; ++i) { x.push_back(static_cast(20 * i)); - y.push_back(::cos(boost::math::double_constants::two_pi + y.push_back(std::cos(boost::math::double_constants::two_pi * static_cast(i) / 10.0)); } double range = x[x.size()-1] - x[0]; @@ -603,7 +603,7 @@ void CSplineTest::testSplineReference(void) for (std::size_t i = 0u; i < x.size(); ++i) { x[i] *= boost::math::double_constants::two_pi; - y.push_back(::sin(x[i])); + y.push_back(std::sin(x[i])); } maths::CSpline<> spline(maths::CSplineTypes::E_Cubic); diff --git a/lib/maths/unittest/CStatisticalTestsTest.cc b/lib/maths/unittest/CStatisticalTestsTest.cc index 2da3af1283..132f14b44d 100644 --- a/lib/maths/unittest/CStatisticalTestsTest.cc +++ b/lib/maths/unittest/CStatisticalTestsTest.cc @@ -60,10 +60,10 @@ void CStatisticalTestsTest::testCramerVonMises(void) { LOG_DEBUG("*** n = " << n[i] << " ***"); { - LOG_DEBUG("N(" << 5.0 << "," << ::sqrt(2.0) << ")"); + LOG_DEBUG("N(" << 5.0 << "," << std::sqrt(2.0) << ")"); TDoubleVec samples; rng.generateNormalSamples(5.0, 2.0, n[i] * 1000, samples); - boost::math::normal_distribution<> normal(5.0, ::sqrt(2.0)); + boost::math::normal_distribution<> normal(5.0, std::sqrt(2.0)); TDoubleVec p; for (std::size_t j = 0u; j < samples.size()/n[i]; ++j) @@ -88,9 +88,9 @@ void CStatisticalTestsTest::testCramerVonMises(void) / static_cast(p.size()); LOG_DEBUG("percentile = " << percentile << ", p value percentile = " << pp - << ", error = " << ::fabs(pp - percentile)); - meanError += ::fabs(pp - percentile); - CPPUNIT_ASSERT(::fabs(pp - percentile) < 0.055); + << ", error = " << std::fabs(pp - percentile)); + meanError += std::fabs(pp - percentile); + CPPUNIT_ASSERT(std::fabs(pp - percentile) < 0.055); } meanError /= 21.0; LOG_DEBUG("meanError = " << meanError); @@ -126,9 +126,9 @@ void CStatisticalTestsTest::testCramerVonMises(void) / static_cast(p.size()); LOG_DEBUG("percentile = " << percentile << ", p value percentile = " << pp - << ", error = " << ::fabs(pp - percentile)); - meanError += ::fabs(pp - percentile); - CPPUNIT_ASSERT(::fabs(pp - percentile) < 0.055); + << ", error = " << std::fabs(pp - percentile)); + meanError += std::fabs(pp - percentile); + CPPUNIT_ASSERT(std::fabs(pp - percentile) < 0.055); } meanError /= 21.0; LOG_DEBUG("meanError = " << meanError); @@ -155,7 +155,7 @@ void CStatisticalTestsTest::testPersist(void) TDoubleVec samples; rng.generateNormalSamples(5.0, 2.0, 25, samples); - boost::math::normal_distribution<> normal(5.0, ::sqrt(2.0)); + boost::math::normal_distribution<> normal(5.0, std::sqrt(2.0)); maths::CStatisticalTests::CCramerVonMises origCvm(9); TDoubleVec p; diff --git a/lib/maths/unittest/CTimeSeriesDecompositionTest.cc b/lib/maths/unittest/CTimeSeriesDecompositionTest.cc index aa16ae8fc3..fbb80c3ecc 100644 --- a/lib/maths/unittest/CTimeSeriesDecompositionTest.cc +++ b/lib/maths/unittest/CTimeSeriesDecompositionTest.cc @@ -76,10 +76,10 @@ void CTimeSeriesDecompositionTest::testSuperpositionOfSines(void) TDoubleVec trend; for (core_t::TTime time = 0; time < 100 * WEEK + 1; time += HALF_HOUR) { - double weekly = 1200.0 + 1000.0 * ::sin(boost::math::double_constants::two_pi + double weekly = 1200.0 + 1000.0 * std::sin(boost::math::double_constants::two_pi * static_cast(time) / static_cast(WEEK)); - double daily = 5.0 + 5.0 * ::sin(boost::math::double_constants::two_pi + double daily = 5.0 + 5.0 * std::sin(boost::math::double_constants::two_pi * static_cast(time) / static_cast(DAY)); times.push_back(time); @@ -128,11 +128,11 @@ void CTimeSeriesDecompositionTest::testSuperpositionOfSines(void) for (core_t::TTime t = lastWeek; t < lastWeek + WEEK; t += HALF_HOUR) { TDoubleDoublePr baseline = decomposition.baseline(t, 70.0); - double residual = ::fabs(trend[t / HALF_HOUR] - mean(baseline)); + double residual = std::fabs(trend[t / HALF_HOUR] - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(trend[t / HALF_HOUR]); - maxValue = std::max(maxValue, ::fabs(trend[t / HALF_HOUR])); + sumValue += std::fabs(trend[t / HALF_HOUR]); + maxValue = std::max(maxValue, std::fabs(trend[t / HALF_HOUR])); percentileError += std::max(std::max(baseline.first - trend[t / HALF_HOUR], trend[t / HALF_HOUR] - baseline.second), 0.0); //f.push_back(mean(baseline)); @@ -296,11 +296,11 @@ void CTimeSeriesDecompositionTest::testDistortedPeriodic(void) { TDoubleDoublePr baseline = decomposition.baseline(tt, 70.0); - double residual = ::fabs(timeseries[tt / HOUR] - mean(baseline)); + double residual = std::fabs(timeseries[tt / HOUR] - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(timeseries[tt / HOUR]); - maxValue = std::max(maxValue, ::fabs(timeseries[tt / HOUR])); + sumValue += std::fabs(timeseries[tt / HOUR]); + maxValue = std::max(maxValue, std::fabs(timeseries[tt / HOUR])); percentileError += std::max(std::max(baseline.first - timeseries[tt / HOUR], timeseries[tt / HOUR] - baseline.second), 0.0); @@ -358,7 +358,7 @@ void CTimeSeriesDecompositionTest::testMinimizeLongComponents(void) for (core_t::TTime time = 0; time < 100 * WEEK; time += HALF_HOUR) { double weight = weights[(time / DAY) % 7]; - double daily = 100.0 * ::sin(boost::math::double_constants::two_pi + double daily = 100.0 * std::sin(boost::math::double_constants::two_pi * static_cast(time) / static_cast(DAY)); times.push_back(time); @@ -410,11 +410,11 @@ void CTimeSeriesDecompositionTest::testMinimizeLongComponents(void) { TDoubleDoublePr baseline = decomposition.baseline(t, 70.0); - double residual = ::fabs(trend[t / HALF_HOUR] - mean(baseline)); + double residual = std::fabs(trend[t / HALF_HOUR] - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(trend[t / HALF_HOUR]); - maxValue = std::max(maxValue, ::fabs(trend[t / HALF_HOUR])); + sumValue += std::fabs(trend[t / HALF_HOUR]); + maxValue = std::max(maxValue, std::fabs(trend[t / HALF_HOUR])); percentileError += std::max(std::max(baseline.first - trend[t / HALF_HOUR], trend[t / HALF_HOUR] - baseline.second), 0.0); @@ -487,7 +487,7 @@ void CTimeSeriesDecompositionTest::testWeekend(void) for (core_t::TTime time = 0; time < 100 * WEEK; time += HALF_HOUR) { double weight = weights[(time / DAY) % 7]; - double daily = 100.0 * ::sin(boost::math::double_constants::two_pi + double daily = 100.0 * std::sin(boost::math::double_constants::two_pi * static_cast(time) / static_cast(DAY)); times.push_back(time); @@ -537,11 +537,11 @@ void CTimeSeriesDecompositionTest::testWeekend(void) { TDoubleDoublePr baseline = decomposition.baseline(t, 70.0); - double residual = ::fabs(trend[t / HALF_HOUR] - mean(baseline)); + double residual = std::fabs(trend[t / HALF_HOUR] - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(trend[t / HALF_HOUR]); - maxValue = std::max(maxValue, ::fabs(trend[t / HALF_HOUR])); + sumValue += std::fabs(trend[t / HALF_HOUR]); + maxValue = std::max(maxValue, std::fabs(trend[t / HALF_HOUR])); percentileError += std::max(std::max(baseline.first - trend[t / HALF_HOUR], trend[t / HALF_HOUR] - baseline.second), 0.0); @@ -594,7 +594,7 @@ void CTimeSeriesDecompositionTest::testSinglePeriodicity(void) TDoubleVec trend; for (core_t::TTime time = 0; time < 10 * WEEK + 1; time += HALF_HOUR) { - double daily = 100.0 + 100.0 * ::sin(boost::math::double_constants::two_pi + double daily = 100.0 + 100.0 * std::sin(boost::math::double_constants::two_pi * static_cast(time) / static_cast(DAY)); times.push_back(time); @@ -648,11 +648,11 @@ void CTimeSeriesDecompositionTest::testSinglePeriodicity(void) { TDoubleDoublePr baseline = decomposition.baseline(t, 70.0); - double residual = ::fabs(trend[t / HALF_HOUR] + noiseMean - mean(baseline)); + double residual = std::fabs(trend[t / HALF_HOUR] + noiseMean - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(trend[t / HALF_HOUR]); - maxValue = std::max(maxValue, ::fabs(trend[t / HALF_HOUR])); + sumValue += std::fabs(trend[t / HALF_HOUR]); + maxValue = std::max(maxValue, std::fabs(trend[t / HALF_HOUR])); percentileError += std::max(std::max(baseline.first - (trend[t / HALF_HOUR] + noiseMean), (trend[t / HALF_HOUR] + noiseMean) - baseline.second), 0.0); @@ -780,11 +780,11 @@ void CTimeSeriesDecompositionTest::testSeasonalOnset(void) { TDoubleDoublePr baseline = decomposition.baseline(t, 70.0); - double residual = ::fabs(trend[t / HOUR] - mean(baseline)); + double residual = std::fabs(trend[t / HOUR] - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(trend[t / HOUR]); - maxValue = std::max(maxValue, ::fabs(trend[t / HOUR])); + sumValue += std::fabs(trend[t / HOUR]); + maxValue = std::max(maxValue, std::fabs(trend[t / HOUR])); percentileError += std::max(std::max(baseline.first - trend[t / HOUR], trend[t / HOUR] - baseline.second), 0.0); //f.push_back(mean(baseline)); @@ -891,7 +891,7 @@ void CTimeSeriesDecompositionTest::testVarianceScale(void) << ", expectedScale = " << expectedScale << ", scale = " << core::CContainerPrinter::print(interval)); double scale = (interval.first + interval.second) / 2.0; - error.add(::fabs(scale - expectedScale)); + error.add(std::fabs(scale - expectedScale)); meanScale.add(scale); percentileError.add(std::max(std::max(interval.first - expectedScale, expectedScale - interval.second), 0.0)); @@ -913,7 +913,7 @@ void CTimeSeriesDecompositionTest::testVarianceScale(void) { for (core_t::TTime t = 0; t < DAY; t += TEN_MINS) { - double baseline = 5.0 * ::sin(boost::math::double_constants::two_pi + double baseline = 5.0 * std::sin(boost::math::double_constants::two_pi * static_cast(t) / static_cast(DAY)); double variance = 1.0; @@ -946,7 +946,7 @@ void CTimeSeriesDecompositionTest::testVarianceScale(void) << ", expectedScale = " << expectedScale << ", scale = " << core::CContainerPrinter::print(interval)); double scale = (interval.first + interval.second) / 2.0; - error.add(::fabs(scale - expectedScale)); + error.add(std::fabs(scale - expectedScale)); meanScale.add(scale); percentileError.add(std::max(std::max(interval.first - expectedScale, expectedScale - interval.second), 0.0)); @@ -969,10 +969,10 @@ void CTimeSeriesDecompositionTest::testVarianceScale(void) { times.push_back(time); double x = static_cast(time); - trend.push_back(150.0 + 100.0 * ::sin( boost::math::double_constants::two_pi * x + trend.push_back(150.0 + 100.0 * std::sin( boost::math::double_constants::two_pi * x / static_cast(240 * DAY) / (1.0 - x / static_cast(2 * length))) - + 10.0 * ::sin( boost::math::double_constants::two_pi * x + + 10.0 * std::sin( boost::math::double_constants::two_pi * x / static_cast(DAY))); } @@ -1052,11 +1052,11 @@ void CTimeSeriesDecompositionTest::testSpikeyDataProblemCase(void) { TDoubleDoublePr baseline = decomposition.baseline(lastWeekTimeseries[j].first, 70.0); - double residual = ::fabs(lastWeekTimeseries[j].second - mean(baseline)); + double residual = std::fabs(lastWeekTimeseries[j].second - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(lastWeekTimeseries[j].second); - maxValue = std::max(maxValue, ::fabs(lastWeekTimeseries[j].second)); + sumValue += std::fabs(lastWeekTimeseries[j].second); + maxValue = std::max(maxValue, std::fabs(lastWeekTimeseries[j].second)); percentileError += std::max(std::max(baseline.first - lastWeekTimeseries[j].second, lastWeekTimeseries[j].second - baseline.second), 0.0); } @@ -1132,7 +1132,7 @@ void CTimeSeriesDecompositionTest::testSpikeyDataProblemCase(void) //raw.push_back(value); //baseline.push_back(mean(decomposition.baseline(time, 70.0))); //scales.push_back(mean(decomposition.scale(time, variance, 70.0))); - //probs.push_back(-::log(pScaled)); + //probs.push_back(-std::log(pScaled)); model.probabilityOfLessLikelySamples( maths_t::E_TwoSided, @@ -1215,11 +1215,11 @@ void CTimeSeriesDecompositionTest::testDiurnalProblemCase(void) { TDoubleDoublePr baseline = decomposition.baseline(lastWeekTimeseries[j].first, 70.0); - double residual = ::fabs(lastWeekTimeseries[j].second - mean(baseline)); + double residual = std::fabs(lastWeekTimeseries[j].second - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(lastWeekTimeseries[j].second); - maxValue = std::max(maxValue, ::fabs(lastWeekTimeseries[j].second)); + sumValue += std::fabs(lastWeekTimeseries[j].second); + maxValue = std::max(maxValue, std::fabs(lastWeekTimeseries[j].second)); percentileError += std::max(std::max(baseline.first - lastWeekTimeseries[j].second, lastWeekTimeseries[j].second - baseline.second), 0.0); @@ -1341,11 +1341,11 @@ void CTimeSeriesDecompositionTest::testComplexDiurnalProblemCase(void) { TDoubleDoublePr baseline = decomposition.baseline(lastWeekTimeseries[j].first, 70.0); - double residual = ::fabs(lastWeekTimeseries[j].second - mean(baseline)); + double residual = std::fabs(lastWeekTimeseries[j].second - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(lastWeekTimeseries[j].second); - maxValue = std::max(maxValue, ::fabs(lastWeekTimeseries[j].second)); + sumValue += std::fabs(lastWeekTimeseries[j].second); + maxValue = std::max(maxValue, std::fabs(lastWeekTimeseries[j].second)); percentileError += std::max(std::max(baseline.first - lastWeekTimeseries[j].second, lastWeekTimeseries[j].second - baseline.second), 0.0); @@ -1432,10 +1432,10 @@ void CTimeSeriesDecompositionTest::testDiurnalPeriodicityWithMissingValues(void) decomposition.addPoint(time, value + noise[0]); if (decomposition.initialized()) { - error.add(::fabs( + error.add(std::fabs( ( value + noise[0] - maths::CBasicStatistics::mean(decomposition.baseline(time, 0.0)))) - / ::fabs(value + noise[0])); + / std::fabs(value + noise[0])); } //times.push_back(time); //values.push_back(value + noise[0]); @@ -1491,10 +1491,10 @@ void CTimeSeriesDecompositionTest::testDiurnalPeriodicityWithMissingValues(void) decomposition.addPoint(time, value + noise[0]); if (decomposition.initialized()) { - error.add(::fabs( + error.add(std::fabs( ( value + noise[0] - maths::CBasicStatistics::mean(decomposition.baseline(time, 0.0)))) - / ::fabs(value + noise[0])); + / std::fabs(value + noise[0])); } //times.push_back(time); //values.push_back(value + noise[0]); @@ -1573,11 +1573,11 @@ void CTimeSeriesDecompositionTest::testLongTermTrend(void) { TDoubleDoublePr baseline = decomposition.baseline(times[j], 70.0); baselines.push_back(mean(baseline)); - double residual = ::fabs(trend[j] - mean(baseline)); + double residual = std::fabs(trend[j] - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(trend[j]); - maxValue = std::max(maxValue, ::fabs(trend[j])); + sumValue += std::fabs(trend[j]); + maxValue = std::max(maxValue, std::fabs(trend[j])); } LOG_DEBUG("'sum residual' / 'sum value' = " @@ -1664,11 +1664,11 @@ void CTimeSeriesDecompositionTest::testLongTermTrend(void) { TDoubleDoublePr baseline = decomposition.baseline(times[j], 70.0); baselines.push_back(mean(baseline)); - double residual = ::fabs(trend[j] - mean(baseline)); + double residual = std::fabs(trend[j] - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(trend[j]); - maxValue = std::max(maxValue, ::fabs(trend[j])); + sumValue += std::fabs(trend[j]); + maxValue = std::max(maxValue, std::fabs(trend[j])); } LOG_DEBUG("'sum residual' / 'sum value' = " @@ -1718,10 +1718,10 @@ void CTimeSeriesDecompositionTest::testLongTermTrendAndPeriodicity(void) { times.push_back(time); double x = static_cast(time); - trend.push_back(150.0 + 100.0 * ::sin( boost::math::double_constants::two_pi * x + trend.push_back(150.0 + 100.0 * std::sin( boost::math::double_constants::two_pi * x / static_cast(240 * DAY) / (1.0 - x / static_cast(2 * length))) - + 10.0 * ::sin( boost::math::double_constants::two_pi * x + + 10.0 * std::sin( boost::math::double_constants::two_pi * x / static_cast(DAY))); } @@ -1763,11 +1763,11 @@ void CTimeSeriesDecompositionTest::testLongTermTrendAndPeriodicity(void) { TDoubleDoublePr baseline = decomposition.baseline(times[j], 70.0); baselines.push_back(mean(baseline)); - double residual = ::fabs(trend[j] - mean(baseline)); + double residual = std::fabs(trend[j] - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(trend[j]); - maxValue = std::max(maxValue, ::fabs(trend[j])); + sumValue += std::fabs(trend[j]); + maxValue = std::max(maxValue, std::fabs(trend[j])); } LOG_DEBUG("'sum residual' / 'sum value' = " @@ -1867,11 +1867,11 @@ void CTimeSeriesDecompositionTest::testNonDiurnal(void) { TDoubleDoublePr baseline = decomposition.baseline(times[j], 70.0); baselines.push_back(mean(baseline)); - double residual = ::fabs(trends[t][j] - mean(baseline)); + double residual = std::fabs(trends[t][j] - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(trends[t][j]); - maxValue = std::max(maxValue, ::fabs(trends[t][j])); + sumValue += std::fabs(trends[t][j]); + maxValue = std::max(maxValue, std::fabs(trends[t][j])); } LOG_DEBUG("'sum residual' / 'sum value' = " @@ -1959,11 +1959,11 @@ void CTimeSeriesDecompositionTest::testNonDiurnal(void) { TDoubleDoublePr baseline = decomposition.baseline(times[j], 70.0); baselines.push_back(mean(baseline)); - double residual = ::fabs(trend[j] - mean(baseline)); + double residual = std::fabs(trend[j] - mean(baseline)); sumResidual += residual; maxResidual = std::max(maxResidual, residual); - sumValue += ::fabs(trend[j]); - maxValue = std::max(maxValue, ::fabs(trend[j])); + sumValue += std::fabs(trend[j]); + maxValue = std::max(maxValue, std::fabs(trend[j])); } LOG_DEBUG("'sum residual' / 'sum value' = " @@ -2017,10 +2017,10 @@ void CTimeSeriesDecompositionTest::testYearly(void) core_t::TTime time = 0; for (/**/; time < 4 * YEAR; time += 4 * HOUR) { - double trend = 15.0 * (2.0 + ::sin( boost::math::double_constants::two_pi + double trend = 15.0 * (2.0 + std::sin( boost::math::double_constants::two_pi * static_cast(time) / static_cast(YEAR))) - + 7.5 * ::sin( boost::math::double_constants::two_pi + + 7.5 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / static_cast(DAY)); rng.generateNormalSamples(0.0, 1.0, 1, noise); @@ -2045,14 +2045,14 @@ void CTimeSeriesDecompositionTest::testYearly(void) TMeanAccumulator meanError; for (/**/; time < 5 * YEAR; time += 4 * HOUR) { - double trend = 15.0 * (2.0 + ::sin( boost::math::double_constants::two_pi + double trend = 15.0 * (2.0 + std::sin( boost::math::double_constants::two_pi * static_cast(time) / static_cast(YEAR))) - + 7.5 * ::sin( boost::math::double_constants::two_pi + + 7.5 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / static_cast(DAY)); double prediction = maths::CBasicStatistics::mean(decomposition.baseline(time, 0.0)); - double error = ::fabs((prediction - trend) / trend); + double error = std::fabs((prediction - trend) / trend); meanError.add(error); times.push_back(time); values.push_back(trend); @@ -2096,7 +2096,7 @@ void CTimeSeriesDecompositionTest::testCalendar(void) auto trend = [&months, &errors](core_t::TTime t) { - double result = 20.0 + 10.0 * ::sin( boost::math::double_constants::two_pi + double result = 20.0 + 10.0 * std::sin( boost::math::double_constants::two_pi * static_cast(t) / static_cast(DAY)); auto i = std::lower_bound(months.begin(), months.end(), t - DAY); @@ -2136,7 +2136,7 @@ void CTimeSeriesDecompositionTest::testCalendar(void) double prediction = maths::CBasicStatistics::mean(decomposition.baseline(time_)); double variance = 4.0 * maths::CBasicStatistics::mean(decomposition.scale(time_, 4.0, 0.0)); double actual = trend(time_); - if (::fabs(prediction - actual) / ::sqrt(variance) > 3.0) + if (std::fabs(prediction - actual) / std::sqrt(variance) > 3.0) { LOG_DEBUG(" prediction = " << prediction); LOG_DEBUG(" variance = " << variance); @@ -2185,7 +2185,7 @@ void CTimeSeriesDecompositionTest::testConditionOfTrend(void) decomposition.addPoint(time, trend(time) + noise[0]); if (time > 10 * WEEK) { - CPPUNIT_ASSERT(::fabs(decomposition.detrend(time, trend(time), 0.0)) < 3.0); + CPPUNIT_ASSERT(std::fabs(decomposition.detrend(time, trend(time), 0.0)) < 3.0); } } } @@ -2204,7 +2204,7 @@ void CTimeSeriesDecompositionTest::testSwap(void) TDoubleVec trend2; for (core_t::TTime time = 0; time < 10 * WEEK + 1; time += HALF_HOUR) { - double daily = 15.0 + 10.0 * ::sin(boost::math::double_constants::two_pi + double daily = 15.0 + 10.0 * std::sin(boost::math::double_constants::two_pi * static_cast(time) / static_cast(DAY)); times.push_back(time); @@ -2250,7 +2250,7 @@ void CTimeSeriesDecompositionTest::testPersist(void) TDoubleVec trend; for (core_t::TTime time = 0; time < 10 * WEEK + 1; time += HALF_HOUR) { - double daily = 15.0 + 10.0 * ::sin(boost::math::double_constants::two_pi + double daily = 15.0 + 10.0 * std::sin(boost::math::double_constants::two_pi * static_cast(time) / static_cast(DAY)); times.push_back(time); diff --git a/lib/maths/unittest/CTimeSeriesModelTest.cc b/lib/maths/unittest/CTimeSeriesModelTest.cc index 6c9cd99eb4..1100994120 100644 --- a/lib/maths/unittest/CTimeSeriesModelTest.cc +++ b/lib/maths/unittest/CTimeSeriesModelTest.cc @@ -348,7 +348,7 @@ void CTimeSeriesModelTest::testMode(void) core_t::TTime time{0}; for (auto &sample : samples) { - sample += 20.0 + 10.0 * ::sin( boost::math::double_constants::two_pi + sample += 20.0 + 10.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / static_cast(core::constants::DAY)); time += bucketLength; @@ -471,7 +471,7 @@ void CTimeSeriesModelTest::testMode(void) double amplitude{10.0}; for (std::size_t i = 0u; i < sample.size(); ++i) { - sample[i] += 30.0 + amplitude * ::sin( boost::math::double_constants::two_pi + sample[i] += 30.0 + amplitude * std::sin( boost::math::double_constants::two_pi * static_cast(time) / static_cast(core::constants::DAY)); amplitude += 4.0; @@ -774,7 +774,7 @@ void CTimeSeriesModelTest::testAddSamples(void) core_t::TTime time{0}; for (auto noise : samples) { - double sample{20.0 + 4.0 * ::sin( boost::math::double_constants::two_pi + double sample{20.0 + 4.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / 86400.0) + (time / bucketLength > 1800 ? 10.0 : 0.0) + noise}; @@ -866,7 +866,7 @@ void CTimeSeriesModelTest::testAddSamples(void) double amplitude{10.0}; for (std::size_t i = 0u; i < sample.size(); ++i) { - sample[i] = 30.0 + amplitude * ::sin( boost::math::double_constants::two_pi + sample[i] = 30.0 + amplitude * std::sin( boost::math::double_constants::two_pi * static_cast(time) / 86400.0) + (time / bucketLength > 1800 ? 10.0 : 0.0) + sample[i]; reinitialize |= trends[i]->addPoint(time, sample[i]); @@ -960,7 +960,7 @@ void CTimeSeriesModelTest::testPredict(void) core_t::TTime time{0}; for (auto sample : samples) { - sample += 10.0 + 5.0 * ::sin( boost::math::double_constants::two_pi + sample += 10.0 + 5.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / 86400.0); maths::CModelAddSamplesParams params; @@ -992,7 +992,7 @@ void CTimeSeriesModelTest::testPredict(void) TMeanAccumulator meanError; for (core_t::TTime time_ = time; time_ < time + 86400; time_ += 3600) { - double trend_{10.0 + 5.0 * ::sin( boost::math::double_constants::two_pi + double trend_{10.0 + 5.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time_) / 86400.0)}; double expected{ maths::CBasicStatistics::mean(trend.baseline(time_)) + maths::CBasicStatistics::mean(prior.marginalLikelihoodConfidenceInterval(0.0))}; @@ -1076,7 +1076,7 @@ void CTimeSeriesModelTest::testPredict(void) { for (auto &coordinate : sample) { - coordinate += 10.0 + 5.0 * ::sin( boost::math::double_constants::two_pi + coordinate += 10.0 + 5.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / 86400.0); } bool reinitialize{false}; @@ -1112,7 +1112,7 @@ void CTimeSeriesModelTest::testPredict(void) maths::CMultivariatePrior::TSizeDoublePr10Vec condition; for (std::size_t i = 0u; i < mean.size(); ++i) { - double trend_{mean[i] + 10.0 + 5.0 * ::sin( boost::math::double_constants::two_pi + double trend_{mean[i] + 10.0 + 5.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time_) / 86400.0)}; maths::CMultivariatePrior::TUnivariatePriorPtr margin{prior.univariate(marginalize, condition).first}; double expected{ maths::CBasicStatistics::mean(trends[i]->baseline(time_)) @@ -1232,7 +1232,7 @@ void CTimeSeriesModelTest::testProbability(void) .trendWeights(weight) .priorWeights(weight); - double trend{5.0 + 5.0 * ::sin( boost::math::double_constants::two_pi + double trend{5.0 + 5.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / 86400.0)}; models[0].addSamples(params, {core::make_triple(time, TDouble2Vec{sample}, TAG)}); @@ -1349,7 +1349,7 @@ void CTimeSeriesModelTest::testProbability(void) TDouble2Vec sample_(sample); models[0].addSamples(params, {core::make_triple(time, sample_, TAG)}); - double trend{5.0 + 5.0 * ::sin( boost::math::double_constants::two_pi + double trend{5.0 + 5.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / 86400.0)}; for (auto &component : sample_) { @@ -1531,7 +1531,7 @@ void CTimeSeriesModelTest::testWeights(void) core_t::TTime time{0}; for (auto sample : samples) { - double scale{10.0 + 5.0 * ::sin( boost::math::double_constants::two_pi + double scale{10.0 + 5.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / 86400.0)}; sample = scale * (1.0 + 0.1 * sample); @@ -1564,7 +1564,7 @@ void CTimeSeriesModelTest::testWeights(void) TMeanAccumulator error; for (core_t::TTime time_ = time; time_ < time + 86400; time_ += 3600) { - double dataScale{::pow(1.0 + 0.5 * ::sin( boost::math::double_constants::two_pi + double dataScale{std::pow(1.0 + 0.5 * std::sin( boost::math::double_constants::two_pi * static_cast(time_) / 86400.0), 2.0)}; double expectedScale{trend.scale(time_, prior.marginalLikelihoodVariance(), 0.0).second}; @@ -1614,7 +1614,7 @@ void CTimeSeriesModelTest::testWeights(void) core_t::TTime time{0}; for (auto &sample : samples) { - double scale{10.0 + 5.0 * ::sin( boost::math::double_constants::two_pi + double scale{10.0 + 5.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / 86400.0)}; bool reinitialize{false}; @@ -1646,7 +1646,7 @@ void CTimeSeriesModelTest::testWeights(void) TMeanAccumulator error; for (core_t::TTime time_ = time; time_ < time + 86400; time_ += 3600) { - double dataScale{::pow(1.0 + 0.5 * ::sin( boost::math::double_constants::two_pi + double dataScale{std::pow(1.0 + 0.5 * std::sin( boost::math::double_constants::two_pi * static_cast(time_) / 86400.0), 2.0)}; for (std::size_t i = 0u; i < 3; ++i) @@ -1711,7 +1711,7 @@ void CTimeSeriesModelTest::testMemoryUsage(void) .weightStyles(maths::CConstantWeights::COUNT) .trendWeights(weights) .priorWeights(weights); - sample += 10.0 + 5.0 * ::sin( boost::math::double_constants::two_pi + sample += 10.0 + 5.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / 86400.0); trend.addPoint(time, sample); model->addSamples(params, {core::make_triple(time, TDouble2Vec{sample}, TAG)}); @@ -1753,7 +1753,7 @@ void CTimeSeriesModelTest::testMemoryUsage(void) .priorWeights(weights); for (auto &coordinate : sample) { - coordinate += 10.0 + 5.0 * ::sin( boost::math::double_constants::two_pi + coordinate += 10.0 + 5.0 * std::sin( boost::math::double_constants::two_pi * static_cast(time) / 86400.0); } trend.addPoint(time, sample[0]); @@ -2153,7 +2153,7 @@ void CTimeSeriesModelTest::testAnomalyModel(void) for (const auto &anomaly : mostAnomalous) { anomalyBuckets.push_back(anomaly.second); - anomalyProbabilities.push_back(::exp(anomaly.first)); + anomalyProbabilities.push_back(std::exp(anomaly.first)); } LOG_DEBUG("anomalies = " << core::CContainerPrinter::print(anomalyBuckets)); LOG_DEBUG("probabilities = " << core::CContainerPrinter::print(anomalyProbabilities)); @@ -2251,7 +2251,7 @@ void CTimeSeriesModelTest::testAnomalyModel(void) for (const auto &anomaly : mostAnomalous) { anomalyBuckets.push_back(anomaly.second); - anomalyProbabilities.push_back(::exp(anomaly.first)); + anomalyProbabilities.push_back(std::exp(anomaly.first)); } LOG_DEBUG("anomalies = " << core::CContainerPrinter::print(anomalyBuckets)); LOG_DEBUG("probabilities = " << core::CContainerPrinter::print(anomalyProbabilities)); diff --git a/lib/maths/unittest/CToolsTest.cc b/lib/maths/unittest/CToolsTest.cc index 65245bc00b..20610887f2 100644 --- a/lib/maths/unittest/CToolsTest.cc +++ b/lib/maths/unittest/CToolsTest.cc @@ -173,7 +173,7 @@ double numericalProbabilityOfLessLikelySampleImpl(const DISTRIBUTION &distributi LOG_TRACE("2) x1 = " << x1 << ", x2 = " << x2); // Binary search. - while (::fabs(x1 - x2) > eps) + while (std::fabs(x1 - x2) > eps) { double x3 = (x1 + x2) / 2.0; if (adapters::pdf(distribution, x3) > pdf) @@ -284,7 +284,7 @@ double numericalProbabilityOfLessLikelySample(const boost::math::beta_distributi double xmin = 1000.0 * std::numeric_limits::min(); if (a >= 1.0 && fx < CTools::safePdf(beta, xmin)) { - return ::exp( a * ::log(xmin) -::log(a) + return std::exp( a * std::log(xmin) -std::log(a) + boost::math::lgamma(a + b) - boost::math::lgamma(a) - boost::math::lgamma(b)) + CTools::safeCdfComplement(beta, x); } @@ -292,8 +292,8 @@ double numericalProbabilityOfLessLikelySample(const boost::math::beta_distributi double xmax = 1.0 - std::numeric_limits::epsilon(); if (b >= 1.0 && fx < CTools::safePdf(beta, xmax)) { - double y = ::exp(::log(boost::math::beta(a, b) * fx) / b); - return ::pow(y, b) / b / boost::math::beta(a, b) + CTools::safeCdf(beta, x); + double y = std::exp(std::log(boost::math::beta(a, b) * fx) / b); + return std::pow(y, b) / b / boost::math::beta(a, b) + CTools::safeCdf(beta, x); } return numericalProbabilityOfLessLikelySampleImpl(beta, x); @@ -393,12 +393,12 @@ class CLogPdf double operator()(double x) const { - return ::log(maths::pdf(m_Mixture, x)); + return std::log(maths::pdf(m_Mixture, x)); } bool operator()(double x, double &fx) const { - fx = ::log(maths::pdf(m_Mixture, x)); + fx = std::log(maths::pdf(m_Mixture, x)); return true; } @@ -506,11 +506,11 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) if (successFraction[i] <= 1.0) { // Monotone decreasing. - double x = ::fabs(::log(successProbability[j])); + double x = std::fabs(std::log(successProbability[j])); for (int l = 0; l < 10; ++l) { tail = maths_t::E_UndeterminedTail; - x = ::floor(2.0 * x + 0.5); + x = std::floor(2.0 * x + 0.5); p1 = CTools::safeCdfComplement(negativeBinomial, x) + CTools::safePdf(negativeBinomial, x); p2 = probabilityOfLessLikelySample(negativeBinomial, x, tail); @@ -531,19 +531,19 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) { offset /= 2.0; - double x = ::floor(m1 - offset); + double x = std::floor(m1 - offset); tail = maths_t::E_UndeterminedTail; p1 = numericalProbabilityOfLessLikelySample(negativeBinomial, x); p2 = probabilityOfLessLikelySample(negativeBinomial, x, tail); LOG_DEBUG("x = " << x << ", p1 = " << p1 << ", p2 = " << p2 - << ", log(p1) = " << ::log(p1) << ", log(p2) = " << ::log(p2)); - CPPUNIT_ASSERT(::fabs(p1 - p2) <= 0.02 * std::max(p1, p2) - || ::fabs(::log(p1) - ::log(p2)) <= 0.02 * ::fabs(std::min(::log(p1), ::log(p2)))); + << ", log(p1) = " << std::log(p1) << ", log(p2) = " << std::log(p2)); + CPPUNIT_ASSERT(std::fabs(p1 - p2) <= 0.02 * std::max(p1, p2) + || std::fabs(std::log(p1) - std::log(p2)) <= 0.02 * std::fabs(std::min(std::log(p1), std::log(p2)))); if (offset > 0.0) CPPUNIT_ASSERT_EQUAL(maths_t::E_LeftTail, tail); if (offset == 0.0) CPPUNIT_ASSERT_EQUAL(maths_t::E_MixedOrNeitherTail, tail); - x = ::ceil(m1 + offset); + x = std::ceil(m1 + offset); tail = maths_t::E_UndeterminedTail; p1 = numericalProbabilityOfLessLikelySample(negativeBinomial, x); p2 = probabilityOfLessLikelySample(negativeBinomial, x, tail); @@ -558,27 +558,27 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) { factor *= 2.0; - double x = ::floor(m1 / factor); + double x = std::floor(m1 / factor); tail = maths_t::E_UndeterminedTail; p1 = numericalProbabilityOfLessLikelySample(negativeBinomial, x); p2 = probabilityOfLessLikelySample(negativeBinomial, x, tail); LOG_DEBUG("x = " << x << ", p1 = " << p1 << ", p2 = " << p2 - << ", log(p1) = " << ::log(p1) << ", log(p2) = " << ::log(p2)); - CPPUNIT_ASSERT(::fabs(p1 - p2) <= 0.01 * std::max(p1, p2) - || ::fabs(::log(p1) - ::log(p2)) <= 0.05 * ::fabs(std::min(::log(p1), ::log(p2)))); + << ", log(p1) = " << std::log(p1) << ", log(p2) = " << std::log(p2)); + CPPUNIT_ASSERT(std::fabs(p1 - p2) <= 0.01 * std::max(p1, p2) + || std::fabs(std::log(p1) - std::log(p2)) <= 0.05 * std::fabs(std::min(std::log(p1), std::log(p2)))); if (x != m1) CPPUNIT_ASSERT_EQUAL(maths_t::E_LeftTail, tail); if (x == m1) CPPUNIT_ASSERT_EQUAL(maths_t::E_MixedOrNeitherTail, tail); - x = ::ceil(m1 * factor); + x = std::ceil(m1 * factor); tail = maths_t::E_UndeterminedTail; p1 = numericalProbabilityOfLessLikelySample(negativeBinomial, x); p2 = probabilityOfLessLikelySample(negativeBinomial, x, tail); LOG_DEBUG("x = " << x << ", p1 = " << p1 << ", p2 = " << p2 - << ", log(p1) = " << ::log(p1) << ", log(p2) = " << ::log(p2)); - CPPUNIT_ASSERT(::fabs(p1 - p2) <= 0.01 * std::max(p1, p2) - || ::fabs(::log(p1) - ::log(p2)) <= 0.05 * ::fabs(std::min(::log(p1), ::log(p2)))); + << ", log(p1) = " << std::log(p1) << ", log(p2) = " << std::log(p2)); + CPPUNIT_ASSERT(std::fabs(p1 - p2) <= 0.01 * std::max(p1, p2) + || std::fabs(std::log(p1) - std::log(p2)) <= 0.05 * std::fabs(std::min(std::log(p1), std::log(p2)))); if (x != m1) CPPUNIT_ASSERT_EQUAL(maths_t::E_RightTail, tail); if (x == m1) CPPUNIT_ASSERT_EQUAL(maths_t::E_MixedOrNeitherTail, tail); } @@ -594,8 +594,8 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) boost::math::lognormal_distribution<> logNormal(1.0, 0.5); tail = maths_t::E_UndeterminedTail; - p1 = -::log(numericalProbabilityOfLessLikelySample(logNormal, 0.3)); - p2 = -::log(probabilityOfLessLikelySample(logNormal, 0.3, tail)); + p1 = -std::log(numericalProbabilityOfLessLikelySample(logNormal, 0.3)); + p2 = -std::log(probabilityOfLessLikelySample(logNormal, 0.3, tail)); LOG_DEBUG("-log(p1) = " << p1 << ", -log(p2) = " << p2); CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 0.05 * std::max(p1, p2)); CPPUNIT_ASSERT_EQUAL(maths_t::E_LeftTail, tail); @@ -609,8 +609,8 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) CPPUNIT_ASSERT_EQUAL(maths_t::E_MixedOrNeitherTail, tail); tail = maths_t::E_UndeterminedTail; - p1 = -::log(numericalProbabilityOfLessLikelySample(logNormal, 12.0)); - p2 = -::log(probabilityOfLessLikelySample(logNormal, 12.0, tail)); + p1 = -std::log(numericalProbabilityOfLessLikelySample(logNormal, 12.0)); + p2 = -std::log(probabilityOfLessLikelySample(logNormal, 12.0, tail)); LOG_DEBUG("-log(p1) = " << p1 << ", -log(p2) = " << p2); CPPUNIT_ASSERT_DOUBLES_EQUAL(p1, p2, 0.01 * std::max(p1, p2)); CPPUNIT_ASSERT_EQUAL(maths_t::E_RightTail, tail); @@ -641,7 +641,7 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) if (m1 == 0.0) { // Monotone decreasing. - double x = ::exp(locations[j]) / 32.0; + double x = std::exp(locations[j]) / 32.0; tail = maths_t::E_UndeterminedTail; for (int l = 0; l < 10; ++l) { @@ -688,9 +688,9 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) p2 = probabilityOfLessLikelySample(logt, x, tail); LOG_DEBUG("x = " << x << ", p1 = " << p1 << ", p2 = " << p2 - << ", log(p1) = " << ::log(p1) << ", log(p2) = " << ::log(p2)); - CPPUNIT_ASSERT(::fabs(p1 - p2) <= 0.01 * std::max(p1, p2) - || ::fabs(::log(p1) - ::log(p2)) <= 0.05 * ::fabs(std::min(::log(p1), ::log(p2)))); + << ", log(p1) = " << std::log(p1) << ", log(p2) = " << std::log(p2)); + CPPUNIT_ASSERT(std::fabs(p1 - p2) <= 0.01 * std::max(p1, p2) + || std::fabs(std::log(p1) - std::log(p2)) <= 0.05 * std::fabs(std::min(std::log(p1), std::log(p2)))); CPPUNIT_ASSERT_EQUAL(maths_t::E_LeftTail, tail); x = m1 * factor; @@ -699,10 +699,10 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) p2 = probabilityOfLessLikelySample(logt, x, tail); LOG_DEBUG("x = " << x << ", p1 = " << p1 << ", p2 = " << p2 - << ", log(p1) = " << ::log(p1) << ", log(p2) = " << ::log(p2)); + << ", log(p1) = " << std::log(p1) << ", log(p2) = " << std::log(p2)); - CPPUNIT_ASSERT(::fabs(p1 - p2) <= 0.01 * std::max(p1, p2) - || ::fabs(::log(p1) - ::log(p2)) <= 0.05 * ::fabs(std::min(::log(p1), ::log(p2)))); + CPPUNIT_ASSERT(std::fabs(p1 - p2) <= 0.01 * std::max(p1, p2) + || std::fabs(std::log(p1) - std::log(p2)) <= 0.05 * std::fabs(std::min(std::log(p1), std::log(p2)))); CPPUNIT_ASSERT_EQUAL(maths_t::E_RightTail, tail); } } @@ -756,9 +756,9 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) p2 = probabilityOfLessLikelySample(gamma, x, tail); LOG_DEBUG("x = " << x << ", p1 = " << p1 << ", p2 = " << p2 - << ", log(p1) = " << ::log(p1) << ", log(p2) = " << ::log(p2)); - CPPUNIT_ASSERT(::fabs(p1 - p2) <= 0.06 * std::max(p1, p2) - || ::fabs(::log(p1) - ::log(p2)) <= 0.01 * ::fabs(std::min(::log(p1), ::log(p2)))); + << ", log(p1) = " << std::log(p1) << ", log(p2) = " << std::log(p2)); + CPPUNIT_ASSERT(std::fabs(p1 - p2) <= 0.06 * std::max(p1, p2) + || std::fabs(std::log(p1) - std::log(p2)) <= 0.01 * std::fabs(std::min(std::log(p1), std::log(p2)))); CPPUNIT_ASSERT_EQUAL(maths_t::E_LeftTail, tail); double y = (1.0 + offset) * m1; @@ -767,9 +767,9 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) p2 = probabilityOfLessLikelySample(gamma, y, tail); LOG_DEBUG("y = " << y << ", p1 = " << p1 << ", p2 = " << p2 - << ", log(p1) = " << ::log(p1) << ", log(p2) = " << ::log(p2)); - CPPUNIT_ASSERT(::fabs(p1 - p2) <= 0.06 * std::max(p1, p2) - || ::fabs(::log(p1) - ::log(p2)) <= 0.01 * ::fabs(std::min(::log(p1), ::log(p2)))); + << ", log(p1) = " << std::log(p1) << ", log(p2) = " << std::log(p2)); + CPPUNIT_ASSERT(std::fabs(p1 - p2) <= 0.06 * std::max(p1, p2) + || std::fabs(std::log(p1) - std::log(p2)) <= 0.01 * std::fabs(std::min(std::log(p1), std::log(p2)))); CPPUNIT_ASSERT_EQUAL(maths_t::E_RightTail, tail); } @@ -784,9 +784,9 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) p2 = probabilityOfLessLikelySample(gamma, x, tail); LOG_DEBUG("x = " << x << ", p1 = " << p1 << ", p2 = " << p2 - << ", log(p1) = " << ::log(p1) << ", log(p2) = " << ::log(p2)); - CPPUNIT_ASSERT(::fabs(p1 - p2) <= 0.1 * std::max(p1, p2) - || ::fabs(::log(p1) - ::log(p2)) <= 0.01 * ::fabs(std::min(::log(p1), ::log(p2)))); + << ", log(p1) = " << std::log(p1) << ", log(p2) = " << std::log(p2)); + CPPUNIT_ASSERT(std::fabs(p1 - p2) <= 0.1 * std::max(p1, p2) + || std::fabs(std::log(p1) - std::log(p2)) <= 0.01 * std::fabs(std::min(std::log(p1), std::log(p2)))); CPPUNIT_ASSERT_EQUAL(maths_t::E_LeftTail, tail); double y = factor * m1; @@ -795,9 +795,9 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) p2 = probabilityOfLessLikelySample(gamma, y, tail); LOG_DEBUG("y = " << y << ", p1 = " << p1 << ", p2 = " << p2 - << ", log(p1) = " << ::log(p1) << ", log(p2) = " << ::log(p2)); - CPPUNIT_ASSERT(::fabs(p1 - p2) <= 0.1 * std::max(p1, p2) - || ::fabs(::log(p1) - ::log(p2)) <= 0.01 * ::fabs(std::min(::log(p1), ::log(p2)))); + << ", log(p1) = " << std::log(p1) << ", log(p2) = " << std::log(p2)); + CPPUNIT_ASSERT(std::fabs(p1 - p2) <= 0.1 * std::max(p1, p2) + || std::fabs(std::log(p1) - std::log(p2)) <= 0.01 * std::fabs(std::min(std::log(p1), std::log(p2)))); CPPUNIT_ASSERT_EQUAL(maths_t::E_RightTail, tail); } } @@ -885,9 +885,9 @@ void CToolsTest::testProbabilityOfLessLikelySample(void) p2 = probabilityOfLessLikelySample(beta, xMinus, tail); LOG_DEBUG("x- = " << xMinus << ", p1 = " << p1 << ", p2 = " << p2 - << ", log(p1) = " << log(p1) << ", log(p2) = " << ::log(p2)); - CPPUNIT_ASSERT(::fabs(p1 - p2) <= 0.05 * std::max(p1, p2) - || ::fabs(::log(p1) - ::log(p2)) < 0.25 * ::fabs(std::min(::log(p1), ::log(p2)))); + << ", log(p1) = " << log(p1) << ", log(p2) = " << std::log(p2)); + CPPUNIT_ASSERT(std::fabs(p1 - p2) <= 0.05 * std::max(p1, p2) + || std::fabs(std::log(p1) - std::log(p2)) < 0.25 * std::fabs(std::min(std::log(p1), std::log(p2)))); if (maximum) CPPUNIT_ASSERT_EQUAL(maths_t::E_LeftTail, tail); if (!maximum) CPPUNIT_ASSERT_EQUAL(maths_t::E_MixedOrNeitherTail, tail); @@ -1070,7 +1070,7 @@ void CToolsTest::testMixtureProbabilityOfLessLikelySample(void) } else { - logFx = ::log(logFx); + logFx = std::log(logFx); } maths::CTools::CMixtureProbabilityOfLessLikelySample calculator(i, x[k], logFx, a, b); @@ -1095,8 +1095,8 @@ void CToolsTest::testMixtureProbabilityOfLessLikelySample(void) double p = pTails + calculator.calculate(logPdf, pTails); double pExpected = pTails; - CTruncatedPdf pdf(mixture, ::exp(logFx)); - for (double xi = a, l = 0, step = 0.5 * (b - a) / ::floor(b - a); + CTruncatedPdf pdf(mixture, std::exp(logFx)); + for (double xi = a, l = 0, step = 0.5 * (b - a) / std::floor(b - a); l < 2 * static_cast(b - a); xi += step, ++l) { @@ -1121,15 +1121,15 @@ void CToolsTest::testMixtureProbabilityOfLessLikelySample(void) } else if (pExpected > 1e-10) { - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(pExpected), ::log(p), 0.15 * ::fabs(::log(pExpected))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(pExpected), std::log(p), 0.15 * std::fabs(std::log(pExpected))); } else { - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(pExpected), ::log(p), 0.015 * ::fabs(::log(pExpected))); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(pExpected), std::log(p), 0.015 * std::fabs(std::log(pExpected))); } - meanError.add(::fabs(p - pExpected)); - meanLogError.add(::fabs(::log(p) - ::log(pExpected)) - / std::max(::fabs(::log(pExpected)), ::fabs(::log(p)))); + meanError.add(std::fabs(p - pExpected)); + meanLogError.add(std::fabs(std::log(p) - std::log(pExpected)) + / std::max(std::fabs(std::log(pExpected)), std::fabs(std::log(p)))); } } @@ -1221,7 +1221,7 @@ void CToolsTest::testSpread(void) } dcost /= 2.0 * eps; LOG_DEBUG("d(cost)/dx = " << dcost); - CPPUNIT_ASSERT(::fabs(dcost) < 2e-6); + CPPUNIT_ASSERT(std::fabs(dcost) < 2e-6); } } } @@ -1242,12 +1242,12 @@ void CToolsTest::testFastLog(void) { if (i % 100 == 0) { - LOG_DEBUG("x = " << ::exp(x[i]) + LOG_DEBUG("x = " << std::exp(x[i]) << ", log(x) = " << x[i] - << ", fast log(x) = " << maths::CTools::fastLog(::exp(x[i]))); + << ", fast log(x) = " << maths::CTools::fastLog(std::exp(x[i]))); } CPPUNIT_ASSERT_DOUBLES_EQUAL(x[i], - maths::CTools::fastLog(::exp(x[i])), + maths::CTools::fastLog(std::exp(x[i])), 5e-5); } } @@ -1260,10 +1260,10 @@ void CToolsTest::testFastLog(void) if (i % 100 == 0) { LOG_DEBUG("x = " << x[i] - << ", log(x) = " << ::log(x[i]) + << ", log(x) = " << std::log(x[i]) << ", fast log(x) = " << maths::CTools::fastLog(x[i])); } - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(x[i]), + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(x[i]), maths::CTools::fastLog(x[i]), 5e-5); } @@ -1276,12 +1276,12 @@ void CToolsTest::testFastLog(void) { if (i % 100 == 0) { - LOG_DEBUG("x = " << ::exp(x[i]) + LOG_DEBUG("x = " << std::exp(x[i]) << ", log(x) = " << x[i] - << ", fast log(x) = " << maths::CTools::fastLog(::exp(x[i]))); + << ", fast log(x) = " << maths::CTools::fastLog(std::exp(x[i]))); } CPPUNIT_ASSERT_DOUBLES_EQUAL(x[i], - maths::CTools::fastLog(::exp(x[i])), + maths::CTools::fastLog(std::exp(x[i])), 5e-5); } } diff --git a/lib/maths/unittest/CTrendTestsTest.cc b/lib/maths/unittest/CTrendTestsTest.cc index b83735d2d8..baded80fd6 100644 --- a/lib/maths/unittest/CTrendTestsTest.cc +++ b/lib/maths/unittest/CTrendTestsTest.cc @@ -148,7 +148,7 @@ void CTrendTestsTest::testRandomizedPeriodicity(void) LOG_DEBUG("time to detect moments = " << timeToDetectionMoments[i]); LOG_DEBUG("maximum time to detect = " << timeToDetectionMax[i][0]); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(timeToDetectionMoments[i]) < 1.5 * DAY); - CPPUNIT_ASSERT(::sqrt(maths::CBasicStatistics::variance(timeToDetectionMoments[i])) < 5 * DAY); + CPPUNIT_ASSERT(std::sqrt(maths::CBasicStatistics::variance(timeToDetectionMoments[i])) < 5 * DAY); CPPUNIT_ASSERT(timeToDetectionMax[i][0] <= 27 * WEEK); } } diff --git a/lib/maths/unittest/CXMeansOnline1dTest.cc b/lib/maths/unittest/CXMeansOnline1dTest.cc index d797d4b2df..afab490778 100644 --- a/lib/maths/unittest/CXMeansOnline1dTest.cc +++ b/lib/maths/unittest/CXMeansOnline1dTest.cc @@ -99,7 +99,7 @@ void CXMeansOnline1dTest::testCluster(void) double expectedCount = maths::CBasicStatistics::count(moments); double expectedCentre = maths::CBasicStatistics::mean(moments); - double expectedSpread = ::sqrt(maths::CBasicStatistics::variance(moments)); + double expectedSpread = std::sqrt(maths::CBasicStatistics::variance(moments)); LOG_DEBUG("expected count = " << expectedCount); LOG_DEBUG("expected centre = " << expectedCentre); LOG_DEBUG("expected spread = " << expectedSpread); @@ -128,7 +128,7 @@ void CXMeansOnline1dTest::testCluster(void) double expectedPercentile = values[static_cast(p / 100.0 * static_cast(values.size()) + 0.5)]; LOG_DEBUG(p << " percentile = " << cluster.percentile(p)); LOG_DEBUG(p << " expected percentile = " << expectedPercentile); - double error = ::fabs(cluster.percentile(p) - expectedPercentile); + double error = std::fabs(cluster.percentile(p) - expectedPercentile); CPPUNIT_ASSERT(error < 0.5); percentileError.add(error / expectedPercentile); } @@ -145,13 +145,13 @@ void CXMeansOnline1dTest::testCluster(void) sampleMoments.add(samples[i]); } double sampleCentre = maths::CBasicStatistics::mean(sampleMoments); - double sampleSpread = ::sqrt(maths::CBasicStatistics::variance(sampleMoments)); + double sampleSpread = std::sqrt(maths::CBasicStatistics::variance(sampleMoments)); LOG_DEBUG("sample centre = " << sampleCentre); LOG_DEBUG("sample spread = " << sampleSpread); CPPUNIT_ASSERT_DOUBLES_EQUAL(cluster.centre(), sampleCentre, 0.02); CPPUNIT_ASSERT_DOUBLES_EQUAL(cluster.spread(), sampleSpread, 0.2); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(cluster.count()), + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(cluster.count()), - cluster.logLikelihoodFromCluster(maths_t::E_ClustersEqualWeight, 1.5) + cluster.logLikelihoodFromCluster(maths_t::E_ClustersFractionWeight, 1.5), 1e-10); @@ -297,13 +297,13 @@ void CXMeansOnline1dTest::testMixtureOfGaussians(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedClusters[j]), clusters[j].centre(), 0.1); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), clusters[j].spread(), 0.4); - meanError += ::fabs(clusters[j].centre() + meanError += std::fabs(clusters[j].centre() - maths::CBasicStatistics::mean(expectedClusters[j])); - spreadError += ::fabs(clusters[j].spread() - - ::sqrt(maths::CBasicStatistics::variance(expectedClusters[j]))); + spreadError += std::fabs(clusters[j].spread() + - std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j]))); } } @@ -362,7 +362,7 @@ void CXMeansOnline1dTest::testMixtureOfGaussians(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedClusters), clusters[0].centre(), 0.05); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::sqrt(maths::CBasicStatistics::variance(expectedClusters)), + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(maths::CBasicStatistics::variance(expectedClusters)), clusters[0].spread(), 0.3); } @@ -427,13 +427,13 @@ void CXMeansOnline1dTest::testMixtureOfGaussians(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedClusters[j]), clusters[j].centre(), 0.4); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), clusters[j].spread(), 0.3); - meanError += ::fabs(clusters[j].centre() + meanError += std::fabs(clusters[j].centre() - maths::CBasicStatistics::mean(expectedClusters[j])); - spreadError += ::fabs(clusters[j].spread() - - ::sqrt(maths::CBasicStatistics::variance(expectedClusters[j]))); + spreadError += std::fabs(clusters[j].spread() + - std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j]))); } } @@ -512,13 +512,13 @@ void CXMeansOnline1dTest::testMixtureOfUniforms(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(maths::CBasicStatistics::mean(expectedClusters[j]), clusters[j].centre(), 0.01); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), clusters[j].spread(), 0.02); - meanError += ::fabs(clusters[j].centre() + meanError += std::fabs(clusters[j].centre() - maths::CBasicStatistics::mean(expectedClusters[j])); - spreadError += ::fabs(clusters[j].spread() - - ::sqrt(maths::CBasicStatistics::variance(expectedClusters[j]))); + spreadError += std::fabs(clusters[j].spread() + - std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j]))); } } @@ -615,14 +615,14 @@ void CXMeansOnline1dTest::testMixtureOfLogNormals(void) clusters[j].centre(), 0.03 * std::max(maths::CBasicStatistics::mean(expectedClusters[j]), clusters[j].centre())); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), clusters[j].spread(), - 0.5 * std::max(::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), + 0.5 * std::max(std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), clusters[j].spread())); - meanError += ::fabs(clusters[j].centre() + meanError += std::fabs(clusters[j].centre() - maths::CBasicStatistics::mean(expectedClusters[j])); - spreadError += ::fabs(clusters[j].spread() - - ::sqrt(maths::CBasicStatistics::variance(expectedClusters[j]))); + spreadError += std::fabs(clusters[j].spread() + - std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j]))); } } @@ -707,14 +707,14 @@ void CXMeansOnline1dTest::testOutliers(void) clusters[j].centre(), 0.01 * std::max(maths::CBasicStatistics::mean(expectedClusters[j]), clusters[j].centre())); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), clusters[j].spread(), - 0.03 * std::max(::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), + 0.03 * std::max(std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j])), clusters[j].spread())); - meanError += ::fabs(clusters[j].centre() + meanError += std::fabs(clusters[j].centre() - maths::CBasicStatistics::mean(expectedClusters[j])); - spreadError += ::fabs(clusters[j].spread() - - ::sqrt(maths::CBasicStatistics::variance(expectedClusters[j]))); + spreadError += std::fabs(clusters[j].spread() + - std::sqrt(maths::CBasicStatistics::variance(expectedClusters[j]))); } } diff --git a/lib/maths/unittest/CXMeansOnlineTest.cc b/lib/maths/unittest/CXMeansOnlineTest.cc index 0549bc8d72..2aa87678e8 100644 --- a/lib/maths/unittest/CXMeansOnlineTest.cc +++ b/lib/maths/unittest/CXMeansOnlineTest.cc @@ -132,7 +132,7 @@ void CXMeansOnlineTest::testCluster(void) double expectedCount = maths::CBasicStatistics::count(moments); TPoint expectedCentre = maths::CBasicStatistics::mean(moments); - double expectedSpread = ::sqrt(maths::CBasicStatistics::maximumLikelihoodCovariances(moments).trace() / 2.0); + double expectedSpread = std::sqrt(maths::CBasicStatistics::maximumLikelihoodCovariances(moments).trace() / 2.0); LOG_DEBUG("expected count = " << expectedCount); LOG_DEBUG("expected centre = " << expectedCentre); LOG_DEBUG("expected spread = " << expectedSpread); @@ -163,13 +163,13 @@ void CXMeansOnlineTest::testCluster(void) sampleMoments.add(samples[i]); } TPoint sampleCentre = maths::CBasicStatistics::mean(sampleMoments); - double sampleSpread = ::sqrt(maths::CBasicStatistics::covariances(sampleMoments).trace() / 2.0); + double sampleSpread = std::sqrt(maths::CBasicStatistics::covariances(sampleMoments).trace() / 2.0); LOG_DEBUG("sample centre = " << sampleCentre); LOG_DEBUG("sample spread = " << sampleSpread); CPPUNIT_ASSERT((sampleCentre - cluster.centre()).euclidean() < 1e-10); CPPUNIT_ASSERT_DOUBLES_EQUAL(cluster.spread(), sampleSpread, 0.1); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::log(cluster.count()), + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::log(cluster.count()), - cluster.logLikelihoodFromCluster(maths_t::E_ClustersEqualWeight, TPoint(1.5)) + cluster.logLikelihoodFromCluster(maths_t::E_ClustersFractionWeight, TPoint(1.5)), 1e-10); @@ -574,10 +574,10 @@ void CXMeansOnlineTest::testManyClusters(void) { double lj; maths::gaussianLogLikelihood(covariances[j], samples[i] - means[j], lj); - lgenerating[i] += static_cast(sizes[j]) * ::exp(lj); + lgenerating[i] += static_cast(sizes[j]) * std::exp(lj); } lgenerating[i] /= Z; - differentialEntropy.add(-::log(lgenerating[i])); + differentialEntropy.add(-std::log(lgenerating[i])); } LOG_DEBUG("differentialEntropy = " << maths::CBasicStatistics::mean(differentialEntropy)); @@ -609,10 +609,10 @@ void CXMeansOnlineTest::testManyClusters(void) const TMatrix &covariance = maths::CBasicStatistics::maximumLikelihoodCovariances(clusters[j].covariances()); double lj; maths::gaussianLogLikelihood(covariance, samples[i] - mean, lj); - l += n * ::exp(lj); + l += n * std::exp(lj); } l /= Z; - loss.add(::log(lgenerating[i]) - ::log(l)); + loss.add(std::log(lgenerating[i]) - std::log(l)); } LOG_DEBUG("loss = " << maths::CBasicStatistics::mean(loss)); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(loss) < 0.02 * maths::CBasicStatistics::mean(differentialEntropy)); @@ -859,11 +859,11 @@ void CXMeansOnlineTest::testLatLongData(void) TMatrix covariance = maths::CBasicStatistics::covariances(clusters[j].covariances()); double llj; maths::gaussianLogLikelihood(covariance, x - mean, llj); - ll += w * ::exp(llj); + ll += w * std::exp(llj); Z += w; } ll /= Z; - LLC.add(::log(ll)); + LLC.add(std::log(ll)); } } diff --git a/lib/maths/unittest/CXMeansTest.cc b/lib/maths/unittest/CXMeansTest.cc index feb759b9ce..ef5e65afc8 100644 --- a/lib/maths/unittest/CXMeansTest.cc +++ b/lib/maths/unittest/CXMeansTest.cc @@ -91,7 +91,7 @@ double logfSphericalGaussian(const POINT &mean, { double d = static_cast(x.dimension()); double r = (x - mean).euclidean(); - return -0.5 * d * ::log(boost::math::double_constants::two_pi * variance) + return -0.5 * d * std::log(boost::math::double_constants::two_pi * variance) -0.5 * r * r / variance; } @@ -101,7 +101,7 @@ class CEmpiricalKullbackLeibler double value(void) const { return maths::CBasicStatistics::mean(m_Divergence) - - ::log(maths::CBasicStatistics::count(m_Divergence)); + - std::log(maths::CBasicStatistics::count(m_Divergence)); } template @@ -555,12 +555,12 @@ void CXMeansTest::testFiveClusters(void) LOG_DEBUG("mean number clusters = " << maths::CBasicStatistics::mean(meanNumberClusters)); LOG_DEBUG("sd number clusters = " - << ::sqrt(maths::CBasicStatistics::variance(meanNumberClusters))); + << std::sqrt(maths::CBasicStatistics::variance(meanNumberClusters))); LOG_DEBUG("KL gain = " << maths::CBasicStatistics::mean(klgain)); LOG_DEBUG("mean total purity = " << maths::CBasicStatistics::mean(meanTotalPurity)); CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, maths::CBasicStatistics::mean(meanNumberClusters), 0.3); - CPPUNIT_ASSERT(::sqrt(maths::CBasicStatistics::variance(meanNumberClusters)) < 0.9); + CPPUNIT_ASSERT(std::sqrt(maths::CBasicStatistics::variance(meanNumberClusters)) < 0.9); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(klgain) > -0.1); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(meanTotalPurity) > 0.93); } @@ -680,7 +680,7 @@ void CXMeansTest::testTwentyClusters(void) LOG_DEBUG("totalPurity = " << maths::CBasicStatistics::mean(totalPurity)); CPPUNIT_ASSERT_DOUBLES_EQUAL(20.0, static_cast(xmeans.clusters().size()), 6.0); - CPPUNIT_ASSERT(klc.value() < kl.value() + 0.05 * std::max(::fabs(klc.value()), ::fabs(kl.value()))); + CPPUNIT_ASSERT(klc.value() < kl.value() + 0.05 * std::max(std::fabs(klc.value()), std::fabs(kl.value()))); CPPUNIT_ASSERT(minPurity > 0.4); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(totalPurity) > 0.8); } diff --git a/lib/maths/unittest/TestUtils.cc b/lib/maths/unittest/TestUtils.cc index b09967fcc9..9544dfab4f 100644 --- a/lib/maths/unittest/TestUtils.cc +++ b/lib/maths/unittest/TestUtils.cc @@ -287,8 +287,8 @@ bool CPriorTestInterface::marginalLikelihoodMeanForTest(double &result) const if (m_Prior->dataType() == maths_t::E_IntegerData) { - b = ::ceil(b); - a = ::floor(a); + b = std::ceil(b); + a = std::floor(a); steps = static_cast(b - a) + 1; } @@ -331,8 +331,8 @@ bool CPriorTestInterface::marginalLikelihoodVarianceForTest(double &result) cons if (m_Prior->dataType() == maths_t::E_IntegerData) { - b = ::ceil(b); - a = ::floor(a); + b = std::ceil(b); + a = std::floor(a); steps = static_cast(b - a) + 1; } diff --git a/lib/model/CAnomalyScore.cc b/lib/model/CAnomalyScore.cc index c9c9b46578..bb31cc068d 100644 --- a/lib/model/CAnomalyScore.cc +++ b/lib/model/CAnomalyScore.cc @@ -181,12 +181,12 @@ bool CAnomalyScore::compute(double jointProbabilityWeight, return false; } - double logMaximumAnomalousProbability = ::log(maximumAnomalousProbability); + double logMaximumAnomalousProbability = std::log(maximumAnomalousProbability); if ( logPJoint > logMaximumAnomalousProbability && logPExtreme > logMaximumAnomalousProbability) { - overallProbability = ::exp(jointProbabilityWeight * logPJoint) - * ::exp(extremeProbabilityWeight * logPExtreme); + overallProbability = std::exp(jointProbabilityWeight * logPJoint) + * std::exp(extremeProbabilityWeight * logPExtreme); return true; } @@ -194,7 +194,7 @@ bool CAnomalyScore::compute(double jointProbabilityWeight, // [e^-100000, 1]. static const double NORMAL_RANGE_SCORE_FRACTION = 0.8; - static const double LOG_SMALLEST_PROBABILITY = ::log(maths::CTools::smallestProbability()); + static const double LOG_SMALLEST_PROBABILITY = std::log(maths::CTools::smallestProbability()); static const double SMALLEST_PROBABILITY_DEVIATION = probabilityToScore(maths::CTools::smallestProbability()); static const double SMALLEST_LOG_JOINT_PROBABILTY = -100000.0; static const double SMALLEST_LOG_EXTREME_PROBABILTY = -1500.0; @@ -213,7 +213,7 @@ bool CAnomalyScore::compute(double jointProbabilityWeight, { overallAnomalyScore = NORMAL_RANGE_SCORE_FRACTION * jointProbabilityWeight - * probabilityToScore(::exp(logPJoint)); + * probabilityToScore(std::exp(logPJoint)); } if (logPExtreme < LOG_SMALLEST_PROBABILITY) @@ -230,7 +230,7 @@ bool CAnomalyScore::compute(double jointProbabilityWeight, { overallAnomalyScore += NORMAL_RANGE_SCORE_FRACTION * extremeProbabilityWeight - * probabilityToScore(::exp(logPExtreme)); + * probabilityToScore(std::exp(logPExtreme)); } // Invert the deviation in the region it is 1-to-1 otherwise @@ -239,8 +239,8 @@ bool CAnomalyScore::compute(double jointProbabilityWeight, scoreToProbability(std::min( overallAnomalyScore / NORMAL_RANGE_SCORE_FRACTION, SMALLEST_PROBABILITY_DEVIATION)) : - ::exp(jointProbabilityWeight * logPJoint) - * ::exp(extremeProbabilityWeight * logPExtreme); + std::exp(jointProbabilityWeight * logPJoint) + * std::exp(extremeProbabilityWeight * logPExtreme); LOG_TRACE("logJointProbability = " << logPJoint << ", jointProbabilityWeight = " << jointProbabilityWeight @@ -428,8 +428,8 @@ bool CAnomalyScore::CNormalizer::normalize(double &score) const double lowerBound; double upperBound; this->quantile(score, CONFIDENCE_INTERVAL, lowerBound, upperBound); - double lowerPercentile = 100.0 * ::pow(lowerBound, 1.0 / m_BucketNormalizationFactor); - double upperPercentile = 100.0 * ::pow(upperBound, 1.0 / m_BucketNormalizationFactor); + double lowerPercentile = 100.0 * std::pow(lowerBound, 1.0 / m_BucketNormalizationFactor); + double upperPercentile = 100.0 * std::pow(upperBound, 1.0 / m_BucketNormalizationFactor); if (lowerPercentile > upperPercentile) { std::swap(lowerPercentile, upperPercentile); @@ -500,11 +500,11 @@ bool CAnomalyScore::CNormalizer::normalize(double &score) const // largest significant and small probability. static const double M = ( probabilityToScore(maths::SMALL_PROBABILITY) - probabilityToScore(maths::LARGEST_SIGNIFICANT_PROBABILITY)) - / ( ::log(maths::SMALL_PROBABILITY) - - ::log(maths::LARGEST_SIGNIFICANT_PROBABILITY)); - static const double C = ::log(maths::LARGEST_SIGNIFICANT_PROBABILITY); + / ( std::log(maths::SMALL_PROBABILITY) + - std::log(maths::LARGEST_SIGNIFICANT_PROBABILITY)); + static const double C = std::log(maths::LARGEST_SIGNIFICANT_PROBABILITY); normalizedScores[3] = m_MaximumNormalizedScore - * (0.95 * M * (::log(scoreToProbability(score)) - C) + 0.05); + * (0.95 * M * (std::log(scoreToProbability(score)) - C) + 0.05); LOG_TRACE("normalizedScores[3] = " << normalizedScores[3] << ", score = " << score << ", probability = " << scoreToProbability(score)); @@ -806,7 +806,7 @@ void CAnomalyScore::CNormalizer::propagateForwardByTime(double time) return; } - double alpha = ::exp(-2.0 * m_DecayRate * time); + double alpha = std::exp(-2.0 * m_DecayRate * time); m_MaxScore.age(alpha); // Quantiles age at a much slower rate than everything else so that @@ -815,7 +815,7 @@ void CAnomalyScore::CNormalizer::propagateForwardByTime(double time) m_TimeToQuantileDecay -= time; if (m_TimeToQuantileDecay <= 0.0) { - time = ::floor( (QUANTILE_DECAY_TIME - m_TimeToQuantileDecay) + time = std::floor( (QUANTILE_DECAY_TIME - m_TimeToQuantileDecay) / QUANTILE_DECAY_TIME); uint64_t n = m_RawScoreQuantileSummary.n(); @@ -829,7 +829,7 @@ void CAnomalyScore::CNormalizer::propagateForwardByTime(double time) * static_cast(m_HighPercentileCount) + 0.5); } m_TimeToQuantileDecay += QUANTILE_DECAY_TIME - + ::floor(-m_TimeToQuantileDecay / QUANTILE_DECAY_TIME); + + std::floor(-m_TimeToQuantileDecay / QUANTILE_DECAY_TIME); } } diff --git a/lib/model/CDetectorEqualizer.cc b/lib/model/CDetectorEqualizer.cc index c46f676b3a..6c2fd1c727 100644 --- a/lib/model/CDetectorEqualizer.cc +++ b/lib/model/CDetectorEqualizer.cc @@ -137,7 +137,7 @@ double CDetectorEqualizer::correct(int detector, double probability) double alpha = maths::CTools::truncate((logp - A) / (B - A), 0.0, 1.0); LOG_TRACE("Corrected log(p) = " << -alpha * logpc - (1.0 - alpha) * logp); - return ::exp(-alpha * logpc - (1.0 - alpha) * logp); + return std::exp(-alpha * logpc - (1.0 - alpha) * logp); } return probability; diff --git a/lib/model/CInterimBucketCorrector.cc b/lib/model/CInterimBucketCorrector.cc index dcda5d477f..5f7e4a4d21 100644 --- a/lib/model/CInterimBucketCorrector.cc +++ b/lib/model/CInterimBucketCorrector.cc @@ -69,7 +69,7 @@ void CInterimBucketCorrector::update(core_t::TTime time, std::size_t bucketCount m_CountTrend.addPoint(bucketMidPoint, static_cast(bucketCount)); - double alpha = ::exp(-meanDecayRate(m_BucketLength)); + double alpha = std::exp(-meanDecayRate(m_BucketLength)); m_CountMean.age(alpha); m_CountMean.add(bucketCount); } diff --git a/lib/model/CMetricBucketGatherer.cc b/lib/model/CMetricBucketGatherer.cc index 546d2b1962..2e58ef21b0 100644 --- a/lib/model/CMetricBucketGatherer.cc +++ b/lib/model/CMetricBucketGatherer.cc @@ -1662,7 +1662,7 @@ void CMetricBucketGatherer::startNewBucket(core_t::TTime time, bool skipUpdates) TUInt64Vec{0}).first->second[0] += CDataGatherer::extractData(count); } } - double alpha = ::exp(-m_DataGatherer.params().s_DecayRate); + double alpha = std::exp(-m_DataGatherer.params().s_DecayRate); for (auto &count : counts) { diff --git a/lib/model/CPopulationModel.cc b/lib/model/CPopulationModel.cc index 41bf9ee57b..9442c33dff 100644 --- a/lib/model/CPopulationModel.cc +++ b/lib/model/CPopulationModel.cc @@ -257,7 +257,7 @@ void CPopulationModel::sample(core_t::TTime startTime, } } - double alpha = ::exp(-this->params().s_DecayRate * 1.0); + double alpha = std::exp(-this->params().s_DecayRate * 1.0); for (std::size_t cid = 0u; cid < m_PersonAttributeBucketCounts.size(); ++cid) { m_PersonAttributeBucketCounts[cid].age(alpha); diff --git a/lib/model/CProbabilityAndInfluenceCalculator.cc b/lib/model/CProbabilityAndInfluenceCalculator.cc index 59dbb6f866..376fc04d4b 100644 --- a/lib/model/CProbabilityAndInfluenceCalculator.cc +++ b/lib/model/CProbabilityAndInfluenceCalculator.cc @@ -448,7 +448,7 @@ void doComputeInfluences(model_t::EFeature feature, LOG_TRACE("log(p) = " << logp << ", tail = " << core::CContainerPrinter::print(tail) << ", v(i) = " << core::CContainerPrinter::print(influencedValue) - << ", log(p(i)) = " << ::log(pi) + << ", log(p(i)) = " << std::log(pi) << ", weight = " << core::CContainerPrinter::print(params.weights()) << ", influence = " << influence << ", influencer field value = " << i->first.get()); @@ -525,7 +525,7 @@ void doComputeCorrelateInfluences(model_t::EFeature feature, TTail2Vec tail; TSize1Vec mostAnomalousCorrelate; - double logp = ::log(probability); + double logp = std::log(probability); TDouble2Vec4Vec1Vec weights(params.weights()); for (const auto &influence_ : influencerValues) { @@ -549,11 +549,11 @@ void doComputeCorrelateInfluences(model_t::EFeature feature, pi = maths::CTools::truncate(pi, maths::CTools::smallestProbability(), 1.0); pi = model_t::adjustProbability(feature, elapsedTime, pi); - double influence = computeInfluence(logp, ::log(pi)); + double influence = computeInfluence(logp, std::log(pi)); LOG_TRACE("log(p) = " << logp << ", v(i) = " << core::CContainerPrinter::print(influencedValue) - << ", log(p(i)) = " << ::log(pi) + << ", log(p(i)) = " << std::log(pi) << ", weight(i) = " << core::CContainerPrinter::print(params.weights()) << ", influence = " << influence << ", influencer field value = " << influence_.first.get()); @@ -798,7 +798,7 @@ void CProbabilityAndInfluenceCalculator::addInfluences(const std::string &influe } } - double logp = ::log(std::max(params.s_Probability, maths::CTools::smallestProbability())); + double logp = std::log(std::max(params.s_Probability, maths::CTools::smallestProbability())); params.s_InfluencerName = canonical(influencerName); params.s_InfluencerValues = influencerValues; @@ -843,7 +843,7 @@ void CProbabilityAndInfluenceCalculator::addInfluences(const std::string &influe } } - double logp = ::log(std::max(params.s_Probability, maths::CTools::smallestProbability())); + double logp = std::log(std::max(params.s_Probability, maths::CTools::smallestProbability())); params.s_InfluencerName = canonical(influencerName); params.s_InfluencerValues = influencerValues[params.s_MostAnomalousCorrelate[0]]; @@ -875,7 +875,7 @@ bool CProbabilityAndInfluenceCalculator::calculate(double &probability, LOG_TRACE("probability = " << probability); - double logp = ::log(probability); + double logp = std::log(probability); influences.reserve(m_InfluencerProbabilities.size()); for (const auto &aggregator : m_InfluencerProbabilities) @@ -887,7 +887,7 @@ bool CProbabilityAndInfluenceCalculator::calculate(double &probability, << core::CContainerPrinter::print(aggregator.first)); } LOG_TRACE("influence probability = " << probability_); - double influence = CInfluenceCalculator::intersectionInfluence(logp, ::log(probability_)); + double influence = CInfluenceCalculator::intersectionInfluence(logp, std::log(probability_)); if (influence >= m_Cutoff) { influences.emplace_back(aggregator.first, influence); @@ -911,7 +911,7 @@ void CProbabilityAndInfluenceCalculator::commitInfluences(model_t::EFeature feat m_ProbabilityTemplate).first->second; if (!model_t::isConstant(feature)) { - double probability = ::exp(influence.second * logp); + double probability = std::exp(influence.second * logp); LOG_TRACE("Adding = " << influence.first.second.get() << " " << probability); aggregator.add(probability, weight); } diff --git a/lib/model/CRuleCondition.cc b/lib/model/CRuleCondition.cc index b98ac64954..059700712b 100644 --- a/lib/model/CRuleCondition.cc +++ b/lib/model/CRuleCondition.cc @@ -215,7 +215,7 @@ bool CRuleCondition::checkCondition(const CAnomalyDetectorModel &model, } for (std::size_t i = 0; i < value.size(); ++i) { - value[i] = ::fabs(value[i] - typical[i]); + value[i] = std::fabs(value[i] - typical[i]); } break; } diff --git a/lib/model/ModelTypes.cc b/lib/model/ModelTypes.cc index 2803c1e976..f4dced9ec8 100644 --- a/lib/model/ModelTypes.cc +++ b/lib/model/ModelTypes.cc @@ -816,7 +816,7 @@ double emptyBucketCountWeight(EFeature feature, double frequency, double cutoff) { static const double M = 1.001; static const double C = 0.025; - static const double K = ::log((M + 1.0) / (M - 1.0)) / C; + static const double K = std::log((M + 1.0) / (M - 1.0)) / C; double df = frequency - std::min(cutoff + C, 1.0); if (df < -C) { @@ -824,7 +824,7 @@ double emptyBucketCountWeight(EFeature feature, double frequency, double cutoff) } else if (df < C) { - double fa = ::exp(K * df); + double fa = std::exp(K * df); return 0.5 * (1.0 + M * (fa - 1.0) / (fa + 1.0)); } } @@ -1198,11 +1198,11 @@ double adjustProbability(EFeature feature, case E_IndividualHighInfoContentByBucketAndPerson: break; case E_IndividualTimeOfDayByBucketAndPerson: - pNewCluster = ::exp(-pow4( static_cast(elapsedTime) + pNewCluster = std::exp(-pow4( static_cast(elapsedTime) / static_cast(core::constants::DAY))); break; case E_IndividualTimeOfWeekByBucketAndPerson: - pNewCluster = ::exp(-pow4( static_cast(elapsedTime) + pNewCluster = std::exp(-pow4( static_cast(elapsedTime) / static_cast(core::constants::WEEK))); break; @@ -1223,11 +1223,11 @@ double adjustProbability(EFeature feature, case E_PopulationHighInfoContentByBucketPersonAndAttribute: break; case E_PopulationTimeOfDayByBucketPersonAndAttribute: - pNewCluster = ::exp(-pow4( static_cast(elapsedTime) + pNewCluster = std::exp(-pow4( static_cast(elapsedTime) / static_cast(core::constants::DAY))); break; case E_PopulationTimeOfWeekByBucketPersonAndAttribute: - pNewCluster = ::exp(-pow4( static_cast(elapsedTime) + pNewCluster = std::exp(-pow4( static_cast(elapsedTime) / static_cast(core::constants::WEEK))); break; @@ -1246,11 +1246,11 @@ double adjustProbability(EFeature feature, case E_PeersHighInfoContentByBucketPersonAndAttribute: break; case E_PeersTimeOfDayByBucketPersonAndAttribute: - pNewCluster = ::exp(-pow4( static_cast(elapsedTime) + pNewCluster = std::exp(-pow4( static_cast(elapsedTime) / static_cast(core::constants::DAY))); break; case E_PeersTimeOfWeekByBucketPersonAndAttribute: - pNewCluster = ::exp(-pow4( static_cast(elapsedTime) + pNewCluster = std::exp(-pow4( static_cast(elapsedTime) / static_cast(core::constants::WEEK))); break; diff --git a/lib/model/unittest/CAnomalyScoreTest.cc b/lib/model/unittest/CAnomalyScoreTest.cc index 25d7d4f87b..d2c9b228e9 100644 --- a/lib/model/unittest/CAnomalyScoreTest.cc +++ b/lib/model/unittest/CAnomalyScoreTest.cc @@ -154,7 +154,7 @@ void CAnomalyScoreTest::testComputeScores(void) CPPUNIT_ASSERT(jointProbabilityCalculator.calculate(jointProbability)); double extremeProbability; CPPUNIT_ASSERT(extremeProbabilityCalculator.calculate(extremeProbability)); - extremeProbability = ::exp(extremeProbability); + extremeProbability = std::exp(extremeProbability); LOG_DEBUG("3) probabilities = " << core::CContainerPrinter::print(p)); LOG_DEBUG(" joint probability = " << jointProbability @@ -196,7 +196,7 @@ void CAnomalyScoreTest::testComputeScores(void) double extremeProbability; CPPUNIT_ASSERT(extremeProbabilityCalculator.calculate(extremeProbability)); - extremeProbability = ::exp(extremeProbability); + extremeProbability = std::exp(extremeProbability); LOG_DEBUG("4) probabilities = " << core::CContainerPrinter::print(probabilities)); LOG_DEBUG(" joint probability = " << jointProbability @@ -238,7 +238,7 @@ void CAnomalyScoreTest::testComputeScores(void) double extremeProbability; CPPUNIT_ASSERT(extremeProbabilityCalculator.calculate(extremeProbability)); - extremeProbability = ::exp(extremeProbability); + extremeProbability = std::exp(extremeProbability); LOG_DEBUG("5) probabilities = " << core::CContainerPrinter::print(probabilities)); LOG_DEBUG(" joint probability = " << jointProbability @@ -313,7 +313,7 @@ void CAnomalyScoreTest::testNormalizeScoresQuantiles(void) normalizer.quantile(samples[i], 0.0, lowerBound, upperBound); double quantile = (lowerBound + upperBound) / 2.0; - double error = ::fabs(quantile - trueQuantile); + double error = std::fabs(quantile - trueQuantile); totalError += error; numberSamples += 1.0; diff --git a/lib/model/unittest/CDetectorEqualizerTest.cc b/lib/model/unittest/CDetectorEqualizerTest.cc index e16ca90d83..bfe7e26f23 100644 --- a/lib/model/unittest/CDetectorEqualizerTest.cc +++ b/lib/model/unittest/CDetectorEqualizerTest.cc @@ -36,7 +36,7 @@ namespace { using TMeanAccumulator = maths::CBasicStatistics::SSampleMean::TAccumulator; -const double THRESHOLD = ::log(0.05); +const double THRESHOLD = std::log(0.05); } @@ -61,7 +61,7 @@ void CDetectorEqualizerTest::testCorrect(void) { if (-logp[j] <= THRESHOLD) { - double p = ::exp(-logp[j]); + double p = std::exp(-logp[j]); equalizer.add(static_cast(i), p); } } @@ -78,7 +78,7 @@ void CDetectorEqualizerTest::testCorrect(void) { if (-logp[j] <= THRESHOLD) { - double p = ::exp(-logp[j]); + double p = std::exp(-logp[j]); raw[i].push_back(p); corrected[i].push_back(equalizer.correct(static_cast(i), p)); } @@ -92,13 +92,13 @@ void CDetectorEqualizerTest::testCorrect(void) { double increase = maths::CStatisticalTests::twoSampleKS(corrected[i], corrected[j]) / maths::CStatisticalTests::twoSampleKS(raw[i], raw[j]); - similarityIncrease.add(::log(increase)); + similarityIncrease.add(std::log(increase)); LOG_DEBUG("similarity increase = " << increase); CPPUNIT_ASSERT(increase > 3.0); } } - LOG_DEBUG("mean similarity increase = " << ::exp(maths::CBasicStatistics::mean(similarityIncrease))); - CPPUNIT_ASSERT(::exp(maths::CBasicStatistics::mean(similarityIncrease)) > 40.0); + LOG_DEBUG("mean similarity increase = " << std::exp(maths::CBasicStatistics::mean(similarityIncrease))); + CPPUNIT_ASSERT(std::exp(maths::CBasicStatistics::mean(similarityIncrease)) > 40.0); } void CDetectorEqualizerTest::testAge(void) @@ -123,7 +123,7 @@ void CDetectorEqualizerTest::testAge(void) { if (-logp[j] <= THRESHOLD) { - double p = ::exp(-logp[j]); + double p = std::exp(-logp[j]); equalizer.add(static_cast(i), p); equalizerAged.add(static_cast(i), p); equalizerAged.age(0.995); @@ -136,19 +136,19 @@ void CDetectorEqualizerTest::testAge(void) TMeanAccumulator meanBias; TMeanAccumulator meanError; double logp = THRESHOLD; - for (std::size_t j = 0u; j < 150; ++j, logp += ::log(0.9)) + for (std::size_t j = 0u; j < 150; ++j, logp += std::log(0.9)) { - double p = ::exp(logp); + double p = std::exp(logp); double pc = equalizer.correct(i, p); double pca = equalizerAged.correct(i, p); - double error = ::fabs((::log(pca) - ::log(pc)) / ::log(pc)); + double error = std::fabs((std::log(pca) - std::log(pc)) / std::log(pc)); meanError.add(error); - meanBias.add((::log(pca) - ::log(pc)) / ::log(pc)); + meanBias.add((std::log(pca) - std::log(pc)) / std::log(pc)); CPPUNIT_ASSERT(error < 0.18); } LOG_DEBUG("mean bias = " << maths::CBasicStatistics::mean(meanBias)); LOG_DEBUG("mean error = " << maths::CBasicStatistics::mean(meanError)); - CPPUNIT_ASSERT(::fabs(maths::CBasicStatistics::mean(meanBias)) < 0.053); + CPPUNIT_ASSERT(std::fabs(maths::CBasicStatistics::mean(meanBias)) < 0.053); CPPUNIT_ASSERT(maths::CBasicStatistics::mean(meanError) < 0.053); } } @@ -174,7 +174,7 @@ void CDetectorEqualizerTest::testPersist(void) { if (-logp[j] <= THRESHOLD) { - double p = ::exp(-logp[j]); + double p = std::exp(-logp[j]); origEqualizer.add(static_cast(i), p); } } diff --git a/lib/model/unittest/CEventRateModelTest.cc b/lib/model/unittest/CEventRateModelTest.cc index bc7677d3b1..87a590a7a4 100644 --- a/lib/model/unittest/CEventRateModelTest.cc +++ b/lib/model/unittest/CEventRateModelTest.cc @@ -159,7 +159,7 @@ void generateSporadicEvents(const core_t::TTime &startTime, TDoubleVec gap; rng.generateUniformSamples(0.0, 10.0 * static_cast(bucketLength), 1u, gap); bucketStartTime += static_cast(bucketLength) - * ::ceil(gap[0] / static_cast(bucketLength)); + * std::ceil(gap[0] / static_cast(bucketLength)); } } @@ -2878,11 +2878,11 @@ void CEventRateModelTest::testDecayRateControl(void) } model->sample(t, t + bucketLength, m_ResourceMonitor); referenceModel->sample(t, t + bucketLength, m_ResourceMonitor); - meanPredictionError.add(::fabs( + meanPredictionError.add(std::fabs( model->currentBucketValue(feature, 0, 0, t + bucketLength / 2)[0] - model->baselineBucketMean(feature, 0, 0, type, NO_CORRELATES, t + bucketLength / 2)[0])); - meanReferencePredictionError.add(::fabs( + meanReferencePredictionError.add(std::fabs( referenceModel->currentBucketValue(feature, 0, 0, t + bucketLength / 2)[0] - referenceModel->baselineBucketMean(feature, 0, 0, type, NO_CORRELATES, t + bucketLength / 2)[0])); @@ -2923,7 +2923,7 @@ void CEventRateModelTest::testDecayRateControl(void) LOG_DEBUG("week " << t / core::constants::WEEK + 1); } - double rate = 10.0 * (1.0 + ::sin( boost::math::double_constants::two_pi + double rate = 10.0 * (1.0 + std::sin( boost::math::double_constants::two_pi * static_cast(t) / static_cast(core::constants::DAY))) * (t < 5 * core::constants::WEEK ? 1.0 : 2.0); @@ -2936,11 +2936,11 @@ void CEventRateModelTest::testDecayRateControl(void) } model->sample(t, t + bucketLength, m_ResourceMonitor); referenceModel->sample(t, t + bucketLength, m_ResourceMonitor); - meanPredictionError.add(::fabs( + meanPredictionError.add(std::fabs( model->currentBucketValue(feature, 0, 0, t + bucketLength / 2)[0] - model->baselineBucketMean(feature, 0, 0, type, NO_CORRELATES, t + bucketLength / 2)[0])); - meanReferencePredictionError.add(::fabs( + meanReferencePredictionError.add(std::fabs( referenceModel->currentBucketValue(feature, 0, 0, t + bucketLength / 2)[0] - referenceModel->baselineBucketMean(feature, 0, 0, type, NO_CORRELATES, t + bucketLength / 2)[0])); @@ -2982,10 +2982,10 @@ void CEventRateModelTest::testDecayRateControl(void) LOG_DEBUG("week " << t / core::constants::WEEK + 1); } - double rate = 10.0 * (1.0 + ::sin( boost::math::double_constants::two_pi + double rate = 10.0 * (1.0 + std::sin( boost::math::double_constants::two_pi * static_cast(t) / static_cast(core::constants::DAY))) - * (1.0 + ::sin( boost::math::double_constants::two_pi + * (1.0 + std::sin( boost::math::double_constants::two_pi * static_cast(t) / 10.0 / static_cast(core::constants::WEEK))); TDoubleVec noise; @@ -2997,11 +2997,11 @@ void CEventRateModelTest::testDecayRateControl(void) } model->sample(t, t + bucketLength, m_ResourceMonitor); referenceModel->sample(t, t + bucketLength, m_ResourceMonitor); - meanPredictionError.add(::fabs( + meanPredictionError.add(std::fabs( model->currentBucketValue(feature, 0, 0, t + bucketLength / 2)[0] - model->baselineBucketMean(feature, 0, 0, type, NO_CORRELATES, t + bucketLength / 2)[0])); - meanReferencePredictionError.add(::fabs( + meanReferencePredictionError.add(std::fabs( referenceModel->currentBucketValue(feature, 0, 0, t + bucketLength / 2)[0] - referenceModel->baselineBucketMean(feature, 0, 0, type, NO_CORRELATES, t + bucketLength / 2)[0])); diff --git a/lib/model/unittest/CEventRatePopulationModelTest.cc b/lib/model/unittest/CEventRatePopulationModelTest.cc index d4a55db351..2e5f48dddb 100644 --- a/lib/model/unittest/CEventRatePopulationModelTest.cc +++ b/lib/model/unittest/CEventRatePopulationModelTest.cc @@ -964,7 +964,7 @@ void CEventRatePopulationModelTest::testFrequency(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0 / static_cast(period[i]), populationModel->personFrequency(pid), 0.1 / static_cast(period[i])); - meanError.add(::fabs( populationModel->personFrequency(pid) + meanError.add(std::fabs( populationModel->personFrequency(pid) - 1.0 / static_cast(period[i]))); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(meanError)); diff --git a/lib/model/unittest/CHierarchicalResultsTest.cc b/lib/model/unittest/CHierarchicalResultsTest.cc index ba566484ed..bb75a726fd 100644 --- a/lib/model/unittest/CHierarchicalResultsTest.cc +++ b/lib/model/unittest/CHierarchicalResultsTest.cc @@ -447,12 +447,12 @@ class CProbabilityGatherer : public model::CHierarchicalResultsLevelSet(t) / static_cast(core::constants::DAY))) * (t < 5 * core::constants::WEEK ? 1.0 : 2.0); @@ -2477,10 +2477,10 @@ void CMetricModelTest::testDecayRateControl(void) LOG_DEBUG("week " << t / core::constants::WEEK + 1); } - double value = 10.0 * (1.0 + ::sin( boost::math::double_constants::two_pi + double value = 10.0 * (1.0 + std::sin( boost::math::double_constants::two_pi * static_cast(t) / static_cast(core::constants::DAY))) - * (1.0 + ::sin( boost::math::double_constants::two_pi + * (1.0 + std::sin( boost::math::double_constants::two_pi * static_cast(t) / 10.0 / static_cast(core::constants::WEEK))); TDoubleVec noise; diff --git a/lib/model/unittest/CMetricPopulationDataGathererTest.cc b/lib/model/unittest/CMetricPopulationDataGathererTest.cc index 3b83a05a7a..c3b17c94b7 100644 --- a/lib/model/unittest/CMetricPopulationDataGathererTest.cc +++ b/lib/model/unittest/CMetricPopulationDataGathererTest.cc @@ -701,7 +701,7 @@ void CMetricPopulationDataGathererTest::testFeatureData(void) sampleMinAccumulators[key].add(messages[i].s_Value); sampleMaxAccumulators[key].add(messages[i].s_Value); if (maths::CBasicStatistics::count(sampleMeanAccumulators[key]) - == ::floor(sampleCount + 0.5)) + == std::floor(sampleCount + 0.5)) { expectedMeanSamples[key].push_back( maths::CBasicStatistics::mean(sampleMeanAccumulators[key])); diff --git a/lib/model/unittest/CMetricPopulationModelTest.cc b/lib/model/unittest/CMetricPopulationModelTest.cc index 5e77de7f43..6cf9363315 100644 --- a/lib/model/unittest/CMetricPopulationModelTest.cc +++ b/lib/model/unittest/CMetricPopulationModelTest.cc @@ -267,7 +267,7 @@ void generateTestMessages(std::size_t dimension, double vd = values[l + d]; if (anomaly && (l % (2 * dimension)) == 0) { - vd += 6.0 * ::sqrt(variances[j]); + vd += 6.0 * std::sqrt(variances[j]); } value[d] = roundToNearestPersisted(vd); } @@ -1232,7 +1232,7 @@ void CMetricPopulationModelTest::testFrequency(void) CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0 / static_cast(period[i]), populationModel->personFrequency(pid), 0.1 / static_cast(period[i])); - meanError.add(::fabs( populationModel->personFrequency(pid) + meanError.add(std::fabs( populationModel->personFrequency(pid) - 1.0 / static_cast(period[i]))); } LOG_DEBUG("error = " << maths::CBasicStatistics::mean(meanError)); diff --git a/lib/model/unittest/CModelMemoryTest.cc b/lib/model/unittest/CModelMemoryTest.cc index f7cf8283b9..b2c7fa8923 100644 --- a/lib/model/unittest/CModelMemoryTest.cc +++ b/lib/model/unittest/CModelMemoryTest.cc @@ -148,7 +148,7 @@ void CModelMemoryTest::testOnlineMetricModel(void) double mean = 5.0; double variance = 2.0; std::size_t anomalousBucket = 12u; - double anomaly = 5 * ::sqrt(variance); + double anomaly = 5 * std::sqrt(variance); CDataGatherer::TFeatureVec features; features.push_back(model_t::E_IndividualMeanByPerson); diff --git a/lib/model/unittest/CProbabilityAndInfluenceCalculatorTest.cc b/lib/model/unittest/CProbabilityAndInfluenceCalculatorTest.cc index 423bee4911..2afad5d5b0 100644 --- a/lib/model/unittest/CProbabilityAndInfluenceCalculatorTest.cc +++ b/lib/model/unittest/CProbabilityAndInfluenceCalculatorTest.cc @@ -468,7 +468,7 @@ void CProbabilityAndInfluenceCalculatorTest::testLogProbabilityComplementInfluen core_t::TTime time{0}; for (auto &sample : samples) { - sample += 100.0 + 100.0 * ::sin(2.0 * 3.1416 * static_cast(time) / 86400.0); + sample += 100.0 + 100.0 * std::sin(2.0 * 3.1416 * static_cast(time) / 86400.0); time += bucketLength; } } @@ -590,8 +590,8 @@ void CProbabilityAndInfluenceCalculatorTest::testLogProbabilityComplementInfluen weight, coordinates, lbs, ubs, tail); - double lb = ::sqrt(lbs[0][0] * lbs[1][0]); - double ub = ::sqrt(ubs[0][0] * ubs[1][0]); + double lb = std::sqrt(lbs[0][0] * lbs[1][0]); + double ub = std::sqrt(ubs[0][0] * ubs[1][0]); TStrCRefDouble1VecDouble1VecPrPrVec influencerValues; influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i1), make_pair( 1.0, 1.0, 1.0, 1.0))); influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i2), make_pair( 1.0, 1.0, 1.0, 1.0))); @@ -625,7 +625,7 @@ void CProbabilityAndInfluenceCalculatorTest::testLogProbabilityComplementInfluen TDouble10Vec4Vec1Vec weight(1, TDouble10Vec4Vec(1, TDouble10Vec(2, 1.0))); for (core_t::TTime time = 0, i = 0; time < 10 * 86400; time += 600, ++i) { - double y = 100.0 + 100.0 * ::sin(2.0 * 3.1416 * static_cast(time) / 86400.0); + double y = 100.0 + 100.0 * std::sin(2.0 * 3.1416 * static_cast(time) / 86400.0); trend[0]->addPoint(time, y + samples[i][0]); trend[1]->addPoint(time, y + samples[i][0]); prior->addSamples(COUNT_WEIGHT, TDouble10Vec1Vec(1, TDouble10Vec(samples[i])), weight); @@ -679,8 +679,8 @@ void CProbabilityAndInfluenceCalculatorTest::testLogProbabilityComplementInfluen weight, coordinates, lbs, ubs, tail); - double lb = ::sqrt(lbs[0][0] * lbs[1][0]); - double ub = ::sqrt(ubs[0][0] * ubs[1][0]); + double lb = std::sqrt(lbs[0][0] * lbs[1][0]); + double ub = std::sqrt(ubs[0][0] * ubs[1][0]); LOG_DEBUG(" p = " << 0.5*(lb+ub) << ", tail = " << tail); TStoredStringPtrStoredStringPtrPrDoublePrVec influences; @@ -931,8 +931,8 @@ void CProbabilityAndInfluenceCalculatorTest::testMeanInfluenceCalculator(void) weights, coordinates, lbs, ubs, tail); - double lb = ::sqrt(lbs[0][0] * lbs[1][0]); - double ub = ::sqrt(ubs[0][0] * ubs[1][0]); + double lb = std::sqrt(lbs[0][0] * lbs[1][0]); + double ub = std::sqrt(ubs[0][0] * ubs[1][0]); TStrCRefDouble1VecDouble1VecPrPrVec influencerValues; influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i1), make_pair(10.0, 20.0, 5.0, 2.5))); influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i2), make_pair( 9.0, 9.0, 7.0, 3.5))); @@ -965,8 +965,8 @@ void CProbabilityAndInfluenceCalculatorTest::testMeanInfluenceCalculator(void) weight, coordinates, lbs, ubs, tail); - double lb = ::sqrt(lbs[0][0] * lbs[1][0]); - double ub = ::sqrt(ubs[0][0] * ubs[1][0]); + double lb = std::sqrt(lbs[0][0] * lbs[1][0]); + double ub = std::sqrt(ubs[0][0] * ubs[1][0]); TStrCRefDouble1VecDouble1VecPrPrVec influencerValues; influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i1), make_pair(10.0, 15.0, 2.0, 5.0))); influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i2), make_pair(12.0, 15.0, 2.0, 6.0))); @@ -997,8 +997,8 @@ void CProbabilityAndInfluenceCalculatorTest::testMeanInfluenceCalculator(void) weight, coordinates, lbs, ubs, tail); - double lb = ::sqrt(lbs[0][0] * lbs[1][0]); - double ub = ::sqrt(ubs[0][0] * ubs[1][0]); + double lb = std::sqrt(lbs[0][0] * lbs[1][0]); + double ub = std::sqrt(ubs[0][0] * ubs[1][0]); TStrCRefDouble1VecDouble1VecPrPrVec influencerValues; influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i1), make_pair(5.0, 5.0, 5.0, 5.0))); influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i2), make_pair(5.0, 5.0, 6.0, 5.0))); @@ -1029,8 +1029,8 @@ void CProbabilityAndInfluenceCalculatorTest::testMeanInfluenceCalculator(void) weight, coordinates, lbs, ubs, tail); - double lb = ::sqrt(lbs[0][0] * lbs[1][0]); - double ub = ::sqrt(ubs[0][0] * ubs[1][0]); + double lb = std::sqrt(lbs[0][0] * lbs[1][0]); + double ub = std::sqrt(ubs[0][0] * ubs[1][0]); TStrCRefDouble1VecDouble1VecPrPrVec influencerValues; influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i1), make_pair( 4.5, 10.0, 9.0, 4.0))); influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i2), make_pair(11.5, 11.0, 20.0, 4.0))); @@ -1140,7 +1140,7 @@ void CProbabilityAndInfluenceCalculatorTest::testLogProbabilityInfluenceCalculat core_t::TTime time{0}; for (auto &sample : samples) { - sample += 100.0 + 100.0 * ::sin(2.0 * 3.1416 * static_cast(time) / 86400.0); + sample += 100.0 + 100.0 * std::sin(2.0 * 3.1416 * static_cast(time) / 86400.0); time += bucketLength; } } @@ -1265,8 +1265,8 @@ void CProbabilityAndInfluenceCalculatorTest::testLogProbabilityInfluenceCalculat // weight, // coordinates, // lbs, ubs, tail); -// double lb = ::sqrt(lbs[0][0] * lbs[1][0]); -// double ub = ::sqrt(ubs[0][0] * ubs[1][0]); +// double lb = std::sqrt(lbs[0][0] * lbs[1][0]); +// double ub = std::sqrt(ubs[0][0] * ubs[1][0]); // TStrCRefDouble1VecDouble1VecPrPrVec influencerValues; // influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i1), make_pair(11.0, 9.0, 1.0, 1.0))); // influencerValues.push_back(TStrCRefDouble1VecDouble1VecPrPr(TStrCRef(i2), make_pair(10.0, 6.0, 1.0, 1.0))); @@ -1303,8 +1303,8 @@ void CProbabilityAndInfluenceCalculatorTest::testLogProbabilityInfluenceCalculat // { // double y[] = // { -// 200.0 + 200.0 * ::sin(2.0 * 3.1416 * static_cast(time) / 86400.0), -// 100.0 + 100.0 * ::sin(2.0 * 3.1416 * static_cast(time) / 86400.0) +// 200.0 + 200.0 * std::sin(2.0 * 3.1416 * static_cast(time) / 86400.0), +// 100.0 + 100.0 * std::sin(2.0 * 3.1416 * static_cast(time) / 86400.0) // }; // trend[0]->addPoint(time, y[0] + samples[i][0]); // trend[1]->addPoint(time, y[1] + samples[i][1]); @@ -1359,8 +1359,8 @@ void CProbabilityAndInfluenceCalculatorTest::testLogProbabilityInfluenceCalculat // weight, // coordinates, // lbs, ubs, tail); -// double lb = ::sqrt(lbs[0][0] * lbs[1][0]); -// double ub = ::sqrt(ubs[0][0] * ubs[1][0]); +// double lb = std::sqrt(lbs[0][0] * lbs[1][0]); +// double ub = std::sqrt(ubs[0][0] * ubs[1][0]); // LOG_DEBUG(" p = " << 0.5*(lb+ub) << ", tail = " << tail); // // TStoredStringPtrStoredStringPtrPrDoublePrVec influences; diff --git a/lib/model/unittest/CToolsTest.cc b/lib/model/unittest/CToolsTest.cc index 5fecb125f1..0a0aa257b1 100644 --- a/lib/model/unittest/CToolsTest.cc +++ b/lib/model/unittest/CToolsTest.cc @@ -157,7 +157,7 @@ void CToolsTest::testProbabilityAggregator(void) joint.calculate(pj); extreme.calculate(pe); LOG_DEBUG("pj = " << pj << " pe = " << pe << " pi = " << pi); - CPPUNIT_ASSERT_DOUBLES_EQUAL(::sqrt(pj) * ::sqrt(pe), pi, 1e-10); + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(pj) * std::sqrt(pe), pi, 1e-10); } } } diff --git a/lib/test/CRandomNumbers.cc b/lib/test/CRandomNumbers.cc index 5cb90782b8..b1eda18225 100644 --- a/lib/test/CRandomNumbers.cc +++ b/lib/test/CRandomNumbers.cc @@ -41,7 +41,7 @@ void CRandomNumbers::generateNormalSamples(double mean, std::size_t numberSamples, TDoubleVec &samples) { - boost::random::normal_distribution<> normal(mean, ::sqrt(variance)); + boost::random::normal_distribution<> normal(mean, std::sqrt(variance)); generateSamples(m_Generator, normal, numberSamples, samples); } @@ -112,7 +112,7 @@ void CRandomNumbers::generateLogNormalSamples(double location, std::size_t numberSamples, TDoubleVec &samples) { - boost::random::lognormal_distribution<> logNormal(location, ::sqrt(squareScale)); + boost::random::lognormal_distribution<> logNormal(location, std::sqrt(squareScale)); generateSamples(m_Generator, logNormal, numberSamples, samples); }