PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Private Types | Private Member Functions
PLearn::BetaKernel Class Reference

The first sentence should be a BRIEF DESCRIPTION of what the class does. More...

#include <BetaKernel.h>

Inheritance diagram for PLearn::BetaKernel:
Inheritance graph
[legend]
Collaboration diagram for PLearn::BetaKernel:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 BetaKernel ()
 Default constructor.
virtual real evaluate (const Vec &x1, const Vec &x2) const
 Compute K(x1,x2).
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual BetaKerneldeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

Static Public Member Functions

static string _classname_ ()
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static Object_new_instance_for_typemap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()

Public Attributes

real width
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
string kernel_type
 Kernel type (simple or alternative)
string output_type
 log_density or density

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares the class options.

Private Types

typedef Kernel inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

The first sentence should be a BRIEF DESCRIPTION of what the class does.

Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html

Todo:
Write class to-do's here if there are any.
Deprecated:
Write deprecated stuff here if there is any. Indicate what else should be used instead.

Definition at line 57 of file BetaKernel.h.


Member Typedef Documentation

Reimplemented from PLearn::Kernel.

Definition at line 59 of file BetaKernel.h.


Constructor & Destructor Documentation

PLearn::BetaKernel::BetaKernel ( )

Default constructor.

Definition at line 57 of file BetaKernel.cc.

    : width(1.),
     kernel_type("simple"),
     output_type("normal")
{
}

Member Function Documentation

string PLearn::BetaKernel::_classname_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file BetaKernel.cc.

OptionList & PLearn::BetaKernel::_getOptionList_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file BetaKernel.cc.

RemoteMethodMap & PLearn::BetaKernel::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file BetaKernel.cc.

bool PLearn::BetaKernel::_isa_ ( const Object o) [static]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file BetaKernel.cc.

Object * PLearn::BetaKernel::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 52 of file BetaKernel.cc.

StaticInitializer BetaKernel::_static_initializer_ & PLearn::BetaKernel::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file BetaKernel.cc.

void PLearn::BetaKernel::build ( ) [virtual]

Post-constructor.

The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.

Reimplemented from PLearn::Kernel.

Definition at line 89 of file BetaKernel.cc.

References PLearn::Kernel::build(), and build_().

{
    // ### Nothing to add here, simply calls build_
    inherited::build();
    build_();
}

Here is the call graph for this function:

void PLearn::BetaKernel::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::Kernel.

Definition at line 99 of file BetaKernel.cc.

Referenced by build().

{
}

Here is the caller graph for this function:

string PLearn::BetaKernel::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file BetaKernel.cc.

void PLearn::BetaKernel::declareOptions ( OptionList ol) [static, protected]

Declares the class options.

Reimplemented from PLearn::Kernel.

Definition at line 67 of file BetaKernel.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Kernel::declareOptions(), kernel_type, output_type, and width.

{

    declareOption(ol, "width", &BetaKernel::width,
                   OptionBase::buildoption,
                  "The (positive, real-valued) smoothing parameter of the kernel (note that this does not quite correspond to the variance). If you use the Beta Kernel to do density estimation, this should go towards zero as the number of samples goes to infinity");
 
    declareOption(ol, "kernel_type", &BetaKernel::kernel_type,
                   OptionBase::buildoption,
                  "A string containing the type of Beta kernel. The \"simple\" kernel has a particularly simple mathematical form and is easily shown to integrate to 1 (thus is a density). The \"alternative\" kernel is slightly more complicated, but is better suited for those distributions that have a lot of mass near the boundaries (0 or 1). It will converge faster, but asymptotically both kernels are boundary bias free. Also, the \"alternative\" kernel is not yet shown by us to integrate to 1, thus we don't know for sure whether it's a valid density. Default is simple");
    
    declareOption(ol, "output_type", &BetaKernel::output_type,
                  OptionBase::buildoption,
                  "A string specifying whether we want log densities as outputs (\"log_value\" ) or just densities (\"normal\"; default)");

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::BetaKernel::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Kernel.

Definition at line 109 of file BetaKernel.h.

:
    //#####  Protected Options  ###############################################
BetaKernel * PLearn::BetaKernel::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Kernel.

Definition at line 52 of file BetaKernel.cc.

real PLearn::BetaKernel::evaluate ( const Vec x1,
const Vec x2 
) const [virtual]

Compute K(x1,x2).

Implements PLearn::Kernel.

Definition at line 106 of file BetaKernel.cc.

References a, b, PLearn::TVec< T >::data(), PLearn::exp(), i, kernel_type, PLearn::TVec< T >::length(), PLearn::log_beta_density(), output_type, PLASSERT_MSG, PLERROR, PLearn::pow(), PLearn::sqrt(), width, and x.

                                                            {
#ifdef BOUNDCHECK
    if(x1.length()!=x2.length())
        PLERROR("In BetaKernel::evaluate x1 and x2 must have the same length");
#endif
    int l = x1.length();
    real* px1 = x1.data();
    real* px2 = x2.data();
    real kvalue = 0.;

    //kernel_type = lowerstring(kernel_type);

    // check http://www.sta.nus.edu.sg/documents/publication_chen2.pdf for an
    // explanation of the estimators ("Beta kernel estimators for
    // density functions" is the paper title)
    if (kernel_type=="simple")
        for(int i=0; i<l; i++)
        {
            real a = px1[i] / width + 1.0;
            real b = (1.0 - px1[i]) / width + 1.0;
            real val = log_beta_density(px2[i],a,b);
            kvalue += val;
        }
    else if (kernel_type=="alternative")
        for(int i=0; i<l; i++)
        {
            real x = px1[i];
            real a, b;

            PLASSERT_MSG(x<0 || x >1 || px2[i] < 0 || px2[i] > 1, "In BetaKernel::evaluate x1 and x2 must contain values in the (closed) interval [0;1]");

            if ((x >= 2*width) && (x <= 1 - 2*width)) {
                a = x / width;
                b = (1 - x) / width;
            }
            else if ((x >= 0) & (x <= 2*width)) {
                a = 2*pow(width,real(2)) + 2.5 - sqrt(4*pow(width,real(4)) + 6*pow(width,real(2)) + 2.25 - x*x - x / width);
                b = (1 - x) / width;
            }
            else {
                a = x / width;
                real y = 1-x;
                b = 2*pow(width,real(2)) + 2.5 - sqrt(4*pow(width,real(4))+ 6*pow(width,real(2)) + 2.25 - y*y - y / width);
            }

            real val = log_beta_density(px2[i],a,b);
            kvalue += val;
        }
    else
        PLERROR("In BetaKernel::evaluate kernel_type must be either \"simple\" or \"alternative\"");

    real retval = 0.0;

    if (output_type=="log_value")
        retval = kvalue;
    else if (output_type=="normal")
        retval = exp(kvalue);
    else
        PLERROR("In BetaKernel::evaluate output_type must be either \"log_value\" or \"normal\"");

    return retval;
}

Here is the call graph for this function:

OptionList & PLearn::BetaKernel::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file BetaKernel.cc.

OptionMap & PLearn::BetaKernel::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file BetaKernel.cc.

RemoteMethodMap & PLearn::BetaKernel::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file BetaKernel.cc.

void PLearn::BetaKernel::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Kernel.

Definition at line 181 of file BetaKernel.cc.

References PLearn::Kernel::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::Kernel.

Definition at line 109 of file BetaKernel.h.

Kernel type (simple or alternative)

Definition at line 70 of file BetaKernel.h.

Referenced by declareOptions(), and evaluate().

log_density or density

Definition at line 72 of file BetaKernel.h.

Referenced by declareOptions(), and evaluate().

### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!

The "width" of the kernel

Definition at line 68 of file BetaKernel.h.

Referenced by declareOptions(), and evaluate().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines