[Math Toolkit] Gamma Distribution
Hi there, the documention of the gamma distribution talks about two different forms. How can can generate the second one with shape=1 and scale=1? I know how to get the first form: boost::math::gamma_distribution<> dist( 1, 1 ); I don't see how to get the second one? Thanks, Christian
Christian Henning wrote:
Hi there, the documention of the gamma distribution talks about two different forms. How can can generate the second one with shape=1 and scale=1? I know how to get the first form:
boost::math::gamma_distribution<> dist( 1, 1 );
I don't see how to get the second one?
Right, the distribution takes two parameters: shape and *scale*, so the construction is always: boost::math::gamma_distribution<> d(myshape, myscale); If instead you have parameters shape and *rate* then it's constructed as: boost::math::gamma_distribution<> d(myshape, 1/myrate); Or as noted in the docs "Therefore to construct a Gamma Distribution from a rate parameter, you should pass the reciprocal of the rate as the scale parameter." In other words the a rate parameter is simply the reciprocal of the scale, and vice versa. Any clearer? HTH, John.
Hi John, thanks for your reply. Your answer is basically what the
documentation describes. But, it still leaves me with question marks
in my head.
Let me ask differently. How do I construct the the red curve in the
second image? Parameters here are: Shape = 1 and Scale = 1. BTW,
shouldn't be the "scale" box in the second image be called "rate"?
Thanks again,
Christian
On Dec 19, 2007 4:46 AM, John Maddock
Christian Henning wrote:
Hi there, the documention of the gamma distribution talks about two different forms. How can can generate the second one with shape=1 and scale=1? I know how to get the first form:
boost::math::gamma_distribution<> dist( 1, 1 );
I don't see how to get the second one?
Right, the distribution takes two parameters: shape and *scale*, so the construction is always:
boost::math::gamma_distribution<> d(myshape, myscale);
If instead you have parameters shape and *rate* then it's constructed as:
boost::math::gamma_distribution<> d(myshape, 1/myrate);
Or as noted in the docs "Therefore to construct a Gamma Distribution from a rate parameter, you should pass the reciprocal of the rate as the scale parameter."
In other words the a rate parameter is simply the reciprocal of the scale, and vice versa.
Any clearer?
HTH, John.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Christian Henning wrote:
Hi John, thanks for your reply. Your answer is basically what the documentation describes. But, it still leaves me with question marks in my head.
Let me ask differently. How do I construct the the red curve in the second image? Parameters here are: Shape = 1 and Scale = 1.
gamma_distribution<> d(1, 1);
BTW, shouldn't be the "scale" box in the second image be called "rate"?
No, the second graph, keeps the shape constant and shows the effect of varying the scale, while the first image keeps the scale constant and shows the effect of varying the shape... But that means that the two red curves in the two graphs should be the same and they're not :-( Looks like I probably messed up generating the graphs, I'll look into this. John.
John Maddock wrote:
Christian Henning wrote:
Hi John, thanks for your reply. Your answer is basically what the documentation describes. But, it still leaves me with question marks in my head.
Let me ask differently. How do I construct the the red curve in the second image? Parameters here are: Shape = 1 and Scale = 1.
With apologies, ignore my previous message, the first graph is correct, the second graph has an incorrect title: it shows how the gamma distribution varies when the shape = 3, and the scale changes. So the red curve on the second graph is for shape = 3, scale = 1. I've just updated SVN to reflect this, and hopefully put an end to the confusion ! :-) John.
This is my first post, I hope I'm doing it correctly. I just downloaded Boost and want to install regex with Builder 2007. (I have older versions of Builder installed on my machine, too) The instructions are for Builder 6 - will they work for 2007? Perhaps with a little editing? Thanks Nate
Robert Lockwood wrote:
This is my first post, I hope I'm doing it correctly. I just downloaded Boost and want to install regex with Builder 2007. (I have older versions of Builder installed on my machine, too) The instructions are for Builder 6 - will they work for 2007? Perhaps with a little editing?
I don't have access to that product, but I believe the C++ Builder 6 instructions should just work. The short answer is to try it and post back if there are any problems :-) And yes, your post is in the right place and perfectly correct :-) HTH, John Maddock.
Robert Lockwood wrote:
I just downloaded Boost and want to install regex with Builder 2007. The instructions are for Builder 6 - will they work for 2007?
John Maddock wrote:
I don't have access to that product, but I believe the C++ Builder 6 instructions should just work.
Didn't work! Failed with two rather long error messages which I think point to stdlib problems. I'll try it again and redirect the output to a file. It appears that boost (no indication if the compiler or a boost emitted the message) suggests that I do configuration tests on the compiler, I'll have to visit the website to see how this is done. (My Lotus Notes doesn't play nice formatting the replies so I guess I'll need to go to gmail...) Think I've seen your name in the past over on the Borland Forums. Nate
Robert Lockwood wrote: This is my first post, I hope I'm doing it correctly. I just downloaded Boost and want to install regex with Builder 2007. (I have older versions of Builder installed on my machine, too) The instructions are for Builder 6 - will they work for 2007? Perhaps with a little editing?
The following text may help you (as it did with me). Note that this will install the all the boost libraries not just regex. It is a post I found at borland.public.cppbuilder.language.cpp web pages. Vaclav
From borland.public.cppbuilder.language.cpp:
To help non-experts or semi-experts like myself to install boost, I
wrote up the procedure which I just performed an hour ago to install the
latest boost version on my system. I use CB2007, but the bcbboost
patches support BDS2006 and BCB6, so this procedure should work for
those systems as well. See http://bcbboost.sourceforge.net for test
results.
-Eliot
Boost 1.34.0 on CodeGear CB2007 [[ or BDS2006, BCB6 ]]
[[ I used CB2007, YMMV for earlier versions. ]]
1. Obtain following files from sourceforge.net:
From http://sourceforge.net/projects/boost,
boost_1_34_0.zip (or .tar.gz or .tar.bz2)
boost-jam-3.1.14-1-ntx86.zip
From http://sourceforge.net/projects/bcbboost/
bcbboost-1_34_0-5_9_0-0.1.zip
2. Unpack boost_1_34_0 to a suitable directory, say \src\boost. This
results in a subdirectory \src\boost\boost_1_34_0.
3. Unpack bjam.exe from boost-jam-3.1.14-1-ntx86 directory of
boost-jam-3.1.14-1-ntx86.zip to \src\boost. This results in
bjam.exe in \src\boost.
4. Copy contents of the bcbboost\boost directory in
bcbboost-1_34_0-5_9_0-0.1.zip to \src\boost\boost_1_34_0. This
will copy into directories of the same name as those in the boost
source tree (select yes to all in the copy).
Note: for header-only installation which covers most common usage of
boost, skip to step 7. If you're not sure, see
http://boost.org/more/getting_started/windows.html#header-only-libraries
if you need to build the libraries for your applications.
5. Edit /Src/Boost/boost_1_34_0/tools/build/v2/user-config.jam by
uncommenting appropriate line. Specifically for CB2007, remove the
leading # from the line starting "#using borland : 5.9.0".
[[ For BDS2006, uncomment line for 5.8.2 ]]
[[ For BCB6, uncomment line for 5.6.4 ]]
6. In a command prompt window, invoke bjam in /src/boost/boost_1_34_0
directory:
cd \src\boost\boost_1_34_0
..\bjam --toolset=borland stage
There are lots of warnings and errors. There is nothing to do
except ignore them. The libraries that can be built will be built.
7. Copy or move the boost include tree, \src\boost\boost_1_34_0\boost,
to your preferred location. I prefer to put it into the program
include directory, i.e.,
C:\Program Files\CodeGear\RAD Studio\5.0\include
This should result in the directory
C:\Program Files\CodeGear\RAD Studio\5.0\include\boost
containing the boost include files, e.g., format.hpp. In code, you
may then write,
#include
Thanks John, now it makes sense.
Christian
On Dec 19, 2007 11:46 AM, John Maddock
John Maddock wrote:
Christian Henning wrote:
Hi John, thanks for your reply. Your answer is basically what the documentation describes. But, it still leaves me with question marks in my head.
Let me ask differently. How do I construct the the red curve in the second image? Parameters here are: Shape = 1 and Scale = 1.
With apologies, ignore my previous message, the first graph is correct, the second graph has an incorrect title: it shows how the gamma distribution varies when the shape = 3, and the scale changes. So the red curve on the second graph is for shape = 3, scale = 1.
I've just updated SVN to reflect this, and hopefully put an end to the confusion ! :-)
John.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
John Maddock
John Maddock wrote:
Christian Henning wrote:
Hi John, thanks for your reply. Your answer is basically what the documentation describes. But, it still leaves me with question marks in my head.
Let me ask differently. How do I construct the the red curve in the second image? Parameters here are: Shape = 1 and Scale = 1.
With apologies, ignore my previous message, the first graph is correct, the second graph has an incorrect title: it shows how the gamma distribution varies when the shape = 3, and the scale changes. So the red curve on the second graph is for shape = 3, scale = 1.
I've just updated SVN to reflect this, and hopefully put an end to the confusion !
John.
Hello, I am confused about the graphs in Gamma Distribution documentation page: http://www.boost.org/doc/libs/1_39_0/libs/math/doc/sf_and_dist/html/math_too... The first (blue) curve in the first graph suggests that Gamma PDF(0.0, 0.5, 1.0) == 1.0. Is this correct? Shouldn't it go to infinity as x approaches 0? PDF(x, k, theta) = x^(k-1)*exp(-x/theta)/(theta^k*gamma(k)) PDF(0.0, 0.5, 1.0) = 0^(-0.5)*1/gamma(0.5) = 1/(0^0.5 * gamma(0.5)) = Inf In the second graph both first and third curves have scale = 2 and shape = 2, yet they look different. Am I missing something? Thank you Mikhail
I am confused about the graphs in Gamma Distribution documentation page: http://www.boost.org/doc/libs/1_39_0/libs/math/doc/sf_and_dist/html/math_too...
The first (blue) curve in the first graph suggests that Gamma PDF(0.0, 0.5, 1.0) == 1.0. Is this correct? Shouldn't it go to infinity as x approaches 0?
It does: the graph is generated automagically, and it just so happens that for that choice of parameters the smallest value sampled is 0.94 giving a misleading looking graph, I'll try and tweak things so it's clear that the curve goes to infinity for shape < 1.
PDF(x, k, theta) = x^(k-1)*exp(-x/theta)/(theta^k*gamma(k)) PDF(0.0, 0.5, 1.0) = 0^(-0.5)*1/gamma(0.5) = 1/(0^0.5 * gamma(0.5)) = Inf
In the second graph both first and third curves have scale = 2 and shape = 2, yet they look different.
Ooops, the labels are wrong: should be scale = 0.5, 1 and 2, will fix in SVN shortly. Apologies for the confusion, and thanks for the feedback! John.
The first (blue) curve in the first graph suggests that Gamma PDF(0.0, 0.5, 1.0) == 1.0. Is this correct? Shouldn't it go to infinity as x approaches 0?
It does: the graph is generated automagically, and it just so happens that for that choice of parameters the smallest value sampled is 0.94 giving a misleading looking graph, I'll try and tweak things so it's clear that the curve goes to infinity for shape < 1.
PLease ignore that - the lables were completely wrong on that graph as well - I've gone through all the graphs and few a few more incorrect lables as well, will regenerate and commit to SVN as soon as I've had a chance to check through them all more thoughoughly. John.
John Maddock
PLease ignore that - the lables were completely wrong on that graph as well - I've gone through all the graphs and few a few more incorrect lables as well, will regenerate and commit to SVN as soon as I've had a chance to check through them all more thoughoughly.
John.
John, thank you! -- Mikhail
participants (5)
-
Christian Henning
-
John Maddock
-
Mikhail Levin
-
Robert Lockwood
-
v2cechura