/
specialfunctions.cs
executable file
·9838 lines (8349 loc) · 336 KB
/
specialfunctions.cs
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
/*************************************************************************
ALGLIB 4.01.0 (source code generated 2023-12-27)
Copyright (c) Sergey Bochkanov (ALGLIB project).
>>> SOURCE LICENSE >>>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation (www.fsf.org); either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>>
*************************************************************************/
#pragma warning disable 1691
#pragma warning disable 162
#pragma warning disable 164
#pragma warning disable 219
#pragma warning disable 8981
using System;
public partial class alglib
{
/*************************************************************************
Gamma function
Input parameters:
X - argument
Domain:
0 < X < 171.6
-170 < X < 0, X is not an integer.
Relative error:
arithmetic domain # trials peak rms
IEEE -170,-33 20000 2.3e-15 3.3e-16
IEEE -33, 33 20000 9.4e-16 2.2e-16
IEEE 33, 171.6 20000 2.3e-15 3.2e-16
Cephes Math Library Release 2.8: June, 2000
Original copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
Translated to AlgoPascal by Bochkanov Sergey (2005, 2006, 2007).
*************************************************************************/
public static double gammafunction(double x)
{
return gammafunc.gammafunction(x, null);
}
public static double gammafunction(double x, alglib.xparams _params)
{
return gammafunc.gammafunction(x, _params);
}
/*************************************************************************
Natural logarithm of gamma function
Input parameters:
X - argument
Result:
logarithm of the absolute value of the Gamma(X).
Output parameters:
SgnGam - sign(Gamma(X))
Domain:
0 < X < 2.55e305
-2.55e305 < X < 0, X is not an integer.
ACCURACY:
arithmetic domain # trials peak rms
IEEE 0, 3 28000 5.4e-16 1.1e-16
IEEE 2.718, 2.556e305 40000 3.5e-16 8.3e-17
The error criterion was relative when the function magnitude
was greater than one but absolute when it was less than one.
The following test used the relative error criterion, though
at certain points the relative error could be much higher than
indicated.
IEEE -200, -4 10000 4.8e-16 1.3e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
Translated to AlgoPascal by Bochkanov Sergey (2005, 2006, 2007).
*************************************************************************/
public static double lngamma(double x, out double sgngam)
{
sgngam = 0;
return gammafunc.lngamma(x, ref sgngam, null);
}
public static double lngamma(double x, out double sgngam, alglib.xparams _params)
{
sgngam = 0;
return gammafunc.lngamma(x, ref sgngam, _params);
}
}
public partial class alglib
{
/*************************************************************************
Error function
The integral is
x
-
2 | | 2
erf(x) = -------- | exp( - t ) dt.
sqrt(pi) | |
-
0
For 0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2); otherwise
erf(x) = 1 - erfc(x).
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,1 30000 3.7e-16 1.0e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
public static double errorfunction(double x)
{
return normaldistr.errorfunction(x, null);
}
public static double errorfunction(double x, alglib.xparams _params)
{
return normaldistr.errorfunction(x, _params);
}
/*************************************************************************
Complementary error function
1 - erf(x) =
inf.
-
2 | | 2
erfc(x) = -------- | exp( - t ) dt
sqrt(pi) | |
-
x
For small x, erfc(x) = 1 - erf(x); otherwise rational
approximations are computed.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,26.6417 30000 5.7e-14 1.5e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
public static double errorfunctionc(double x)
{
return normaldistr.errorfunctionc(x, null);
}
public static double errorfunctionc(double x, alglib.xparams _params)
{
return normaldistr.errorfunctionc(x, _params);
}
/*************************************************************************
Same as normalcdf(), obsolete name.
*************************************************************************/
public static double normaldistribution(double x)
{
return normaldistr.normaldistribution(x, null);
}
public static double normaldistribution(double x, alglib.xparams _params)
{
return normaldistr.normaldistribution(x, _params);
}
/*************************************************************************
Normal distribution PDF
Returns Gaussian probability density function:
1
f(x) = --------- * exp(-x^2/2)
sqrt(2pi)
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
public static double normalpdf(double x)
{
return normaldistr.normalpdf(x, null);
}
public static double normalpdf(double x, alglib.xparams _params)
{
return normaldistr.normalpdf(x, _params);
}
/*************************************************************************
Normal distribution CDF
Returns the area under the Gaussian probability density
function, integrated from minus infinity to x:
x
-
1 | | 2
ndtr(x) = --------- | exp( - t /2 ) dt
sqrt(2pi) | |
-
-inf.
= ( 1 + erf(z) ) / 2
= erfc(z) / 2
where z = x/sqrt(2). Computation is via the functions
erf and erfc.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE -13,0 30000 3.4e-14 6.7e-15
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
public static double normalcdf(double x)
{
return normaldistr.normalcdf(x, null);
}
public static double normalcdf(double x, alglib.xparams _params)
{
return normaldistr.normalcdf(x, _params);
}
/*************************************************************************
Inverse of the error function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
public static double inverf(double e)
{
return normaldistr.inverf(e, null);
}
public static double inverf(double e, alglib.xparams _params)
{
return normaldistr.inverf(e, _params);
}
/*************************************************************************
Same as invnormalcdf(), deprecated name
*************************************************************************/
public static double invnormaldistribution(double y0)
{
return normaldistr.invnormaldistribution(y0, null);
}
public static double invnormaldistribution(double y0, alglib.xparams _params)
{
return normaldistr.invnormaldistribution(y0, _params);
}
/*************************************************************************
Inverse of Normal CDF
Returns the argument, x, for which the area under the
Gaussian probability density function (integrated from
minus infinity to x) is equal to y.
For small arguments 0 < y < exp(-2), the program computes
z = sqrt( -2.0 * log(y) ); then the approximation is
x = z - log(z)/z - (1/z) P(1/z) / Q(1/z).
There are two rational functions P/Q, one for 0 < y < exp(-32)
and the other for y up to exp(-2). For larger arguments,
w = y - 0.5, and x/sqrt(2pi) = w + w**3 R(w**2)/S(w**2)).
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0.125, 1 20000 7.2e-16 1.3e-16
IEEE 3e-308, 0.135 50000 4.6e-16 9.8e-17
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
public static double invnormalcdf(double y0)
{
return normaldistr.invnormalcdf(y0, null);
}
public static double invnormalcdf(double y0, alglib.xparams _params)
{
return normaldistr.invnormalcdf(y0, _params);
}
/*************************************************************************
Bivariate normal PDF
Returns probability density function of the bivariate Gaussian with
correlation parameter equal to Rho:
1 ( x^2 - 2*rho*x*y + y^2 )
f(x,y,rho) = ----------------- * exp( - ----------------------- )
2pi*sqrt(1-rho^2) ( 2*(1-rho^2) )
with -1<rho<+1 and arbitrary x, y.
This function won't fail as long as Rho is in (-1,+1) range.
-- ALGLIB --
Copyright 15.11.2019 by Bochkanov Sergey
*************************************************************************/
public static double bivariatenormalpdf(double x, double y, double rho)
{
return normaldistr.bivariatenormalpdf(x, y, rho, null);
}
public static double bivariatenormalpdf(double x, double y, double rho, alglib.xparams _params)
{
return normaldistr.bivariatenormalpdf(x, y, rho, _params);
}
/*************************************************************************
Bivariate normal CDF
Returns the area under the bivariate Gaussian PDF with correlation
parameter equal to Rho, integrated from minus infinity to (x,y):
x y
- -
1 | | | |
bvn(x,y,rho) = ------------------- | | f(u,v,rho)*du*dv
2pi*sqrt(1-rho^2) | | | |
- -
-INF -INF
where
( u^2 - 2*rho*u*v + v^2 )
f(u,v,rho) = exp( - ----------------------- )
( 2*(1-rho^2) )
with -1<rho<+1 and arbitrary x, y.
This subroutine uses high-precision approximation scheme proposed by
Alan Genz in "Numerical Computation of Rectangular Bivariate and
Trivariate Normal and t probabilities", which computes CDF with
absolute error roughly equal to 1e-14.
This function won't fail as long as Rho is in (-1,+1) range.
-- ALGLIB --
Copyright 15.11.2019 by Bochkanov Sergey
*************************************************************************/
public static double bivariatenormalcdf(double x, double y, double rho)
{
return normaldistr.bivariatenormalcdf(x, y, rho, null);
}
public static double bivariatenormalcdf(double x, double y, double rho, alglib.xparams _params)
{
return normaldistr.bivariatenormalcdf(x, y, rho, _params);
}
}
public partial class alglib
{
/*************************************************************************
Incomplete beta integral
Returns incomplete beta integral of the arguments, evaluated
from zero to x. The function is defined as
x
- -
| (a+b) | | a-1 b-1
----------- | t (1-t) dt.
- - | |
| (a) | (b) -
0
The domain of definition is 0 <= x <= 1. In this
implementation a and b are restricted to positive values.
The integral from x to 1 may be obtained by the symmetry
relation
1 - incbet( a, b, x ) = incbet( b, a, 1-x ).
The integral is evaluated by a continued fraction expansion
or, when b*x is small, by a power series.
ACCURACY:
Tested at uniformly distributed random points (a,b,x) with a and b
in "domain" and x between 0 and 1.
Relative error
arithmetic domain # trials peak rms
IEEE 0,5 10000 6.9e-15 4.5e-16
IEEE 0,85 250000 2.2e-13 1.7e-14
IEEE 0,1000 30000 5.3e-12 6.3e-13
IEEE 0,10000 250000 9.3e-11 7.1e-12
IEEE 0,100000 10000 8.7e-10 4.8e-11
Outputs smaller than the IEEE gradual underflow threshold
were excluded from these statistics.
Cephes Math Library, Release 2.8: June, 2000
Copyright 1984, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
public static double incompletebeta(double a, double b, double x)
{
return ibetaf.incompletebeta(a, b, x, null);
}
public static double incompletebeta(double a, double b, double x, alglib.xparams _params)
{
return ibetaf.incompletebeta(a, b, x, _params);
}
/*************************************************************************
Inverse of imcomplete beta integral
Given y, the function finds x such that
incbet( a, b, x ) = y .
The routine performs interval halving or Newton iterations to find the
root of incbet(a,b,x) - y = 0.
ACCURACY:
Relative error:
x a,b
arithmetic domain domain # trials peak rms
IEEE 0,1 .5,10000 50000 5.8e-12 1.3e-13
IEEE 0,1 .25,100 100000 1.8e-13 3.9e-15
IEEE 0,1 0,5 50000 1.1e-12 5.5e-15
With a and b constrained to half-integer or integer values:
IEEE 0,1 .5,10000 50000 5.8e-12 1.1e-13
IEEE 0,1 .5,100 100000 1.7e-14 7.9e-16
With a = .5, b constrained to half-integer or integer values:
IEEE 0,1 .5,10000 10000 8.3e-11 1.0e-11
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1996, 2000 by Stephen L. Moshier
*************************************************************************/
public static double invincompletebeta(double a, double b, double y)
{
return ibetaf.invincompletebeta(a, b, y, null);
}
public static double invincompletebeta(double a, double b, double y, alglib.xparams _params)
{
return ibetaf.invincompletebeta(a, b, y, _params);
}
}
public partial class alglib
{
/*************************************************************************
Student's t distribution
Computes the integral from minus infinity to t of the Student
t distribution with integer k > 0 degrees of freedom:
t
-
| |
- | 2 -(k+1)/2
| ( (k+1)/2 ) | ( x )
---------------------- | ( 1 + --- ) dx
- | ( k )
sqrt( k pi ) | ( k/2 ) |
| |
-
-inf.
Relation to incomplete beta integral:
1 - stdtr(k,t) = 0.5 * incbet( k/2, 1/2, z )
where
z = k/(k + t**2).
For t < -2, this is the method of computation. For higher t,
a direct method is derived from integration by parts.
Since the function is symmetric about t=0, the area under the
right tail of the density is found by calling the function
with -t instead of t.
ACCURACY:
Tested at random 1 <= k <= 25. The "domain" refers to t.
Relative error:
arithmetic domain # trials peak rms
IEEE -100,-2 50000 5.9e-15 1.4e-15
IEEE -2,100 500000 2.7e-15 4.9e-17
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
public static double studenttdistribution(int k, double t)
{
return studenttdistr.studenttdistribution(k, t, null);
}
public static double studenttdistribution(int k, double t, alglib.xparams _params)
{
return studenttdistr.studenttdistribution(k, t, _params);
}
/*************************************************************************
Functional inverse of Student's t distribution
Given probability p, finds the argument t such that stdtr(k,t)
is equal to p.
ACCURACY:
Tested at random 1 <= k <= 100. The "domain" refers to p:
Relative error:
arithmetic domain # trials peak rms
IEEE .001,.999 25000 5.7e-15 8.0e-16
IEEE 10^-6,.001 25000 2.0e-12 2.9e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
public static double invstudenttdistribution(int k, double p)
{
return studenttdistr.invstudenttdistribution(k, p, null);
}
public static double invstudenttdistribution(int k, double p, alglib.xparams _params)
{
return studenttdistr.invstudenttdistribution(k, p, _params);
}
}
public partial class alglib
{
/*************************************************************************
F distribution
Returns the area from zero to x under the F density
function (also known as Snedcor's density or the
variance ratio density). This is the density
of x = (u1/df1)/(u2/df2), where u1 and u2 are random
variables having Chi square distributions with df1
and df2 degrees of freedom, respectively.
The incomplete beta integral is used, according to the
formula
P(x) = incbet( df1/2, df2/2, (df1*x/(df2 + df1*x) ).
The arguments a and b are greater than zero, and x is
nonnegative.
ACCURACY:
Tested at random points (a,b,x).
x a,b Relative error:
arithmetic domain domain # trials peak rms
IEEE 0,1 0,100 100000 9.8e-15 1.7e-15
IEEE 1,5 0,100 100000 6.5e-15 3.5e-16
IEEE 0,1 1,10000 100000 2.2e-11 3.3e-12
IEEE 1,5 1,10000 100000 1.1e-11 1.7e-13
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
public static double fdistribution(int a, int b, double x)
{
return fdistr.fdistribution(a, b, x, null);
}
public static double fdistribution(int a, int b, double x, alglib.xparams _params)
{
return fdistr.fdistribution(a, b, x, _params);
}
/*************************************************************************
Complemented F distribution
Returns the area from x to infinity under the F density
function (also known as Snedcor's density or the
variance ratio density).
inf.
-
1 | | a-1 b-1
1-P(x) = ------ | t (1-t) dt
B(a,b) | |
-
x
The incomplete beta integral is used, according to the
formula
P(x) = incbet( df2/2, df1/2, (df2/(df2 + df1*x) ).
ACCURACY:
Tested at random points (a,b,x) in the indicated intervals.
x a,b Relative error:
arithmetic domain domain # trials peak rms
IEEE 0,1 1,100 100000 3.7e-14 5.9e-16
IEEE 1,5 1,100 100000 8.0e-15 1.6e-15
IEEE 0,1 1,10000 100000 1.8e-11 3.5e-13
IEEE 1,5 1,10000 100000 2.0e-11 3.0e-12
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
public static double fcdistribution(int a, int b, double x)
{
return fdistr.fcdistribution(a, b, x, null);
}
public static double fcdistribution(int a, int b, double x, alglib.xparams _params)
{
return fdistr.fcdistribution(a, b, x, _params);
}
/*************************************************************************
Inverse of complemented F distribution
Finds the F density argument x such that the integral
from x to infinity of the F density is equal to the
given probability p.
This is accomplished using the inverse beta integral
function and the relations
z = incbi( df2/2, df1/2, p )
x = df2 (1-z) / (df1 z).
Note: the following relations hold for the inverse of
the uncomplemented F distribution:
z = incbi( df1/2, df2/2, p )
x = df2 z / (df1 (1-z)).
ACCURACY:
Tested at random points (a,b,p).
a,b Relative error:
arithmetic domain # trials peak rms
For p between .001 and 1:
IEEE 1,100 100000 8.3e-15 4.7e-16
IEEE 1,10000 100000 2.1e-11 1.4e-13
For p between 10^-6 and 10^-3:
IEEE 1,100 50000 1.3e-12 8.4e-15
IEEE 1,10000 50000 3.0e-12 4.8e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
public static double invfdistribution(int a, int b, double y)
{
return fdistr.invfdistribution(a, b, y, null);
}
public static double invfdistribution(int a, int b, double y, alglib.xparams _params)
{
return fdistr.invfdistribution(a, b, y, _params);
}
}
public partial class alglib
{
/*************************************************************************
Incomplete gamma integral
The function is defined by
x
-
1 | | -t a-1
igam(a,x) = ----- | e t dt.
- | |
| (a) -
0
In this implementation both arguments must be positive.
The integral is evaluated by either a power series or
continued fraction expansion, depending on the relative
values of a and x.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,30 200000 3.6e-14 2.9e-15
IEEE 0,100 300000 9.9e-14 1.5e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1985, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
public static double incompletegamma(double a, double x)
{
return igammaf.incompletegamma(a, x, null);
}
public static double incompletegamma(double a, double x, alglib.xparams _params)
{
return igammaf.incompletegamma(a, x, _params);
}
/*************************************************************************
Complemented incomplete gamma integral
The function is defined by
igamc(a,x) = 1 - igam(a,x)
inf.
-
1 | | -t a-1
= ----- | e t dt.
- | |
| (a) -
x
In this implementation both arguments must be positive.
The integral is evaluated by either a power series or
continued fraction expansion, depending on the relative
values of a and x.
ACCURACY:
Tested at random a, x.
a x Relative error:
arithmetic domain domain # trials peak rms
IEEE 0.5,100 0,100 200000 1.9e-14 1.7e-15
IEEE 0.01,0.5 0,100 200000 1.4e-13 1.6e-15
Cephes Math Library Release 2.8: June, 2000
Copyright 1985, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
public static double incompletegammac(double a, double x)
{
return igammaf.incompletegammac(a, x, null);
}
public static double incompletegammac(double a, double x, alglib.xparams _params)
{
return igammaf.incompletegammac(a, x, _params);
}
/*************************************************************************
Inverse of complemented imcomplete gamma integral
Given p, the function finds x such that
igamc( a, x ) = p.
Starting with the approximate value
3
x = a t
where
t = 1 - d - ndtri(p) sqrt(d)
and
d = 1/9a,
the routine performs up to 10 Newton iterations to find the
root of igamc(a,x) - p = 0.
ACCURACY:
Tested at random a, p in the intervals indicated.
a p Relative error:
arithmetic domain domain # trials peak rms
IEEE 0.5,100 0,0.5 100000 1.0e-14 1.7e-15
IEEE 0.01,0.5 0,0.5 100000 9.0e-14 3.4e-15
IEEE 0.5,10000 0,0.5 20000 2.3e-13 3.8e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
public static double invincompletegammac(double a, double y0)
{
return igammaf.invincompletegammac(a, y0, null);
}
public static double invincompletegammac(double a, double y0, alglib.xparams _params)
{
return igammaf.invincompletegammac(a, y0, _params);
}
}
public partial class alglib
{
/*************************************************************************
Chi-square distribution
Returns the area under the left hand tail (from 0 to x)
of the Chi square probability density function with
v degrees of freedom.
x
-
1 | | v/2-1 -t/2
P( x | v ) = ----------- | t e dt
v/2 - | |
2 | (v/2) -
0
where x is the Chi-square variable.
The incomplete gamma integral is used, according to the
formula
y = chdtr( v, x ) = igam( v/2.0, x/2.0 ).
The arguments must both be positive.
ACCURACY:
See incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
public static double chisquaredistribution(double v, double x)
{
return chisquaredistr.chisquaredistribution(v, x, null);
}
public static double chisquaredistribution(double v, double x, alglib.xparams _params)
{
return chisquaredistr.chisquaredistribution(v, x, _params);
}
/*************************************************************************
Complemented Chi-square distribution
Returns the area under the right hand tail (from x to
infinity) of the Chi square probability density function
with v degrees of freedom:
inf.
-
1 | | v/2-1 -t/2
P( x | v ) = ----------- | t e dt
v/2 - | |
2 | (v/2) -
x
where x is the Chi-square variable.
The incomplete gamma integral is used, according to the
formula
y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ).
The arguments must both be positive.
ACCURACY:
See incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
public static double chisquarecdistribution(double v, double x)
{
return chisquaredistr.chisquarecdistribution(v, x, null);
}
public static double chisquarecdistribution(double v, double x, alglib.xparams _params)
{
return chisquaredistr.chisquarecdistribution(v, x, _params);
}
/*************************************************************************
Inverse of complemented Chi-square distribution
Finds the Chi-square argument x such that the integral
from x to infinity of the Chi-square density is equal
to the given cumulative probability y.
This is accomplished using the inverse gamma integral
function and the relation
x/2 = igami( df/2, y );
ACCURACY:
See inverse incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
public static double invchisquaredistribution(double v, double y)
{