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;








-2















How do I output the probability density of a gamma distribution at a specific value x? (also the cdf, if possible!) Thanks!










share|improve this question
























  • 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


















-2















How do I output the probability density of a gamma distribution at a specific value x? (also the cdf, if possible!) Thanks!










share|improve this question
























  • 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














-2












-2








-2








How do I output the probability density of a gamma distribution at a specific value x? (also the cdf, if possible!) Thanks!










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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













1 Answer
1






active

oldest

votes


















0
















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.






share|improve this answer

























  • 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













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
);



);














draft saved

draft discarded
















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









0
















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.






share|improve this answer

























  • 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















0
















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.






share|improve this answer

























  • 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













0














0










0









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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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




















draft saved

draft discarded















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현