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