程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Calculate the CDF of Poisson Distribution with Boost C++ Lib

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

編輯:C++入門知識

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved