7 #ifndef XGBOOST_COMMON_MATH_H_ 8 #define XGBOOST_COMMON_MATH_H_ 26 return 1.0f / (1.0f + expf(-x));
37 template <
typename Iterator>
40 typename std::remove_reference<
41 decltype(std::declval<Iterator>().
operator*())>::type
43 "Values should be of type bst_float");
45 for (Iterator i = start+1; i != end; ++i) {
46 wmax = fmaxf(*i, wmax);
49 for (Iterator i = start; i != end; ++i) {
53 for (Iterator i = start; i != end; ++i) {
54 *i /=
static_cast<float>(wsum);
65 template<
typename Iterator>
67 Iterator maxit = begin;
68 for (Iterator it = begin; it != end; ++it) {
69 if (*it > *maxit) maxit = it;
80 inline float LogSum(
float x,
float y) {
82 return y + std::log(std::exp(x - y) + 1.0f);
84 return x + std::log(std::exp(y - x) + 1.0f);
95 template<
typename Iterator>
96 inline float LogSum(Iterator begin, Iterator end) {
98 for (Iterator it = begin; it != end; ++it) {
99 mx = std::max(mx, *it);
102 for (Iterator it = begin; it != end; ++it) {
103 sum += std::exp(*it - mx);
105 return mx + std::log(sum);
109 inline static bool CmpFirst(
const std::pair<float, unsigned> &a,
110 const std::pair<float, unsigned> &b) {
111 return a.first > b.first;
113 inline static bool CmpSecond(
const std::pair<float, unsigned> &a,
114 const std::pair<float, unsigned> &b) {
115 return a.second > b.second;
118 #if XGBOOST_STRICT_R_MODE 125 return (_isnan(v) != 0);
127 return std::isnan(v);
130 #endif // XGBOOST_STRICT_R_MODE_ 134 #if XGBOOST_STRICT_R_MODE && !defined(XGBOOST_USE_CUDA) 137 #else // Not R or R with GPU. 146 #pragma message("Warning: lgamma function was not available until VS2013"\ 147 ", poisson regression will be disabled") 148 utils::Error(
"lgamma function was not available until VS2013");
149 return static_cast<T
>(1.0);
150 #endif // _MSC_VER >= 1800 157 #endif // XGBOOST_STRICT_R_MODE && !defined(XGBOOST_USE_CUDA) 161 #endif // XGBOOST_COMMON_MATH_H_ float bst_float
float type, used for storing statistics
Definition: base.h:89
bool CheckNAN(T v)
Definition: math.h:123
float LogSum(float x, float y)
perform numerically safe logsum
Definition: math.h:80
XGBOOST_DEVICE void Softmax(Iterator start, Iterator end)
Do inplace softmax transformaton on start to end.
Definition: math.h:38
XGBOOST_DEVICE T LogGamma(T v)
Definition: math.h:140
XGBOOST_DEVICE Iterator FindMaxIndex(Iterator begin, Iterator end)
Find the maximum iterator within the iterators.
Definition: math.h:66
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:75
namespace of xgboost
Definition: base.h:79
defines configuration macros of xgboost.
XGBOOST_DEVICE float Sigmoid(float x)
calculate the sigmoid of the input.
Definition: math.h:25