Medial Code Documentation
Loading...
Searching...
No Matches
probability_distribution.h
Go to the documentation of this file.
1
8#ifndef XGBOOST_COMMON_PROBABILITY_DISTRIBUTION_H_
9#define XGBOOST_COMMON_PROBABILITY_DISTRIBUTION_H_
10
11#include <cmath>
12
13namespace xgboost {
14namespace common {
15
16#ifndef __CUDACC__
17
18using std::exp;
19using std::sqrt;
20using std::isinf;
21using std::isnan;
22
23#endif // __CUDACC__
24
26constexpr double kPI = 3.14159265358979323846;
28constexpr double kEulerMascheroni = 0.57721566490153286060651209008240243104215933593992;
29
32 kNormal = 0, kLogistic = 1, kExtreme = 2
33};
34
36 XGBOOST_DEVICE static double PDF(double z) {
37 return exp(-z * z / 2.0) / sqrt(2.0 * kPI);
38 }
39
40 XGBOOST_DEVICE static double CDF(double z) {
41 return 0.5 * (1 + erf(z / sqrt(2.0)));
42 }
43
44 XGBOOST_DEVICE static double GradPDF(double z) {
45 return -z * PDF(z);
46 }
47
48 XGBOOST_DEVICE static double HessPDF(double z) {
49 return (z * z - 1.0) * PDF(z);
50 }
51
53 return ProbabilityDistributionType::kNormal;
54 }
55};
56
58 XGBOOST_DEVICE static double PDF(double z) {
59 const double w = exp(z);
60 const double sqrt_denominator = 1 + w;
61 if (isinf(w) || isinf(w * w)) {
62 return 0.0;
63 } else {
64 return w / (sqrt_denominator * sqrt_denominator);
65 }
66 }
67
68 XGBOOST_DEVICE static double CDF(double z) {
69 const double w = exp(z);
70 return isinf(w) ? 1.0 : (w / (1 + w));
71 }
72
73 XGBOOST_DEVICE static double GradPDF(double z) {
74 const double w = exp(z);
75 return isinf(w) ? 0.0 : (PDF(z) * (1 - w) / (1 + w));
76 }
77
78 XGBOOST_DEVICE static double HessPDF(double z) {
79 const double w = exp(z);
80 if (isinf(w) || isinf(w * w)) {
81 return 0.0;
82 } else {
83 return PDF(z) * (w * w - 4 * w + 1) / ((1 + w) * (1 + w));
84 }
85 }
86
88 return ProbabilityDistributionType::kLogistic;
89 }
90};
91
93 XGBOOST_DEVICE static double PDF(double z) {
94 const double w = exp(z);
95 return isinf(w) ? 0.0 : (w * exp(-w));
96 }
97
98 XGBOOST_DEVICE static double CDF(double z) {
99 const double w = exp(z);
100 return 1 - exp(-w);
101 }
102
103 XGBOOST_DEVICE static double GradPDF(double z) {
104 const double w = exp(z);
105 return isinf(w) ? 0.0 : ((1 - w) * PDF(z));
106 }
107
108 XGBOOST_DEVICE static double HessPDF(double z) {
109 const double w = exp(z);
110 if (isinf(w) || isinf(w * w)) {
111 return 0.0;
112 } else {
113 return (w * w - 3 * w + 1) * PDF(z);
114 }
115 }
116
118 return ProbabilityDistributionType::kExtreme;
119 }
120};
121
122} // namespace common
123} // namespace xgboost
124
125#endif // XGBOOST_COMMON_PROBABILITY_DISTRIBUTION_H_
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition base.h:64
ProbabilityDistributionType
Enum encoding possible choices of probability distribution.
Definition probability_distribution.h:31
constexpr double kEulerMascheroni
The Euler-Mascheroni_constant.
Definition probability_distribution.h:28
constexpr double kPI
Constant PI.
Definition probability_distribution.h:26
namespace of xgboost
Definition base.h:90
Definition probability_distribution.h:92
Definition probability_distribution.h:57
Definition probability_distribution.h:35