hyperexponential_more_snips.cpp 6.2 KB

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