Open PaperOpt
OpenPaperOpt/DistributionTable.h
Go to the documentation of this file.
00001 #ifndef DISTRIBUTIONTABLE_H
00002 #define DISTRIBUTIONTABLE_H
00003 
00004 #include "Distribution.h"
00005 
00006 namespace Distributions
00007 {
00008         class DistributionTable :public Distribution
00009         {
00010         public:
00011                 DistributionTable();
00012                 ~DistributionTable(void);
00013 
00024                 DistributionTable (const double Pdf[], const int NumElements, 
00025                         const double MinX=0, const double MaxX=1);
00026                 
00032                 double GenerateRandomNumber() const;
00033 
00034 private:
00035 
00036                 //Contains the cumulative distribution function table
00037                 double* mpCdf;
00038 
00039                 //Number of elements in the cdf table
00040                 int mNumElements;
00041 
00042                 //min_x - starting x-value in the pdf function (the lowest possible random number)
00043                 double mMinX, mDeltaX;
00044 
00045                 /* Calculates the value of Finv(y) (the inverse of the cumulative distribution function) */
00046                 double InvF(const double Y) const;
00047 
00048                 /* Interpolates val between a and b and returns a value [0,1]. No checkings are done (for speed). */
00049                 inline double Interp(const double A, const double B, const double Val) const;
00050         }; 
00051 }
00052 
00053 #endif