CVR-Lib last update 20 Sep 2009

cvrUnivariateContinuousDistribution.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007
00003  * ITCR, Pablo Alvarado
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 /**
00042  * \file   cvrUnivariateContinuousDistribution.h
00043  *         Contains the class cvr::univariateContinuousDistribution,
00044  *         parent of all univariate continuous random distributions.
00045  * \author Pablo Alvarado
00046  * \date   23.09.2007
00047  *
00048  * revisions ..: $Id: cvrUnivariateContinuousDistribution.h,v 1.1 2007/09/26 21:21:52 alvarado Exp $
00049  */
00050 
00051 #ifndef _CVR_UNIVARIATE_CONTINUOUS_DISTRIBUTION_H_
00052 #define _CVR_UNIVARIATE_CONTINUOUS_DISTRIBUTION_H_
00053 
00054 #include "cvrRandomDistribution.h"
00055 
00056 namespace cvr {
00057 
00058   /**
00059    * Class univariateContinuousDistribution
00060    *
00061    * All univariate continuous distributions return random numbers in a
00062    * floating point format.  This class establishes the basic interface to
00063    * allow virtual inheritance of the apply methods.
00064    *
00065    * @see univariateContinuousDistribution::parameters.
00066    *
00067    * @ingroup gRandomContinuous
00068    */
00069   class univariateContinuousDistribution : public randomDistribution {
00070   public:
00071     /**
00072      * Default constructor.
00073      *
00074      * Inherited classes can turn off the parameter initialization, since
00075      * they do the job.
00076      */
00077     univariateContinuousDistribution(const bool initParams=true);
00078 
00079     /**
00080      * Construct a functor using the given parameters
00081      */
00082     univariateContinuousDistribution(const parameters& par);
00083 
00084     /**
00085      * Copy constructor
00086      * @param o the object to be copied
00087      */
00088     univariateContinuousDistribution(const univariateContinuousDistribution& o);
00089     /**
00090      * Destructor
00091      */
00092     virtual ~univariateContinuousDistribution();
00093 
00094     /**
00095      * Get a random number.
00096      *
00097      * Returns a random number distributed accordingly to the type of the
00098      * current instance.
00099      *
00100      * The univariateContinuousDistribution can be used to obtain numbers
00101      * in the interval [0,1).
00102      *
00103      * @param rnd float reference where the random number has to be left.
00104      * @return true if apply successful or false otherwise.
00105      */
00106     virtual bool apply(float& rnd);
00107 
00108     /**
00109      * Get a random number.
00110      *
00111      * Returns a random number distributed accordingly to the type of the
00112      * current instance.
00113      *
00114      * The univariateContinuousDistribution can be used to obtain numbers
00115      * in the interval [0,1).
00116      *
00117      * @param rnd double reference where the random number has to be left.
00118      * @return true if apply successful or false otherwise.
00119      */
00120     virtual bool apply(double& rnd);
00121 
00122     /**
00123      * Get a single precision random number.
00124      *
00125      * Returns a random number distributed accordingly to the type of the
00126      * current instance.
00127      *
00128      * The univariateContinuousDistribution can be used to obtain numbers
00129      * in the interval [0,1).
00130      *
00131      * @return a random float number.
00132      */
00133     virtual float fdraw();
00134 
00135     /**
00136      * Get a double precision random number.
00137      *
00138      * Returns a random number distributed accordingly to the type of the
00139      * current instance.
00140      *
00141      * The univariateContinuousDistribution can be used to obtain numbers
00142      * in the interval [0,1).
00143      *
00144      * @return a random double number.
00145      */
00146     virtual double draw();
00147 
00148     /**
00149      * Non-virtual method to get a single precision random number.
00150      *
00151      * Returns a random number distributed accordingly to the type of the
00152      * current instance.
00153      *
00154      * The univariateContinuousDistribution can be used to obtain numbers
00155      * in the interval [0,1).
00156      *
00157      * @return a random float number.
00158      */
00159     float frand();
00160 
00161     /**
00162      * Non-virtual method to get a double precision random number.
00163      *
00164      * Returns a random number distributed accordingly to the type of the
00165      * current instance.
00166      *
00167      * The univariateContinuousDistribution can be used to obtain numbers
00168      * in the interval [0,1).
00169      *
00170      * @return a random double number.
00171      */
00172     double rand();
00173 
00174 
00175     /**
00176      * Copy data of "other" functor.
00177      * @param other the functor to be copied
00178      * @return a reference to this functor object
00179      */
00180     univariateContinuousDistribution&
00181     copy(const univariateContinuousDistribution& other);
00182 
00183     /**
00184      * Alias for copy member
00185      * @param other the functor to be copied
00186      * @return a reference to this functor object
00187      */
00188     univariateContinuousDistribution&
00189     operator=(const univariateContinuousDistribution& other);
00190 
00191     /**
00192      * Returns the complete name of the functor class
00193      */
00194     virtual const std::string& name() const;
00195 
00196     /**
00197      * Returns a pointer to a clone of this functor.
00198      */
00199     virtual univariateContinuousDistribution* clone() const;
00200 
00201     /**
00202      * Returns a pointer to a new instance of this functor.
00203      */
00204     virtual univariateContinuousDistribution* newInstance() const;
00205 
00206     /**
00207      * Returns used parameters
00208      */
00209     bool updateParameters();
00210 
00211   protected:
00212     /**
00213      * Float normalizer.
00214      */
00215     float fnorm_;
00216 
00217     /**
00218      * Double normalizer.
00219      */
00220     double dnorm_;
00221 
00222   };
00223 }
00224 
00225 #endif
00226 

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8