diff options
Diffstat (limited to 'libs/math/doc/graphs/dist_graphs.cpp')
-rw-r--r-- | libs/math/doc/graphs/dist_graphs.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/libs/math/doc/graphs/dist_graphs.cpp b/libs/math/doc/graphs/dist_graphs.cpp index 07f2f7316..515d392ef 100644 --- a/libs/math/doc/graphs/dist_graphs.cpp +++ b/libs/math/doc/graphs/dist_graphs.cpp @@ -79,33 +79,34 @@ public: void add(const Dist& d, const std::string& name) { - // - // Add to our list for later: - // + // Add name of distribution to our list for later: m_distributions.push_back(std::make_pair(name, d)); // - // Get the extent: - // + // Get the extent of the distribution from the support: double a, b; std::tr1::tie(a, b) = support(d); // - // PDF maximimum is at the mode: - // + // PDF maximimum is at the mode (probably): double mod; try { mod = mode(d); } catch(const std::domain_error& ) - { + { // but if not use the lower limit of support. mod = a; } if((mod <= a) && !is_discrete_distribution<Dist>::value) - { - if((a != 0) && (fabs(a) > 1e-2)) - mod = a * (1 + 1e-2); + { // Continuous distribution at or below lower limit of support. + double margin = 1e-2; // Margin of 1% (say) to get lowest off the 'end stop'. + if((a != 0) && (fabs(a) > margin)) + { + mod = a * (1 + ((a > 0) ? margin : -margin)); + } else - mod = 1e-2; + { // Case of mod near zero? + mod = margin; + } } double peek_y = pdf(d, mod); double min_y = peek_y / 20; @@ -266,6 +267,7 @@ public: .line_color(colors[color_index]) .line_width(1.) .shape(none); + //.bezier_on(true) // Bezier can't cope with badly behaved like uniform & triangular. ++color_index; color_index = color_index % (sizeof(colors)/sizeof(colors[0])); @@ -322,6 +324,9 @@ private: int main() { + try + { + distribution_plotter<boost::math::gamma_distribution<> > gamma_plotter; gamma_plotter.add(boost::math::gamma_distribution<>(0.75), "shape = 0.75"); @@ -653,6 +658,16 @@ int main() hypergeometric_plotter2.add(boost::math::hypergeometric_distribution<>(450, 50, 500), "N=500, r=50, n=450"); hypergeometric_plotter2.plot("Hypergeometric Distribution PDF", "hypergeometric_pdf_2.svg"); + } + catch (std::exception ex) + { + std::cout << ex.what() << std::endl; + } + + + + /* these graphs for hyperexponential distribution not used. + distribution_plotter<boost::math::hyperexponential_distribution<> > hyperexponential_plotter; { @@ -695,11 +710,13 @@ int main() hyperexponential_plotter3.add(boost::math::hyperexponential_distribution<>(probs1,rates1), "α=(1.0), λ=(2.0)"); const double probs2[] = {0.5,0.5}; const double rates2[] = {0.3,1.5}; - hyperexponential_plotter3.add(boost::math::hyperexponential_distribution<>(probs2_1,rates2_1), "α=(0.5,0.5), λ=(0.3,1.5)"); + hyperexponential_plotter3.add(boost::math::hyperexponential_distribution<>(probs2,rates2), "α=(0.5,0.5), λ=(0.3,1.5)"); const double probs3[] = {1.0/3.0,1.0/3.0,1.0/3.0}; const double rates3[] = {0.2,1.5,3.0}; - hyperexponential_plotter3.add(boost::math::hyperexponential_distribution<>(probs2_2,rates2_2), "α=(1.0/3.0,1.0/3.0,1.0/3.0), λ=(0.2,1.5,3.0)"); + hyperexponential_plotter3.add(boost::math::hyperexponential_distribution<>(probs2,rates2), "α=(1.0/3.0,1.0/3.0,1.0/3.0), λ=(0.2,1.5,3.0)"); } hyperexponential_plotter3.plot("Hyperexponential Distribution PDF (Different Number of Phases, Same Mean)", "hyperexponential_pdf_samemean.svg"); + */ + } // int main() |