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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* Upgrade PyTorch to version 1.11. (See {ml-pull}2233[#2233], {ml-pull}2235[#2235]
and {ml-pull}2238[#2238].)
* Upgrade zlib to version 1.2.12 on Windows. (See {ml-pull}2253[#2253].)
* Address root cause for actuals equals typical equals zero anomalies. (See {ml-pull}2270[#2270].)

=== Bug Fixes

Expand Down
70 changes: 48 additions & 22 deletions include/maths/common/CLinearAlgebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <cmath>
#include <cstddef>
#include <numeric>

BOOST_GEOMETRY_REGISTER_STD_ARRAY_CS(cs::cartesian)

Expand Down Expand Up @@ -168,7 +169,7 @@ struct SSymmetricMatrix {
//! The Frobenius norm.
double frobenius(std::size_t d) const {
double result = 0.0;
for (std::size_t i = 0u, i_ = 0; i < d; ++i, ++i_) {
for (std::size_t i = 0, i_ = 0; i < d; ++i, ++i_) {
for (std::size_t j = 0; j < i; ++j, ++i_) {
result += 2.0 * m_LowerTriangle[i_] * m_LowerTriangle[i_];
}
Expand All @@ -177,10 +178,17 @@ struct SSymmetricMatrix {
return std::sqrt(result);
}

//! Get the mean of the matrix elements.
double mean(std::size_t d) const {
return (2.0 * std::accumulate(m_LowerTriangle.begin(), m_LowerTriangle.end(), 0.0) -
this->trace(d)) /
static_cast<double>(d * d);
}

//! Convert to the MATRIX representation.
template<typename MATRIX>
inline MATRIX& toType(std::size_t d, MATRIX& result) const {
for (std::size_t i = 0u, i_ = 0; i < d; ++i) {
for (std::size_t i = 0, i_ = 0; i < d; ++i) {
for (std::size_t j = 0; j <= i; ++j, ++i_) {
result(i, j) = result(j, i) = m_LowerTriangle[i_];
}
Expand Down Expand Up @@ -267,7 +275,7 @@ class CSymmetricMatrixNxN : private boost::equality_comparable< CSymmetricMatrix

//! Construct from C-style array of arrays.
explicit CSymmetricMatrixNxN(const TArray& m) {
for (std::size_t i = 0u, i_ = 0; i < N; ++i) {
for (std::size_t i = 0, i_ = 0; i < N; ++i) {
for (std::size_t j = 0; j <= i; ++j, ++i_) {
TBase::m_LowerTriangle[i_] = m[i][j];
}
Expand All @@ -276,7 +284,7 @@ class CSymmetricMatrixNxN : private boost::equality_comparable< CSymmetricMatrix

//! Construct from a vector of vectors.
explicit CSymmetricMatrixNxN(const TVecVec& m) {
for (std::size_t i = 0u, i_ = 0; i < N; ++i) {
for (std::size_t i = 0, i_ = 0; i < N; ++i) {
for (std::size_t j = 0; j <= i; ++j, ++i_) {
TBase::m_LowerTriangle[i_] = m[i][j];
}
Expand All @@ -286,7 +294,7 @@ class CSymmetricMatrixNxN : private boost::equality_comparable< CSymmetricMatrix
//! Construct from a small vector of small vectors.
template<std::size_t M>
explicit CSymmetricMatrixNxN(const core::CSmallVectorBase<core::CSmallVector<T, M>>& m) {
for (std::size_t i = 0u, i_ = 0; i < N; ++i) {
for (std::size_t i = 0, i_ = 0; i < N; ++i) {
for (std::size_t j = 0; j <= i; ++j, ++i_) {
TBase::m_LowerTriangle[i_] = m[i][j];
}
Expand Down Expand Up @@ -319,7 +327,7 @@ class CSymmetricMatrixNxN : private boost::equality_comparable< CSymmetricMatrix

//! Assignment if the underlying type is implicitly convertible.
template<typename U>
const CSymmetricMatrixNxN& operator=(const CSymmetricMatrixNxN<U, N>& other) {
CSymmetricMatrixNxN& operator=(const CSymmetricMatrixNxN<U, N>& other) {
this->assign(other.base());
return *this;
}
Expand Down Expand Up @@ -428,6 +436,9 @@ class CSymmetricMatrixNxN : private boost::equality_comparable< CSymmetricMatrix
//! Get the Frobenius norm.
double frobenius() const { return this->TBase::frobenius(N); }

//! Get the mean of the matrix elements.
double mean() const { return this->TBase::mean(N); }

//! Convert to a vector of vectors.
template<typename VECTOR_OF_VECTORS>
inline VECTOR_OF_VECTORS toVectors() const {
Expand All @@ -454,7 +465,7 @@ class CSymmetricMatrixNxN : private boost::equality_comparable< CSymmetricMatrix
}

//! Get a checksum for the matrix.
uint64_t checksum() const { return this->TBase::checksum(); }
std::uint64_t checksum() const { return this->TBase::checksum(); }
};

//! \brief Gets a constant symmetric matrix with specified dimension.
Expand Down Expand Up @@ -518,7 +529,7 @@ class CSymmetricMatrix : private boost::equality_comparable< CSymmetricMatrix<T>

public:
//! Set to multiple of ones matrix.
explicit CSymmetricMatrix(std::size_t d = 0u, T v = T(0)) : m_D(d) {
explicit CSymmetricMatrix(std::size_t d = 0, T v = T(0)) : m_D(d) {
if (d > 0) {
TBase::m_LowerTriangle.resize(d * (d + 1) / 2, v);
}
Expand All @@ -527,7 +538,7 @@ class CSymmetricMatrix : private boost::equality_comparable< CSymmetricMatrix<T>
//! Construct from C-style array of arrays.
explicit CSymmetricMatrix(const TArray& m) : m_D(m.size()) {
TBase::m_LowerTriangle.resize(m_D * (m_D + 1) / 2);
for (std::size_t i = 0u, i_ = 0; i < m_D; ++i) {
for (std::size_t i = 0, i_ = 0; i < m_D; ++i) {
for (std::size_t j = 0; j <= i; ++j, ++i_) {
TBase::m_LowerTriangle[i_] = m[i][j];
}
Expand All @@ -539,7 +550,7 @@ class CSymmetricMatrix : private boost::equality_comparable< CSymmetricMatrix<T>
explicit CSymmetricMatrix(const core::CSmallVectorBase<core::CSmallVector<T, M>>& m)
: m_D(m.size()) {
TBase::m_LowerTriangle.resize(m_D * (m_D + 1) / 2);
for (std::size_t i = 0u, i_ = 0; i < m_D; ++i) {
for (std::size_t i = 0, i_ = 0; i < m_D; ++i) {
for (std::size_t j = 0; j <= i; ++j, ++i_) {
TBase::m_LowerTriangle[i_] = m[i][j];
}
Expand Down Expand Up @@ -581,7 +592,7 @@ class CSymmetricMatrix : private boost::equality_comparable< CSymmetricMatrix<T>
//! \note Because this is template it is *not* an copy assignment
//! operator so this class has implicit move semantics.
template<typename U>
const CSymmetricMatrix& operator=(const CSymmetricMatrix<U>& other) {
CSymmetricMatrix& operator=(const CSymmetricMatrix<U>& other) {
m_D = other.m_D;
TBase::m_LowerTriangle.resize(m_D * (m_D + 1) / 2);
this->assign(other.base());
Expand Down Expand Up @@ -702,6 +713,9 @@ class CSymmetricMatrix : private boost::equality_comparable< CSymmetricMatrix<T>
//! The Frobenius norm.
double frobenius() const { return this->TBase::frobenius(m_D); }

//! Get the mean of the matrix elements.
double mean() const { return this->TBase::mean(m_D); }

//! Convert to a vector of vectors.
template<typename VECTOR_OF_VECTORS>
inline VECTOR_OF_VECTORS toVectors() const {
Expand All @@ -728,9 +742,9 @@ class CSymmetricMatrix : private boost::equality_comparable< CSymmetricMatrix<T>
}

//! Get a checksum for the matrix.
uint64_t checksum() const {
std::uint64_t checksum() const {
return core::CHashing::hashCombine(this->TBase::checksum(),
static_cast<uint64_t>(m_D));
static_cast<std::uint64_t>(m_D));
}

private:
Expand Down Expand Up @@ -867,6 +881,12 @@ struct SVector {
return result;
}

//! Get the mean of the vector components.
double mean() const {
return std::accumulate(m_X.begin(), m_X.end(), 0.0) /
static_cast<double>(m_X.size());
}

//! Convert to the VECTOR representation.
template<typename VECTOR>
inline VECTOR& toType(VECTOR& result) const {
Expand Down Expand Up @@ -1000,7 +1020,7 @@ class CVectorNx1 : private boost::equality_comparable< CVectorNx1<T, N>,

//! Assignment if the underlying type is implicitly convertible.
template<typename U>
const CVectorNx1& operator=(const CVectorNx1<U, N>& other) {
CVectorNx1& operator=(const CVectorNx1<U, N>& other) {
this->assign(other.base());
return *this;
}
Expand Down Expand Up @@ -1118,6 +1138,9 @@ class CVectorNx1 : private boost::equality_comparable< CVectorNx1<T, N>,
//! Euclidean norm.
double euclidean() const { return std::sqrt(this->inner(*this)); }

//! Get the mean of the vector components.
double mean() const { return this->TBase::mean(); }

//! Convert to a vector on a different underlying type.
template<typename U>
inline CVectorNx1<U, N> to() const {
Expand All @@ -1143,7 +1166,7 @@ class CVectorNx1 : private boost::equality_comparable< CVectorNx1<T, N>,
}

//! Get a checksum of this vector's components.
uint64_t checksum() const { return this->TBase::checksum(); }
std::uint64_t checksum() const { return this->TBase::checksum(); }

//! Get the smallest possible vector.
static const CVectorNx1& smallest() {
Expand All @@ -1164,14 +1187,14 @@ CSymmetricMatrixNxN<T, N>::CSymmetricMatrixNxN(ESymmetricMatrixType type,
const CVectorNx1<T, N>& x) {
switch (type) {
case E_OuterProduct:
for (std::size_t i = 0u, i_ = 0; i < N; ++i) {
for (std::size_t i = 0, i_ = 0; i < N; ++i) {
for (std::size_t j = 0; j <= i; ++j, ++i_) {
TBase::m_LowerTriangle[i_] = x(i) * x(j);
}
}
break;
case E_Diagonal:
for (std::size_t i = 0u, i_ = 0; i < N; ++i) {
for (std::size_t i = 0, i_ = 0; i < N; ++i) {
for (std::size_t j = 0; j <= i; ++j, ++i_) {
TBase::m_LowerTriangle[i_] = i == j ? x(i) : T(0);
}
Expand Down Expand Up @@ -1233,7 +1256,7 @@ class CVector : private boost::equality_comparable< CVector<T>,

public:
//! Set to multiple of ones vector.
explicit CVector(std::size_t d = 0u, T v = T(0)) {
explicit CVector(std::size_t d = 0, T v = T(0)) {
if (d > 0) {
TBase::m_X.resize(d, v);
}
Expand Down Expand Up @@ -1284,7 +1307,7 @@ class CVector : private boost::equality_comparable< CVector<T>,
//! \note Because this is template it is *not* an copy assignment
//! operator so this class has implicit move semantics.
template<typename U>
const CVector& operator=(const CVector<U>& other) {
CVector& operator=(const CVector<U>& other) {
TBase::m_X.resize(other.dimension());
this->TBase::assign(other.base());
return *this;
Expand Down Expand Up @@ -1425,6 +1448,9 @@ class CVector : private boost::equality_comparable< CVector<T>,
//! Euclidean norm.
double euclidean() const { return std::sqrt(this->inner(*this)); }

//! Get the mean of the vector components.
double mean() const { return this->TBase::mean(); }

//! Convert to a vector on a different underlying type.
template<typename U>
inline CVector<U> to() const {
Expand All @@ -1447,7 +1473,7 @@ class CVector : private boost::equality_comparable< CVector<T>,
}

//! Get a checksum of this vector's components.
uint64_t checksum() const { return this->TBase::checksum(); }
std::uint64_t checksum() const { return this->TBase::checksum(); }

//! Get the smallest possible vector.
static const CVector& smallest(std::size_t d) {
Expand All @@ -1468,14 +1494,14 @@ CSymmetricMatrix<T>::CSymmetricMatrix(ESymmetricMatrixType type, const CVector<T
TBase::m_LowerTriangle.resize(m_D * (m_D + 1) / 2);
switch (type) {
case E_OuterProduct:
for (std::size_t i = 0u, i_ = 0; i < x.dimension(); ++i) {
for (std::size_t i = 0, i_ = 0; i < x.dimension(); ++i) {
for (std::size_t j = 0; j <= i; ++j, ++i_) {
TBase::m_LowerTriangle[i_] = x(i) * x(j);
}
}
break;
case E_Diagonal:
for (std::size_t i = 0u, i_ = 0; i < x.dimension(); ++i) {
for (std::size_t i = 0, i_ = 0; i < x.dimension(); ++i) {
for (std::size_t j = 0; j <= i; ++j, ++i_) {
TBase::m_LowerTriangle[i_] = i == j ? x(i) : T(0);
}
Expand Down
16 changes: 14 additions & 2 deletions include/maths/common/CLinearAlgebraShims.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,31 @@ typename SCoordinate<VECTOR>::Type L1(const CAnnotatedVector<VECTOR, ANNOTATION>
return L1(static_cast<const VECTOR&>(x));
}

//! Get the Manhattan norm of one of our internal vector classes.
template<typename TENSOR>
double mean(const TENSOR& x) {
return x.mean();
}

//! Get the mean of the elements of an annotated vector.
template<typename VECTOR, typename ANNOTATION>
double mean(const CAnnotatedVector<VECTOR, ANNOTATION>& x) {
return mean(static_cast<const VECTOR&>(x));
}

//! Get the Frobenius norm of one of our internal matrices.
template<typename MATRIX>
typename SCoordinate<MATRIX>::Type frobenius(const MATRIX& m) {
return m.frobenius();
}

//! Get the Euclidean norm of an Eigen dense vector.
//! Get the Frobenius norm of an Eigen dense matrix.
template<typename SCALAR>
SCALAR frobenius(const CDenseMatrix<SCALAR>& x) {
return x.norm();
}

//! Get the Euclidean norm of an Eigen memory mapped matrix.
//! Get the Frobenius norm of an Eigen memory mapped matrix.
template<typename SCALAR, Eigen::AlignmentType ALIGNMENT>
SCALAR frobenius(const CMemoryMappedDenseMatrix<SCALAR, ALIGNMENT>& x) {
return x.norm();
Expand Down
4 changes: 2 additions & 2 deletions include/maths/common/CModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ class MATHS_COMMON_EXPORT CModelAddSamplesParams {

public:
//! Set whether or not the data are integer valued.
CModelAddSamplesParams& integer(bool integer);
CModelAddSamplesParams& isInteger(bool isInteger);
//! Get the data type.
maths_t::EDataType type() const;

//! Set whether or not the data are non-negative.
CModelAddSamplesParams& nonNegative(bool nonNegative);
CModelAddSamplesParams& isNonNegative(bool isNonNegative);
//! Get the whether the data are non-negative.
bool isNonNegative() const;

Expand Down
6 changes: 3 additions & 3 deletions include/maths/time_series/CCalendarComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class MATHS_TIME_SERIES_EXPORT CCalendarComponent : private CDecompositionCompon
//! \param[in] time The time of interest.
//! \param[in] confidence The symmetric confidence interval for the variance
//! as a percentage.
TDoubleDoublePr value(core_t::TTime time, double confidence) const;
TVector2x1 value(core_t::TTime time, double confidence) const;

//! Get the mean value of the component.
double meanValue() const;
Expand All @@ -137,13 +137,13 @@ class MATHS_TIME_SERIES_EXPORT CCalendarComponent : private CDecompositionCompon
//! \param[in] time The time of interest.
//! \param[in] confidence The symmetric confidence interval for the
//! variance as a percentage.
TDoubleDoublePr variance(core_t::TTime time, double confidence) const;
TVector2x1 variance(core_t::TTime time, double confidence) const;

//! Get the mean variance of the component residuals.
double meanVariance() const;

//! Get a checksum for this object.
uint64_t checksum(uint64_t seed = 0) const;
std::uint64_t checksum(std::uint64_t seed = 0) const;

//! Debug the memory used by this component.
void debugMemoryUsage(const core::CMemoryUsage::TMemoryUsagePtr& mem) const;
Expand Down
Loading