]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/hyperexponential_snips.cpp
1 // Copyright John Maddock 2014.
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt
6 // or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // Caution: this file contains Quickbook markup as well as code
9 // and comments, don't change any of the special comment markups!
12 # pragma warning (disable : 4996) // disable -D_SCL_SECURE_NO_WARNINGS C++ 'Checked Iterators'
15 #include <boost/math/distributions/hyperexponential.hpp>
18 #ifndef BOOST_NO_CXX11_HDR_ARRAY
25 //[hyperexponential_snip1
26 //=#include <boost/math/distributions/hyperexponential.hpp>
27 //=#include <iostream>
30 const double rates
[] = { 1.0 / 10.0, 1.0 / 12.0 };
32 boost::math::hyperexponential
he(rates
);
34 std::cout
<< "Average lifetime: "
35 << boost::math::mean(he
)
36 << " years" << std::endl
;
37 std::cout
<< "Probability that the appliance will work for more than 15 years: "
38 << boost::math::cdf(boost::math::complement(he
, 15.0))
43 using namespace boost::math
;
44 #ifndef BOOST_NO_CXX11_HDR_ARRAY
46 //[hyperexponential_snip2
47 std::array
<double, 2> phase_prob
= { 0.5, 0.5 };
48 std::array
<double, 2> rates
= { 1.0 / 10, 1.0 / 12 };
50 hyperexponential
he(phase_prob
.begin(), phase_prob
.end(), rates
.begin(), rates
.end());
55 //[hyperexponential_snip3
56 // We could be using any standard library container here... vector, deque, array, list etc:
57 std::array
<double, 2> phase_prob
= { 0.5, 0.5 };
58 std::array
<double, 2> rates
= { 1.0 / 10, 1.0 / 12 };
60 hyperexponential
he1(phase_prob
, rates
); // Construct from standard library container.
62 double phase_probs2
[] = { 0.5, 0.5 };
63 double rates2
[] = { 1.0 / 10, 1.0 / 12 };
65 hyperexponential
he2(phase_probs2
, rates2
); // Construct from native C++ array.
69 //[hyperexponential_snip4
70 // We could be using any standard library container here... vector, deque, array, list etc:
71 std::array
<double, 2> rates
= { 1.0 / 10, 1.0 / 12 };
73 hyperexponential
he(rates
.begin(), rates
.end());
75 assert(he
.probabilities()[0] == 0.5); // Phase probabilities will be equal and normalised to unity.
79 //[hyperexponential_snip5
80 std::array
<double, 2> rates
= { 1.0 / 10, 1.0 / 12 };
82 hyperexponential
he(rates
);
84 assert(he
.probabilities()[0] == 0.5); // Phase probabilities will be equal and normalised to unity.
88 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !(defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION < 40500))
90 //[hyperexponential_snip6
91 hyperexponential he
= { { 0.5, 0.5 }, { 1.0 / 10, 1.0 / 12 } };
95 //[hyperexponential_snip7
96 hyperexponential he
= { 1.0 / 10, 1.0 / 12 };
98 assert(he
.probabilities()[0] == 0.5);