Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleGSL.cpp

Example for usage of GSL, GNU Scientific Library

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** @example ExampleGSL.cpp
@relates GSL
@ingroup g_examples
@brief Example for usage of GSL, GNU Scientific Library
@author MIP
*/
#include <bias_config.h>
#ifdef BIAS_HAVE_GSL
#include <Base/Math/Random.hh>
#include <MathAlgo/GSL.hh>
using namespace BIAS;
using namespace std;
// dart smoketest: Does calling GSL directly compute expecteed values? (JW)
# include <gsl/gsl_cdf.h>
int TestGSL(){
const double x (5.678);
const double nu (3.21);
const double groundtruth(0.85341575204989784);
const double eps (0.0000000000001);
// call func directly to test lib instead of wrapping
double val = gsl_cdf_chisq_P (x, nu);
//cout<<"val="<<setprecision(30)<<val<<endl;
// TODO: robust comparison against ground truth precomputed value
if (fabs(val-groundtruth)>eps){
return -1; // failure
} else {
return 0; // OK
}
}
int main(int /*argc*/, char ** /*argv*/ )
{
Random rand;
const int count=100;
const int deg_freedom = 2;
double x;
for (int i=0; i<count; i++){
x = rand.GetUniformDistributed(0.0, 1.0);
cout << setw(13) << setprecision(3) << x
<< setw(13) << setprecision(3)
<< BIAS::InvChiSquareCulmProbFun(x, deg_freedom) /* from BIAS/MathAlgo/GSL.hh */
<< endl;
}
return TestGSL(); // darttest
//return 0;
}
#endif // BIAS_HAVE_GSL