From df2448613e942baaa83d82e84f435bbf00e834c6 Mon Sep 17 00:00:00 2001 From: shugeo Date: Tue, 15 Oct 2019 20:00:07 +0300 Subject: [PATCH] Added gamma distribution functions. --- libnd4j/include/templatemath.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libnd4j/include/templatemath.h b/libnd4j/include/templatemath.h index 908323369..2ce8cd338 100644 --- a/libnd4j/include/templatemath.h +++ b/libnd4j/include/templatemath.h @@ -733,6 +733,27 @@ namespace nd4j { T temp = val1; val1=val2; val2=temp; }; +// template +// math_def inline Z nd4j_gamma(X a) { +// +// } + template + math_def inline Z nd4j_igamma(X a, X x) { + Z aim = nd4j_pow(x, a) / (nd4j_exp(x) * std::tgamma(a)); + auto sum = Z(0.); + auto denom = Z(1.); + for (auto i = 0; Z(1./denom) > Z(1.0e-6); i++) { + denom *= (a + i); + sum += nd4j_pow(x, i) / denom; + } + return aim * sum; + } + + template + math_def inline Z nd4j_igammac(X a, X x) { + return Z(1.) - nd4j_igamma(a, x); + } + #ifdef __CUDACC__ namespace atomics { template