-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpg_math.c
2693 lines (2134 loc) · 84.8 KB
/
pg_math.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* pg_math.c:
* Functions with prefix "cdf" is for cumulative distribution calculation
* Functions with prefix "rdf" is for random distribution calculation
* Available Distributions:
1. F-Distribution
2. Gaussian Distribution
3. Unit Gaussian Distribution
4. Gaussian Tail Distribution
5. Bivariate Gaussian Distribution
6. Exponential Distribution
7. Laplace Distribution
8. Exponential Power Distribution
9. Cauchy Distribution
10. Rayleigh Distribution
11. Rayleigh Tail Distribution
12. Landau Distribution
13. Gamma Distribution
14. Flat (Uniform) Distribution
15. Lognormal Distribution
16. Chi-squared Distribution
17. T-Distribution
18. Beta Distribution
19. Logistic Distribution
20. Pareto Distribution
21. Weibull Distribution
22. Type-1 Gumbel Distribution
23. Type-2 Gumbel Distribution
24. Poisson Distribution
25. Bernoulli Distribution
26. Binomial Distribution
27. Negative Binomial Distribution
28. Pascal Distribution
29. Geometric Distribution
30. Hypergeometric Distribution
31. Logarithmic Distribution
* Dependency modules/packages : libgsl (GSL - GNU Scientific Library)
*/
#include <postgres.h>
#include <fmgr.h>
#include <math.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
PG_MODULE_MAGIC;
/* F Distribution Function Prototypes */
Datum rdf_fdist(PG_FUNCTION_ARGS);
Datum cdf_fdist_p(PG_FUNCTION_ARGS);
Datum cdf_fdist_q(PG_FUNCTION_ARGS);
Datum cdf_fdist_pinv(PG_FUNCTION_ARGS);
Datum cdf_fdist_qinv(PG_FUNCTION_ARGS);
/* Gaussian Distribution Function Prototypes */
Datum rdf_gaussian(PG_FUNCTION_ARGS);
Datum cdf_gaussian_p(PG_FUNCTION_ARGS);
Datum cdf_gaussian_q(PG_FUNCTION_ARGS);
Datum cdf_gaussian_pinv(PG_FUNCTION_ARGS);
Datum cdf_gaussian_qinv(PG_FUNCTION_ARGS);
/* Unit Gaussian Distribution Function Prototypes */
Datum rdf_unit_gaussian(PG_FUNCTION_ARGS);
Datum cdf_unit_gaussian_p(PG_FUNCTION_ARGS);
Datum cdf_unit_gaussian_q(PG_FUNCTION_ARGS);
Datum cdf_unit_gaussian_pinv(PG_FUNCTION_ARGS);
Datum cdf_unit_gaussian_qinv(PG_FUNCTION_ARGS);
/* Gaussian Tail Distribution Function Prototypes */
Datum rdf_gaussian_tail(PG_FUNCTION_ARGS);
Datum rdf_unit_gaussian_tail(PG_FUNCTION_ARGS);
/* Bivariate Gaussian Distribution Function ProtoTypes */
Datum rdf_bivariate_gaussian(PG_FUNCTION_ARGS);
/* Exponential Distribution Function Prototypes */
Datum rdf_exponential(PG_FUNCTION_ARGS);
Datum cdf_exponential_p(PG_FUNCTION_ARGS);
Datum cdf_exponential_q(PG_FUNCTION_ARGS);
Datum cdf_exponential_pinv(PG_FUNCTION_ARGS);
Datum cdf_exponential_qinv(PG_FUNCTION_ARGS);
/* Laplace Distribution Function Prototypes */
Datum rdf_laplace(PG_FUNCTION_ARGS);
Datum cdf_laplace_p(PG_FUNCTION_ARGS);
Datum cdf_laplace_q(PG_FUNCTION_ARGS);
Datum cdf_laplace_pinv(PG_FUNCTION_ARGS);
Datum cdf_laplace_qinv(PG_FUNCTION_ARGS);
/* Exponential Power Distribution Function Prototypes */
Datum rdf_exppow(PG_FUNCTION_ARGS);
Datum cdf_exppow_p(PG_FUNCTION_ARGS);
Datum cdf_exppow_q(PG_FUNCTION_ARGS);
/* Cauchy Distribution Function Prototypes */
Datum rdf_cauchy(PG_FUNCTION_ARGS);
Datum cdf_cauchy_p(PG_FUNCTION_ARGS);
Datum cdf_cauchy_q(PG_FUNCTION_ARGS);
Datum cdf_cauchy_pinv(PG_FUNCTION_ARGS);
Datum cdf_cauchy_qinv(PG_FUNCTION_ARGS);
/* Rayleigh Distribution Function Prototypes */
Datum rdf_rayleigh(PG_FUNCTION_ARGS);
Datum cdf_rayleigh_p(PG_FUNCTION_ARGS);
Datum cdf_rayleigh_q(PG_FUNCTION_ARGS);
Datum cdf_rayleigh_pinv(PG_FUNCTION_ARGS);
Datum cdf_rayleigh_qinv(PG_FUNCTION_ARGS);
/* Rayleigh Tail Distribution Function Prototypes */
Datum rdf_rayleigh_tail(PG_FUNCTION_ARGS);
/* Landau Distribution Function Prototypes */
Datum rdf_landau(PG_FUNCTION_ARGS);
/* Gamma Distribution Function Prototypes */
Datum rdf_gamma(PG_FUNCTION_ARGS);
Datum cdf_gamma_p(PG_FUNCTION_ARGS);
Datum cdf_gamma_q(PG_FUNCTION_ARGS);
Datum cdf_gamma_pinv(PG_FUNCTION_ARGS);
Datum cdf_gamma_qinv(PG_FUNCTION_ARGS);
/* Flat (Uniform) Distribution Function Prototypes */
Datum rdf_flat_unif(PG_FUNCTION_ARGS);
Datum cdf_flat_unif_p(PG_FUNCTION_ARGS);
Datum cdf_flat_unif_q(PG_FUNCTION_ARGS);
Datum cdf_flat_unif_pinv(PG_FUNCTION_ARGS);
Datum cdf_flat_unif_qinv(PG_FUNCTION_ARGS);
/* Lognormal Distribution Function Prototypes */
Datum rdf_lognormal(PG_FUNCTION_ARGS);
Datum cdf_lognormal_p(PG_FUNCTION_ARGS);
Datum cdf_lognormal_q(PG_FUNCTION_ARGS);
Datum cdf_lognormal_pinv(PG_FUNCTION_ARGS);
Datum cdf_lognormal_qinv(PG_FUNCTION_ARGS);
/* Chi-squared Distribution Function Prototypes */
Datum rdf_chisq(PG_FUNCTION_ARGS);
Datum cdf_chisq_p(PG_FUNCTION_ARGS);
Datum cdf_chisq_q(PG_FUNCTION_ARGS);
Datum cdf_chisq_pinv(PG_FUNCTION_ARGS);
Datum cdf_chisq_qinv(PG_FUNCTION_ARGS);
/* T-Distribution Function Prototypes */
Datum rdf_tdist(PG_FUNCTION_ARGS);
Datum cdf_tdist_p(PG_FUNCTION_ARGS);
Datum cdf_tdist_q(PG_FUNCTION_ARGS);
Datum cdf_tdist_pinv(PG_FUNCTION_ARGS);
Datum cdf_tdist_qinv(PG_FUNCTION_ARGS);
/* Beta Distribution Function Prototypes */
Datum rdf_beta(PG_FUNCTION_ARGS);
Datum cdf_beta_p(PG_FUNCTION_ARGS);
Datum cdf_beta_q(PG_FUNCTION_ARGS);
Datum cdf_beta_pinv(PG_FUNCTION_ARGS);
Datum cdf_beta_qinv(PG_FUNCTION_ARGS);
/* Logistic Distribution Function Prototypes */
Datum rdf_logistic(PG_FUNCTION_ARGS);
Datum cdf_logistic_p(PG_FUNCTION_ARGS);
Datum cdf_logistic_q(PG_FUNCTION_ARGS);
Datum cdf_logistic_pinv(PG_FUNCTION_ARGS);
Datum cdf_logistic_qinv(PG_FUNCTION_ARGS);
/* Pareto Distribution Function Prototypes */
Datum rdf_pareto(PG_FUNCTION_ARGS);
Datum cdf_pareto_p(PG_FUNCTION_ARGS);
Datum cdf_pareto_q(PG_FUNCTION_ARGS);
Datum cdf_pareto_pinv(PG_FUNCTION_ARGS);
Datum cdf_pareto_qinv(PG_FUNCTION_ARGS);
/* Weibull Distribution Function Prototypes */
Datum rdf_weibull(PG_FUNCTION_ARGS);
Datum cdf_weibull_p(PG_FUNCTION_ARGS);
Datum cdf_weibull_q(PG_FUNCTION_ARGS);
Datum cdf_weibull_pinv(PG_FUNCTION_ARGS);
Datum cdf_weibull_qinv(PG_FUNCTION_ARGS);
/* Type-1 Gumbel Distribution Function Prototypes */
Datum rdf_gumbel1(PG_FUNCTION_ARGS);
Datum cdf_gumbel1_p(PG_FUNCTION_ARGS);
Datum cdf_gumbel1_q(PG_FUNCTION_ARGS);
Datum cdf_gumbel1_pinv(PG_FUNCTION_ARGS);
Datum cdf_gumbel1_qinv(PG_FUNCTION_ARGS);
/* Type-2 Gumbel Distribution Function Prototypes */
Datum rdf_gumbel2(PG_FUNCTION_ARGS);
Datum cdf_gumbel2_p(PG_FUNCTION_ARGS);
Datum cdf_gumbel2_q(PG_FUNCTION_ARGS);
Datum cdf_gumbel2_pinv(PG_FUNCTION_ARGS);
Datum cdf_gumbel2_qinv(PG_FUNCTION_ARGS);
/* Poisson Distribution Function Prototypes */
Datum rdf_poisson(PG_FUNCTION_ARGS);
Datum cdf_poisson_p(PG_FUNCTION_ARGS);
Datum cdf_poisson_q(PG_FUNCTION_ARGS);
/* Bernoulli Distribution Function Prototypes */
Datum rdf_bernoulli(PG_FUNCTION_ARGS);
/* Binomial Distribution Function Prototypes */
Datum rdf_binomial(PG_FUNCTION_ARGS);
Datum cdf_binomial_p(PG_FUNCTION_ARGS);
Datum cdf_binomial_q(PG_FUNCTION_ARGS);
/* Negative Binomial Distribution Function Prototypes */
Datum rdf_negative_binomial(PG_FUNCTION_ARGS);
Datum cdf_negative_binomial_p(PG_FUNCTION_ARGS);
Datum cdf_negative_binomial_q(PG_FUNCTION_ARGS);
/* Pascal Distribution Function Prototypes */
Datum rdf_pascal(PG_FUNCTION_ARGS);
Datum cdf_pascal_p(PG_FUNCTION_ARGS);
Datum cdf_pascal_q(PG_FUNCTION_ARGS);
/* Geometric Distribution Function Prototypes */
Datum rdf_geometric(PG_FUNCTION_ARGS);
Datum cdf_geometric_p(PG_FUNCTION_ARGS);
Datum cdf_geometric_q(PG_FUNCTION_ARGS);
/* Hypergeometric Distribution Function Prototypes */
Datum rdf_hypergeometric(PG_FUNCTION_ARGS);
Datum cdf_hypergeometric_p(PG_FUNCTION_ARGS);
Datum cdf_hypergeometric_q(PG_FUNCTION_ARGS);
/* Logarithmic Distribution Function Prototypes */
Datum rdf_logarithmic(PG_FUNCTION_ARGS);
/* Version 1 Calling */
PG_FUNCTION_INFO_V1(rdf_fdist);
PG_FUNCTION_INFO_V1(cdf_fdist_p);
PG_FUNCTION_INFO_V1(cdf_fdist_q);
PG_FUNCTION_INFO_V1(cdf_fdist_pinv);
PG_FUNCTION_INFO_V1(cdf_fdist_qinv);
PG_FUNCTION_INFO_V1(rdf_gaussian);
PG_FUNCTION_INFO_V1(cdf_gaussian_p);
PG_FUNCTION_INFO_V1(cdf_gaussian_q);
PG_FUNCTION_INFO_V1(cdf_gaussian_pinv);
PG_FUNCTION_INFO_V1(cdf_gaussian_qinv);
PG_FUNCTION_INFO_V1(rdf_unit_gaussian);
PG_FUNCTION_INFO_V1(cdf_unit_gaussian_p);
PG_FUNCTION_INFO_V1(cdf_unit_gaussian_q);
PG_FUNCTION_INFO_V1(cdf_unit_gaussian_pinv);
PG_FUNCTION_INFO_V1(cdf_unit_gaussian_qinv);
PG_FUNCTION_INFO_V1(rdf_gaussian_tail);
PG_FUNCTION_INFO_V1(rdf_unit_gaussian_tail);
PG_FUNCTION_INFO_V1(rdf_bivariate_gaussian);
PG_FUNCTION_INFO_V1(rdf_exponential);
PG_FUNCTION_INFO_V1(cdf_exponential_p);
PG_FUNCTION_INFO_V1(cdf_exponential_q);
PG_FUNCTION_INFO_V1(cdf_exponential_pinv);
PG_FUNCTION_INFO_V1(cdf_exponential_qinv);
PG_FUNCTION_INFO_V1(rdf_laplace);
PG_FUNCTION_INFO_V1(cdf_laplace_p);
PG_FUNCTION_INFO_V1(cdf_laplace_q);
PG_FUNCTION_INFO_V1(cdf_laplace_pinv);
PG_FUNCTION_INFO_V1(cdf_laplace_qinv);
PG_FUNCTION_INFO_V1(rdf_exppow);
PG_FUNCTION_INFO_V1(cdf_exppow_p);
PG_FUNCTION_INFO_V1(cdf_exppow_q);
PG_FUNCTION_INFO_V1(rdf_cauchy);
PG_FUNCTION_INFO_V1(cdf_cauchy_p);
PG_FUNCTION_INFO_V1(cdf_cauchy_q);
PG_FUNCTION_INFO_V1(cdf_cauchy_pinv);
PG_FUNCTION_INFO_V1(cdf_cauchy_qinv);
PG_FUNCTION_INFO_V1(rdf_rayleigh);
PG_FUNCTION_INFO_V1(cdf_rayleigh_p);
PG_FUNCTION_INFO_V1(cdf_rayleigh_q);
PG_FUNCTION_INFO_V1(cdf_rayleigh_pinv);
PG_FUNCTION_INFO_V1(cdf_rayleigh_qinv);
PG_FUNCTION_INFO_V1(rdf_rayleigh_tail);
PG_FUNCTION_INFO_V1(rdf_landau);
PG_FUNCTION_INFO_V1(rdf_gamma);
PG_FUNCTION_INFO_V1(cdf_gamma_p);
PG_FUNCTION_INFO_V1(cdf_gamma_q);
PG_FUNCTION_INFO_V1(cdf_gamma_pinv);
PG_FUNCTION_INFO_V1(cdf_gamma_qinv);
PG_FUNCTION_INFO_V1(rdf_flat_unif);
PG_FUNCTION_INFO_V1(cdf_flat_unif_p);
PG_FUNCTION_INFO_V1(cdf_flat_unif_q);
PG_FUNCTION_INFO_V1(cdf_flat_unif_pinv);
PG_FUNCTION_INFO_V1(cdf_flat_unif_qinv);
PG_FUNCTION_INFO_V1(rdf_lognormal);
PG_FUNCTION_INFO_V1(cdf_lognormal_p);
PG_FUNCTION_INFO_V1(cdf_lognormal_q);
PG_FUNCTION_INFO_V1(cdf_lognormal_pinv);
PG_FUNCTION_INFO_V1(cdf_lognormal_qinv);
PG_FUNCTION_INFO_V1(rdf_chisq);
PG_FUNCTION_INFO_V1(cdf_chisq_p);
PG_FUNCTION_INFO_V1(cdf_chisq_q);
PG_FUNCTION_INFO_V1(cdf_chisq_pinv);
PG_FUNCTION_INFO_V1(cdf_chisq_qinv);
PG_FUNCTION_INFO_V1(rdf_tdist);
PG_FUNCTION_INFO_V1(cdf_tdist_p);
PG_FUNCTION_INFO_V1(cdf_tdist_q);
PG_FUNCTION_INFO_V1(cdf_tdist_pinv);
PG_FUNCTION_INFO_V1(cdf_tdist_qinv);
PG_FUNCTION_INFO_V1(rdf_beta);
PG_FUNCTION_INFO_V1(cdf_beta_p);
PG_FUNCTION_INFO_V1(cdf_beta_q);
PG_FUNCTION_INFO_V1(cdf_beta_pinv);
PG_FUNCTION_INFO_V1(cdf_beta_qinv);
PG_FUNCTION_INFO_V1(rdf_logistic);
PG_FUNCTION_INFO_V1(cdf_logistic_p);
PG_FUNCTION_INFO_V1(cdf_logistic_q);
PG_FUNCTION_INFO_V1(cdf_logistic_pinv);
PG_FUNCTION_INFO_V1(cdf_logistic_qinv);
PG_FUNCTION_INFO_V1(rdf_pareto);
PG_FUNCTION_INFO_V1(cdf_pareto_p);
PG_FUNCTION_INFO_V1(cdf_pareto_q);
PG_FUNCTION_INFO_V1(cdf_pareto_pinv);
PG_FUNCTION_INFO_V1(cdf_pareto_qinv);
PG_FUNCTION_INFO_V1(rdf_weibull);
PG_FUNCTION_INFO_V1(cdf_weibull_p);
PG_FUNCTION_INFO_V1(cdf_weibull_q);
PG_FUNCTION_INFO_V1(cdf_weibull_pinv);
PG_FUNCTION_INFO_V1(cdf_weibull_qinv);
PG_FUNCTION_INFO_V1(rdf_gumbel1);
PG_FUNCTION_INFO_V1(cdf_gumbel1_p);
PG_FUNCTION_INFO_V1(cdf_gumbel1_q);
PG_FUNCTION_INFO_V1(cdf_gumbel1_pinv);
PG_FUNCTION_INFO_V1(cdf_gumbel1_qinv);
PG_FUNCTION_INFO_V1(rdf_gumbel2);
PG_FUNCTION_INFO_V1(cdf_gumbel2_p);
PG_FUNCTION_INFO_V1(cdf_gumbel2_q);
PG_FUNCTION_INFO_V1(cdf_gumbel2_pinv);
PG_FUNCTION_INFO_V1(cdf_gumbel2_qinv);
PG_FUNCTION_INFO_V1(rdf_poisson);
PG_FUNCTION_INFO_V1(cdf_poisson_p);
PG_FUNCTION_INFO_V1(cdf_poisson_q);
PG_FUNCTION_INFO_V1(rdf_bernoulli);
PG_FUNCTION_INFO_V1(rdf_binomial);
PG_FUNCTION_INFO_V1(cdf_binomial_p);
PG_FUNCTION_INFO_V1(cdf_binomial_q);
PG_FUNCTION_INFO_V1(rdf_negative_binomial);
PG_FUNCTION_INFO_V1(cdf_negative_binomial_p);
PG_FUNCTION_INFO_V1(cdf_negative_binomial_q);
PG_FUNCTION_INFO_V1(rdf_pascal);
PG_FUNCTION_INFO_V1(cdf_pascal_p);
PG_FUNCTION_INFO_V1(cdf_pascal_q);
PG_FUNCTION_INFO_V1(rdf_geometric);
PG_FUNCTION_INFO_V1(cdf_geometric_p);
PG_FUNCTION_INFO_V1(cdf_geometric_q);
PG_FUNCTION_INFO_V1(rdf_hypergeometric);
PG_FUNCTION_INFO_V1(cdf_hypergeometric_p);
PG_FUNCTION_INFO_V1(cdf_hypergeometric_q);
PG_FUNCTION_INFO_V1(rdf_logarithmic);
/* F Distribution Function Definitions */
Datum rdf_fdist(PG_FUNCTION_ARGS)
{
const double alpha = PG_GETARG_FLOAT8(0);
const double df1 = PG_GETARG_FLOAT8(1);
const double df2 = PG_GETARG_FLOAT8(2);
float res;
gsl_set_error_handler_off();
res = gsl_ran_fdist_pdf(alpha, df1, df2);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate rdf_fdist(alpha,df1,df2)."),
errhint("The rdf_fdist function computes probability density p(x) at x for an F-distribution with nu1 and nu2 degrees of freedom.")));
}
Datum cdf_fdist_p(PG_FUNCTION_ARGS)
{
const double alpha = PG_GETARG_FLOAT8(0);
const double df1 = PG_GETARG_FLOAT8(1);
const double df2 = PG_GETARG_FLOAT8(2);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_fdist_P(alpha, df1, df2);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_fdist_p(alpha,df1,df2)."),
errhint("The cdf_fdist_p function computes cumulative distribution P(x) for the F-distribution with nu1 and nu2 degrees of freedom.")));
}
Datum cdf_fdist_q(PG_FUNCTION_ARGS)
{
const double alpha = PG_GETARG_FLOAT8(0);
const double df1 = PG_GETARG_FLOAT8(1);
const double df2 = PG_GETARG_FLOAT8(2);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_fdist_Q(alpha, df1, df2);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_fdist_q(alpha,df1,df2)."),
errhint("The cdf_fdist_q function computes cumulative distribution Q(x) for the F-distribution with nu1 and nu2 degrees of freedom.")));
}
Datum cdf_fdist_pinv(PG_FUNCTION_ARGS)
{
const double alpha = PG_GETARG_FLOAT8(0);
const double df1 = PG_GETARG_FLOAT8(1);
const double df2 = PG_GETARG_FLOAT8(2);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_fdist_Pinv(alpha, df1, df2);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_fdist_pinv(alpha,df1,df2)."),
errhint("The cdf_fdist_pinv function computes inverse of cumulative distribution P(x) for the F-distribution with nu1 and nu2 degrees of freedom.")));
}
Datum cdf_fdist_qinv(PG_FUNCTION_ARGS)
{
const double alpha = PG_GETARG_FLOAT8(0);
const double df1 = PG_GETARG_FLOAT8(1);
const double df2 = PG_GETARG_FLOAT8(2);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_fdist_Qinv(alpha, df1, df2);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_fdist_qinv(alpha,df1,df2)."),
errhint("The cdf_fdist_qinv function computes inverse of cumulative distribution Q(x) for the F-distribution with nu1 and nu2 degrees of freedom.")));
}
/* Gaussian Distribution Function Definitions */
Datum rdf_gaussian(PG_FUNCTION_ARGS)
{
double x = PG_GETARG_FLOAT8(0);
double sigma = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_ran_gaussian_pdf(x, sigma);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate rdf_gaussian(x,sigma)."),
errhint("The rdf_gaussian function computes probability density p(x) at x for a Gaussian distribution with standard deviation sigma.")));
}
Datum cdf_gaussian_p(PG_FUNCTION_ARGS)
{
double x = PG_GETARG_FLOAT8(0);
double sigma = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_gaussian_P(x, sigma);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_gaussian_p(x,sigma)."),
errhint("The cdf_gaussian_p function computes cumulative distribution P(x) for the Gaussian distribution with standard deviation sigma.")));
}
Datum cdf_gaussian_q(PG_FUNCTION_ARGS)
{
double x = PG_GETARG_FLOAT8(0);
double sigma = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_gaussian_Q(x, sigma);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_gaussian_q(x,sigma)."),
errhint("The cdf_gaussian_q function computes cumulative distribution Q(x) for the Gaussian distribution with standard deviation sigma.")));
}
Datum cdf_gaussian_pinv(PG_FUNCTION_ARGS)
{
double P = PG_GETARG_FLOAT8(0);
double sigma = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_gaussian_Pinv(P, sigma);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_gaussian_pinv(P,sigma)."),
errhint("The cdf_gaussian_pinv function computes inverse of cumulative distribution P(x) for the Gaussian distribution with standard deviation sigma.")));
}
Datum cdf_gaussian_qinv(PG_FUNCTION_ARGS)
{
double Q = PG_GETARG_FLOAT8(0);
double sigma = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_gaussian_P(Q, sigma);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_gaussian_qinv(Q,sigma)."),
errhint("The cdf_gaussian_qinv function computes inverse of cumulative distribution Q(x) for the Gaussian distribution with standard deviation sigma.")));
}
/* Unit Gaussian Distribution Function Definitions */
Datum rdf_unit_gaussian(PG_FUNCTION_ARGS)
{
double x = PG_GETARG_FLOAT8(0);
float res;
gsl_set_error_handler_off();
res = gsl_ran_ugaussian_pdf(x);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate rdf_unit_gaussian(x)."),
errhint("The rdf_unit_gaussian function computes probability density p(x) at x for the unit Gaussian distribution with a default standard deviation of one, sigma = 1.")));
}
Datum cdf_unit_gaussian_p(PG_FUNCTION_ARGS)
{
double x = PG_GETARG_FLOAT8(0);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_ugaussian_P(x);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_unit_gaussian_p(x)."),
errhint("The cdf_unit_gaussian_p function computes cumulative distribution P(x) for the unit Gaussian distribution with a default standard deviation of one, sigma = 1.")));
}
Datum cdf_unit_gaussian_q(PG_FUNCTION_ARGS)
{
double x = PG_GETARG_FLOAT8(0);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_ugaussian_Q(x);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_unit_gaussian_q(x)."),
errhint("The cdf_unit_gaussian_q function computes cumulative distribution Q(x) for the unit Gaussian distribution with a default standard deviation of one, sigma = 1.")));
}
Datum cdf_unit_gaussian_pinv(PG_FUNCTION_ARGS)
{
double P = PG_GETARG_FLOAT8(0);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_ugaussian_Pinv(P);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_unit_gaussian_pinv(P)."),
errhint("The cdf_unit_gaussian_pinv function computes inverse of cumulative distribution P(x) for the unit Gaussian distribution with a default standard deviation of one, sigma = 1.")));
}
Datum cdf_unit_gaussian_qinv(PG_FUNCTION_ARGS)
{
double Q = PG_GETARG_FLOAT8(0);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_ugaussian_Qinv(Q);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_unit_gaussian_qinv(Q)."),
errhint("The cdf_unit_gaussian_qinv function computes inverse of cumulative distribution Q(x) for the unit Gaussian distribution with a default standard deviation of one, sigma = 1.")));
}
/* Gaussian Tail Distribution Function Definitions */
Datum rdf_gaussian_tail(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
const double sigma = PG_GETARG_FLOAT8(2);
float res;
gsl_set_error_handler_off();
res = gsl_ran_gaussian_tail_pdf(x, a, sigma);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate rdf_gaussian_tail(x,a,sigma)."),
errhint("The rdf_gaussian_tail function computes probability density p(x) at x for a Gaussian tail distribution with standard deviation sigma and lower limit a.")));
}
Datum rdf_unit_gaussian_tail(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_ran_ugaussian_tail_pdf(x, a);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate rdf_unit_gaussian_tail(x,a)."),
errhint("The rdf_unit_gaussian_tail function computes probability density p(x) at x for a tail of a unit Gaussian distribution with a default standard deviation of one, sigma = 1 and lower limit a.")));
}
/* Bivariate Gaussian Distribution Function Definitions */
Datum rdf_bivariate_gaussian(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double y = PG_GETARG_FLOAT8(1);
const double sigma_x = PG_GETARG_FLOAT8(2);
const double sigma_y = PG_GETARG_FLOAT8(3);
const double rho = PG_GETARG_FLOAT8(4);
float res;
gsl_set_error_handler_off();
res = gsl_ran_bivariate_gaussian_pdf(x, y, sigma_x, sigma_y, rho);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate rdf_bivariate_gaussian(x,y,sigma_x,sigma_y,rho)."),
errhint("The rdf_bivariate_gaussian function computes probability density p(x,y) at (x, y) for a bivariate Gaussian distribution with standard deviations sigma_x, sigma_y and correlation coefficient rho.")));
}
/* Exponential Distribution Function Definitions */
Datum rdf_exponential(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double mu = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_ran_exponential_pdf(x, mu);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate rdf_exponential(x,mu)."),
errhint("The rdf_exponential function computes probability density p(x) at x for an exponential distribution with mean mu.")));
}
Datum cdf_exponential_p(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double mu = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_exponential_P(x, mu);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_exponential_p(x,mu)."),
errhint("The cdf_exponential_p function computes cumulative distribution P(x) for the exponential distribution with mean mu.")));
}
Datum cdf_exponential_q(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double mu = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_exponential_Q(x, mu);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_exponential_q(x,mu)."),
errhint("The cdf_exponential_q function computes cumulative distribution Q(x) for the exponential distribution with mean mu.")));
}
Datum cdf_exponential_pinv(PG_FUNCTION_ARGS)
{
const double P = PG_GETARG_FLOAT8(0);
const double mu = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_exponential_Pinv(P, mu);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_exponential_pinv(P,mu)."),
errhint("The cdf_exponential_pinv function computes inverse of cumulative distribution P(x) for the exponential distribution with mean mu.")));
}
Datum cdf_exponential_qinv(PG_FUNCTION_ARGS)
{
const double Q = PG_GETARG_FLOAT8(0);
const double mu = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_exponential_Qinv(Q, mu);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_exponential_qinv(Q,mu)."),
errhint("The cdf_exponential_qinv function computes inverse of cumulative distribution Q(x) for the exponential distribution with mean mu.")));
}
/* Laplace Distribution Function Definitions */
Datum rdf_laplace(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_ran_laplace_pdf(x, a);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate rdf_laplace(x,a)."),
errhint("The rdf_laplace function computes probability density p(x) at x for a Laplace distribution with width a.")));
}
Datum cdf_laplace_p(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_laplace_P(x, a);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_laplace_p(x,a)."),
errhint("The cdf_laplace_p function computes cumulative distribution P(x) for the Laplace distribution with width a.")));
}
Datum cdf_laplace_q(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_laplace_Q(x, a);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_laplace_q(x,a)."),
errhint("The cdf_laplace_q function computes cumulative distribution Q(x) for the Laplace distribution with width a.")));
}
Datum cdf_laplace_pinv(PG_FUNCTION_ARGS)
{
const double P = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_laplace_Pinv(P, a);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_laplace_pinv(P,a)."),
errhint("The cdf_laplace_pinv function computes inverse of cumulative distribution P(x) for the Laplace distribution with width a.")));
}
Datum cdf_laplace_qinv(PG_FUNCTION_ARGS)
{
const double Q = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_laplace_Qinv(Q, a);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_laplace_qinv(Q,a)."),
errhint("The cdf_laplace_qinv function computes inverse of cumulative distribution Q(x) for the Laplace distribution with width a.")));
}
/* Exponential Power Distribution Function Definitions */
Datum rdf_exppow(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
const double b = PG_GETARG_FLOAT8(2);
float res;
gsl_set_error_handler_off();
res = gsl_ran_exppow_pdf(x, a, b);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate rdf_exppow(x,a,b)."),
errhint("The rdf_exppow function computes probability density p(x) at x for an exponential power distribution with scale parameter a and exponent b.")));
}
Datum cdf_exppow_p(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
const double b = PG_GETARG_FLOAT8(2);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_exppow_P(x, a, b);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_exppow_p(x,a,b)."),
errhint("The cdf_exppow_p function computes cumulative distribution P(x) for the exponential power distribution with parameters a and b.")));
}
Datum cdf_exppow_q(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
const double b = PG_GETARG_FLOAT8(2);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_exppow_Q(x, a, b);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_exppow_q(x,a,b)."),
errhint("The cdf_exppow_q function computes cumulative distribution Q(x) for the exponential power distribution with parameters a and b.")));
}
/* Cauchy Distribution Function Definitions */
Datum rdf_cauchy(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_ran_cauchy_pdf(x, a);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate rdf_cauchy(x,a)."),
errhint("The rdf_cauchy function computes probability density p(x) at x for a Cauchy distribution with scale parameter a.")));
}
Datum cdf_cauchy_p(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_cauchy_P(x, a);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_cauchy_p(x,a)."),
errhint("The cdf_cauchy_p function computes cumulative distribution P(x) for the Cauchy distribution with scale parameter a.")));
}
Datum cdf_cauchy_q(PG_FUNCTION_ARGS)
{
const double x = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();
res = gsl_cdf_cauchy_Q(x, a);
if (gsl_finite(res))
PG_RETURN_FLOAT8(res);
else
ereport(ERROR, (
errmsg("Unable to calculate cdf_cauchy_q(x,a)."),
errhint("The cdf_cauchy_q function computes cumulative distribution Q(x) for the Cauchy distribution with scale parameter a.")));
}
Datum cdf_cauchy_pinv(PG_FUNCTION_ARGS)
{
const double P = PG_GETARG_FLOAT8(0);
const double a = PG_GETARG_FLOAT8(1);
float res;
gsl_set_error_handler_off();