]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/math/tools/bivariate_statistics.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / math / tools / bivariate_statistics.hpp
index a15e28b49116c8b3c876379d1c1798f6eeafe774..eaed5838ea968270e4fc9d24e8fc086daf8f082b 100644 (file)
@@ -8,10 +8,11 @@
 
 #include <iterator>
 #include <tuple>
-#include <boost/assert.hpp>
-#include <boost/config/header_deprecated.hpp>
+#include <limits>
+#include <boost/math/tools/assert.hpp>
+#include <boost/math/tools/header_deprecated.hpp>
 
-BOOST_HEADER_DEPRECATED("<boost/math/statistics/bivariate_statistics.hpp>");
+BOOST_MATH_HEADER_DEPRECATED("<boost/math/statistics/bivariate_statistics.hpp>");
 
 namespace boost{ namespace math{ namespace tools {
 
@@ -20,8 +21,8 @@ auto means_and_covariance(Container const & u, Container const & v)
 {
     using Real = typename Container::value_type;
     using std::size;
-    BOOST_ASSERT_MSG(size(u) == size(v), "The size of each vector must be the same to compute covariance.");
-    BOOST_ASSERT_MSG(size(u) > 0, "Computing covariance requires at least one sample.");
+    BOOST_MATH_ASSERT_MSG(size(u) == size(v), "The size of each vector must be the same to compute covariance.");
+    BOOST_MATH_ASSERT_MSG(size(u) > 0, "Computing covariance requires at least one sample.");
 
     // See Equation III.9 of "Numerically Stable, Single-Pass, Parallel Statistics Algorithms", Bennet et al.
     Real cov = 0;
@@ -52,8 +53,8 @@ auto correlation_coefficient(Container const & u, Container const & v)
 {
     using Real = typename Container::value_type;
     using std::size;
-    BOOST_ASSERT_MSG(size(u) == size(v), "The size of each vector must be the same to compute covariance.");
-    BOOST_ASSERT_MSG(size(u) > 0, "Computing covariance requires at least two samples.");
+    BOOST_MATH_ASSERT_MSG(size(u) == size(v), "The size of each vector must be the same to compute covariance.");
+    BOOST_MATH_ASSERT_MSG(size(u) > 0, "Computing covariance requires at least two samples.");
 
     Real cov = 0;
     Real mu_u = u[0];
@@ -72,15 +73,12 @@ auto correlation_coefficient(Container const & u, Container const & v)
         mu_v = mu_v + v_tmp/(i+1);
     }
 
-    // If both datasets are constant, then they are perfectly correlated.
-    if (Qu == 0 && Qv == 0)
-    {
-        return Real(1);
-    }
-    // If one dataset is constant and the other isn't, then they have no correlation:
+    // If one dataset is constant, then they have no correlation:
+    // See https://stats.stackexchange.com/questions/23676/normalized-correlation-with-a-constant-vector
+    // Thanks to zbjornson for pointing this out.
     if (Qu == 0 || Qv == 0)
     {
-        return Real(0);
+        return std::numeric_limits<Real>::quiet_NaN();
     }
 
     // Make sure rho in [-1, 1], even in the presence of numerical noise.