contrib/mul/pdf1d/pdf1d_prob_ks.cxx
Go to the documentation of this file.
00001 // This is mul/pdf1d/pdf1d_prob_ks.cxx
00002 #include "pdf1d_prob_ks.h"
00003 //:
00004 // \file
00005 // \author Tim Cootes
00006 // \brief Probability used in Kolmogorov-Smirnov test
00007 
00008 #include <vcl_cmath.h>
00009 
00010 const double f1 = 0.001;
00011 const double f2 = 1.0e-8;
00012 
00013 //: Probability used in Kolmogorov-Smirnov test
00014 //  This is the prob. that the maximum difference between two cumulative
00015 //  distributions is larger than x.
00016 double pdf1d_prob_ks(double x)
00017 {
00018   double k=2.0,sum=0.0,term,previous_term=0.0;
00019 
00020   double a2 = -2.0*x*x;
00021   for (int j=1;j<=100;j++)
00022   {
00023     term=k*vcl_exp(a2*j*j);
00024     sum += term;
00025     if (vcl_fabs(term) <= f1*previous_term || vcl_fabs(term) <= f2*sum) return sum;
00026     k = -k;
00027     previous_term=vcl_fabs(term);
00028   }
00029   return 1.0;
00030 }