00001 // This is mul/pdf1d/pdf1d_exponential.h 00002 #ifndef pdf1d_exponential_h 00003 #define pdf1d_exponential_h 00004 00005 //: 00006 // \file 00007 // \brief Univariate exponential PDF 00008 // \author Tim Cootes 00009 00010 #include <pdf1d/pdf1d_pdf.h> 00011 #include <vcl_iosfwd.h> 00012 00013 //: Class for exponential distributions 00014 // $p(x)=\lambda exp(-\lambda x)$ 00015 class pdf1d_exponential : public pdf1d_pdf 00016 { 00017 double lambda_; 00018 double log_lambda_; 00019 00020 public: 00021 //: Dflt ctor (creates exponential distribution in range [0,1]) 00022 pdf1d_exponential(); 00023 00024 //: Dflt ctor (creates exponential distribution in range [lo,hi]) 00025 pdf1d_exponential(double lambda); 00026 00027 //: Destructor 00028 virtual ~pdf1d_exponential(); 00029 00030 //: Return standard deviation 00031 double sd() const { return 1.0/lambda_; } 00032 00033 //: Creates exponential distribution with given lambda 00034 void set_lambda(double lambda); 00035 00036 //: Value of lambda 00037 double lambda() const { return lambda_; } 00038 00039 //: Create a sampler object on the heap 00040 // Caller is responsible for deletion. 00041 virtual pdf1d_sampler* new_sampler() const; 00042 00043 //: Probability density at x 00044 virtual double operator()(double x) const; 00045 00046 //: Log of probability density at x 00047 // This value is also the Normalised Mahalanobis distance 00048 // from the centroid to the given vector. 00049 virtual double log_p(double x) const; 00050 00051 //: Cumulative Probability (P(x'<x) for x' drawn from the distribution) 00052 // Returns 1-exp(-x/lambda) 00053 virtual double cdf(double x) const; 00054 00055 //: Return true if cdf() uses an analytic implementation 00056 virtual bool cdf_is_analytic() const; 00057 00058 //: Gradient of PDF at x 00059 virtual double gradient(double x, double& p) const; 00060 00061 //: Compute threshold for PDF to pass a given proportion 00062 virtual double log_prob_thresh(double pass_proportion) const; 00063 00064 //: Compute nearest point to x which has a density above a threshold 00065 // If log_p(x)>log_p_min then x returned unchanged. Otherwise x is moved 00066 // (typically up the gradient) until log_p(x)>=log_p_min. 00067 // \param x This may be modified to the nearest plausible position. 00068 // \param log_p_min lower threshold for log_p(x) 00069 virtual double nearest_plausible(double x, double log_p_min) const; 00070 00071 00072 //: Version number for I/O 00073 short version_no() const; 00074 00075 //: Name of the class 00076 virtual vcl_string is_a() const; 00077 00078 //: Does the name of the class match the argument? 00079 virtual bool is_class(vcl_string const& s) const; 00080 00081 //: Create a copy on the heap and return base class pointer 00082 virtual pdf1d_pdf* clone() const; 00083 00084 //: Print class to os 00085 virtual void print_summary(vcl_ostream& os) const; 00086 00087 //: Save class to binary file stream 00088 virtual void b_write(vsl_b_ostream& bfs) const; 00089 00090 00091 //: Load class from binary file stream 00092 virtual void b_read(vsl_b_istream& bfs); 00093 }; 00094 00095 #endif // pdf1d_exponential_h