multidimSampling.C: example of sampling a multi-dim distribution using the DistSampler class | Math tutorials | permute.C: tutorial illustrating the use of TMath::Permute |
// tutorial illustrating the new statistical distributions functions (pdf, cdf and quantile) #ifndef __CINT__ #include "Math/DistFunc.h" #include "TF1.h" #include "TCanvas.h" #include "TSystem.h" #include "TLegend.h" #include "TAxis.h" #endif void normalDist() { #ifdef __CINT__ gSystem->Load("libMathCore"); gSystem->Load("libMathMore"); #endif TF1 *pdfunc = new TF1("pdf","ROOT::Math::normal_pdf(x, [0],[1])",-5,5); TF1 *cdfunc = new TF1("cdf","ROOT::Math::normal_cdf(x, [0],[1])",-5,5); TF1 *ccdfunc = new TF1("cdf_c","ROOT::Math::normal_cdf_c(x, [0])",-5,5); TF1 *qfunc = new TF1("quantile","ROOT::Math::normal_quantile(x, [0])",0,1); TF1 *cqfunc = new TF1("quantile_c","ROOT::Math::normal_quantile_c(x, [0])",0,1); pdfunc->SetParameters(1.0,0.0); // set sigma to 1 and mean to zero pdfunc->SetTitle(""); pdfunc->SetLineColor(kBlue); pdfunc->GetXaxis()->SetLabelSize(0.06); pdfunc->GetXaxis()->SetTitle("x"); pdfunc->GetXaxis()->SetTitleSize(0.07); pdfunc->GetXaxis()->SetTitleOffset(0.55); pdfunc->GetYaxis()->SetLabelSize(0.06); cdfunc->SetParameters(1.0,0.0); // set sigma to 1 and mean to zero cdfunc->SetTitle(""); cdfunc->SetLineColor(kRed); cdfunc->GetXaxis()->SetLabelSize(0.06); cdfunc->GetXaxis()->SetTitle("x"); cdfunc->GetXaxis()->SetTitleSize(0.07); cdfunc->GetXaxis()->SetTitleOffset(0.55); cdfunc->GetYaxis()->SetLabelSize(0.06); cdfunc->GetYaxis()->SetTitle("p"); cdfunc->GetYaxis()->SetTitleSize(0.07); cdfunc->GetYaxis()->SetTitleOffset(0.55); ccdfunc->SetParameters(1.0,0.0); // set sigma to 1 and mean to zero ccdfunc->SetTitle(""); ccdfunc->SetLineColor(kGreen); qfunc->SetParameter(0, 1.0); // set sigma to 1 qfunc->SetTitle(""); qfunc->SetLineColor(kRed); qfunc->SetNpx(1000); // to get more precision for p close to 0 or 1 qfunc->GetXaxis()->SetLabelSize(0.06); qfunc->GetXaxis()->SetTitle("p"); qfunc->GetYaxis()->SetLabelSize(0.06); qfunc->GetXaxis()->SetTitleSize(0.07); qfunc->GetXaxis()->SetTitleOffset(0.55); qfunc->GetYaxis()->SetTitle("x"); qfunc->GetYaxis()->SetTitleSize(0.07); qfunc->GetYaxis()->SetTitleOffset(0.55); cqfunc->SetParameter(0, 1.0); // set sigma to 1 cqfunc->SetTitle(""); cqfunc->SetLineColor(kGreen); cqfunc->SetNpx(1000); TCanvas * c1 = new TCanvas("c1","Normal Distributions",100,10,600,800); c1->Divide(1,3); c1->cd(1); pdfunc->Draw(); TLegend *legend1 = new TLegend(0.583893,0.601973,0.885221,0.854151); legend1->AddEntry(pdfunc,"normal_pdf","l"); legend1->Draw(); c1->cd(2); cdfunc->Draw(); ccdfunc->Draw("same"); TLegend *legend2 = new TLegend(0.585605,0.462794,0.886933,0.710837); legend2->AddEntry(cdfunc,"normal_cdf","l"); legend2->AddEntry(ccdfunc,"normal_cdf_c","l"); legend2->Draw(); c1->cd(3); qfunc->Draw(); cqfunc->Draw("same"); TLegend *legend3 = new TLegend(0.315094,0.633668,0.695179,0.881711); legend3->AddEntry(qfunc,"normal_quantile","l"); legend3->AddEntry(cqfunc,"normal_quantile_c","l"); legend3->Draw(); } normalDist.C:1 normalDist.C:2 normalDist.C:3 normalDist.C:4 normalDist.C:5 normalDist.C:6 normalDist.C:7 normalDist.C:8 normalDist.C:9 normalDist.C:10 normalDist.C:11 normalDist.C:12 normalDist.C:13 normalDist.C:14 normalDist.C:15 normalDist.C:16 normalDist.C:17 normalDist.C:18 normalDist.C:19 normalDist.C:20 normalDist.C:21 normalDist.C:22 normalDist.C:23 normalDist.C:24 normalDist.C:25 normalDist.C:26 normalDist.C:27 normalDist.C:28 normalDist.C:29 normalDist.C:30 normalDist.C:31 normalDist.C:32 normalDist.C:33 normalDist.C:34 normalDist.C:35 normalDist.C:36 normalDist.C:37 normalDist.C:38 normalDist.C:39 normalDist.C:40 normalDist.C:41 normalDist.C:42 normalDist.C:43 normalDist.C:44 normalDist.C:45 normalDist.C:46 normalDist.C:47 normalDist.C:48 normalDist.C:49 normalDist.C:50 normalDist.C:51 normalDist.C:52 normalDist.C:53 normalDist.C:54 normalDist.C:55 normalDist.C:56 normalDist.C:57 normalDist.C:58 normalDist.C:59 normalDist.C:60 normalDist.C:61 normalDist.C:62 normalDist.C:63 normalDist.C:64 normalDist.C:65 normalDist.C:66 normalDist.C:67 normalDist.C:68 normalDist.C:69 normalDist.C:70 normalDist.C:71 normalDist.C:72 normalDist.C:73 normalDist.C:74 normalDist.C:75 normalDist.C:76 normalDist.C:77 normalDist.C:78 normalDist.C:79 normalDist.C:80 normalDist.C:81 normalDist.C:82 normalDist.C:83 normalDist.C:84 normalDist.C:85 normalDist.C:86 normalDist.C:87 normalDist.C:88 normalDist.C:89 normalDist.C:90 normalDist.C:91 normalDist.C:92 normalDist.C:93 normalDist.C:94 normalDist.C:95 normalDist.C:96 normalDist.C:97 normalDist.C:98 normalDist.C:99 normalDist.C:100 normalDist.C:101 normalDist.C:102 normalDist.C:103 normalDist.C:104 normalDist.C:105 normalDist.C:106 normalDist.C:107 normalDist.C:108 |
|