Univariate Epanechnikov kernel PDF $k(x)=0.75(1-0.2x^2)/{2}$. More...
#include <pdf1d_weighted_epanech_kernel_pdf.h>
Public Member Functions | |
pdf1d_weighted_epanech_kernel_pdf () | |
Dflt ctor. | |
pdf1d_weighted_epanech_kernel_pdf (int n, double sep, double width) | |
Define n kernels centred at i*sep (i=0..n-1). | |
virtual | ~pdf1d_weighted_epanech_kernel_pdf () |
Destructor. | |
virtual pdf1d_sampler * | new_sampler () const |
Create a sampler object on the heap. | |
virtual double | operator() (double x) const |
Probability density at x. | |
virtual double | log_p (double x) const |
Log of probability density at x. | |
virtual double | cdf (double x) const |
Cumulative Probability (P(x'<x) for x' drawn from the distribution). | |
virtual bool | cdf_is_analytic () const |
Return true if cdf() uses an analytic implementation. | |
virtual double | gradient (double x, double &p) const |
Gradient of PDF at x. | |
virtual double | nearest_plausible (double x, double log_p_min) const |
Compute nearest point to x which has a density above a threshold. | |
short | version_no () const |
Version number for I/O. | |
virtual vcl_string | is_a () const |
Name of the class. | |
virtual bool | is_class (vcl_string const &s) const |
Does the name of the class match the argument?. | |
virtual pdf1d_pdf * | clone () const |
Create a copy on the heap and return base class pointer. | |
void | set_weight (const vnl_vector< double > &weights) |
Set the weights. | |
void | swap_weight (vnl_vector< double > &weights) |
Swap in the weights values. | |
const vnl_vector< double > & | weight () const |
Weight of each kernel. | |
virtual void | set_centres (const vnl_vector< double > &x, double width) |
Initialise so all kernels have the same width. | |
virtual void | set_centres (const vnl_vector< double > &x, const vnl_vector< double > &width) |
Initialise so all kernels have given width. | |
virtual void | print_summary (vcl_ostream &os) const |
Print class to os. | |
virtual void | b_write (vsl_b_ostream &bfs) const |
Save class to binary file stream. | |
virtual void | b_read (vsl_b_istream &bfs) |
Load class from binary file stream. | |
const vnl_vector< double > & | centre () const |
Position of kernel centres. | |
const vnl_vector< double > & | width () const |
Width of each kernel. | |
bool | all_same_width () const |
True if all kernels have the same width. | |
virtual double | inverse_cdf (double P) const |
The inverse cdf. | |
double | mean () const |
Mean of distribution. | |
double | variance () const |
Variance of each dimension. | |
virtual int | n_peaks () const |
Number of peaks of distribution. | |
virtual double | peak (int) const |
Position of the i'th peak. | |
virtual double | log_prob_thresh (double pass_proportion) const |
Compute threshold for PDF to pass a given proportion. | |
virtual bool | is_valid_pdf () const |
Return true if the object represents a valid PDF. | |
void | get_samples (vnl_vector< double > &x) const |
Fill x with samples drawn from distribution. | |
bool | write_plot_file (const vcl_string &plot_file, double min_x, double max_x, int n) const |
Write values (x,p(x)) to text file suitable for plotting. | |
Static Public Member Functions | |
static void | pdf1d_weighted_kernel_mean_var (double &mean, double &var, const vnl_vector< double > ¢res, const vnl_vector< double > &widths, const vnl_vector< double > &weights) |
calc the weighted mean and var of kernels. | |
Protected Member Functions | |
void | set_mean (double m) |
void | set_variance (double v) |
Protected Attributes | |
vnl_vector< double > | weight_ |
Weight of each kernel. | |
double | sum_weights_ |
vnl_vector< double > | x_ |
Position of kernel centres. | |
vnl_vector< double > | width_ |
Width of each kernel. | |
vcl_vector< int > | index_ |
Workspace. | |
bool | all_same_width_ |
True if all kernels have the same width. | |
Friends | |
class | pdf1d_weighted_epanech_kernel_sampler |
Univariate Epanechnikov kernel PDF $k(x)=0.75(1-0.2x^2)/{2}$.
Definition at line 14 of file pdf1d_weighted_epanech_kernel_pdf.h.
pdf1d_weighted_epanech_kernel_pdf::pdf1d_weighted_epanech_kernel_pdf | ( | ) |
Dflt ctor.
Definition at line 19 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
pdf1d_weighted_epanech_kernel_pdf::pdf1d_weighted_epanech_kernel_pdf | ( | int | n, |
double | sep, | ||
double | width | ||
) |
Define n kernels centred at i*sep (i=0..n-1).
Definition at line 25 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
pdf1d_weighted_epanech_kernel_pdf::~pdf1d_weighted_epanech_kernel_pdf | ( | ) | [virtual] |
Destructor.
Definition at line 38 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
bool pdf1d_kernel_pdf::all_same_width | ( | ) | const [inline, inherited] |
True if all kernels have the same width.
Definition at line 61 of file pdf1d_kernel_pdf.h.
void pdf1d_weighted_kernel_pdf::b_read | ( | vsl_b_istream & | bfs | ) | [virtual, inherited] |
Load class from binary file stream.
Reimplemented from pdf1d_kernel_pdf.
Definition at line 140 of file pdf1d_weighted_kernel_pdf.cxx.
void pdf1d_weighted_kernel_pdf::b_write | ( | vsl_b_ostream & | bfs | ) | const [virtual, inherited] |
Save class to binary file stream.
Reimplemented from pdf1d_kernel_pdf.
Definition at line 130 of file pdf1d_weighted_kernel_pdf.cxx.
double pdf1d_weighted_epanech_kernel_pdf::cdf | ( | double | x0 | ) | const [virtual] |
Cumulative Probability (P(x'<x) for x' drawn from the distribution).
CDF of if
Reimplemented from pdf1d_pdf.
Definition at line 87 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
bool pdf1d_weighted_epanech_kernel_pdf::cdf_is_analytic | ( | ) | const [virtual] |
Return true if cdf() uses an analytic implementation.
Reimplemented from pdf1d_pdf.
Definition at line 112 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
const vnl_vector<double>& pdf1d_kernel_pdf::centre | ( | ) | const [inline, inherited] |
Position of kernel centres.
Definition at line 55 of file pdf1d_kernel_pdf.h.
pdf1d_pdf * pdf1d_weighted_epanech_kernel_pdf::clone | ( | ) | const [virtual] |
Create a copy on the heap and return base class pointer.
Implements pdf1d_pdf.
Definition at line 181 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
void pdf1d_pdf::get_samples | ( | vnl_vector< double > & | x | ) | const [inherited] |
Fill x with samples drawn from distribution.
Utility function. This calls new_sampler() to do the work, then deletes the sampler again. If you intend calling this repeatedly, create a sampler yourself.
Definition at line 132 of file pdf1d_pdf.cxx.
double pdf1d_weighted_epanech_kernel_pdf::gradient | ( | double | x, |
double & | p | ||
) | const [virtual] |
Gradient of PDF at x.
Implements pdf1d_pdf.
Definition at line 119 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
double pdf1d_kernel_pdf::inverse_cdf | ( | double | P | ) | const [virtual, inherited] |
The inverse cdf.
The value of x: P(x'<x) = P for x' drawn from distribution pdf. Uses Newton-Raphson.
The value of x: P(x'<x) = P for x' drawn from distribution pdf.
Reimplemented from pdf1d_pdf.
Definition at line 69 of file pdf1d_kernel_pdf.cxx.
vcl_string pdf1d_weighted_epanech_kernel_pdf::is_a | ( | ) | const [virtual] |
Name of the class.
Reimplemented from pdf1d_weighted_kernel_pdf.
Definition at line 159 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
bool pdf1d_weighted_epanech_kernel_pdf::is_class | ( | vcl_string const & | s | ) | const [virtual] |
Does the name of the class match the argument?.
Reimplemented from pdf1d_weighted_kernel_pdf.
Definition at line 167 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
bool pdf1d_pdf::is_valid_pdf | ( | ) | const [virtual, inherited] |
Return true if the object represents a valid PDF.
This will return false, if n_dims() is 0, for example just ofter default construction.
Reimplemented in pdf1d_mixture.
Definition at line 126 of file pdf1d_pdf.cxx.
double pdf1d_weighted_epanech_kernel_pdf::log_p | ( | double | x | ) | const [virtual] |
Log of probability density at x.
Implements pdf1d_pdf.
Definition at line 79 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
double pdf1d_pdf::log_prob_thresh | ( | double | pass_proportion | ) | const [virtual, inherited] |
Compute threshold for PDF to pass a given proportion.
Reimplemented in pdf1d_flat, pdf1d_gaussian, and pdf1d_exponential.
Definition at line 68 of file pdf1d_pdf.cxx.
double pdf1d_pdf::mean | ( | ) | const [inline, inherited] |
Mean of distribution.
Definition at line 42 of file pdf1d_pdf.h.
virtual int pdf1d_pdf::n_peaks | ( | ) | const [inline, virtual, inherited] |
Number of peaks of distribution.
Definition at line 48 of file pdf1d_pdf.h.
double pdf1d_weighted_epanech_kernel_pdf::nearest_plausible | ( | double | x, |
double | log_p_min | ||
) | const [virtual] |
Compute nearest point to x which has a density above a threshold.
If log_p(x)>log_p_min then x returned unchanged. Otherwise x is moved (typically up the gradient) until log_p(x)>=log_p_min.
x | This may be modified to the nearest plausible position. |
log_p_min | lower threshold for log_p(x) |
Implements pdf1d_pdf.
Definition at line 150 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
pdf1d_sampler * pdf1d_weighted_epanech_kernel_pdf::new_sampler | ( | ) | const [virtual] |
Create a sampler object on the heap.
Caller is responsible for deletion.
Implements pdf1d_pdf.
Definition at line 44 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
double pdf1d_weighted_epanech_kernel_pdf::operator() | ( | double | x | ) | const [virtual] |
Probability density at x.
Reimplemented from pdf1d_pdf.
Definition at line 55 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
void pdf1d_weighted_kernel_pdf::pdf1d_weighted_kernel_mean_var | ( | double & | mean, |
double & | var, | ||
const vnl_vector< double > & | centres, | ||
const vnl_vector< double > & | widths, | ||
const vnl_vector< double > & | weights | ||
) | [static, inherited] |
calc the weighted mean and var of kernels.
w is expected to sum to n.
Definition at line 22 of file pdf1d_weighted_kernel_pdf.cxx.
virtual double pdf1d_pdf::peak | ( | int | ) | const [inline, virtual, inherited] |
Position of the i'th peak.
Definition at line 51 of file pdf1d_pdf.h.
void pdf1d_weighted_kernel_pdf::print_summary | ( | vcl_ostream & | os | ) | const [virtual, inherited] |
Print class to os.
Reimplemented from pdf1d_kernel_pdf.
Definition at line 121 of file pdf1d_weighted_kernel_pdf.cxx.
void pdf1d_weighted_kernel_pdf::set_centres | ( | const vnl_vector< double > & | x, |
double | width | ||
) | [virtual, inherited] |
Initialise so all kernels have the same width.
This function resets the weights.
Reimplemented from pdf1d_kernel_pdf.
Definition at line 48 of file pdf1d_weighted_kernel_pdf.cxx.
void pdf1d_weighted_kernel_pdf::set_centres | ( | const vnl_vector< double > & | x, |
const vnl_vector< double > & | width | ||
) | [virtual, inherited] |
Initialise so all kernels have given width.
This function resets the weights.
Reimplemented from pdf1d_kernel_pdf.
Definition at line 57 of file pdf1d_weighted_kernel_pdf.cxx.
void pdf1d_pdf::set_mean | ( | double | m | ) | [inline, protected, inherited] |
Reimplemented in pdf1d_gaussian.
Definition at line 31 of file pdf1d_pdf.h.
void pdf1d_pdf::set_variance | ( | double | v | ) | [inline, protected, inherited] |
Definition at line 32 of file pdf1d_pdf.h.
void pdf1d_weighted_kernel_pdf::set_weight | ( | const vnl_vector< double > & | weights | ) | [inherited] |
Set the weights.
The weights will be scaled to sum to 1.0
Definition at line 70 of file pdf1d_weighted_kernel_pdf.cxx.
void pdf1d_weighted_kernel_pdf::swap_weight | ( | vnl_vector< double > & | weights | ) | [inherited] |
Swap in the weights values.
This function is fast when you are changing the weights regularly The weights will be scaled to sum to 1.0
This function is fast when you are changing the weights regularly The weights will be scaled to sum to n
Definition at line 88 of file pdf1d_weighted_kernel_pdf.cxx.
double pdf1d_pdf::variance | ( | ) | const [inline, inherited] |
Variance of each dimension.
Definition at line 45 of file pdf1d_pdf.h.
short pdf1d_weighted_epanech_kernel_pdf::version_no | ( | ) | const |
Version number for I/O.
Reimplemented from pdf1d_weighted_kernel_pdf.
Definition at line 174 of file pdf1d_weighted_epanech_kernel_pdf.cxx.
const vnl_vector<double>& pdf1d_weighted_kernel_pdf::weight | ( | ) | const [inline, inherited] |
Weight of each kernel.
Definition at line 50 of file pdf1d_weighted_kernel_pdf.h.
const vnl_vector<double>& pdf1d_kernel_pdf::width | ( | ) | const [inline, inherited] |
Width of each kernel.
Definition at line 58 of file pdf1d_kernel_pdf.h.
bool pdf1d_pdf::write_plot_file | ( | const vcl_string & | plot_file, |
double | min_x, | ||
double | max_x, | ||
int | n | ||
) | const [inherited] |
Write values (x,p(x)) to text file suitable for plotting.
Evaluate pdf at n points in range [min_x,max_x] and write a text file, each line of which is {x p(x)}, suitable for plotting with many graph packages
Definition at line 142 of file pdf1d_pdf.cxx.
friend class pdf1d_weighted_epanech_kernel_sampler [friend] |
Definition at line 64 of file pdf1d_weighted_epanech_kernel_pdf.h.
bool pdf1d_kernel_pdf::all_same_width_ [protected, inherited] |
True if all kernels have the same width.
Definition at line 38 of file pdf1d_kernel_pdf.h.
vcl_vector<int> pdf1d_kernel_pdf::index_ [mutable, protected, inherited] |
Workspace.
If non-empty x_(index[i]) <= x_(index[i+1])
Definition at line 35 of file pdf1d_kernel_pdf.h.
double pdf1d_weighted_kernel_pdf::sum_weights_ [protected, inherited] |
Definition at line 30 of file pdf1d_weighted_kernel_pdf.h.
vnl_vector<double> pdf1d_weighted_kernel_pdf::weight_ [protected, inherited] |
Weight of each kernel.
Definition at line 29 of file pdf1d_weighted_kernel_pdf.h.
vnl_vector<double> pdf1d_kernel_pdf::width_ [protected, inherited] |
Width of each kernel.
Definition at line 31 of file pdf1d_kernel_pdf.h.
vnl_vector<double> pdf1d_kernel_pdf::x_ [protected, inherited] |
Position of kernel centres.
Definition at line 28 of file pdf1d_kernel_pdf.h.