blob: aa757f3ea6f416e5bbba47f1fc08afa37ca19bc6 (
plain)
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
|
// arcsine_example.cpp
// Copyright John Maddock 2014.
// Copyright Paul A. Bristow 2014.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
// Example for the arcsine Distribution.
// Note: Contains Quickbook snippets in comments.
//[arcsine_snip_1
#include <boost/math/distributions/arcsine.hpp> // For arcsine_distribution.
//] [/arcsine_snip_1]
#include <iostream>
#include <exception>
#include <boost/assert.hpp>
int main()
{
std::cout << "Examples of Arcsine distribution." << std::endl;
std::cout.precision(3); // Avoid uninformative decimal digits.
using boost::math::arcsine;
arcsine as; // Construct a default `double` standard [0, 1] arcsine distribution.
//[arcsine_snip_2
std::cout << pdf(as, 1. / 2) << std::endl; // 0.637
// pdf has a minimum at x = 0.5
//] [/arcsine_snip_2]
//[arcsine_snip_3
std::cout << pdf(as, 1. / 4) << std::endl; // 0.735
//] [/arcsine_snip_3]
//[arcsine_snip_4
std::cout << cdf(as, 0.05) << std::endl; // 0.144
//] [/arcsine_snip_4]
//[arcsine_snip_5
std::cout << 2 * cdf(as, 1 - 0.975) << std::endl; // 0.202
//] [/arcsine_snip_5]
//[arcsine_snip_6
std::cout << 2 * cdf(complement(as, 0.975)) << std::endl; // 0.202
//] [/arcsine_snip_6]
//[arcsine_snip_7
std::cout << quantile(as, 1 - 0.2 / 2) << std::endl; // 0.976
std::cout << quantile(complement(as, 0.2 / 2)) << std::endl; // 0.976
//] [/arcsine_snip_7]
{
//[arcsine_snip_8
using boost::math::arcsine_distribution;
arcsine_distribution<> as(2, 5); // Constructs a double arcsine distribution.
BOOST_ASSERT(as.x_min() == 2.); // as.x_min() returns 2.
BOOST_ASSERT(as.x_max() == 5.); // as.x_max() returns 5.
//] [/arcsine_snip_8]
}
return 0;
} // int main()
/*
[arcsine_output
Example of Arcsine distribution
0.637
0.735
0.144
0.202
0.202
0.976
0.976
] [/arcsine_output]
*/
|