How do I output a probability density for gamma distribution at a specific value x? In C++What are the rules about using an underscore in a C++ identifier?How can I profile C++ code running on Linux?Gamma Distribution in BoostGamma distributed random variables in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Image Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionR calculated gamma distribution density wrong?How can we find percentile or quantile of gamma distribution in MATLAB?compute the density of a multivariate Dirichlet and Gamma distribution in RAbout Gamma density simulation
How can this Stack Exchange site have an animated favicon?
Why was LOGO created?
New road bike: alloy dual pivot brakes work poorly
Duplicate Tuples in two different ways
Difference between "rip up" and "rip down"
Neural Network vs regression
Can I enter the UK without my husband if we said we'd travel together in our visa application?
Why does C++ have 'Undefined Behaviour' and other languages like C# or Java don't?
Align all symbols in a LaTeX equation
What exactly did this mechanic sabotage on the American Airlines 737, and how dangerous was it?
What are examples of EU policies that are beneficial for one EU country, disadvantagious for another?
Designing a time thief proof safe
Why does the leading tone (G#) go to E rather than A in this example?
Beyond Futuristic Technology for an Alien Warship?
How can I tell the difference between fishing for rolls and being involved?
Need Improvement on Script Which Continuously Tests Website
Subverting the emotional woman and stoic man trope
What does Sartre mean by "pédéraste" - pederast or homosexual?
Why is a road bike faster than a city bike with the same effort? How much faster it can be?
I reverse the source code, you reverse the input!
Why does my browser attempt to download pages from http://clhs.lisp.se instead of viewing them normally?
Iterating over &Vec<T> and Vec<&T>
Can someone give the intuition behind Mean Absolute Error and the Median?
Algorithm that generates orthogonal vectors: C++ implementation
How do I output a probability density for gamma distribution at a specific value x? In C++
What are the rules about using an underscore in a C++ identifier?How can I profile C++ code running on Linux?Gamma Distribution in BoostGamma distributed random variables in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Image Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionR calculated gamma distribution density wrong?How can we find percentile or quantile of gamma distribution in MATLAB?compute the density of a multivariate Dirichlet and Gamma distribution in RAbout Gamma density simulation
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How do I output the probability density of a gamma distribution at a specific value x? (also the cdf, if possible!) Thanks!
c++ gamma-distribution
add a comment
|
How do I output the probability density of a gamma distribution at a specific value x? (also the cdf, if possible!) Thanks!
c++ gamma-distribution
Are you trying to hardcode the implementation of the gamma distribution or use a library add-on? I guarantee the boost library already has this implemented and optimized for you if you're willing to put in the work to figure out how to use it. boost.org/doc/libs/1_46_1/libs/math/doc/sf_and_dist/html/…
– CodeoftheWarrior
Mar 28 at 18:42
Did you try anything?
– Valentino
Mar 28 at 19:24
1
@CodeoftheWarrior Since C++ 11 the standard headers already have these functions. en.cppreference.com/w/cpp/numeric/math/tgamma
– Max Langhof
Mar 28 at 20:50
@MaxLanghof Thank you for that. That is the gamma function not the gamma distribution, but it pointed me in the right direction. OP, look in the <random> header file for the pdf of the gamma distribution. cplusplus.com/reference/random/gamma_distribution Correction this generates a value based on the distribution not the actual probability.
– CodeoftheWarrior
Mar 28 at 21:21
add a comment
|
How do I output the probability density of a gamma distribution at a specific value x? (also the cdf, if possible!) Thanks!
c++ gamma-distribution
How do I output the probability density of a gamma distribution at a specific value x? (also the cdf, if possible!) Thanks!
c++ gamma-distribution
c++ gamma-distribution
asked Mar 28 at 18:38
rnt88rnt88
1
1
Are you trying to hardcode the implementation of the gamma distribution or use a library add-on? I guarantee the boost library already has this implemented and optimized for you if you're willing to put in the work to figure out how to use it. boost.org/doc/libs/1_46_1/libs/math/doc/sf_and_dist/html/…
– CodeoftheWarrior
Mar 28 at 18:42
Did you try anything?
– Valentino
Mar 28 at 19:24
1
@CodeoftheWarrior Since C++ 11 the standard headers already have these functions. en.cppreference.com/w/cpp/numeric/math/tgamma
– Max Langhof
Mar 28 at 20:50
@MaxLanghof Thank you for that. That is the gamma function not the gamma distribution, but it pointed me in the right direction. OP, look in the <random> header file for the pdf of the gamma distribution. cplusplus.com/reference/random/gamma_distribution Correction this generates a value based on the distribution not the actual probability.
– CodeoftheWarrior
Mar 28 at 21:21
add a comment
|
Are you trying to hardcode the implementation of the gamma distribution or use a library add-on? I guarantee the boost library already has this implemented and optimized for you if you're willing to put in the work to figure out how to use it. boost.org/doc/libs/1_46_1/libs/math/doc/sf_and_dist/html/…
– CodeoftheWarrior
Mar 28 at 18:42
Did you try anything?
– Valentino
Mar 28 at 19:24
1
@CodeoftheWarrior Since C++ 11 the standard headers already have these functions. en.cppreference.com/w/cpp/numeric/math/tgamma
– Max Langhof
Mar 28 at 20:50
@MaxLanghof Thank you for that. That is the gamma function not the gamma distribution, but it pointed me in the right direction. OP, look in the <random> header file for the pdf of the gamma distribution. cplusplus.com/reference/random/gamma_distribution Correction this generates a value based on the distribution not the actual probability.
– CodeoftheWarrior
Mar 28 at 21:21
Are you trying to hardcode the implementation of the gamma distribution or use a library add-on? I guarantee the boost library already has this implemented and optimized for you if you're willing to put in the work to figure out how to use it. boost.org/doc/libs/1_46_1/libs/math/doc/sf_and_dist/html/…
– CodeoftheWarrior
Mar 28 at 18:42
Are you trying to hardcode the implementation of the gamma distribution or use a library add-on? I guarantee the boost library already has this implemented and optimized for you if you're willing to put in the work to figure out how to use it. boost.org/doc/libs/1_46_1/libs/math/doc/sf_and_dist/html/…
– CodeoftheWarrior
Mar 28 at 18:42
Did you try anything?
– Valentino
Mar 28 at 19:24
Did you try anything?
– Valentino
Mar 28 at 19:24
1
1
@CodeoftheWarrior Since C++ 11 the standard headers already have these functions. en.cppreference.com/w/cpp/numeric/math/tgamma
– Max Langhof
Mar 28 at 20:50
@CodeoftheWarrior Since C++ 11 the standard headers already have these functions. en.cppreference.com/w/cpp/numeric/math/tgamma
– Max Langhof
Mar 28 at 20:50
@MaxLanghof Thank you for that. That is the gamma function not the gamma distribution, but it pointed me in the right direction. OP, look in the <random> header file for the pdf of the gamma distribution. cplusplus.com/reference/random/gamma_distribution Correction this generates a value based on the distribution not the actual probability.
– CodeoftheWarrior
Mar 28 at 21:21
@MaxLanghof Thank you for that. That is the gamma function not the gamma distribution, but it pointed me in the right direction. OP, look in the <random> header file for the pdf of the gamma distribution. cplusplus.com/reference/random/gamma_distribution Correction this generates a value based on the distribution not the actual probability.
– CodeoftheWarrior
Mar 28 at 21:21
add a comment
|
1 Answer
1
active
oldest
votes
double gammapdf(double value, double alpha, double beta)
return (std::pow(beta, alpha)*std::pow(value, (alpha-1))*std::pow(M_E, (-1*beta*value)))/tgamma(alpha);
This implements the gamma distribution pdf calculation as listed on wikipedia. Did a little digging. The cdf is a bit more difficult and I'm not sure how to solve that one.
Thanks very much for this! That's great! I have implemented it and it seems to work ok. I can also numerically integrate it for the cdf which is a good workaround... However, your suggestion of using a boost library also sounds good. I'm inexperienced at this - do I simply add a #include at the top pointing at the boost library (which I should download as a file)? Thank you!!
– rnt88
Mar 29 at 10:47
boost.org/doc/libs/1_62_0/more/getting_started/windows.html Unfortunately, no. Boost is an add-on library and you are going to need to find some way to compile the libraries and then link those libraries to the project that needs them. It will require some leg-work, but it's good experience.
– CodeoftheWarrior
Mar 29 at 15:37
I would be curious if this calculation is also ok from a numerical perspective. There are many algorithms (e.g. gauss elimination) where a straightforward replication of the mathematical operations can introduce massive floating point errors. But I have no idea if that is relevant in this particular case.
– Max Langhof
Mar 29 at 22:17
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404723%2fhow-do-i-output-a-probability-density-for-gamma-distribution-at-a-specific-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
double gammapdf(double value, double alpha, double beta)
return (std::pow(beta, alpha)*std::pow(value, (alpha-1))*std::pow(M_E, (-1*beta*value)))/tgamma(alpha);
This implements the gamma distribution pdf calculation as listed on wikipedia. Did a little digging. The cdf is a bit more difficult and I'm not sure how to solve that one.
Thanks very much for this! That's great! I have implemented it and it seems to work ok. I can also numerically integrate it for the cdf which is a good workaround... However, your suggestion of using a boost library also sounds good. I'm inexperienced at this - do I simply add a #include at the top pointing at the boost library (which I should download as a file)? Thank you!!
– rnt88
Mar 29 at 10:47
boost.org/doc/libs/1_62_0/more/getting_started/windows.html Unfortunately, no. Boost is an add-on library and you are going to need to find some way to compile the libraries and then link those libraries to the project that needs them. It will require some leg-work, but it's good experience.
– CodeoftheWarrior
Mar 29 at 15:37
I would be curious if this calculation is also ok from a numerical perspective. There are many algorithms (e.g. gauss elimination) where a straightforward replication of the mathematical operations can introduce massive floating point errors. But I have no idea if that is relevant in this particular case.
– Max Langhof
Mar 29 at 22:17
add a comment
|
double gammapdf(double value, double alpha, double beta)
return (std::pow(beta, alpha)*std::pow(value, (alpha-1))*std::pow(M_E, (-1*beta*value)))/tgamma(alpha);
This implements the gamma distribution pdf calculation as listed on wikipedia. Did a little digging. The cdf is a bit more difficult and I'm not sure how to solve that one.
Thanks very much for this! That's great! I have implemented it and it seems to work ok. I can also numerically integrate it for the cdf which is a good workaround... However, your suggestion of using a boost library also sounds good. I'm inexperienced at this - do I simply add a #include at the top pointing at the boost library (which I should download as a file)? Thank you!!
– rnt88
Mar 29 at 10:47
boost.org/doc/libs/1_62_0/more/getting_started/windows.html Unfortunately, no. Boost is an add-on library and you are going to need to find some way to compile the libraries and then link those libraries to the project that needs them. It will require some leg-work, but it's good experience.
– CodeoftheWarrior
Mar 29 at 15:37
I would be curious if this calculation is also ok from a numerical perspective. There are many algorithms (e.g. gauss elimination) where a straightforward replication of the mathematical operations can introduce massive floating point errors. But I have no idea if that is relevant in this particular case.
– Max Langhof
Mar 29 at 22:17
add a comment
|
double gammapdf(double value, double alpha, double beta)
return (std::pow(beta, alpha)*std::pow(value, (alpha-1))*std::pow(M_E, (-1*beta*value)))/tgamma(alpha);
This implements the gamma distribution pdf calculation as listed on wikipedia. Did a little digging. The cdf is a bit more difficult and I'm not sure how to solve that one.
double gammapdf(double value, double alpha, double beta)
return (std::pow(beta, alpha)*std::pow(value, (alpha-1))*std::pow(M_E, (-1*beta*value)))/tgamma(alpha);
This implements the gamma distribution pdf calculation as listed on wikipedia. Did a little digging. The cdf is a bit more difficult and I'm not sure how to solve that one.
answered Mar 28 at 21:48
CodeoftheWarriorCodeoftheWarrior
974 bronze badges
974 bronze badges
Thanks very much for this! That's great! I have implemented it and it seems to work ok. I can also numerically integrate it for the cdf which is a good workaround... However, your suggestion of using a boost library also sounds good. I'm inexperienced at this - do I simply add a #include at the top pointing at the boost library (which I should download as a file)? Thank you!!
– rnt88
Mar 29 at 10:47
boost.org/doc/libs/1_62_0/more/getting_started/windows.html Unfortunately, no. Boost is an add-on library and you are going to need to find some way to compile the libraries and then link those libraries to the project that needs them. It will require some leg-work, but it's good experience.
– CodeoftheWarrior
Mar 29 at 15:37
I would be curious if this calculation is also ok from a numerical perspective. There are many algorithms (e.g. gauss elimination) where a straightforward replication of the mathematical operations can introduce massive floating point errors. But I have no idea if that is relevant in this particular case.
– Max Langhof
Mar 29 at 22:17
add a comment
|
Thanks very much for this! That's great! I have implemented it and it seems to work ok. I can also numerically integrate it for the cdf which is a good workaround... However, your suggestion of using a boost library also sounds good. I'm inexperienced at this - do I simply add a #include at the top pointing at the boost library (which I should download as a file)? Thank you!!
– rnt88
Mar 29 at 10:47
boost.org/doc/libs/1_62_0/more/getting_started/windows.html Unfortunately, no. Boost is an add-on library and you are going to need to find some way to compile the libraries and then link those libraries to the project that needs them. It will require some leg-work, but it's good experience.
– CodeoftheWarrior
Mar 29 at 15:37
I would be curious if this calculation is also ok from a numerical perspective. There are many algorithms (e.g. gauss elimination) where a straightforward replication of the mathematical operations can introduce massive floating point errors. But I have no idea if that is relevant in this particular case.
– Max Langhof
Mar 29 at 22:17
Thanks very much for this! That's great! I have implemented it and it seems to work ok. I can also numerically integrate it for the cdf which is a good workaround... However, your suggestion of using a boost library also sounds good. I'm inexperienced at this - do I simply add a #include at the top pointing at the boost library (which I should download as a file)? Thank you!!
– rnt88
Mar 29 at 10:47
Thanks very much for this! That's great! I have implemented it and it seems to work ok. I can also numerically integrate it for the cdf which is a good workaround... However, your suggestion of using a boost library also sounds good. I'm inexperienced at this - do I simply add a #include at the top pointing at the boost library (which I should download as a file)? Thank you!!
– rnt88
Mar 29 at 10:47
boost.org/doc/libs/1_62_0/more/getting_started/windows.html Unfortunately, no. Boost is an add-on library and you are going to need to find some way to compile the libraries and then link those libraries to the project that needs them. It will require some leg-work, but it's good experience.
– CodeoftheWarrior
Mar 29 at 15:37
boost.org/doc/libs/1_62_0/more/getting_started/windows.html Unfortunately, no. Boost is an add-on library and you are going to need to find some way to compile the libraries and then link those libraries to the project that needs them. It will require some leg-work, but it's good experience.
– CodeoftheWarrior
Mar 29 at 15:37
I would be curious if this calculation is also ok from a numerical perspective. There are many algorithms (e.g. gauss elimination) where a straightforward replication of the mathematical operations can introduce massive floating point errors. But I have no idea if that is relevant in this particular case.
– Max Langhof
Mar 29 at 22:17
I would be curious if this calculation is also ok from a numerical perspective. There are many algorithms (e.g. gauss elimination) where a straightforward replication of the mathematical operations can introduce massive floating point errors. But I have no idea if that is relevant in this particular case.
– Max Langhof
Mar 29 at 22:17
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404723%2fhow-do-i-output-a-probability-density-for-gamma-distribution-at-a-specific-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you trying to hardcode the implementation of the gamma distribution or use a library add-on? I guarantee the boost library already has this implemented and optimized for you if you're willing to put in the work to figure out how to use it. boost.org/doc/libs/1_46_1/libs/math/doc/sf_and_dist/html/…
– CodeoftheWarrior
Mar 28 at 18:42
Did you try anything?
– Valentino
Mar 28 at 19:24
1
@CodeoftheWarrior Since C++ 11 the standard headers already have these functions. en.cppreference.com/w/cpp/numeric/math/tgamma
– Max Langhof
Mar 28 at 20:50
@MaxLanghof Thank you for that. That is the gamma function not the gamma distribution, but it pointed me in the right direction. OP, look in the <random> header file for the pdf of the gamma distribution. cplusplus.com/reference/random/gamma_distribution Correction this generates a value based on the distribution not the actual probability.
– CodeoftheWarrior
Mar 28 at 21:21