Go to the documentation of this file.00001 
00002 #ifndef vpdfl_pdf_base_h
00003 #define vpdfl_pdf_base_h
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 
00008 
00009 
00010 
00011 
00012 
00013 #include <vnl/io/vnl_io_vector.h>
00014 #include <vsl/vsl_binary_io.h>
00015 #include <vcl_string.h>
00016 #include <vcl_iosfwd.h>
00017 
00018 
00019 
00020 class vpdfl_sampler_base;
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 class vpdfl_pdf_base
00031 {
00032   vnl_vector<double> mean_;
00033   vnl_vector<double> var_;
00034  protected:
00035   void set_mean(const vnl_vector<double>& m) { mean_ = m; }
00036   void set_variance(const vnl_vector<double>& v) { var_ = v; }
00037  public:
00038 
00039   
00040   vpdfl_pdf_base();
00041 
00042   
00043   virtual ~vpdfl_pdf_base();
00044 
00045   
00046   const vnl_vector<double>& mean() const { return mean_; }
00047 
00048   
00049   const vnl_vector<double>& variance() const { return var_; }
00050 
00051   
00052   int n_dims() const { return mean_.size(); }
00053 
00054   
00055   virtual int n_peaks() const { return 1; }
00056 
00057   
00058   virtual const vnl_vector<double>& peak(int) const { return mean_; }
00059 
00060   
00061   virtual double log_p(const vnl_vector<double>& x) const =0;
00062 
00063   
00064   virtual double operator()(const vnl_vector<double>& x) const;
00065 
00066   
00067   
00068   virtual void gradient(vnl_vector<double>& g,
00069                         const vnl_vector<double>& x, double& p) const =0;
00070 
00071   
00072   
00073   
00074   
00075   virtual void gradient_logp(vnl_vector<double>& g,
00076                         const vnl_vector<double>& x) const;
00077 
00078   
00079   
00080   virtual vpdfl_sampler_base* new_sampler()const=0 ;
00081 
00082   
00083   virtual double log_prob_thresh(double pass_proportion)const;
00084 
00085   
00086   
00087   
00088   
00089   
00090   virtual void nearest_plausible(vnl_vector<double>& x, double log_p_min)const =0;
00091 
00092   
00093   
00094   
00095   virtual bool is_valid_pdf() const;
00096 
00097   
00098   short version_no() const;
00099 
00100   
00101   virtual vcl_string is_a() const;
00102 
00103   
00104   virtual bool is_class(vcl_string const& s) const;
00105 
00106   
00107   virtual vpdfl_pdf_base* clone() const = 0;
00108 
00109   
00110   virtual void print_summary(vcl_ostream& os) const = 0;
00111 
00112   
00113   virtual void b_write(vsl_b_ostream& bfs) const = 0;
00114 
00115   
00116   virtual void b_read(vsl_b_istream& bfs) = 0;
00117 };
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 void vsl_add_to_binary_loader(const vpdfl_pdf_base& b);
00129 
00130 
00131 void vsl_b_write(vsl_b_ostream& bfs, const vpdfl_pdf_base& b);
00132 
00133 
00134 void vsl_b_read(vsl_b_istream& bfs, vpdfl_pdf_base& b);
00135 
00136 
00137 void vsl_print_summary(vcl_ostream& os,const vpdfl_pdf_base& b);
00138 
00139 
00140 void vsl_print_summary(vcl_ostream& os,const vpdfl_pdf_base* b);
00141 
00142 
00143 vcl_ostream& operator<<(vcl_ostream& os,const vpdfl_pdf_base& b);
00144 
00145 
00146 vcl_ostream& operator<<(vcl_ostream& os,const vpdfl_pdf_base* b);
00147 
00148 #endif // vpdfl_pdf_base_h