diff --git a/src/gradient.cpp b/src/gradient.cpp index deee6347..4a58dcd7 100644 --- a/src/gradient.cpp +++ b/src/gradient.cpp @@ -22,7 +22,8 @@ // UMAP umap_gradient::umap_gradient(const double a, const double b, const double gamma) : - a(a), b(b), a_b_m2(-2.0 * a * b), gamma_b_2(2.0 * gamma * b) { } + clip_max(4.0), a(a), b(b), a_b_m2(-2.0 * a * b), gamma_b_2(2.0 * gamma * b) + { } // The Python implementation does two pow calls: one for d^b, and one for // d^(b-1) I have replaced the second call with (d^b) / d, which saves on the @@ -73,7 +74,8 @@ double fastPrecisePow(double a, double b) { // Approximate-Power UMAP: UMAP with an approximation to the slow pow calculation apumap_gradient::apumap_gradient(const double a, const double b, const double gamma) : - a(a), b(b), a_b_m2(-2.0 * a * b), gamma_b_2(2.0 * gamma * b) { } + clip_max(4.0), a(a), b(b), a_b_m2(-2.0 * a * b), gamma_b_2(2.0 * gamma * b) + { } const double apumap_gradient::grad_attr(const double dist_squared) const { const double pd2b = fastPrecisePow(dist_squared, b); @@ -87,7 +89,7 @@ const double apumap_gradient::grad_rep(const double dist_squared) const { // t-UMAP -tumap_gradient::tumap_gradient() {} +tumap_gradient::tumap_gradient() : clip_max(4.0) {} const double tumap_gradient::grad_attr(const double dist_squared) const { return -2.0 / (dist_squared + 1.0); @@ -100,7 +102,8 @@ const double tumap_gradient::grad_rep(const double dist_squared) const { // LargeVis -largevis_gradient::largevis_gradient(const double gamma) : gamma_2(gamma * 2.0) {} +largevis_gradient::largevis_gradient(const double gamma) : clip_max(5.0), +gamma_2(gamma * 2.0) {} const double largevis_gradient::grad_attr(const double dist_squared) const { return -2.0 / (dist_squared + 1.0); diff --git a/src/gradient.h b/src/gradient.h index 3aa9cc3c..27c2dc67 100644 --- a/src/gradient.h +++ b/src/gradient.h @@ -27,7 +27,8 @@ class umap_gradient { umap_gradient(const double a, const double b, const double gamma); const double grad_attr(const double dist_squared) const; const double grad_rep(const double dist_squared) const; - static const constexpr double clip_max = 4.0; + // static const constexpr double clip_max = 4.0; + const double clip_max; private: const double a; const double b; @@ -41,7 +42,8 @@ class apumap_gradient { apumap_gradient(const double a, const double b, const double gamma); const double grad_attr(const double dist_squared) const; const double grad_rep(const double dist_squared) const; - static const constexpr double clip_max = 4.0; + // static const constexpr double clip_max = 4.0; + const double clip_max; private: const double a; const double b; @@ -60,7 +62,8 @@ class tumap_gradient { tumap_gradient(); const double grad_attr(const double dist_squared) const; const double grad_rep(const double dist_squared) const; - static const constexpr double clip_max = 4.0; + // static const constexpr double clip_max = 4.0; + const double clip_max; }; class largevis_gradient { @@ -68,7 +71,8 @@ class largevis_gradient { largevis_gradient(const double gamma); const double grad_attr(const double dist_squared) const; const double grad_rep(const double dist_squared) const; - static const constexpr double clip_max = 5.0; + // static const constexpr double clip_max = 5.0; + const double clip_max; private: const double gamma_2;