Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleGSL.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 /** @example ExampleGSL.cpp
27  @relates GSL
28  @ingroup g_examples
29  @brief Example for usage of GSL, GNU Scientific Library
30  @author MIP
31 */
32 
33 
34 #include <bias_config.h>
35 #ifdef BIAS_HAVE_GSL
36 
37 #include <Base/Math/Random.hh>
38 #include <MathAlgo/GSL.hh>
39 
40 
41 using namespace BIAS;
42 using namespace std;
43 
44 
45 // dart smoketest: Does calling GSL directly compute expecteed values? (JW)
46 # include <gsl/gsl_cdf.h>
47 int TestGSL(){
48  const double x (5.678);
49  const double nu (3.21);
50  const double groundtruth(0.85341575204989784);
51  const double eps (0.0000000000001);
52  // call func directly to test lib instead of wrapping
53  double val = gsl_cdf_chisq_P (x, nu);
54  //cout<<"val="<<setprecision(30)<<val<<endl;
55  // TODO: robust comparison against ground truth precomputed value
56  if (fabs(val-groundtruth)>eps){
57  return -1; // failure
58  } else {
59  return 0; // OK
60  }
61 }
62 
63 
64 int main(int /*argc*/, char ** /*argv*/ )
65 {
66  Random rand;
67  const int count=100;
68  const int deg_freedom = 2;
69  double x;
70 
71  for (int i=0; i<count; i++){
72  x = rand.GetUniformDistributed(0.0, 1.0);
73  cout << setw(13) << setprecision(3) << x
74  << setw(13) << setprecision(3)
75  << BIAS::InvChiSquareCulmProbFun(x, deg_freedom) /* from BIAS/MathAlgo/GSL.hh */
76  << endl;
77  }
78 
79  return TestGSL(); // darttest
80  //return 0;
81 }
82 #endif // BIAS_HAVE_GSL
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Definition: Random.hh:84
BIASMathAlgo_EXPORT double InvChiSquareCulmProbFun(double x, int deg_freedom)
Definition: GSL.cpp:81
class for producing random numbers from different distributions
Definition: Random.hh:51