• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 Marco Guazzone (marco.guazzone@gmail.com).
2 
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)
7 
8 // Caution: this file contains Quickbook markup as well as code
9 // and comments, don't change any of the special comment markups!
10 
11 
12 //[hyperexponential_more_snip1
13 #include <boost/math/distributions.hpp>
14 #include <iostream>
15 #include <string>
16 
17 struct ds_info
18 {
19    std::string name;
20    double iat_sample_mean;
21    double iat_sample_sd;
22    boost::math::hyperexponential iat_he;
23    double multi_lt_sample_mean;
24    double multi_lt_sample_sd;
25    boost::math::hyperexponential multi_lt_he;
26    double single_lt_sample_mean;
27    double single_lt_sample_sd;
28    boost::math::hyperexponential single_lt_he;
29 };
30 
31 // DS1 dataset
make_ds1()32 ds_info make_ds1()
33 {
34    ds_info ds;
35 
36    ds.name = "DS1";
37 
38    // VM interarrival time distribution
39    const double iat_fit_probs[] = { 0.34561,0.08648,0.56791 };
40    const double iat_fit_rates[] = { 0.0008,0.00005,0.02894 };
41    ds.iat_sample_mean = 2202.1;
42    ds.iat_sample_sd = 2.2e+4;
43    ds.iat_he = boost::math::hyperexponential(iat_fit_probs, iat_fit_rates);
44 
45    // Multi-core VM lifetime distribution
46    const double multi_lt_fit_probs[] = { 0.24667,0.37948,0.37385 };
47    const double multi_lt_fit_rates[] = { 0.00004,0.000002,0.00059 };
48    ds.multi_lt_sample_mean = 257173;
49    ds.multi_lt_sample_sd = 4.6e+5;
50    ds.multi_lt_he = boost::math::hyperexponential(multi_lt_fit_probs, multi_lt_fit_rates);
51 
52    // Single-core VM lifetime distribution
53    const double single_lt_fit_probs[] = { 0.09325,0.22251,0.68424 };
54    const double single_lt_fit_rates[] = { 0.000003,0.00109,0.00109 };
55    ds.single_lt_sample_mean = 28754.4;
56    ds.single_lt_sample_sd = 1.6e+5;
57    ds.single_lt_he = boost::math::hyperexponential(single_lt_fit_probs, single_lt_fit_rates);
58 
59    return ds;
60 }
61 
62 // DS2 dataset
make_ds2()63 ds_info make_ds2()
64 {
65    ds_info ds;
66 
67    ds.name = "DS2";
68 
69    // VM interarrival time distribution
70    const double iat_fit_probs[] = { 0.38881,0.18227,0.42892 };
71    const double iat_fit_rates[] = { 0.000006,0.05228,0.00081 };
72    ds.iat_sample_mean = 41285.7;
73    ds.iat_sample_sd = 1.1e+05;
74    ds.iat_he = boost::math::hyperexponential(iat_fit_probs, iat_fit_rates);
75 
76    // Multi-core VM lifetime distribution
77    const double multi_lt_fit_probs[] = { 0.42093,0.43960,0.13947 };
78    const double multi_lt_fit_rates[] = { 0.00186,0.00008,0.0000008 };
79    ds.multi_lt_sample_mean = 144669.0;
80    ds.multi_lt_sample_sd = 7.9e+05;
81    ds.multi_lt_he = boost::math::hyperexponential(multi_lt_fit_probs, multi_lt_fit_rates);
82 
83    // Single-core VM lifetime distribution
84    const double single_lt_fit_probs[] = { 0.44885,0.30675,0.2444 };
85    const double single_lt_fit_rates[] = { 0.00143,0.00005,0.0000004 };
86    ds.single_lt_sample_mean = 599815.0;
87    ds.single_lt_sample_sd = 1.7e+06;
88    ds.single_lt_he = boost::math::hyperexponential(single_lt_fit_probs, single_lt_fit_rates);
89 
90    return ds;
91 }
92 
93 // DS3 dataset
make_ds3()94 ds_info make_ds3()
95 {
96    ds_info ds;
97 
98    ds.name = "DS3";
99 
100    // VM interarrival time distribution
101    const double iat_fit_probs[] = { 0.39442,0.24644,0.35914 };
102    const double iat_fit_rates[] = { 0.00030,0.00003,0.00257 };
103    ds.iat_sample_mean = 11238.8;
104    ds.iat_sample_sd = 3.0e+04;
105    ds.iat_he = boost::math::hyperexponential(iat_fit_probs, iat_fit_rates);
106 
107    // Multi-core VM lifetime distribution
108    const double multi_lt_fit_probs[] = { 0.37621,0.14838,0.47541 };
109    const double multi_lt_fit_rates[] = { 0.00498,0.000005,0.00022 };
110    ds.multi_lt_sample_mean = 30739.2;
111    ds.multi_lt_sample_sd = 1.6e+05;
112    ds.multi_lt_he = boost::math::hyperexponential(multi_lt_fit_probs, multi_lt_fit_rates);
113 
114    // Single-core VM lifetime distribution
115    const double single_lt_fit_probs[] = { 0.34131,0.12544,0.53325 };
116    const double single_lt_fit_rates[] = { 0.000297,0.000003,0.00410 };
117    ds.single_lt_sample_mean = 44447.8;
118    ds.single_lt_sample_sd = 2.2e+05;
119    ds.single_lt_he = boost::math::hyperexponential(single_lt_fit_probs, single_lt_fit_rates);
120 
121    return ds;
122 }
123 
print_fitted(ds_info const & ds)124 void print_fitted(ds_info const& ds)
125 {
126    const double secs_in_a_hour = 3600;
127    const double secs_in_a_month = 30 * 24 * secs_in_a_hour;
128 
129    std::cout << "### " << ds.name << std::endl;
130    std::cout << "* Fitted Request Interarrival Time" << std::endl;
131    std::cout << " - Mean (SD): " << boost::math::mean(ds.iat_he) << " (" << boost::math::standard_deviation(ds.iat_he) << ") seconds." << std::endl;
132    std::cout << " - 99th Percentile: " << boost::math::quantile(ds.iat_he, 0.99) << " seconds." << std::endl;
133    std::cout << " - Probability that a VM will arrive within 30 minutes: " << boost::math::cdf(ds.iat_he, secs_in_a_hour / 2.0) << std::endl;
134    std::cout << " - Probability that a VM will arrive after 1 hour: " << boost::math::cdf(boost::math::complement(ds.iat_he, secs_in_a_hour)) << std::endl;
135    std::cout << "* Fitted Multi-core VM Lifetime" << std::endl;
136    std::cout << " - Mean (SD): " << boost::math::mean(ds.multi_lt_he) << " (" << boost::math::standard_deviation(ds.multi_lt_he) << ") seconds." << std::endl;
137    std::cout << " - 99th Percentile: " << boost::math::quantile(ds.multi_lt_he, 0.99) << " seconds." << std::endl;
138    std::cout << " - Probability that a VM will last for less than 1 month: " << boost::math::cdf(ds.multi_lt_he, secs_in_a_month) << std::endl;
139    std::cout << " - Probability that a VM will last for more than 3 months: " << boost::math::cdf(boost::math::complement(ds.multi_lt_he, 3.0*secs_in_a_month)) << std::endl;
140    std::cout << "* Fitted Single-core VM Lifetime" << std::endl;
141    std::cout << " - Mean (SD): " << boost::math::mean(ds.single_lt_he) << " (" << boost::math::standard_deviation(ds.single_lt_he) << ") seconds." << std::endl;
142    std::cout << " - 99th Percentile: " << boost::math::quantile(ds.single_lt_he, 0.99) << " seconds." << std::endl;
143    std::cout << " - Probability that a VM will last for less than 1 month: " << boost::math::cdf(ds.single_lt_he, secs_in_a_month) << std::endl;
144    std::cout << " - Probability that a VM will last for more than 3 months: " << boost::math::cdf(boost::math::complement(ds.single_lt_he, 3.0*secs_in_a_month)) << std::endl;
145 }
146 
main()147 int main()
148 {
149    print_fitted(make_ds1());
150 
151    print_fitted(make_ds2());
152 
153    print_fitted(make_ds3());
154 }
155 //]
156