Added nd4j_gamma, nd4j_igamma and nd4j_igammac functions.
parent
df2448613e
commit
f90e6da97e
|
@ -733,25 +733,26 @@ namespace nd4j {
|
||||||
T temp = val1; val1=val2; val2=temp;
|
T temp = val1; val1=val2; val2=temp;
|
||||||
};
|
};
|
||||||
|
|
||||||
// template <typename X, typename Z>
|
|
||||||
// math_def inline Z nd4j_gamma(X a) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
template <typename X, typename Z>
|
template <typename X, typename Z>
|
||||||
math_def inline Z nd4j_igamma(X a, X x) {
|
math_def inline Z nd4j_gamma(X a) {
|
||||||
Z aim = nd4j_pow<X, X, Z>(x, a) / (nd4j_exp<X,Z>(x) * std::tgamma(a));
|
return (Z)std::tgamma(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename X, typename Y, typename Z>
|
||||||
|
math_def inline Z nd4j_igamma(X a, Y x) {
|
||||||
|
Z aim = nd4j_pow<X, X, Z>(x, a) / (nd4j_exp<X, Z>(x) * nd4j_gamma<Y, Z>(a));
|
||||||
auto sum = Z(0.);
|
auto sum = Z(0.);
|
||||||
auto denom = Z(1.);
|
auto denom = Z(1.);
|
||||||
for (auto i = 0; Z(1./denom) > Z(1.0e-6); i++) {
|
for (int i = 0; Z(1./denom) > Z(1.0e-12); i++) {
|
||||||
denom *= (a + i);
|
denom *= (a + i);
|
||||||
sum += nd4j_pow<X, int>(x, i) / denom;
|
sum += nd4j_pow<X, int, Z>(x, i) / denom;
|
||||||
}
|
}
|
||||||
return aim * sum;
|
return aim * sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename X, typename Z>
|
template <typename X, typename Y, typename Z>
|
||||||
math_def inline Z nd4j_igammac(X a, X x) {
|
math_def inline Z nd4j_igammac(X a, Y x) {
|
||||||
return Z(1.) - nd4j_igamma<X, Z>(a, x);
|
return Z(1.) - nd4j_igamma<X, Y, Z>(a, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __CUDACC__
|
#ifdef __CUDACC__
|
||||||
|
|
Loading…
Reference in New Issue