MCPcopy Create free account
hub / github.com/numpy/numpy / random_standard_gamma

Function random_standard_gamma

numpy/random/src/distributions/distributions.c:220–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220double random_standard_gamma(bitgen_t *bitgen_state,
221 double shape) {
222 double b, c;
223 double U, V, X, Y;
224
225 if (shape == 1.0) {
226 return random_standard_exponential(bitgen_state);
227 } else if (shape == 0.0) {
228 return 0.0;
229 } else if (shape < 1.0) {
230 for (;;) {
231 U = next_double(bitgen_state);
232 V = random_standard_exponential(bitgen_state);
233 if (U <= 1.0 - shape) {
234 X = pow(U, 1. / shape);
235 if (X <= V) {
236 return X;
237 }
238 } else {
239 Y = -log((1 - U) / shape);
240 X = pow(1.0 - shape + shape * Y, 1. / shape);
241 if (X <= (V + Y)) {
242 return X;
243 }
244 }
245 }
246 } else {
247 b = shape - 1. / 3.;
248 c = 1. / sqrt(9 * b);
249 for (;;) {
250 do {
251 X = random_standard_normal(bitgen_state);
252 V = 1.0 + c * X;
253 } while (V <= 0.0);
254
255 V = V * V * V;
256 U = next_double(bitgen_state);
257 if (U < 1.0 - 0.0331 * (X * X) * (X * X))
258 return (b * V);
259 /* log(0.0) ok here */
260 if (log(U) < 0.5 * X * X + b * (1. - V + log(V)))
261 return (b * V);
262 }
263 }
264}
265
266float random_standard_gamma_f(bitgen_t *bitgen_state,
267 float shape) {

Callers 4

random_gammaFunction · 0.85
random_betaFunction · 0.85
random_chisquareFunction · 0.85
random_standard_tFunction · 0.85

Calls 6

next_doubleFunction · 0.85
powFunction · 0.85
random_standard_normalFunction · 0.85
logFunction · 0.50
sqrtFunction · 0.50

Tested by

no test coverage detected