当前位置:编程学习 > C/C++ >>

Calculate the CDF of Poisson Distribution with Boost C++ Library

The Cumulative Distribution Function(CDF) of Poisson distribution can be easily calculated by R function ppois() or octave/Matlab function poisspdf(). However, it is not a easy thing to deal with statistics with C++ from scratch.

Today I found a very powerful C++ mathematical library(actually not limited to math), boost. Unfortunately, it is hard to figure out the API of boost library from the code if you are not familiar with generalization programming(just like me). Besides, there is no useful “hello world” examples on the Internet to show the boost library handling statistics(examples on webpage C++ Statistical Distributions in Boost is a bit complicated and the header files are not included).

Therefore, I made up following example to show how to get the cdf of Poisson distribution with boost C++ library:
[cpp]
#include <boost/math/distributions/poisson.hpp> 
#include <iostream> 
 
using namespace std; 
using namespace boost::math; 
 
int main() 

        poisson_distribution<> p(2.9); 
        cout<<"cdf: ppois(1,2.9)="<<cdf(p,1)<<endl; 
 
        return 0; 

References:

http://www.boost.org/doc/libs/1_52_0/libs/math/doc/sf_and_dist/html/math_toolkit/dist/dist_ref/dists/poisson_dist.html
C++ Statistical Distributions in Boost
http://www.datasimfinancial.com/forum/viewtopic.php?t=111

补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,