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