Shark Machine Learning Library
  • About Shark
  • Sourceforge
    • Project Summary
    • Downloads
    • Subversion Repository
  • Getting Started
  • Tutorials
  • FAQ
  • Main Modules
    • ReClaM
    • EALib
    • MOO-EALib
    • Fuzzy
  • Tools
    • Mixture
    • Array
    • Rng
    • LinAlg
    • FileUtil
  • Main Page
  • Classes

HyperGeometric.cpp

Go to the documentation of this file.
00001 //===========================================================================
00043 //===========================================================================
00044 
00045 
00046 #include <cmath>
00047 #include "Rng/HyperGeometric.h"
00048 
00049 
00050 //========================================================================
00091 HyperGeometric::HyperGeometric(double mean, double variance)
00092         : pMean(mean), pVariance(variance)
00093 {
00094     setState();
00095 }
00096 
00097 
00098 //========================================================================
00142 HyperGeometric::HyperGeometric(double mean, double variance, RNG& r)
00143         : RandomVar< double >(r), pMean(mean), pVariance(variance)
00144 {
00145     setState();
00146 }
00147 
00148 
00149 // Calculates the probability "p", i.e. the relation of the number of
00150 // events of type T1 to the total number of events given
00151 // by "p = N1/N" from the stored mean value and the
00152 // variance. "p" will always be a real number greater than or equal
00153 // to zero. If the stored mean value is zero, then "p" will be set
00154 // to "0.", as for the default values "mean = 0" and "variance = 1".
00155 // Change: 2002-04-16, ra:
00156 // If the mean value is equal to zero or the calculation
00157 // of "p" results in a negative value then "p" will be set to "0." now.
00158 //
00159 void HyperGeometric::setState()
00160 {
00161     if (pMean == 0) {
00162         pP = 0.;
00163         return;
00164     }
00165 
00166     double z = pVariance / (pMean * pMean);
00167     pP = (1 - sqrt((z - 1) / (z + 1))) / 2;
00168 
00169     if (pP < 0.) pP = 0.;
00170     return;
00171 }
00172 
00173 
00174 
00175 //========================================================================
00200 void HyperGeometric::mean(double newMean)
00201 {
00202     pMean = newMean;
00203     setState();
00204 }
00205 
00206 
00207 //========================================================================
00232 void HyperGeometric::variance(double newVariance)
00233 {
00234     pVariance = newVariance;
00235     setState();
00236 }
00237 
00238 
00239 
00240 //========================================================================
00268 double HyperGeometric::operator()()
00269 {
00270     return -pMean * log(rng()) / (2 *(rng() > pP ? 1 - pP : pP));
00271 }
00272 
00273 
00274 
00275 //========================================================================
00296 double HyperGeometric::p(const double& x) const
00297 {
00298     return 0.; // !!!
00299 }
00300 
00301 
00302 
00303 
00304 
00305 
00306 
00307 
00308 
00309 
00310 
00311