LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiGaussDist.h

00001 /*
00002  * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*----------------------------------------------------------------
00025  * project ....: LTI Digital Image/Signal Processing Library
00026  * file .......: ltiGaussDist.h
00027  * authors ....: Thomas Rusert
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 21.04.99
00030  * revisions ..: $Id: ltiGaussDist.h,v 1.6 2006/02/23 18:02:29 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_GAUSSDIST_H_
00034 #define _LTI_GAUSSDIST_H_
00035 
00036 #include "ltiContinuousRandDist.h"
00037 
00038 namespace lti {
00039   /**
00040    * Normal distributed random number class.
00041    */
00042   class gaussianDistribution : public continuousRandomDistribution {
00043   public:
00044 
00045     /**
00046      * parameters for gaussian distribution
00047      */
00048     class parameters : public continuousRandomDistribution::parameters {
00049     public:
00050       /**
00051        * default constructor
00052        */
00053       parameters()
00054         : continuousRandomDistribution::parameters(),sigma(1.0),mu(.0) {};
00055 
00056       /**
00057        * copy constructor
00058        */
00059       parameters(const parameters& other)
00060         : continuousRandomDistribution::parameters() {
00061         copy(other);
00062       };
00063 
00064       /**
00065        * destructor
00066        */
00067       ~parameters() {};
00068 
00069       /**
00070        * standard deviation
00071        *
00072        * Default: 1.0
00073        */
00074       double sigma;
00075 
00076       /**
00077        * mean
00078        *
00079        * Default: 0.
00080        */
00081       double mu;
00082 
00083       /**
00084        * copy data of "other" parameters
00085        */
00086       parameters& copy(const parameters& other) {
00087 #ifndef _LTI_MSC_6
00088   // MS Visual C++ 6 is not able to compile this...
00089   continuousRandomDistribution::parameters::copy(other);
00090 #else
00091   // ...so we have to use this workaround.
00092   // Conditional on that, copy may not be virtual.
00093   continuousRandomDistribution::parameters&
00094     (continuousRandomDistribution::parameters::* p_copy)
00095     (const continuousRandomDistribution::parameters&) =
00096     continuousRandomDistribution::parameters::copy;
00097   (this->*p_copy)(other);
00098 #endif
00099 
00100   sigma = other.sigma;
00101   mu = other.mu;
00102 
00103   return (*this);
00104       }
00105 
00106       /**
00107        * returns a pointer to a clone of the parameters.
00108        */
00109       virtual functor::parameters* clone() const {
00110   return (new parameters(*this));
00111       };
00112 
00113       /**
00114        * returns the name of this type
00115        */
00116       virtual const char* getTypeName() const {
00117   return "gaussianDistribution::parameters";
00118       };
00119     };
00120 
00121     /**
00122      * default constructor. Sets mean and standard deviation and mean.
00123      */
00124     gaussianDistribution(const double mean=0.0,
00125                          const double stdDeviation=1.0);
00126 
00127     /**
00128      * constructor, sets the parameters
00129      */
00130     gaussianDistribution(const parameters& theParams);
00131 
00132     /**
00133      * destructor
00134      */
00135     virtual ~gaussianDistribution() {};
00136 
00137     /**
00138      * returns the current parameters.
00139      */
00140     const parameters& getParameters() const;
00141 
00142     /**
00143      * draws a number from the distribution.
00144      */
00145     virtual double draw() const;
00146 
00147     /**
00148      * draw a number for the distribution with the given average and
00149      * std. deviation
00150      */
00151     double draw(const double& average, const double& stdDeviation) const;
00152 
00153     /**
00154      * return a gaussian distributed random number.
00155      * @param average mean value of the distribution
00156      * @param stdDeviation std. deviation of the distribution
00157      * @param result value from the distribution
00158      * @return true if successful, false otherwise.
00159      */
00160     bool apply(const double& average,
00161                const double& stdDeviation,
00162                double& result) const;
00163 
00164     /**
00165      * copy data of "other" functor.
00166      */
00167     gaussianDistribution& copy(const gaussianDistribution& other);
00168 
00169     /**
00170      * returns a pointer to a clone of the functor.
00171      */
00172     virtual functor* clone() const {
00173       return (new gaussianDistribution(*this));
00174     };
00175 
00176     /**
00177      * returns the name of this type
00178      */
00179     virtual const char* getTypeName() const {
00180       return "gaussianDistribution";
00181     };
00182 
00183   protected:
00184     mutable double V1, V2, S;
00185     mutable int phase;
00186   };
00187 }
00188 
00189 #endif

Generated on Sat Apr 10 15:25:33 2010 for LTI-Lib by Doxygen 1.6.1