00001 #include "vifa_gaussian.h" 00002 //: 00003 // \file 00004 #include <vcl_cmath.h> 00005 #include <vnl/vnl_math.h> 00006 00007 // From GeneralUtility/Stat/stat_constants.h in TargetJr 00008 #define StatEPSILON 1e-8 00009 #define EXPLIMIT 37.0 00010 00011 float vifa_gaussian::pdf(float x) 00012 { 00013 if (sigma_ < StatEPSILON) 00014 { 00015 // Degenerate distribution: 00016 // The variance is zero, so the pdf is a unit impulse at the mean. 00017 // Return 1.0 if x == mean, and 0.0 otherwise. 00018 00019 return vcl_fabs(x - mu_) < StatEPSILON ? 1.0f : 0.0f; 00020 } 00021 else 00022 { 00023 float xp = (x - mu_) / sigma_; 00024 return norm_dens(xp) / sigma_; 00025 } 00026 } 00027 00028 00029 float vifa_gaussian::norm_dens(float x) 00030 { 00031 // Check to see if the magnitude of x is large enough to 00032 // warrant clipping the pdf to 0.0 00033 return x < -EXPLIMIT || 00034 x > EXPLIMIT ? 0.0f : float(vnl_math::one_over_sqrt2pi * vcl_exp(-0.5*x*x)); 00035 }