User Documentation
 All Files Functions Groups
prob.sql_in
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------- *//**
2  *
3  * @file prob.sql_in
4  *
5  * @brief SQL functions for evaluating probability functions
6  *
7  * @sa For an overview of probability functions, see the module
8  * description \ref grp_prob.
9  *
10  *//* ----------------------------------------------------------------------- */
11 
12 m4_include(`SQLCommon.m4')
13 
14 /**
15 @addtogroup grp_prob
16 
17 @about
18 
19 The Probability Functions module provides cumulative distribution, density/mass,
20 and quantile functions for a wide range of probability distributions.
21 
22 Unless otherwise documented, all of these functions are wrappers around
23 functionality provided by the boost C++ library [1, “<a href=
24 "http://www.boost.org/doc/libs/1_49_0/libs/math/doc/sf_and_dist/html/math_toolkit/dist.html"
25 >Statistical Distributions and Functions</a>”].
26 
27 For convenience, all cumulative distribution and density/mass functions (CDFs
28 and PDF/PMFs in short) are defined over the range of all floating-point numbers
29 including infinity. Inputs that are \c NULL or \c NaN (not a number) will always
30 produce a \c NULL or \c NaN result, respectively. Inputs that are plus or minus
31 infinity will return the respective limits.
32 
33 A quantile function for a probability distrution with CDF \f$ F \f$ takes a
34 probability argument \f$ p \in [0,1] \f$ and returns the value \f$ x \f$ so that
35 \f$ F(x) = p \f$, provided such an \f$ x \f$ exists and it is unique. If it does
36 not, the result will be
37 \f$
38  \sup \{ x \in D \mid F(x) \leq p \}
39 \f$
40 (interpreted as 0 if the supremum is over an empty set) if \f$ p < 0.5 \f$, and
41 \f$
42  \inf \{ x \in D \mid F(x) \geq p \}
43 \f$
44 if \f$ p \geq 0.5 \f$. Here \f$ D \f$ denotes the domain of the distribution,
45 which is the set of reals \f$ \mathbb R \f$ for continuous and the set of
46 nonnegative integers \f$ \mathbb N_0 \f$ for discrete distributions.
47 
48 Intuitively, the formulas in the previous paragraph deal with the following
49 special cases. The 0-quantile will always be the “left end” of the support,
50 and the 1-quantile will be the “right end” of the support of the distribution.
51 For discrete distributions, most values of \f$ p \in [0,1] \f$ do not admit an
52 \f$ x \f$ with \f$ F(x) = p \f$. Instead, there is an \f$ x \in \mathbb N_0 \f$
53 so that \f$ F(x) < p < F(x + 1) \f$. The above formulas mean that the
54 value returned as \f$ p \f$-quantile is \f$ x \f$ if \f$ p < 0.5 \f$, and it
55 is \f$ x + 1 \f$ if \f$ p \geq 0.5 \f$. (As a special case, in order to ensure
56 that quantiles are always within the support, the \f$ p \f$-quantile will be 0
57 if \f$ p < F(0) \f$).
58 
59 The rationale for choosing this behavior is that \f$p\f$-quantiles for
60 \f$ p < 0.5 \f$ are typically requested when interested in the value
61 \f$ x \f$ such that with confidence level <strong>at least</strong>
62 \f$ 1 - p \f$ a random variable will be \f$ > x \f$ (or equivalently, with
63 probability <strong>at most</strong> \f$ p \f$, it will be \f$ \leq x \f$).
64 Likewise, \f$p\f$-quantiles for \f$ p \geq 0.5 \f$ are typically requested when
65 interested in the value \f$ x \f$ such that with confidence level <strong>at
66 least</strong> \f$ p \f$ a random variable will be \f$ \leq x \f$. See also
67 [1, “<a href=
68 "http://www.boost.org/doc/libs/1_46_1/libs/math/doc/sf_and_dist/html/math_toolkit/policy/pol_tutorial/understand_dis_quant.html"
69 >Understanding Quantiles of Discrete Distributions</a>”].
70 
71 @usage
72 
73 - Cumulative distribution functions:
74  <pre>SELECT <em>distribution</em>_cdf(<em>random variate</em>[, <em>parameter1</em> [, <em>parameter2</em> [, <em>parameter3</em>] ] ])</pre>
75 - Probability density/mass functions:
76  <pre>SELECT <em>distribution</em>_{pdf|pmf}(<em>random variate</em>[, <em>parameter1</em> [, <em>parameter2</em> [, <em>parameter3</em>] ] ])</pre>
77 - Quantile functions:
78  <pre>SELECT <em>distribution</em>_quantile(<em>probability</em>[, <em>parameter1</em> [, <em>parameter2</em> [, <em>parameter3</em>] ] ])</pre>
79 
80 For concrete function signatures, see \ref prob.sql_in.
81 
82 @examp
83 
84 @verbatim
85 sql> SELECT normal_cdf(0);
86  normal_cdf
87 ------------
88  0.5
89 
90 sql> SELECT normal_quantile(0.5, 0, 1);
91  normal_quantile
92 -----------------
93  0
94 (1 row)
95 @endverbatim
96 
97 @literature
98 
99 [1] John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno Lalande,
100  Johan Råde, Gautam Sewani and Thijs van den Berg:
101  <em>Boost Math Toolkit</em>, Version 1.49, available at:
102  http://www.boost.org/doc/libs/1_49_0/libs/math/doc/sf_and_dist/html/index.html
103 
104 @sa File prob.sql_in documenting the SQL functions.
105 */
106 
107 
108 /**
109  * @brief Bernoulli cumulative distribution function
110  *
111  * @param x Random variate \f$ x \f$
112  * @param sp Success probability \f$ p \in [0,1] \f$
113  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a Bernoulli-distributed
114  * random variable with success probability \f$ \mathit{sp} \f$
115  */
116 CREATE FUNCTION MADLIB_SCHEMA.bernoulli_cdf(
117  x DOUBLE PRECISION,
118  sp DOUBLE PRECISION
119 ) RETURNS DOUBLE PRECISION
120 AS 'MODULE_PATHNAME'
121 LANGUAGE C
122 IMMUTABLE STRICT;
123 
124 /**
125  * @brief Bernoulli probability mass function
126  *
127  * @param x Random variate \f$ x \f$
128  * @param sp Success probability \f$ \mathit{sp} \in [0,1] \f$
129  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability mass function of
130  * a Bernoulli-distributed random variable with success probability
131  * \f$ \mathit{sp} \f$
132  */
133 CREATE FUNCTION MADLIB_SCHEMA.bernoulli_pmf(
134  x INT4,
135  sp DOUBLE PRECISION
136 ) RETURNS DOUBLE PRECISION
137 AS 'MODULE_PATHNAME'
138 LANGUAGE C
139 IMMUTABLE STRICT;
140 
141 /**
142  * @brief Bernoulli quantile function
143  *
144  * @param p Probability \f$ p \in [0,1] \f$
145  * @param sp Success probability \f$ \mathit{sp} \in [0,1] \f$
146  * @return 0 if \f$ p \leq 1 - \mathit{sp} \f$ and 1 otherwise
147  */
148 CREATE FUNCTION MADLIB_SCHEMA.bernoulli_quantile(
149  p DOUBLE PRECISION,
150  sp DOUBLE PRECISION
151 ) RETURNS DOUBLE PRECISION
152 AS 'MODULE_PATHNAME'
153 LANGUAGE C
154 IMMUTABLE STRICT;
156 
157 /**
158  * @brief Beta cumulative distribution function
159  *
160  * @param x Random variate \f$ x \f$
161  * @param alpha Shape \f$ \alpha > 0 \f$
162  * @param beta Shape \f$ \beta > 0 \f$
163  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a beta distributed random
164  * variable with shape parameters \f$ \alpha \f$ and \f$ \beta \f$
165  */
166 CREATE FUNCTION MADLIB_SCHEMA.beta_cdf(
167  x DOUBLE PRECISION,
168  alpha DOUBLE PRECISION,
169  beta DOUBLE PRECISION
170 ) RETURNS DOUBLE PRECISION
171 AS 'MODULE_PATHNAME'
172 LANGUAGE C
173 IMMUTABLE STRICT;
174 
175 /**
176  * @brief Beta probability density function
177  *
178  * @param x Random variate \f$ x \f$
179  * @param alpha Shape \f$ \alpha > 0 \f$
180  * @param beta Shape \f$ \beta > 0 \f$
181  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
182  * a beta random variable with shape parameters \f$ \alpha \f$ and
183  * \f$ \beta \f$
184  */
185 CREATE FUNCTION MADLIB_SCHEMA.beta_pdf(
186  x DOUBLE PRECISION,
187  alpha DOUBLE PRECISION,
188  beta DOUBLE PRECISION
189 ) RETURNS DOUBLE PRECISION
190 AS 'MODULE_PATHNAME'
191 LANGUAGE C
192 IMMUTABLE STRICT;
193 
194 /**
195  * @brief Beta quantile function
196  *
197  * @param p Probability \f$ p \in [0,1] \f$
198  * @param alpha Shape \f$ \alpha > 0 \f$
199  * @param beta Shape \f$ \beta > 0 \f$
200  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is
201  * beta distribution random variable with shape parameters \f$ \alpha \f$
202  * and \f$ \beta \f$
203  */
204 CREATE FUNCTION MADLIB_SCHEMA.beta_quantile(
205  p DOUBLE PRECISION,
206  alpha DOUBLE PRECISION,
207  beta DOUBLE PRECISION
208 ) RETURNS DOUBLE PRECISION
209 AS 'MODULE_PATHNAME'
210 LANGUAGE C
211 IMMUTABLE STRICT;
212 
213 
214 /**
215  * @brief Binomial cumulative distribution function
216  *
217  * @param x Random variate \f$ x \f$
218  * @param n The number of trials \f$ n \in \mathbb N_0 \f$
219  * @param sp Success probability \f$ \mathit{sp} \in [0,1] \f$
220  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a binomially distributed
221  * random variable with \f$ n \f$ trials and success probability
222  * \f$ \mathit{sp} \f$
223  */
224 CREATE FUNCTION MADLIB_SCHEMA.binomial_cdf(
225  x DOUBLE PRECISION,
226  n INT4,
227  sp DOUBLE PRECISION
228 ) RETURNS DOUBLE PRECISION
229 AS 'MODULE_PATHNAME'
230 LANGUAGE C
231 IMMUTABLE STRICT;
232 
233 /**
234  * @brief Binomial probability mass function
235  *
236  * @param x Random variate \f$ x \f$
237  * @param n The number of trials \f$ n \in \mathbb N_0 \f$
238  * @param sp Success probability \f$ \mathit{sp} \in [0,1] \f$
239  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability mass function of
240  * a binomially distributed random variable with \f$ n \f$ trials and
241  * success probability \f$ \mathit{sp} \f$
242  */
243 CREATE FUNCTION MADLIB_SCHEMA.binomial_pmf(
244  x INT4,
245  n INT4,
246  sp DOUBLE PRECISION
247 ) RETURNS DOUBLE PRECISION
248 AS 'MODULE_PATHNAME'
249 LANGUAGE C
250 IMMUTABLE STRICT;
251 
252 /**
253  * @brief Binomial quantile function
254  *
255  * @param p Probability \f$ p \in [0,1] \f$
256  * @param n The number of trials \f$ n \in \mathbb N_0 \f$
257  * @param sp Success probability \f$ \mathit{sp} \in [0,1] \f$
258  * @return If \f$ p < 0.5 \f$ the maximum \f$ x \f$ such that
259  * \f$ p \geq \Pr[X \leq x] \f$. If \f$ p \geq 0.5 \f$ the minimum \f$ x \f$
260  * such that \f$ p \leq \Pr[X \leq x] \f$. Here, \f$ X \f$ is a
261  * binomially distributed random variable with \f$ n \f$ trials and
262  * success probability \f$ \mathit{sp} \f$.
263  */
264 CREATE FUNCTION MADLIB_SCHEMA.binomial_quantile(
265  p DOUBLE PRECISION,
266  n INT4,
267  sp DOUBLE PRECISION
268 ) RETURNS DOUBLE PRECISION
269 AS 'MODULE_PATHNAME'
270 LANGUAGE C
271 IMMUTABLE STRICT;
272 
273 
274 /**
275  * @brief Cauchy cumulative distribution function
276  *
277  * @param x Random variate \f$ x \f$
278  * @param location Location \f$ x_0 \f$
279  * @param scale Scale \f$ \gamma > 0 \f$
280  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a Cauchy-distributed random
281  * variable with location and scale parameters \f$ x_0 \f$ and
282  * \f$ \gamma \f$, respectively
283  */
284 CREATE FUNCTION MADLIB_SCHEMA.cauchy_cdf(
285  x DOUBLE PRECISION,
286  location DOUBLE PRECISION,
287  scale DOUBLE PRECISION
288 ) RETURNS DOUBLE PRECISION
289 AS 'MODULE_PATHNAME'
290 LANGUAGE C
291 IMMUTABLE STRICT;
292 
293 /**
294  * @brief Cauchy probability density function
295  *
296  * @param x Random variate \f$ x \f$
297  * @param location Location \f$ x_0 \f$
298  * @param scale Scale \f$ \gamma > 0 \f$
299  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
300  * a Cauchy-distributed random variable with location and scale parameters
301  * \f$ x_0 \f$ and \f$ \gamma \f$, respectively
302  */
303 CREATE FUNCTION MADLIB_SCHEMA.cauchy_pdf(
304  x DOUBLE PRECISION,
305  location DOUBLE PRECISION,
306  scale DOUBLE PRECISION
307 ) RETURNS DOUBLE PRECISION
308 AS 'MODULE_PATHNAME'
309 LANGUAGE C
310 IMMUTABLE STRICT;
311 
312 /**
313  * @brief Cauchy quantile function
314  *
315  * @param p Probability \f$ p \in [0,1] \f$
316  * @param location Location \f$ x_0 \f$
317  * @param scale Scale \f$ \gamma > 0 \f$
318  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
319  * Cauchy-distributed random variable with location and scale parameters
320  * \f$ x_0 \f$ and \f$ \gamma \f$, respectively
321  */
322 CREATE FUNCTION MADLIB_SCHEMA.cauchy_quantile(
323  p DOUBLE PRECISION,
324  location DOUBLE PRECISION,
325  scale DOUBLE PRECISION
326 ) RETURNS DOUBLE PRECISION
327 AS 'MODULE_PATHNAME'
328 LANGUAGE C
329 IMMUTABLE STRICT;
330 
331 
332 /**
333  * @brief Chi-squared cumulative distribution function
334  *
335  * @param x Random variate \f$ x \f$
336  * @param df Degrees of freedom \f$ \nu > 0 \f$
337  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a chi-squared distributed
338  * random variable with \f$ \nu \f$ degrees of freedom
339  */
340 CREATE FUNCTION MADLIB_SCHEMA.chi_squared_cdf(
341  x DOUBLE PRECISION,
342  df DOUBLE PRECISION
343 ) RETURNS DOUBLE PRECISION
344 AS 'MODULE_PATHNAME'
345 LANGUAGE C
346 IMMUTABLE STRICT;
347 
348 /**
349  * @brief Chi-squared distribution probability density function
350  *
351  * @param x Random variate \f$ x \f$
352  * @param df Degrees of freedom \f$ \nu > 0 \f$
353  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
354  * a chi-squared distributed random variable with \f$ \nu \f$ degrees of
355  * freedom
356  */
357 CREATE FUNCTION MADLIB_SCHEMA.chi_squared_pdf(
358  x DOUBLE PRECISION,
359  df DOUBLE PRECISION
360 ) RETURNS DOUBLE PRECISION
361 AS 'MODULE_PATHNAME'
362 LANGUAGE C
363 IMMUTABLE STRICT;
364 
365 /**
366  * @brief Chi-squared distribution quantile function
367  *
368  * @param p Probability \f$ p \in [0,1] \f$
369  * @param df Degrees of freedom \f$ \mu > 0 \f$
370  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
371  * chi-squared distributed random variable with \f$ \nu \f$ degrees of
372  * freedom
373  */
374 CREATE FUNCTION MADLIB_SCHEMA.chi_squared_quantile(
375  p DOUBLE PRECISION,
376  df DOUBLE PRECISION
377 ) RETURNS DOUBLE PRECISION
378 AS 'MODULE_PATHNAME'
379 LANGUAGE C
380 IMMUTABLE STRICT;
381 
382 
383 /**
384  * @brief Exponential cumulative distribution function
385  *
386  * @param x Random variate \f$ x \f$
387  * @param lambda Rate parameter \f$ \lambda > 0 \f$
388  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is an exponentially distributed
389  * random variable with rate parameter \f$ \lambda \f$
390  */
391 CREATE FUNCTION MADLIB_SCHEMA.exponential_cdf(
392  x DOUBLE PRECISION,
393  lambda DOUBLE PRECISION
394 ) RETURNS DOUBLE PRECISION
395 AS 'MODULE_PATHNAME'
396 LANGUAGE C
397 IMMUTABLE STRICT;
398 
399 /**
400  * @brief Exponential probability density function
401  *
402  * @param x Random variate \f$ x \f$
403  * @param lambda Rate parameter \f$ \lambda > 0 \f$
404  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
405  * exponentially distributed random variable with rate parameter
406  * \f$ \lambda \f$
407  */
408 CREATE FUNCTION MADLIB_SCHEMA.exponential_pdf(
409  x DOUBLE PRECISION,
410  lambda DOUBLE PRECISION
411 ) RETURNS DOUBLE PRECISION
412 AS 'MODULE_PATHNAME'
413 LANGUAGE C
414 IMMUTABLE STRICT;
415 
416 /**
417  * @brief Exponential quantile function
418  *
419  * @param p Probability \f$ p \in [0,1] \f$
420  * @param lambda Rate parameter \f$ \lambda > 0 \f$
421  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
422  * exponentially distributed random variable with rate parameter
423  * \f$ \lambda \f$
424  */
425 CREATE FUNCTION MADLIB_SCHEMA.exponential_quantile(
426  p DOUBLE PRECISION,
427  lambda DOUBLE PRECISION
428 ) RETURNS DOUBLE PRECISION
429 AS 'MODULE_PATHNAME'
430 LANGUAGE C
431 IMMUTABLE STRICT;
432 
433 
434 /**
435  * @brief Extreme Value cumulative distribution function
436  *
437  * @param x Random variate \f$ x \f$
438  * @param location Location \f$ \alpha \f$
439  * @param scale Scale \f$ \beta > 0 \f$
440  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is an extreme-value distributed
441  * random variable with location and scale parameters \f$ \alpha \f$ and
442  * \f$ \beta \f$, respectively
443  */
444 CREATE FUNCTION MADLIB_SCHEMA.extreme_value_cdf(
445  x DOUBLE PRECISION,
446  location DOUBLE PRECISION,
447  scale DOUBLE PRECISION
448 ) RETURNS DOUBLE PRECISION
449 AS 'MODULE_PATHNAME'
450 LANGUAGE C
451 IMMUTABLE STRICT;
452 
453 /**
454  * @brief Extreme Value probability density function
455  *
456  * @param x Random variate \f$ x \f$
457  * @param location Location \f$ \alpha \f$
458  * @param scale Scale \f$ \beta > 0 \f$
459  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
460  * an extreme-value distributed random variable with location and scale
461  * parameters \f$ \alpha \f$ and \f$ \beta \f$, respectively
462  */
463 CREATE FUNCTION MADLIB_SCHEMA.extreme_value_pdf(
464  x DOUBLE PRECISION,
465  location DOUBLE PRECISION,
466  scale DOUBLE PRECISION
467 ) RETURNS DOUBLE PRECISION
468 AS 'MODULE_PATHNAME'
469 LANGUAGE C
470 IMMUTABLE STRICT;
471 
472 /**
473  * @brief Extreme Value quantile function
474  *
475  * @param p Probability \f$ p \in [0,1] \f$
476  * @param location Location \f$ \alpha \f$
477  * @param scale Scale \f$ \beta > 0 \f$
478  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is
479  * an extreme-value distributed random variable with location and scale
480  * parameters \f$ \alpha \f$ and \f$ \beta \f$, respectively
481  */
482 CREATE FUNCTION MADLIB_SCHEMA.extreme_value_quantile(
483  p DOUBLE PRECISION,
484  location DOUBLE PRECISION,
485  scale DOUBLE PRECISION
486 ) RETURNS DOUBLE PRECISION
487 AS 'MODULE_PATHNAME'
488 LANGUAGE C
489 IMMUTABLE STRICT;
490 
491 
492 /**
493  * @brief Fisher F cumulative distribution function
494  *
495  * @param x Random variate \f$ x \f$
496  * @param df1 Degrees of freedom in numerator \f$ \nu_1 > 0 \f$
497  * @param df2 Degrees of freedom in denominator \f$ \nu_1 > 0 \f$
498  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a Fisher F-distributed
499  * random variable with parameters \f$ \nu_1 \f$ and \f$ \nu_2 \f$
500  */
501 CREATE FUNCTION MADLIB_SCHEMA.fisher_f_cdf(
502  x DOUBLE PRECISION,
503  df1 DOUBLE PRECISION,
504  df2 DOUBLE PRECISION
505 ) RETURNS DOUBLE PRECISION
506 AS 'MODULE_PATHNAME'
507 LANGUAGE C
508 IMMUTABLE STRICT;
509 
510 /**
511  * @brief Fisher F probability density function
512  *
513  * @param x Random variate \f$ x \f$
514  * @param df1 Degrees of freedom in numerator \f$ \nu_1 > 0 \f$
515  * @param df2 Degrees of freedom in denominator \f$ \nu_1 > 0 \f$
516  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
517  * a Fisher F-distributed random variable with parameters \f$ \nu_1 \f$ and
518  * \f$ \nu_2 \f$
519  */
520 CREATE FUNCTION MADLIB_SCHEMA.fisher_f_pdf(
521  x DOUBLE PRECISION,
522  df1 DOUBLE PRECISION,
523  df2 DOUBLE PRECISION
524 ) RETURNS DOUBLE PRECISION
525 AS 'MODULE_PATHNAME'
526 LANGUAGE C
527 IMMUTABLE STRICT;
528 
529 /**
530  * @brief Fisher F quantile function
531  *
532  * @param p Probability \f$ p \in [0,1] \f$
533  * @param df1 Degrees of freedom in numerator \f$ \nu_1 > 0 \f$
534  * @param df2 Degrees of freedom in denominator \f$ \nu_1 > 0 \f$
535  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
536  * Fisher F-distributed random variable with parameters \f$ \nu_1 \f$ and
537  * \f$ \nu_2 \f$
538  */
539 CREATE FUNCTION MADLIB_SCHEMA.fisher_f_quantile(
540  p DOUBLE PRECISION,
541  df1 DOUBLE PRECISION,
542  df2 DOUBLE PRECISION
543 ) RETURNS DOUBLE PRECISION
544 AS 'MODULE_PATHNAME'
545 LANGUAGE C
546 IMMUTABLE STRICT;
547 
548 
549 /**
550  * @brief Gamma cumulative distribution function
551  *
552  * @param x Random variate \f$ x \f$
553  * @param shape Shape \f$ k > 0 \f$
554  * @param scale Scale \f$ \theta > 0 \f$
555  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a gamma distributed random
556  * variable with shape and scale parameters \f$ k \f$ and
557  * \f$ \theta \f$, respectively
558  */
559 CREATE FUNCTION MADLIB_SCHEMA.gamma_cdf(
560  x DOUBLE PRECISION,
561  shape DOUBLE PRECISION,
562  scale DOUBLE PRECISION
563 ) RETURNS DOUBLE PRECISION
564 AS 'MODULE_PATHNAME'
565 LANGUAGE C
566 IMMUTABLE STRICT;
567 
568 /**
569  * @brief Gamma probability density function
570  *
571  * @param x Random variate \f$ x \f$
572  * @param shape Shape \f$ k > 0 \f$
573  * @param scale Scale \f$ \theta > 0 \f$
574  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
575  * a gamma distributed random variable with shape and scale parameters
576  * \f$ k \f$ and \f$ \theta \f$, respectively
577  */
578 CREATE FUNCTION MADLIB_SCHEMA.gamma_pdf(
579  x DOUBLE PRECISION,
580  shape DOUBLE PRECISION,
581  scale DOUBLE PRECISION
582 ) RETURNS DOUBLE PRECISION
583 AS 'MODULE_PATHNAME'
584 LANGUAGE C
585 IMMUTABLE STRICT;
586 
587 /**
588  * @brief Gamma quantile function
589  *
590  * @param p Probability \f$ p \in [0,1] \f$
591  * @param shape Shape \f$ k > 0 \f$
592  * @param scale Scale \f$ \theta > 0 \f$
593  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is
594  * a gamma distributed random variable with shape and scale parameters
595  * \f$ k \f$ and \f$ \theta \f$, respectively
596  */
597 CREATE FUNCTION MADLIB_SCHEMA.gamma_quantile(
598  p DOUBLE PRECISION,
599  shape DOUBLE PRECISION,
600  scale DOUBLE PRECISION
601 ) RETURNS DOUBLE PRECISION
602 AS 'MODULE_PATHNAME'
603 LANGUAGE C
604 IMMUTABLE STRICT;
605 
606 
607 /**
608  * @brief Geometric cumulative distribution function
609  *
610  * @param x Random variate \f$ x \f$
611  * @param sp Success probability \f$ \mathit{sp} \in [0,1] \f$
612  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a geometrically distributed
613  * random variable with success probability \f$ \mathit{sp} \f$.
614  */
615 CREATE FUNCTION MADLIB_SCHEMA.geometric_cdf(
616  x DOUBLE PRECISION,
617  sp DOUBLE PRECISION
618 ) RETURNS DOUBLE PRECISION
619 AS 'MODULE_PATHNAME'
620 LANGUAGE C
621 IMMUTABLE STRICT;
622 
623 /**
624  * @brief Geometric probability mass function
625  *
626  * @param x Random variate \f$ x \f$
627  * @param sp Success probability \f$ \mathit{sp} \in [0,1] \f$
628  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability mass function of a
629  * geometrically distributed random variable with success probability
630  * \f$ \mathit{sp} \f$
631  */
632 CREATE FUNCTION MADLIB_SCHEMA.geometric_pmf(
633  x INT4,
634  sp DOUBLE PRECISION
635 ) RETURNS DOUBLE PRECISION
636 AS 'MODULE_PATHNAME'
637 LANGUAGE C
638 IMMUTABLE STRICT;
639 
640 /**
641  * @brief Geometric quantile function
642  *
643  * @param p Probability \f$ p \in [0,1] \f$
644  * @param sp Success probability \f$ \mathit{sp} \in [0,1] \f$
645  * @return If \f$ p < 0.5 \f$ the maximum \f$ x \f$ such that
646  * \f$ p \geq \Pr[X \leq x] \f$. If \f$ p \geq 0.5 \f$ the minimum \f$ x \f$
647  * such that \f$ p \leq \Pr[X \leq x] \f$. Here, \f$ X \f$ is a
648  * geometrically distributed random variable with success probability
649  * \f$ \mathit{sp} \f$.
650  */
651 CREATE FUNCTION MADLIB_SCHEMA.geometric_quantile(
652  p DOUBLE PRECISION,
653  sp DOUBLE PRECISION
654 ) RETURNS DOUBLE PRECISION
655 AS 'MODULE_PATHNAME'
656 LANGUAGE C
657 IMMUTABLE STRICT;
658 
659 
660 /**
661  * @brief Hypergeometric cumulative distribution function
662  *
663  * @param x Random variate \f$ x \f$
664  * @param r Number \f$ r \in \{ 0, 1, \dots, N \} \f$ of items with
665  * distinct property (sometimes called the number of <em>success states</em>
666  * in population)
667  * @param n Number \f$ n \in \{ 0, 1, \dots, N \} \f$ of draws (without
668  * replacement)
669  * @param N Total number \f$ N \in \mathbb N \f$ of items
670  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a hypergeometrically
671  * distributed random variable with parameters \f$ r, n, N \f$
672  *
673  * @internal Boost error messages refer to parameters 'r', 'n', 'N', so for now
674  * we use the same identifiers for our function definition.
675  */
676 CREATE FUNCTION MADLIB_SCHEMA.hypergeometric_cdf(
677  x DOUBLE PRECISION,
678  r INT4,
679  n INT4,
680  "N" INT4
681 ) RETURNS DOUBLE PRECISION
682 AS 'MODULE_PATHNAME'
683 LANGUAGE C
684 IMMUTABLE STRICT;
685 
686 /**
687  * @brief Hypergeometric probability mass function
688  *
689  * @param x Random variate \f$ x \f$
690  * @param r Number \f$ r \in \{ 0, 1, \dots, N \} \f$ of items with
691  * distinct property (sometimes called the number of <em>success states</em>
692  * in population)
693  * @param n Number \f$ n \in \{ 0, 1, \dots, N \} \f$ of draws (without
694  * replacement)
695  * @param N Total number \f$ N \in \mathbb N \f$ of items
696  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability mass function of
697  * a hypergeometrically distributed random variable with parameters
698  * \f$ r, n, N \f$
699  */
700 CREATE FUNCTION MADLIB_SCHEMA.hypergeometric_pmf(
701  x INT4,
702  r INT4,
703  n INT4,
704  "N" INT4
705 ) RETURNS DOUBLE PRECISION
706 AS 'MODULE_PATHNAME'
707 LANGUAGE C
708 IMMUTABLE STRICT;
709 
710 
711 /**
712  * @brief Hypergeometric quantile function
713  *
714  * @param p Probability \f$ p \in [0,1] \f$
715  * @param r Number \f$ r \in \{ 0, 1, \dots, N \} \f$ of items with
716  * distinct property (sometimes called the number of <em>success states</em>
717  * in population)
718  * @param n Number \f$ n \in \{ 0, 1, \dots, N \} \f$ of draws (without
719  * replacement)
720  * @param N Total number \f$ N \in \mathbb N \f$ of items
721  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is
722  * a hypergeometrically distributed random variable with parameters
723  * \f$ r, n, N \f$
724  */
725 CREATE FUNCTION MADLIB_SCHEMA.hypergeometric_quantile(
726  p DOUBLE PRECISION,
727  r INT4,
728  n INT4,
729  "N" INT4
730 ) RETURNS DOUBLE PRECISION
731 AS 'MODULE_PATHNAME'
732 LANGUAGE C
733 IMMUTABLE STRICT;
734 
735 
736 /**
737  * @brief Inverse Gamma cumulative distribution function
738  *
739  * @param x Random variate \f$ x \f$
740  * @param shape Shape \f$ \alpha > 0 \f$
741  * @param scale Scale \f$ \beta > 0 \f$
742  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is an inverse-gamma distributed
743  * random variable with shape and scale parameters \f$ \alpha \f$ and
744  * \f$ \beta \f$, respectively
745  */
746 CREATE FUNCTION MADLIB_SCHEMA.inverse_gamma_cdf(
747  x DOUBLE PRECISION,
748  shape DOUBLE PRECISION,
749  scale DOUBLE PRECISION
750 ) RETURNS DOUBLE PRECISION
751 AS 'MODULE_PATHNAME'
752 LANGUAGE C
753 IMMUTABLE STRICT;
754 
755 /**
756  * @brief Inverse Gamma probability density function
757  *
758  * @param x Random variate \f$ x \f$
759  * @param shape Shape \f$ \alpha > 0 \f$
760  * @param scale Scale \f$ \beta > 0 \f$
761  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
762  * an inverse-gamma distributed random variable with shape and scale
763  * parameters \f$ \alpha \f$ and \f$ \beta \f$, respectively
764  */
765 CREATE FUNCTION MADLIB_SCHEMA.inverse_gamma_pdf(
766  x DOUBLE PRECISION,
767  shape DOUBLE PRECISION,
768  scale DOUBLE PRECISION
769 ) RETURNS DOUBLE PRECISION
770 AS 'MODULE_PATHNAME'
771 LANGUAGE C
772 IMMUTABLE STRICT;
773 
774 /**
775  * @brief Inverse Gamma quantile function
776  *
777  * @param p Probability \f$ p \in [0,1] \f$
778  * @param shape Shape \f$ \alpha > 0 \f$
779  * @param scale Scale \f$ \beta > 0 \f$
780  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is
781  * an inverse-gamma distributed random variable with shape and scale
782  * parameters \f$ \alpha \f$ and \f$ \beta \f$, respectively
783  */
784 CREATE FUNCTION MADLIB_SCHEMA.inverse_gamma_quantile(
785  p DOUBLE PRECISION,
786  shape DOUBLE PRECISION,
787  scale DOUBLE PRECISION
788 ) RETURNS DOUBLE PRECISION
789 AS 'MODULE_PATHNAME'
790 LANGUAGE C
791 IMMUTABLE STRICT;
792 
793 
794 /**
795  * @brief Kolmogorov cumulative distribution function
796  *
797  * @param x Random variate \f$ x \f$
798  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a Kolmogorov distributed
799  * random variable
800  *
801  * @sa Kolmogorov-Smirnov test: ks_test()
802  */
803 CREATE FUNCTION MADLIB_SCHEMA.kolmogorov_cdf(
804  x DOUBLE PRECISION
805 ) RETURNS DOUBLE PRECISION
806 AS 'MODULE_PATHNAME'
807 LANGUAGE C
808 IMMUTABLE STRICT;
809 
810 
811 /**
812  * @brief Laplace cumulative distribution function
813  *
814  * @param x Random variate \f$ x \f$
815  * @param mean Mean \f$ \mu \f$
816  * @param scale Scale \f$ b > 0 \f$
817  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a Laplace-distributed random
818  * variable with mean \f$ \mu \f$ and variance \f$ 2 b^2 \f$
819  */
820 CREATE FUNCTION MADLIB_SCHEMA.laplace_cdf(
821  x DOUBLE PRECISION,
822  mean DOUBLE PRECISION,
823  scale DOUBLE PRECISION
824 ) RETURNS DOUBLE PRECISION
825 AS 'MODULE_PATHNAME'
826 LANGUAGE C
827 IMMUTABLE STRICT;
828 
829 /**
830  * @brief Laplace probability density function
831  *
832  * @param x Random variate \f$ x \f$
833  * @param mean Mean \f$ \mu \f$
834  * @param scale Scale \f$ b > 0 \f$
835  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
836  * a Laplace-distributed random variable with mean \f$ \mu \f$ and variance
837  * \f$ 2 b^2 \f$
838  */
839 CREATE FUNCTION MADLIB_SCHEMA.laplace_pdf(
840  x DOUBLE PRECISION,
841  mean DOUBLE PRECISION,
842  scale DOUBLE PRECISION
843 ) RETURNS DOUBLE PRECISION
844 AS 'MODULE_PATHNAME'
845 LANGUAGE C
846 IMMUTABLE STRICT;
847 
848 /**
849  * @brief Laplace quantile function
850  *
851  * @param p Probability \f$ p \in [0,1] \f$
852  * @param mean Mean \f$ \mu \f$
853  * @param scale Scale \f$ b > 0 \f$
854  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
855  * Laplace-distributed random variable with mean \f$ \mu \f$ and variance
856  * \f$ 2 b^2 \f$
857  */
858 CREATE FUNCTION MADLIB_SCHEMA.laplace_quantile(
859  p DOUBLE PRECISION,
860  mean DOUBLE PRECISION,
861  scale DOUBLE PRECISION
862 ) RETURNS DOUBLE PRECISION
863 AS 'MODULE_PATHNAME'
864 LANGUAGE C
865 IMMUTABLE STRICT;
866 
867 
868 /**
869  * @brief Logistic cumulative distribution function
870  *
871  * @param x Random variate \f$ x \f$
872  * @param mean Mean \f$ \mu \f$
873  * @param scale Scale \f$ s > 0 \f$
874  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a logistically distributed
875  * random variable with mean \f$ \mu \f$ and scale parameter \f$ s \f$
876  */
877 CREATE FUNCTION MADLIB_SCHEMA.logistic_cdf(
878  x DOUBLE PRECISION,
879  mean DOUBLE PRECISION,
880  scale DOUBLE PRECISION
881 ) RETURNS DOUBLE PRECISION
882 AS 'MODULE_PATHNAME'
883 LANGUAGE C
884 IMMUTABLE STRICT;
885 
886 /**
887  * @brief Logistic probability density function
888  *
889  * @param x Random variate \f$ x \f$
890  * @param mean Mean \f$ \mu \f$
891  * @param scale Scale \f$ s > 0 \f$
892  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
893  * a logistically distributed random variable with mean \f$ \mu \f$ and
894  * scale parameter \f$ s \f$
895  */
896 CREATE FUNCTION MADLIB_SCHEMA.logistic_pdf(
897  x DOUBLE PRECISION,
898  mean DOUBLE PRECISION,
899  scale DOUBLE PRECISION
900 ) RETURNS DOUBLE PRECISION
901 AS 'MODULE_PATHNAME'
902 LANGUAGE C
903 IMMUTABLE STRICT;
904 
905 /**
906  * @brief Logistic quantile function
907  *
908  * @param p Probability \f$ p \in [0,1] \f$
909  * @param mean Mean \f$ \mu \f$
910  * @param scale Scale \f$ s > 0 \f$
911  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is
912  * a logistically distributed random variable with mean \f$ \mu \f$ and
913  * scale parameter \f$ s \f$
914  */
915 CREATE FUNCTION MADLIB_SCHEMA.logistic_quantile(
916  p DOUBLE PRECISION,
917  mean DOUBLE PRECISION,
918  scale DOUBLE PRECISION
919 ) RETURNS DOUBLE PRECISION
920 AS 'MODULE_PATHNAME'
921 LANGUAGE C
922 IMMUTABLE STRICT;
923 
924 
925 /**
926  * @brief Log-normal cumulative distribution function
927  *
928  * @param x Random variate \f$ x \f$
929  * @param location Location \f$ m \f$
930  * @param scale Scale \f$ s > 0 \f$
931  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a lognormally distributed
932  * random variable with location and scale parameters \f$ m \f$ and
933  * \f$ s \f$, respectively
934  */
935 CREATE FUNCTION MADLIB_SCHEMA.lognormal_cdf(
936  x DOUBLE PRECISION,
937  location DOUBLE PRECISION,
938  scale DOUBLE PRECISION
939 ) RETURNS DOUBLE PRECISION
940 AS 'MODULE_PATHNAME'
941 LANGUAGE C
942 IMMUTABLE STRICT;
943 
944 /**
945  * @brief Log-normal probability density function
946  *
947  * @param x Random variate \f$ x \f$
948  * @param location Location \f$ m \f$
949  * @param scale Scale \f$ s > 0 \f$
950  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
951  * a lognormally distributed random variable with location and scale
952  * parameters \f$ m \f$ and \f$ s \f$, respectively
953  */
954 CREATE FUNCTION MADLIB_SCHEMA.lognormal_pdf(
955  x DOUBLE PRECISION,
956  location DOUBLE PRECISION,
957  scale DOUBLE PRECISION
958 ) RETURNS DOUBLE PRECISION
959 AS 'MODULE_PATHNAME'
960 LANGUAGE C
961 IMMUTABLE STRICT;
962 
963 /**
964  * @brief Log-normal quantile function
965  *
966  * @param p Probability \f$ p \in [0,1] \f$
967  * @param location Location \f$ m \f$
968  * @param scale Scale \f$ s > 0 \f$
969  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is
970  * a lognormally distributed random variable with location and scale
971  * parameters \f$ m \f$ and \f$ s \f$, respectively
972  */
973 CREATE FUNCTION MADLIB_SCHEMA.lognormal_quantile(
974  p DOUBLE PRECISION,
975  location DOUBLE PRECISION,
976  scale DOUBLE PRECISION
977 ) RETURNS DOUBLE PRECISION
978 AS 'MODULE_PATHNAME'
979 LANGUAGE C
980 IMMUTABLE STRICT;
981 
982 
983 /**
984  * @brief Negative binomial cumulative distribution function
985  *
986  * @param x Random variate \f$ x \f$
987  * @param r Total number \f$ r > 0 \f$ of successes in \f$ x + r \f$ trials
988  * (assuming success in the last trial)
989  * @param sp Success probability \f$ \mathit{sp} \in (0,1] \f$ in each trial
990  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a negative-binomially
991  * distributed random variable with parameters \f$ r, \mathit{sp} \f$
992  */
993 CREATE FUNCTION MADLIB_SCHEMA.negative_binomial_cdf(
994  x DOUBLE PRECISION,
995  r DOUBLE PRECISION,
996  sp DOUBLE PRECISION
997 ) RETURNS DOUBLE PRECISION
998 AS 'MODULE_PATHNAME'
999 LANGUAGE C
1000 IMMUTABLE STRICT;
1001 
1002 /**
1003  * @brief Negative binomial probability mass function
1004  *
1005  * @param x Random variate \f$ x \f$
1006  * @param r Total number \f$ r > 0 \f$ of successes in \f$ x + r \f$ trials
1007  * (assuming success in the last trial)
1008  * @param sp Success probability \f$ \mathit{sp} \in (0,1] \f$ in each trial
1009  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability mass function of
1010  * a negative-binomially distributed random variable with parameters
1011  * \f$ r, \mathit{sp} \f$
1012  */
1013 CREATE FUNCTION MADLIB_SCHEMA.negative_binomial_pmf(
1014  x INT4,
1015  r DOUBLE PRECISION,
1016  sp DOUBLE PRECISION
1017 ) RETURNS DOUBLE PRECISION
1018 AS 'MODULE_PATHNAME'
1019 LANGUAGE C
1020 IMMUTABLE STRICT;
1021 
1022 /**
1023  * @brief Negative binomial quantile function
1024  *
1025  * @param p Probability \f$ p \in [0,1] \f$
1026  * @param r Total number \f$ r > 0 \f$ of successes in \f$ x + r \f$ trials
1027  * (assuming success in the last trial)
1028  * @param sp Success probability \f$ \mathit{sp} \in (0,1] \f$ in each trial
1029  * @return If \f$ p < 0.5 \f$ the maximum \f$ x \f$ such that
1030  * \f$ p \geq \Pr[X \leq x] \f$. If \f$ p \geq 0.5 \f$ the minimum \f$ x \f$
1031  * such that \f$ p \leq \Pr[X \leq x] \f$. Here, \f$ X \f$ is
1032  * a negative-binomially distributed random variable with parameters
1033  * \f$ r, \mathit{sp} \f$
1034  */
1035 CREATE FUNCTION MADLIB_SCHEMA.negative_binomial_quantile(
1036  p DOUBLE PRECISION,
1037  r DOUBLE PRECISION,
1038  sp DOUBLE PRECISION
1039 ) RETURNS DOUBLE PRECISION
1040 AS 'MODULE_PATHNAME'
1041 LANGUAGE C
1042 IMMUTABLE STRICT;
1043 
1044 
1045 /**
1046  * @brief Noncentral beta cumulative distribution function
1047  *
1048  * @param x Random variate \f$ x \f$
1049  * @param alpha Shape \f$ \alpha > 0 \f$
1050  * @param beta Shape \f$ \beta > 0 \f$
1051  * @param ncp Noncentrality parameter \f$ \delta \geq 0 \f$
1052  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a noncentral-beta
1053  * distributed random variable with shape parameters \f$ shape_1 \f$ and
1054  * \f$ shape_2 \f$ and noncentrality parameter \f$ \delta \f$
1055  */
1056 CREATE FUNCTION MADLIB_SCHEMA.non_central_beta_cdf(
1057  x DOUBLE PRECISION,
1058  alpha DOUBLE PRECISION,
1059  beta DOUBLE PRECISION,
1060  ncp DOUBLE PRECISION
1061 ) RETURNS DOUBLE PRECISION
1062 AS 'MODULE_PATHNAME'
1063 LANGUAGE C
1064 IMMUTABLE STRICT;
1065 
1066 /**
1067  * @brief Noncentral beta probability density function
1068  *
1069  * @param x Random variate \f$ x \f$
1070  * @param alpha Shape \f$ \alpha > 0 \f$
1071  * @param beta Shape \f$ \beta > 0 \f$
1072  * @param ncp Noncentrality parameter \f$ \delta \geq 0 \f$
1073  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
1074  * a noncentral-beta distributed random variable with shape parameters
1075  * \f$ shape_1 \f$ and \f$ shape_2 \f$ and noncentrality parameter
1076  * \f$ \delta \f$
1077  */
1078 CREATE FUNCTION MADLIB_SCHEMA.non_central_beta_pdf(
1079  x DOUBLE PRECISION,
1080  alpha DOUBLE PRECISION,
1081  beta DOUBLE PRECISION,
1082  ncp DOUBLE PRECISION
1083 ) RETURNS DOUBLE PRECISION
1084 AS 'MODULE_PATHNAME'
1085 LANGUAGE C
1086 IMMUTABLE STRICT;
1087 
1088 /**
1089  * @brief Noncentral beta quantile function
1090  *
1091  * @param p Probability \f$ p \in [0,1] \f$
1092  * @param alpha Shape \f$ \alpha > 0 \f$
1093  * @param beta Shape \f$ \beta > 0 \f$
1094  * @param ncp Noncentrality parameter \f$ \delta \geq 0 \f$
1095  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is
1096  * a noncentral-beta distributed random variable with shape parameters
1097  * \f$ shape_1 \f$ and \f$ shape_2 \f$ and noncentrality parameter
1098  * \f$ \delta \f$
1099  */
1100 CREATE FUNCTION MADLIB_SCHEMA.non_central_beta_quantile(
1101  p DOUBLE PRECISION,
1102  alpha DOUBLE PRECISION,
1103  beta DOUBLE PRECISION,
1104  ncp DOUBLE PRECISION
1105 ) RETURNS DOUBLE PRECISION
1106 AS 'MODULE_PATHNAME'
1107 LANGUAGE C
1108 IMMUTABLE STRICT;
1109 
1110 
1111 /**
1112  * @brief Noncentral chi-squared cumulative distribution function
1113  *
1114  * @param x Random variate \f$ x \f$
1115  * @param df Degrees of freedom \f$ \nu > 0 \f$
1116  * @param ncp The noncentrality parameter \f$ \lambda \geq 0 \f$
1117  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a noncentral-chi-squared
1118  * distributed random variable with \f$ \nu \f$ degrees of freedom and
1119  * noncentrality parameter \f$ \lambda \f$
1120  */
1121 CREATE FUNCTION MADLIB_SCHEMA.non_central_chi_squared_cdf(
1122  x DOUBLE PRECISION,
1123  df DOUBLE PRECISION,
1124  ncp DOUBLE PRECISION
1125 ) RETURNS DOUBLE PRECISION
1126 AS 'MODULE_PATHNAME'
1127 LANGUAGE C
1128 IMMUTABLE STRICT;
1129 
1130 /**
1131  * @brief Noncentral chi-squared distribution probability density function
1132  *
1133  * @param x Random variate \f$ x \f$
1134  * @param df Degrees of freedom \f$ \nu > 0 \f$
1135  * @param ncp The noncentrality parameter \f$ \lambda \geq 0 \f$
1136  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
1137  * a noncentral-chi-squared distributed random variable with \f$ \nu \f$
1138  * degrees of freedom and noncentrality parameter \f$ \lambda \f$
1139  */
1140 CREATE FUNCTION MADLIB_SCHEMA.non_central_chi_squared_pdf(
1141  x DOUBLE PRECISION,
1142  df DOUBLE PRECISION,
1143  ncp DOUBLE PRECISION
1144 ) RETURNS DOUBLE PRECISION
1145 AS 'MODULE_PATHNAME'
1146 LANGUAGE C
1147 IMMUTABLE STRICT;
1148 
1149 /**
1150  * @brief Noncentral chi-squared distribution quantile function
1151  *
1152  * @param p Probability \f$ p \in [0,1] \f$
1153  * @param df Degrees of freedom \f$ \nu > 0 \f$
1154  * @param ncp The noncentrality parameter \f$ \lambda \geq 0 \f$
1155  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1156  * noncentral-chi-squared distributed random variable with \f$ \nu \f$
1157  * degrees of freedom and noncentrality parameter \f$ \lambda \f$
1158  */
1159 CREATE FUNCTION MADLIB_SCHEMA.non_central_chi_squared_quantile(
1160  p DOUBLE PRECISION,
1161  df DOUBLE PRECISION,
1162  ncp DOUBLE PRECISION
1163 ) RETURNS DOUBLE PRECISION
1164 AS 'MODULE_PATHNAME'
1165 LANGUAGE C
1166 IMMUTABLE STRICT;
1167 
1168 
1169 /**
1170  * @brief Noncentral Fisher F cumulative distribution function
1171  *
1172  * @param x Random variate \f$ x \f$
1173  * @param df1 Degrees of freedom in numerator \f$ \nu_1 > 0 \f$
1174  * @param df2 Degrees of freedom in denominator \f$ \nu_1 > 0 \f$
1175  * @param ncp The noncentrality parameter \f$ \lambda \geq 0 \f$
1176  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a
1177  * noncentral Fisher F-distributed random variable with parameters
1178  * \f$ \nu_1, \nu_2, \lambda \f$
1179  */
1180 CREATE FUNCTION MADLIB_SCHEMA.non_central_f_cdf(
1181  x DOUBLE PRECISION,
1182  df1 DOUBLE PRECISION,
1183  df2 DOUBLE PRECISION,
1184  ncp DOUBLE PRECISION
1185 ) RETURNS DOUBLE PRECISION
1186 AS 'MODULE_PATHNAME'
1187 LANGUAGE C
1188 IMMUTABLE STRICT;
1189 
1190 /**
1191  * @brief Noncentral Fisher F probability density function
1192  *
1193  * @param x Random variate \f$ x \f$
1194  * @param df1 Degrees of freedom in numerator \f$ \nu_1 > 0 \f$
1195  * @param df2 Degrees of freedom in denominator \f$ \nu_1 > 0 \f$
1196  * @param ncp The noncentrality parameter \f$ \lambda \geq 0 \f$
1197  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of a
1198  * noncentral Fisher F-distributed random variable with parameters
1199  * \f$ \nu_1, \nu_2, \lambda \f$
1200  */
1201 CREATE FUNCTION MADLIB_SCHEMA.non_central_f_pdf(
1202  x DOUBLE PRECISION,
1203  df1 DOUBLE PRECISION,
1204  df2 DOUBLE PRECISION,
1205  ncp DOUBLE PRECISION
1206 ) RETURNS DOUBLE PRECISION
1207 AS 'MODULE_PATHNAME'
1208 LANGUAGE C
1209 IMMUTABLE STRICT;
1210 
1211 /**
1212  * @brief Noncentral Fisher F quantile function
1213  *
1214  * @param p Probability \f$ p \in [0,1] \f$
1215  * @param df1 Degrees of freedom in numerator \f$ \nu_1 > 0 \f$
1216  * @param df2 Degrees of freedom in denominator \f$ \nu_1 > 0 \f$
1217  * @param ncp The noncentrality parameter \f$ \lambda \geq 0 \f$
1218  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1219  * noncentral Fisher F-distributed random variable with parameters
1220  * \f$ \nu_1, \nu_2, \lambda \f$
1221  */
1222 CREATE FUNCTION MADLIB_SCHEMA.non_central_f_quantile(
1223  p DOUBLE PRECISION,
1224  df1 DOUBLE PRECISION,
1225  df2 DOUBLE PRECISION,
1226  ncp DOUBLE PRECISION
1227 ) RETURNS DOUBLE PRECISION
1228 AS 'MODULE_PATHNAME'
1229 LANGUAGE C
1230 IMMUTABLE STRICT;
1231 
1232 
1233 /**
1234  * @brief Noncentral Student-t cumulative distribution function
1235  *
1236  * @param x Random variate \f$ x \f$
1237  * @param df Degrees of freedom \f$ \nu > 0 \f$
1238  * @param ncp Noncentrality parameter \f$ \delta \f$
1239  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a noncentral Student's
1240  * t-distributed random variable with \f$ \nu \f$ degrees of freedom and
1241  * noncentrality parameter \f$ \delta \f$
1242  */
1243 CREATE FUNCTION MADLIB_SCHEMA.non_central_t_cdf(
1244  x DOUBLE PRECISION,
1245  df DOUBLE PRECISION,
1246  ncp DOUBLE PRECISION
1247 ) RETURNS DOUBLE PRECISION
1248 AS 'MODULE_PATHNAME'
1249 LANGUAGE C
1250 IMMUTABLE STRICT;
1251 
1252 /**
1253  * @brief Noncentral Student-t probability density function
1254  *
1255  * @param x Random variate \f$ x \f$
1256  * @param df Degrees of freedom \f$ \nu > 0 \f$
1257  * @param ncp Noncentrality parameter \f$ \delta \f$
1258  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1259  * noncentral Student's t-distributed random variable with \f$ \nu \f$
1260  * degrees of freedom and noncentrality parameter \f$ \delta \f$
1261  */
1262 CREATE FUNCTION MADLIB_SCHEMA.non_central_t_pdf(
1263  x DOUBLE PRECISION,
1264  df DOUBLE PRECISION,
1265  ncp DOUBLE PRECISION
1266 ) RETURNS DOUBLE PRECISION
1267 AS 'MODULE_PATHNAME'
1268 LANGUAGE C
1269 IMMUTABLE STRICT;
1270 
1271 /**
1272  * @brief Noncentral Student-t quantile function
1273  *
1274  * @param p Probability \f$ p \in [0,1] \f$
1275  * @param df Degrees of freedom \f$ \nu > 0 \f$
1276  * @param ncp Noncentrality parameter \f$ \delta \f$
1277  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1278  * noncentral Student's t-distributed random variable with \f$ \nu \f$
1279  * degrees of freedom and noncentrality parameter \f$ \delta \f$
1280  */
1281 CREATE FUNCTION MADLIB_SCHEMA.non_central_t_quantile(
1282  p DOUBLE PRECISION,
1283  df DOUBLE PRECISION,
1284  ncp DOUBLE PRECISION
1285 ) RETURNS DOUBLE PRECISION
1286 AS 'MODULE_PATHNAME'
1287 LANGUAGE C
1288 IMMUTABLE STRICT;
1289 
1290 
1291 /**
1292  * @brief Normal cumulative distribution function
1293  *
1294  * @param x Random variate \f$ x \f$
1295  * @param mean Mean \f$ \mu \f$
1296  * @param sd Standard deviation \f$ \sigma > 0 \f$
1297  * @return \f$ \Pr[X \leq x] \f$ where \f$ T \f$ is a normally distributed
1298  * random variable with mean \f$ \mu \f$ and variance \f$ \sigma^2 \f$
1299  */
1300 CREATE FUNCTION MADLIB_SCHEMA.normal_cdf(
1301  x DOUBLE PRECISION,
1302  mean DOUBLE PRECISION /*+ DEFAULT 0 */,
1303  sd DOUBLE PRECISION /*+ DEFAULT 1 */
1304 ) RETURNS DOUBLE PRECISION
1305 AS 'MODULE_PATHNAME'
1306 LANGUAGE C
1307 IMMUTABLE STRICT;
1308 
1309 CREATE FUNCTION MADLIB_SCHEMA.normal_cdf(
1310  x DOUBLE PRECISION,
1311  mean DOUBLE PRECISION
1312 ) RETURNS DOUBLE PRECISION
1313 IMMUTABLE
1314 STRICT
1315 LANGUAGE sql AS $$
1316  SELECT MADLIB_SCHEMA.normal_cdf($1, $2, 1)
1317 $$;
1318 
1319 CREATE FUNCTION MADLIB_SCHEMA.normal_cdf(
1320  x DOUBLE PRECISION
1321 ) RETURNS DOUBLE PRECISION
1322 IMMUTABLE
1323 STRICT
1324 LANGUAGE sql AS $$
1325  SELECT MADLIB_SCHEMA.normal_cdf($1, 0, 1)
1326 $$;
1327 
1328 /**
1329  * @brief Normal probability density function
1330  *
1331  * @param x Random variate \f$ x \f$
1332  * @param mean Mean \f$ \mu \f$
1333  * @param sd Standard deviation \f$ \sigma > 0 \f$
1334  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
1335  * a normally distributed random variable with mean \f$ \mu \f$ and
1336  * variance \f$ \sigma^2 \f$
1337  */
1338 CREATE FUNCTION MADLIB_SCHEMA.normal_pdf(
1339  x DOUBLE PRECISION,
1340  mean DOUBLE PRECISION /*+ DEFAULT 0 */,
1341  sd DOUBLE PRECISION /*+ DEFAULT 1 */
1342 ) RETURNS DOUBLE PRECISION
1343 AS 'MODULE_PATHNAME'
1344 LANGUAGE C
1345 IMMUTABLE STRICT;
1346 
1347 CREATE FUNCTION MADLIB_SCHEMA.normal_pdf(
1348  x DOUBLE PRECISION,
1349  mean DOUBLE PRECISION
1350 ) RETURNS DOUBLE PRECISION
1351 IMMUTABLE
1352 STRICT
1353 LANGUAGE sql AS $$
1354  SELECT MADLIB_SCHEMA.normal_pdf($1, $2, 1)
1355 $$;
1356 
1357 CREATE FUNCTION MADLIB_SCHEMA.normal_pdf(
1358  x DOUBLE PRECISION
1359 ) RETURNS DOUBLE PRECISION
1360 IMMUTABLE
1361 STRICT
1362 LANGUAGE sql AS $$
1363  SELECT MADLIB_SCHEMA.normal_pdf($1, 0, 1)
1364 $$;
1365 
1366 /**
1367  * @brief Normal quantile function
1368  *
1369  * @param p Probability \f$ p \in [0,1] \f$
1370  * @param mean Mean \f$ \mu \f$
1371  * @param sd Standard deviation \f$ \sigma > 0 \f$
1372  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1373  * normally distributed random variable with mean \f$ \mu \f$ and
1374  * variance \f$ \sigma^2 \f$
1375  */
1376 CREATE FUNCTION MADLIB_SCHEMA.normal_quantile(
1377  p DOUBLE PRECISION,
1378  mean DOUBLE PRECISION /*+ DEFAULT 0 */,
1379  sd DOUBLE PRECISION /*+ DEFAULT 1 */
1380 ) RETURNS DOUBLE PRECISION
1381 AS 'MODULE_PATHNAME'
1382 LANGUAGE C
1383 IMMUTABLE STRICT;
1384 
1385 CREATE FUNCTION MADLIB_SCHEMA.normal_quantile(
1386  p DOUBLE PRECISION,
1387  mean DOUBLE PRECISION
1388 ) RETURNS DOUBLE PRECISION
1389 IMMUTABLE
1390 STRICT
1391 LANGUAGE sql AS $$
1392  SELECT MADLIB_SCHEMA.normal_quantile($1, $2, 1)
1393 $$;
1394 
1395 CREATE FUNCTION MADLIB_SCHEMA.normal_quantile(
1396  p DOUBLE PRECISION
1397 ) RETURNS DOUBLE PRECISION
1398 IMMUTABLE
1399 STRICT
1400 LANGUAGE sql AS $$
1401  SELECT MADLIB_SCHEMA.normal_quantile($1, 0, 1)
1402 $$;
1403 
1404 
1405 /**
1406  * @brief Pareto cumulative distribution function
1407  *
1408  * @param x Random variate \f$ x \f$
1409  * @param scale Scale \f$ \beta > 0 \f$
1410  * @param shape Shape \f$ \alpha > 0 \f$
1411  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a Pareto-distributed random
1412  * variable with shape and scale parameters \f$ \alpha \f$ and
1413  * \f$ \beta \f$, respectively
1414  */
1415 CREATE FUNCTION MADLIB_SCHEMA.pareto_cdf(
1416  x DOUBLE PRECISION,
1417  scale DOUBLE PRECISION,
1418  shape DOUBLE PRECISION
1419 ) RETURNS DOUBLE PRECISION
1420 AS 'MODULE_PATHNAME'
1421 LANGUAGE C
1422 IMMUTABLE STRICT;
1423 
1424 /**
1425  * @brief Pareto probability density function
1426  *
1427  * @param x Random variate \f$ x \f$
1428  * @param scale Scale \f$ \beta > 0 \f$
1429  * @param shape Shape \f$ \alpha > 0 \f$
1430  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
1431  * a Pareto-distributed random variable with shape and scale parameters
1432  * \f$ \alpha \f$ and \f$ \beta \f$, respectively
1433  */
1434 CREATE FUNCTION MADLIB_SCHEMA.pareto_pdf(
1435  x DOUBLE PRECISION,
1436  scale DOUBLE PRECISION,
1437  shape DOUBLE PRECISION
1438 ) RETURNS DOUBLE PRECISION
1439 AS 'MODULE_PATHNAME'
1440 LANGUAGE C
1441 IMMUTABLE STRICT;
1442 
1443 /**
1444  * @brief Pareto quantile function
1445  *
1446  * @param p Probability \f$ p \in [0,1] \f$
1447  * @param scale Scale \f$ \beta > 0 \f$
1448  * @param shape Shape \f$ \alpha > 0 \f$
1449  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1450  * Pareto-distributed random variable with shape and scale parameters
1451  * \f$ \alpha \f$ and \f$ \beta \f$, respectively
1452  */
1453 CREATE FUNCTION MADLIB_SCHEMA.pareto_quantile(
1454  p DOUBLE PRECISION,
1455  scale DOUBLE PRECISION,
1456  shape DOUBLE PRECISION
1457 ) RETURNS DOUBLE PRECISION
1458 AS 'MODULE_PATHNAME'
1459 LANGUAGE C
1460 IMMUTABLE STRICT;
1461 
1462 
1463 /**
1464  * @brief Poisson cumulative distribution function
1465  *
1466  * @param x Random variate \f$ x \f$
1467  * @param mean Average occurrence rate \f$ \lambda > 0 \f$
1468  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a Poisson distributed random
1469  * variable with mean \f$ \lambda \f$
1470  */
1471 CREATE FUNCTION MADLIB_SCHEMA.poisson_cdf(
1472  x DOUBLE PRECISION,
1473  mean DOUBLE PRECISION
1474 ) RETURNS DOUBLE PRECISION
1475 AS 'MODULE_PATHNAME'
1476 LANGUAGE C
1477 IMMUTABLE STRICT;
1478 
1479 /**
1480  * @brief Poisson probability mass function
1481  *
1482  * @param x Random variate \f$ x \f$
1483  * @param mean Average occurrence rate \f$ \lambda > 0 \f$
1484  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability mass function of a
1485  * Poisson distributed random variable with mean \f$ \lambda \f$
1486  */
1487 CREATE FUNCTION MADLIB_SCHEMA.poisson_pmf(
1488  x INT4,
1489  mean DOUBLE PRECISION
1490 ) RETURNS DOUBLE PRECISION
1491 AS 'MODULE_PATHNAME'
1492 LANGUAGE C
1493 IMMUTABLE STRICT;
1494 
1495 /**
1496  * @brief Poisson quantile function
1497  *
1498  * @param p Probability \f$ p \in [0,1] \f$
1499  * @param mean Average occurrence rate \f$ \lambda > 0 \f$
1500  * @return If \f$ p < 0.5 \f$ the maximum \f$ x \f$ such that
1501  * \f$ p \geq \Pr[X \leq x] \f$. If \f$ p \geq 0.5 \f$ the minimum \f$ x \f$
1502  * such that \f$ p \leq \Pr[X \leq x] \f$. Here, \f$ X \f$ is a
1503  * Poisson distributed random variable with mean \f$ \lambda \f$
1504  */
1505 CREATE FUNCTION MADLIB_SCHEMA.poisson_quantile(
1506  p DOUBLE PRECISION,
1507  mean DOUBLE PRECISION
1508 ) RETURNS DOUBLE PRECISION
1509 AS 'MODULE_PATHNAME'
1510 LANGUAGE C
1511 IMMUTABLE STRICT;
1512 
1513 
1514 /**
1515  * @brief Rayleigh cumulative distribution function
1516  *
1517  * @param x Random variate \f$ x \f$
1518  * @param scale Scale \f$ \sigma > 0 \f$
1519  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a Rayleigh-distributed
1520  * random variable with parameter \f$ \sigma \f$
1521  */
1522 CREATE FUNCTION MADLIB_SCHEMA.rayleigh_cdf(
1523  x DOUBLE PRECISION,
1524  scale DOUBLE PRECISION
1525 ) RETURNS DOUBLE PRECISION
1526 AS 'MODULE_PATHNAME'
1527 LANGUAGE C
1528 IMMUTABLE STRICT;
1529 
1530 /**
1531  * @brief Rayleigh probability density function
1532  *
1533  * @param x Random variate \f$ x \f$
1534  * @param scale Scale \f$ \sigma > 0 \f$
1535  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
1536  * a Rayleigh-distributed random variable with parameter \f$ \sigma \f$
1537  */
1538 CREATE FUNCTION MADLIB_SCHEMA.rayleigh_pdf(
1539  x DOUBLE PRECISION,
1540  scale DOUBLE PRECISION
1541 ) RETURNS DOUBLE PRECISION
1542 AS 'MODULE_PATHNAME'
1543 LANGUAGE C
1544 IMMUTABLE STRICT;
1545 
1546 /**
1547  * @brief Rayleigh quantile function
1548  *
1549  * @param p Probability \f$ p \in [0,1] \f$
1550  * @param scale Scale \f$ \sigma > 0 \f$
1551  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1552  * Rayleigh-distributed random variable with parameter \f$ \sigma \f$
1553  */
1554 CREATE FUNCTION MADLIB_SCHEMA.rayleigh_quantile(
1555  p DOUBLE PRECISION,
1556  scale DOUBLE PRECISION
1557 ) RETURNS DOUBLE PRECISION
1558 AS 'MODULE_PATHNAME'
1559 LANGUAGE C
1560 IMMUTABLE STRICT;
1561 
1562 
1563 /**
1564  * @brief Student's t cumulative distribution function
1565  *
1566  * @param x Random variate \f$ x \f$
1567  * @param df Degrees of freedom \f$ \nu > 0 \f$
1568  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a Student's t-distributed
1569  * random variable with \f$ \nu \f$ degrees of freedom
1570  */
1571 CREATE FUNCTION MADLIB_SCHEMA.students_t_cdf(
1572  x DOUBLE PRECISION,
1573  df DOUBLE PRECISION
1574 ) RETURNS DOUBLE PRECISION
1575 AS 'MODULE_PATHNAME'
1576 LANGUAGE C
1577 IMMUTABLE STRICT;
1578 
1579 /**
1580  * @brief Student's t probability density function
1581  *
1582  * @param x Random variate \f$ x \f$
1583  * @param df Degrees of freedom \f$ \nu > 0 \f$
1584  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
1585  * a Stundent's t-distributed random variable with \f$ \nu \f$ degrees of
1586  * freedom
1587  */
1588 CREATE FUNCTION MADLIB_SCHEMA.students_t_pdf(
1589  x DOUBLE PRECISION,
1590  df DOUBLE PRECISION
1591 ) RETURNS DOUBLE PRECISION
1592 AS 'MODULE_PATHNAME'
1593 LANGUAGE C
1594 IMMUTABLE STRICT;
1595 
1596 /**
1597  * @brief Student's t quantile function
1598  *
1599  * @param p Probability \f$ p \in [0,1] \f$
1600  * @param df Degrees of freedom \f$ \nu > 0 \f$
1601  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1602  * Student's t-distributed random variable with \f$ \nu \f$ degrees of
1603  * freedom
1604  */
1605 CREATE FUNCTION MADLIB_SCHEMA.students_t_quantile(
1606  p DOUBLE PRECISION,
1607  df DOUBLE PRECISION
1608 ) RETURNS DOUBLE PRECISION
1609 AS 'MODULE_PATHNAME'
1610 LANGUAGE C
1611 IMMUTABLE STRICT;
1612 
1613 
1614 /**
1615  * @brief Triangular cumulative distribution function
1616  *
1617  * @param x Random variate \f$ x \f$
1618  * @param lower Lower bound \f$ a \f$
1619  * @param mode Mode \f$ c \geq a \f$
1620  * @param upper Upper bound \f$ b \geq c \f$, where \f$ b > a \f$
1621  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a triangular distributed
1622  * random variable with parameters \f$ a, b, c \f$
1623  */
1624 CREATE FUNCTION MADLIB_SCHEMA.triangular_cdf(
1625  x DOUBLE PRECISION,
1626  lower DOUBLE PRECISION,
1627  mode DOUBLE PRECISION,
1628  upper DOUBLE PRECISION
1629 ) RETURNS DOUBLE PRECISION
1630 AS 'MODULE_PATHNAME'
1631 LANGUAGE C
1632 IMMUTABLE STRICT;
1633 
1634 /**
1635  * @brief Triangular probability density function
1636  *
1637  * @param x Random variate \f$ x \f$
1638  * @param lower Lower bound \f$ a \f$
1639  * @param mode Mode \f$ c \geq a \f$
1640  * @param upper Upper bound \f$ b \geq c \f$, where \f$ b > a \f$
1641  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
1642  * a triangular distributed random variable with parameters \f$ a, b, c \f$
1643  */
1644 CREATE FUNCTION MADLIB_SCHEMA.triangular_pdf(
1645  x DOUBLE PRECISION,
1646  lower DOUBLE PRECISION,
1647  mode DOUBLE PRECISION,
1648  upper DOUBLE PRECISION
1649 ) RETURNS DOUBLE PRECISION
1650 AS 'MODULE_PATHNAME'
1651 LANGUAGE C
1652 IMMUTABLE STRICT;
1653 
1654 /**
1655  * @brief Triangular quantile function
1656  *
1657  * @param p Probability \f$ p \in [0,1] \f$
1658  * @param lower Lower bound \f$ a \f$
1659  * @param mode Mode \f$ c \geq a \f$
1660  * @param upper Upper bound \f$ b \geq c \f$, where \f$ b > a \f$
1661  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1662  * trianbular distributed random variable with parameters \f$ a, b, c \f$
1663  */
1664 CREATE FUNCTION MADLIB_SCHEMA.triangular_quantile(
1665  p DOUBLE PRECISION,
1666  lower DOUBLE PRECISION,
1667  mode DOUBLE PRECISION,
1668  upper DOUBLE PRECISION
1669 ) RETURNS DOUBLE PRECISION
1670 AS 'MODULE_PATHNAME'
1671 LANGUAGE C
1672 IMMUTABLE STRICT;
1673 
1674 
1675 /**
1676  * @brief Uniform cumulative distribution function
1677  *
1678  * @param x Random variate \f$ x \f$
1679  * @param lower Lower bound \f$ a \f$
1680  * @param upper Upper bound \f$ b \f$
1681  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a uniform distributed random
1682  * variable with support \f$ [a, b] \f$
1683  */
1684 CREATE FUNCTION MADLIB_SCHEMA.uniform_cdf(
1685  x DOUBLE PRECISION,
1686  lower DOUBLE PRECISION,
1687  upper DOUBLE PRECISION
1688 ) RETURNS DOUBLE PRECISION
1689 AS 'MODULE_PATHNAME'
1690 LANGUAGE C
1691 IMMUTABLE STRICT;
1692 
1693 /**
1694  * @brief Uniform probability density function
1695  *
1696  * @param x Random variate \f$ x \f$
1697  * @param lower Lower bound \f$ a \f$
1698  * @param upper Upper bound \f$ b \f$
1699  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
1700  * a uniform distributed random variable with support \f$ [a, b] \f$
1701  */
1702 CREATE FUNCTION MADLIB_SCHEMA.uniform_pdf(
1703  x DOUBLE PRECISION,
1704  lower DOUBLE PRECISION,
1705  upper DOUBLE PRECISION
1706 ) RETURNS DOUBLE PRECISION
1707 AS 'MODULE_PATHNAME'
1708 LANGUAGE C
1709 IMMUTABLE STRICT;
1710 
1711 /**
1712  * @brief Uniform quantile function
1713  *
1714  * @param p Probability \f$ p \in [0,1] \f$
1715  * @param lower Lower bound \f$ a \f$
1716  * @param upper Upper bound \f$ b \f$
1717  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1718  * uniform distributed random variable with support \f$ [a, b] \f$
1719  */
1720 CREATE FUNCTION MADLIB_SCHEMA.uniform_quantile(
1721  p DOUBLE PRECISION,
1722  lower DOUBLE PRECISION,
1723  upper DOUBLE PRECISION
1724 ) RETURNS DOUBLE PRECISION
1725 AS 'MODULE_PATHNAME'
1726 LANGUAGE C
1727 IMMUTABLE STRICT;
1728 
1729 
1730 /**
1731  * @brief Weibull cumulative distribution function
1732  *
1733  * @param x Random variate \f$ x \f$
1734  * @param shape Shape \f$ \alpha > 0 \f$
1735  * @param scale Scale \f$ \beta > 0 \f$
1736  * @return \f$ \Pr[X \leq x] \f$ where \f$ X \f$ is a weibull distributed random
1737  * variable with shape and scale parameters \f$ \alpha \f$ and
1738  * \f$ \beta \f$, respectively
1739  */
1740 CREATE FUNCTION MADLIB_SCHEMA.weibull_cdf(
1741  x DOUBLE PRECISION,
1742  shape DOUBLE PRECISION,
1743  scale DOUBLE PRECISION
1744 ) RETURNS DOUBLE PRECISION
1745 AS 'MODULE_PATHNAME'
1746 LANGUAGE C
1747 IMMUTABLE STRICT;
1748 
1749 /**
1750  * @brief Weibull probability density function
1751  *
1752  * @param x Random variate \f$ x \f$
1753  * @param shape Shape \f$ \alpha > 0 \f$
1754  * @param scale Scale \f$ \beta > 0 \f$
1755  * @return \f$ f(x) \f$ where \f$ f \f$ is the probability density function of
1756  * a weibull distributed random variable with shape and scale parameters
1757  * \f$ \alpha \f$ and \f$ \beta \f$, respectively
1758  */
1759 CREATE FUNCTION MADLIB_SCHEMA.weibull_pdf(
1760  x DOUBLE PRECISION,
1761  shape DOUBLE PRECISION,
1762  scale DOUBLE PRECISION
1763 ) RETURNS DOUBLE PRECISION
1764 AS 'MODULE_PATHNAME'
1765 LANGUAGE C
1766 IMMUTABLE STRICT;
1767 
1768 /**
1769  * @brief Weibull quantile function
1770  *
1771  * @param p Probability \f$ p \in [0,1] \f$
1772  * @param shape Shape \f$ \alpha > 0 \f$
1773  * @param scale Scale \f$ \beta > 0 \f$
1774  * @return \f$ x \f$ such that \f$ p = \Pr[X \leq x] \f$ where \f$ X \f$ is a
1775  * weibull distributed random variable with shape and scale parameters
1776  * \f$ \alpha \f$ and \f$ \beta \f$, respectively
1777  */
1778 CREATE FUNCTION MADLIB_SCHEMA.weibull_quantile(
1779  p DOUBLE PRECISION,
1780  shape DOUBLE PRECISION,
1781  scale DOUBLE PRECISION
1782 ) RETURNS DOUBLE PRECISION
1783 AS 'MODULE_PATHNAME'
1784 LANGUAGE C
1785 IMMUTABLE STRICT;