-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtruncated_normal.cpp
4536 lines (4120 loc) · 88.9 KB
/
truncated_normal.cpp
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
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <cmath>
# include <ctime>
# include <cstring>
using namespace std;
# include "truncated_normal.hpp"
//****************************************************************************80
int i4_uniform_ab ( int a, int b, int &seed )
//****************************************************************************80
//
// Purpose:
//
// I4_UNIFORM_AB returns a scaled pseudorandom I4 between A and B.
//
// Discussion:
//
// The pseudorandom number should be uniformly distributed
// between A and B.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 02 October 2012
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Paul Bratley, Bennett Fox, Linus Schrage,
// A Guide to Simulation,
// Second Edition,
// Springer, 1987,
// ISBN: 0387964673,
// LC: QA76.9.C65.B73.
//
// Bennett Fox,
// Algorithm 647:
// Implementation and Relative Efficiency of Quasirandom
// Sequence Generators,
// ACM Transactions on Mathematical Software,
// Volume 12, Number 4, December 1986, pages 362-376.
//
// Pierre L'Ecuyer,
// Random Number Generation,
// in Handbook of Simulation,
// edited by Jerry Banks,
// Wiley, 1998,
// ISBN: 0471134031,
// LC: T57.62.H37.
//
// Peter Lewis, Allen Goodman, James Miller,
// A Pseudo-Random Number Generator for the System/360,
// IBM Systems Journal,
// Volume 8, Number 2, 1969, pages 136-143.
//
// Parameters:
//
// Input, int A, B, the limits of the interval.
//
// Input/output, int &SEED, the "seed" value, which should NOT be 0.
// On output, SEED has been updated.
//
// Output, int I4_UNIFORM_AB, a number between A and B.
//
{
int c;
const int i4_huge = 2147483647;
int k;
float r;
int value;
if ( seed == 0 )
{
cerr << "\n";
cerr << "I4_UNIFORM_AB - Fatal error!\n";
cerr << " Input value of SEED = 0.\n";
exit ( 1 );
}
//
// Guarantee A <= B.
//
if ( b < a )
{
c = a;
a = b;
b = c;
}
k = seed / 127773;
seed = 16807 * ( seed - k * 127773 ) - k * 2836;
if ( seed < 0 )
{
seed = seed + i4_huge;
}
r = ( float ) ( seed ) * 4.656612875E-10;
//
// Scale R to lie between A-0.5 and B+0.5.
//
r = ( 1.0 - r ) * ( ( float ) a - 0.5 )
+ r * ( ( float ) b + 0.5 );
//
// Use rounding to convert R to an integer between A and B.
//
value = round ( r );
//
// Guarantee A <= VALUE <= B.
//
if ( value < a )
{
value = a;
}
if ( b < value )
{
value = b;
}
return value;
}
//****************************************************************************80
double normal_01_cdf ( double x )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_01_CDF evaluates the Normal 01 CDF.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 10 February 1999
//
// Author:
//
// John Burkardt
//
// Reference:
//
// A G Adams,
// Areas Under the Normal Curve,
// Algorithm 39,
// Computer j.,
// Volume 12, pages 197-198, 1969.
//
// Parameters:
//
// Input, double X, the argument of the CDF.
//
// Output, double CDF, the value of the CDF.
//
{
double a1 = 0.398942280444;
double a2 = 0.399903438504;
double a3 = 5.75885480458;
double a4 = 29.8213557808;
double a5 = 2.62433121679;
double a6 = 48.6959930692;
double a7 = 5.92885724438;
double b0 = 0.398942280385;
double b1 = 3.8052E-08;
double b2 = 1.00000615302;
double b3 = 3.98064794E-04;
double b4 = 1.98615381364;
double b5 = 0.151679116635;
double b6 = 5.29330324926;
double b7 = 4.8385912808;
double b8 = 15.1508972451;
double b9 = 0.742380924027;
double b10 = 30.789933034;
double b11 = 3.99019417011;
double cdf;
double q;
double y;
//
// |X| <= 1.28.
//
if ( fabs ( x ) <= 1.28 )
{
y = 0.5 * x * x;
q = 0.5 - fabs ( x ) * ( a1 - a2 * y / ( y + a3 - a4 / ( y + a5
+ a6 / ( y + a7 ) ) ) );
//
// 1.28 < |X| <= 12.7
//
}
else if ( fabs ( x ) <= 12.7 )
{
y = 0.5 * x * x;
q = exp ( - y ) * b0 / ( fabs ( x ) - b1
+ b2 / ( fabs ( x ) + b3
+ b4 / ( fabs ( x ) - b5
+ b6 / ( fabs ( x ) + b7
- b8 / ( fabs ( x ) + b9
+ b10 / ( fabs ( x ) + b11 ) ) ) ) ) );
//
// 12.7 < |X|
//
}
else
{
q = 0.0;
}
//
// Take account of negative X.
//
if ( x < 0.0 )
{
cdf = q;
}
else
{
cdf = 1.0 - q;
}
return cdf;
}
//****************************************************************************80
double normal_01_cdf_inv ( double p )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_01_CDF_INV inverts the standard normal CDF.
//
// Discussion:
//
// The result is accurate to about 1 part in 10**16.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 27 December 2004
//
// Author:
//
// Original FORTRAN77 version by Michael Wichura.
// C++ version by John Burkardt.
//
// Reference:
//
// Michael Wichura,
// The Percentage Points of the Normal Distribution,
// Algorithm AS 241,
// Applied Statistics,
// Volume 37, Number 3, pages 477-484, 1988.
//
// Parameters:
//
// Input, double P, the value of the cumulative probability
// densitity function. 0 < P < 1. If P is outside this range, an
// "infinite" value is returned.
//
// Output, double NORMAL_01_CDF_INV, the normal deviate value
// with the property that the probability of a standard normal deviate being
// less than or equal to this value is P.
//
{
double a[8] = {
3.3871328727963666080, 1.3314166789178437745E+2,
1.9715909503065514427E+3, 1.3731693765509461125E+4,
4.5921953931549871457E+4, 6.7265770927008700853E+4,
3.3430575583588128105E+4, 2.5090809287301226727E+3 };
double b[8] = {
1.0, 4.2313330701600911252E+1,
6.8718700749205790830E+2, 5.3941960214247511077E+3,
2.1213794301586595867E+4, 3.9307895800092710610E+4,
2.8729085735721942674E+4, 5.2264952788528545610E+3 };
double c[8] = {
1.42343711074968357734, 4.63033784615654529590,
5.76949722146069140550, 3.64784832476320460504,
1.27045825245236838258, 2.41780725177450611770E-1,
2.27238449892691845833E-2, 7.74545014278341407640E-4 };
double const1 = 0.180625;
double const2 = 1.6;
double d[8] = {
1.0, 2.05319162663775882187,
1.67638483018380384940, 6.89767334985100004550E-1,
1.48103976427480074590E-1, 1.51986665636164571966E-2,
5.47593808499534494600E-4, 1.05075007164441684324E-9 };
double e[8] = {
6.65790464350110377720, 5.46378491116411436990,
1.78482653991729133580, 2.96560571828504891230E-1,
2.65321895265761230930E-2, 1.24266094738807843860E-3,
2.71155556874348757815E-5, 2.01033439929228813265E-7 };
double f[8] = {
1.0, 5.99832206555887937690E-1,
1.36929880922735805310E-1, 1.48753612908506148525E-2,
7.86869131145613259100E-4, 1.84631831751005468180E-5,
1.42151175831644588870E-7, 2.04426310338993978564E-15 };
double q;
double r;
double split1 = 0.425;
double split2 = 5.0;
double value;
if ( p <= 0.0 )
{
value = -r8_huge ( );
return value;
}
if ( 1.0 <= p )
{
value = r8_huge ( );
return value;
}
q = p - 0.5;
if ( fabs ( q ) <= split1 )
{
r = const1 - q * q;
value = q * r8poly_value_horner ( 7, a, r )
/ r8poly_value_horner ( 7, b, r );
}
else
{
if ( q < 0.0 )
{
r = p;
}
else
{
r = 1.0 - p;
}
if ( r <= 0.0 )
{
value = r8_huge ( );
}
else
{
r = sqrt ( - log ( r ) );
if ( r <= split2 )
{
r = r - const2;
value = r8poly_value_horner ( 7, c, r )
/ r8poly_value_horner ( 7, d, r );
}
else
{
r = r - split2;
value = r8poly_value_horner ( 7, e, r )
/ r8poly_value_horner ( 7, f, r );
}
}
if ( q < 0.0 )
{
value = - value;
}
}
return value;
}
//****************************************************************************80
void normal_01_cdf_values ( int &n_data, double &x, double &fx )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_01_CDF_VALUES returns some values of the Normal 01 CDF.
//
// Discussion:
//
// In Mathematica, the function can be evaluated by:
//
// Needs["Statistics`ContinuousDistributions`"]
// dist = NormalDistribution [ 0, 1 ]
// CDF [ dist, x ]
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 28 August 2004
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Milton Abramowitz, Irene Stegun,
// Handbook of Mathematical Functions,
// National Bureau of Standards, 1964,
// ISBN: 0-486-61272-4,
// LC: QA47.A34.
//
// Stephen Wolfram,
// The Mathematica Book,
// Fourth Edition,
// Cambridge University Press, 1999,
// ISBN: 0-521-64314-7,
// LC: QA76.95.W65.
//
// Parameters:
//
// Input/output, int &N_DATA. The user sets N_DATA to 0 before the
// first call. On each call, the routine increments N_DATA by 1, and
// returns the corresponding data; when there is no more data, the
// output value of N_DATA will be 0 again.
//
// Output, double &X, the argument of the function.
//
// Output, double &FX, the value of the function.
//
{
# define N_MAX 17
static double fx_vec[N_MAX] = {
0.5000000000000000E+00,
0.5398278372770290E+00,
0.5792597094391030E+00,
0.6179114221889526E+00,
0.6554217416103242E+00,
0.6914624612740131E+00,
0.7257468822499270E+00,
0.7580363477769270E+00,
0.7881446014166033E+00,
0.8159398746532405E+00,
0.8413447460685429E+00,
0.9331927987311419E+00,
0.9772498680518208E+00,
0.9937903346742239E+00,
0.9986501019683699E+00,
0.9997673709209645E+00,
0.9999683287581669E+00 };
static double x_vec[N_MAX] = {
0.0000000000000000E+00,
0.1000000000000000E+00,
0.2000000000000000E+00,
0.3000000000000000E+00,
0.4000000000000000E+00,
0.5000000000000000E+00,
0.6000000000000000E+00,
0.7000000000000000E+00,
0.8000000000000000E+00,
0.9000000000000000E+00,
0.1000000000000000E+01,
0.1500000000000000E+01,
0.2000000000000000E+01,
0.2500000000000000E+01,
0.3000000000000000E+01,
0.3500000000000000E+01,
0.4000000000000000E+01 };
if ( n_data < 0 )
{
n_data = 0;
}
n_data = n_data + 1;
if ( N_MAX < n_data )
{
n_data = 0;
x = 0.0;
fx = 0.0;
}
else
{
x = x_vec[n_data-1];
fx = fx_vec[n_data-1];
}
return;
# undef N_MAX
}
//****************************************************************************80
double normal_01_mean ( )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_01_MEAN returns the mean of the Normal 01 PDF.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 18 September 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Output, double MEAN, the mean of the PDF.
//
{
double mean;
mean = 0.0;
return mean;
}
//****************************************************************************80
double normal_01_moment ( int order )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_01_MOMENT evaluates moments of the Normal 01 PDF.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 31 August 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int ORDER, the order of the moment.
// 0 <= ORDER.
//
// Output, double NORMAL_01_MOMENT, the value of the moment.
//
{
double value;
if ( ( order % 2 ) == 0 )
{
value = r8_factorial2 ( order - 1 );
}
else
{
value = 0.0;
}
return value;
}
//****************************************************************************80
double normal_01_pdf ( double x )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_01_PDF evaluates the Normal 01 PDF.
//
// Discussion:
//
// The Normal 01 PDF is also called the "Standard Normal" PDF, or
// the Normal PDF with 0 mean and standard deviation 1.
//
// PDF(X) = exp ( - 0.5 * X^2 ) / sqrt ( 2 * PI )
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 18 September 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double X, the argument of the PDF.
//
// Output, double PDF, the value of the PDF.
//
{
double pdf;
const double r8_pi = 3.14159265358979323;
pdf = exp ( -0.5 * x * x ) / sqrt ( 2.0 * r8_pi );
return pdf;
}
//****************************************************************************80
double normal_01_sample ( int &seed )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_01_SAMPLE samples the standard normal probability distribution.
//
// Discussion:
//
// The standard normal probability distribution function (PDF) has
// mean 0 and standard deviation 1.
//
// The Box-Muller method is used, which is efficient, but
// generates two values at a time.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 26 August 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input/output, int &SEED, a seed for the random number generator.
//
// Output, double NORMAL_01_SAMPLE, a normally distributed random value.
//
{
double r1;
double r2;
const double r8_pi = 3.14159265358979323;
double x;
r1 = r8_uniform_01 ( seed );
r2 = r8_uniform_01 ( seed );
x = sqrt ( -2.0 * log ( r1 ) ) * cos ( 2.0 * r8_pi * r2 );
return x;
}
//****************************************************************************80
double normal_01_variance ( )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_01_VARIANCE returns the variance of the Normal 01 PDF.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 18 September 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Output, double VARIANCE, the variance of the PDF.
//
{
double variance;
variance = 1.0;
return variance;
}
//****************************************************************************80
double normal_ms_cdf ( double x, double mu, double sigma )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_MS_CDF evaluates the Normal CDF.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 September 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double X, the argument of the CDF.
//
// Input, double MU, SIGMA, the parameters of the PDF.
// 0.0 < SIGMA.
//
// Output, double NORMAL_MS_CDF, the value of the CDF.
//
{
double cdf;
double y;
y = ( x - mu ) / sigma;
cdf = normal_01_cdf ( y );
return cdf;
}
//****************************************************************************80
double normal_ms_cdf_inv ( double cdf, double mu, double sigma )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_MS_CDF_INV inverts the Normal CDF.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 September 2004
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Algorithm AS 111,
// Applied Statistics,
// Volume 26, pages 118-121, 1977.
//
// Parameters:
//
// Input, double CDF, the value of the CDF.
// 0.0 <= CDF <= 1.0.
//
// Input, double MU, SIGMA, the parameters of the PDF.
// 0.0 < SIGMA.
//
// Output, double NORMAL_MS_CDF_INV, the corresponding argument.
//
{
double x;
double x2;
if ( cdf < 0.0 || 1.0 < cdf )
{
cout << "\n";
cout << "NORMAL_MS_CDF_INV - Fatal error!\n";
cout << " CDF < 0 or 1 < CDF.\n";
exit ( 1 );
}
x2 = normal_01_cdf_inv ( cdf );
x = mu + sigma * x2;
return x;
}
//****************************************************************************80
double normal_ms_mean ( double mu, double sigma )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_MS_MEAN returns the mean of the Normal PDF.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 September 2004
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double MU, SIGMA, the parameters of the PDF.
// 0.0 < SIGMA.
//
// Output, double NORMAL_MS_MEAN, the mean of the PDF.
//
{
double mean;
mean = mu;
return mean;
}
//****************************************************************************80
double normal_ms_moment ( int order, double mu, double sigma )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_MS_MOMENT evaluates moments of the Normal PDF.
//
// Discussion:
//
// The formula was posted by John D Cook.
//
// Order Moment
// ----- ------
// 0 1
// 1 mu
// 2 mu^2 + sigma^2
// 3 mu^3 + 3 mu sigma^2
// 4 mu^4 + 6 mu^2 sigma^2 + 3 sigma^4
// 5 mu^5 + 10 mu^3 sigma^2 + 15 mu sigma^4
// 6 mu^6 + 15 mu^4 sigma^2 + 45 mu^2 sigma^4 + 15 sigma^6
// 7 mu^7 + 21 mu^5 sigma^2 + 105 mu^3 sigma^4 + 105 mu sigma^6
// 8 mu^8 + 28 mu^6 sigma^2 + 210 mu^4 sigma^4 + 420 mu^2 sigma^6
// + 105 sigma^8
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 31 August 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int ORDER, the order of the moment.
// 0 <= ORDER.
//
// Input, double MU, the mean of the distribution.
//
// Input, double SIGMA, the standard deviation of the distribution.
//
// Output, double NORMAL_MS_MOMENT, the value of the central moment.
//
{
int j;
int j_hi;
double value;
j_hi = ( order / 2 );
value = 0.0;
for ( j = 0; j <= j_hi; j++ )
{
value = value
+ r8_choose ( order, 2 * j )
* r8_factorial2 ( 2 * j - 1 )
* pow ( mu, order - 2 * j ) * pow ( sigma, 2 * j );
}
return value;
}
//****************************************************************************80
double normal_ms_moment_central ( int order, double mu, double sigma )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_MS_MOMENT_CENTRAL evaluates central moments of the Normal PDF.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 31 August 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int ORDER, the order of the moment.
// 0 <= ORDER.
//
// Input, double MU, the mean of the distribution.
//
// Input, double SIGMA, the standard deviation of the distribution.
//
// Output, double NORMAL_MS_MOMENT_CENTRAL, the value of the central moment.
//
{
double value;
if ( ( order % 2 ) == 0 )
{
value = r8_factorial2 ( order - 1 ) * pow ( sigma, order );
}
else
{
value = 0.0;
}
return value;
}
//****************************************************************************80
double normal_ms_moment_central_values ( int order, double mu, double sigma )
//****************************************************************************80
//
// Purpose:
//
// NORMAL_MS_MOMENT_CENTRAL_VALUES: moments 0 through 10 of the Normal PDF.
//
// Discussion:
//
// The formula was posted by John D Cook.
//
// Order Moment
// ----- ------
// 0 1
// 1 0
// 2 sigma^2
// 3 0
// 4 3 sigma^4
// 5 0
// 6 15 sigma^6
// 7 0
// 8 105 sigma^8
// 9 0
// 10 945 sigma^10
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 31 August 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int ORDER, the order of the moment.
// 0 <= ORDER <= 10.
//
// Input, double MU, the mean of the distribution.
//
// Input, double SIGMA, the standard deviation of the distribution.
//
// Output, double NORMAL_MS_MOMENT_CENTRAL_VALUES, the value of the