faq.qbk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. [section:main_faq Boost.Math Frequently Asked Questions (FAQs)]
  2. # ['I'm a FORTRAN/NAG/SPSS/SAS/Cephes/MathCad/R user
  3. and I don't see where the functions like dnorm(mean, sd) are in Boost.Math?]
  4. Nearly all are provided, and many more like mean, skewness, quantiles, complements ...
  5. but Boost.Math makes full use of C++, and it looks a bit different.
  6. But do not panic! See section on construction and the many examples.
  7. Briefly, the distribution is constructed with the parameters (like location and scale)
  8. (things after the | in representation like P(X=k|n, p) or ; in a common represention of pdf f(x; [mu][sigma][super 2]).
  9. Functions like pdf, cdf are called with the name of that distribution and the random variate often called x or k.
  10. For example, `normal my_norm(0, 1); pdf(my_norm, 2.0);`
  11. # I'm a user of [@http://support.sas.com/rnd/app/da/new/probabilityfunctions.html New SAS Functions for Computing Probabilities].
  12. You will find the interface more familar, but to be able to select a distribution (perhaps using a string)
  13. see the Extras/Future Directions section,
  14. and /boost/libs/math/dot_net_example/boost_math.cpp for an example that is used to create a C# (C sharp) utility
  15. (that you might also find useful):
  16. see [@http://sourceforge.net/projects/distexplorer/ Statistical Distribution Explorer].
  17. # ['I'm allegic to reading manuals and prefer to learn from examples.]
  18. Fear not - you are not alone! Many examples are available for functions and distributions.
  19. Some are referenced directly from the text. Others can be found at `\boost_latest_release\libs\math\example`,
  20. for example
  21. If you are a Visual Studio user, you should be able to create projects from each of these,
  22. making sure that the Boost library is in the include directories list (there are usually NO libraries that must be built).
  23. # ['How do I make sure that the Boost library is in the Visual Studio include directories list?]
  24. You can add an include path, for example, your Boost place /boost-latest_release,
  25. for example `X:/boost_1_70_0/` if you have a separate partition X for Boost releases.
  26. Or you can use an environment variable BOOST_ROOT set to your Boost place, and include that.
  27. Visual Studio before 2010 provided Tools, Options, VC++ Directories to control directories:
  28. Visual Studio 2010 instead provides property sheets to assist.
  29. You may find it convenient to create a new one adding \boost-latest_release;
  30. to the existing include items in $(IncludePath).
  31. # ['I'm a FORTRAN/NAG/SPSS/SAS/Cephes/MathCad/R user and
  32. I don't see where the properties like mean, median, mode, variance, skewness of distributions are in Boost.Math?]
  33. They are all available (if defined for the parameters with which you constructed the distribution) via __usual_accessors.
  34. # ['I am a C programmer. Can I user Boost.Math with C?]
  35. Yes you can, including all the special functions, and TR1 functions like isnan.
  36. They appear as C functions, by being declared as "extern C".
  37. # ['I am a C# (Basic? F# FORTRAN? Other CLI?) programmer. Can I use Boost.Math with C#? (or ...)?]
  38. Yes you can, including all the special functions, and TR1 functions like isnan.
  39. But you [*must build the Boost.Math as a dynamic library (.dll) and compile with the /CLI option].
  40. See the boost/math/dot_net_example folder which contains an example that
  41. builds a simple statistical distribution app with a GUI.
  42. See [@http://sourceforge.net/projects/distexplorer/ Statistical Distribution Explorer]
  43. # ['What these "policies" things for?]
  44. Policies are a powerful (if necessarily complex) fine-grain mechanism that
  45. allow you to customise the behaviour of the Boost.Math library according to your precise needs.
  46. See __policy_section. But if, very probably, the default behaviour suits you, you don't need to know more.
  47. # ['I am a C user and expect to see global C-style`::errno` set for overflow/errors etc?]
  48. You can achieve what you want - see __error_policy and __user_error_handling and many examples.
  49. # ['I am a C user and expect to silently return a max value for overflow?]
  50. You (and C++ users too) can return whatever you want on overflow
  51. - see __overflow_error and __error_policy and several examples.
  52. # ['I don't want any error message for overflow etc?]
  53. You can control exactly what happens for all the abnormal conditions, including the values returned.
  54. See __domain_error, __overflow_error __error_policy __user_error_handling etc and examples.
  55. # ['My environment doesn't allow and/or I don't want exceptions. Can I still user Boost.Math?]
  56. Yes but you must customise the error handling: see __user_error_handling and __changing_policy_defaults .
  57. # ['The docs are several hundreds of pages long! Can I read the docs off-line or on paper?]
  58. Yes - you can download the Boost current release of most documentation
  59. as a zip of pdfs (including Boost.Math) from Sourceforge, for example
  60. [@https://sourceforge.net/projects/boost/files/boost-docs/1.45.0/boost_pdf_1_45_0.tar.gz/download].
  61. And you can print any pages you need (or even print all pages - but be warned that there are several hundred!).
  62. Both html and pdf versions are highly hyperlinked.
  63. The entire Boost.Math pdf can be searched with Adobe Reader, Edit, Find ...
  64. This can often find what you seek, a partial substitute for a full index.
  65. # ['I want a compact version for an embedded application. Can I use float precision?]
  66. Yes - by selecting RealType template parameter as float:
  67. for example normal_distribution<float> your_normal(mean, sd);
  68. (But double may still be used internally, so space saving may be less that you hope for).
  69. You can also change the promotion policy, but accuracy might be much reduced.
  70. # ['I seem to get somewhat different results compared to other programs. Why?]
  71. We hope Boost.Math to be more accurate: our priority is accuracy (over speed).
  72. See the section on accuracy. But for evaluations that require iterations
  73. there are parameters which can change the required accuracy (see __policy_section).
  74. You might be able to squeeze a little more (or less) accuracy at the cost of runtime.
  75. # ['Will my program run more slowly compared to other math functions and statistical libraries?]
  76. Probably, thought not always, and not by too much: our priority is accuracy.
  77. For most functions, making sure you have the latest compiler version with all optimisations switched on is the key to speed.
  78. For evaluations that require iteration, you may be able to gain a little more speed at the expense of accuracy.
  79. See detailed suggestions and results on __performance.
  80. # ['How do I handle infinity and NaNs portably?]
  81. See __fp_facets for Facets for Floating-Point Infinities and NaNs.
  82. # ['Where are the pre-built libraries?]
  83. Good news - you probably don't need any! - just `#include <boost/`['math/distribution_you_want>].
  84. But in the unlikely event that you do, see __building.
  85. # ['I don't see the function or distribution that I want.]
  86. You could try an email to ask the authors - but no promises!
  87. # ['I need more decimal digits for values/computations.]
  88. You can use Boost.Math with __multiprecision: typically
  89. __cpp_dec_float is a useful user-defined type to provide a fixed number of decimal digits, usually 50 or 100.
  90. # Why can't I write something really simple like `cpp_int one(1); cpp_dec_float_50 two(2); one * two;`
  91. Because `cpp_int` might be bigger than `cpp_dec_float can hold`, so you must make an [*explicit] conversion.
  92. See [@http://svn.boost.org/svn/boost/trunk/libs/multiprecision/doc/html/boost_multiprecision/intro.html mixed multiprecision arithmetic]
  93. and [@http://svn.boost.org/svn/boost/trunk/libs/multiprecision/doc/html/boost_multiprecision/tut/conversions.html conversion].
  94. # ['How do I choose between Boost.Multiprecision cpp_bin_50 and cpp_dec_50?]
  95. Unless you have a specific reason to choose `cpp_dec_`, then the default choice should be `cpp_bin_`, for example using the convenience `typedefs` like
  96. `boost::multiprecision::cpp_bin_50` or `boost::multiprecision::cpp_bin_100`.
  97. In general, both work well and give the same results and at roughly the same speed with `cpp_dec_50` sometimes faster.
  98. cpp_dec_ was developed first paving the way for cpp_bin_. cpp_dec_ has several guard digits and is not rounded at all, using 'brute force' to get the promised number of decimal digits correct,
  99. but making it difficult to reason about precision and computational uncertainty, for example
  100. see [*https://svn.boost.org/trac10/ticket/12133].
  101. It also has a fast but imprecise division operator giving surprising results sometimes,
  102. see [*https://svn.boost.org/trac10/ticket/11178].
  103. cpp_bin_ is correctly/exactly rounded making it possible to reason about both the precision and rounding of the results.
  104. #['How do I see or report bugs and features, and request new functions?]
  105. Currently open bug reports can be viewed
  106. [@https://github.com/boostorg/math/issues here] on GITHUB.
  107. All old bug reports including closed ones can be viewed on Trac (now read-only)
  108. [@https://svn.boost.org/trac/boost/query?status=assigned&status=closed&status=new&status=reopened&component=math&col=id&col=summary&col=status&col=type&col=milestone&col=component&order=priority here]
  109. and more recent issues on GIThub [@https://github.com/boostorg/math/issues?utf8=%E2%9C%93&q=is%3Aissue here].
  110. #[' How can I tell if my compiler will work with Boost.Math?]
  111. You should start by assuming that your compiler/platform *will* compile, even if it only supports a C++03 standard.
  112. Boost in general does *not* 'support' a particular C++ standard or compiler or platform.
  113. Each library has its own requirements, and for Boost.Math, each individual function or distribution
  114. or tool may have different requirements and may or may not work on any particular compiler.
  115. So the short answer is to try it and see what works for you.
  116. Some recent functions are written to require more recent standards, even perhaps not-yet-standardized features.
  117. Some clues about requirements can be gleaned from tests and examples (see jamfiles) and notes on requirements in documentation.
  118. You can refer to the [@https://www.boost.org/development/tests/develop/developer/math.html Boost Test Matrix] to see the
  119. current results for Boost.Math tests of many compilers on many platforms.
  120. But bear in mind that the testing or demonstration code may use C++11 or higher features like
  121. `std::numeric_limits<>max_digits10`, `auto`, `lambdas ...` for convenience;
  122. these may not be needed for your application.
  123. [endsect] [/section:faq Frequently Asked Questions]
  124. [/
  125. Copyright 2010, 2012 John Maddock and Paul A. Bristow.
  126. Distributed under the Boost Software License, Version 1.0.
  127. (See accompanying file LICENSE_1_0.txt or copy at
  128. http://www.boost.org/LICENSE_1_0.txt).
  129. ]