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::SoftHistogramBinner Class Reference

#include <SoftHistogramBinner.h>

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

List of all members.

Public Member Functions

 SoftHistogramBinner ()
 Default constructor.
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual SoftHistogramBinnerdeepCopy (CopiesMap &copies) const
virtual TVec< TVec< int > > getBins (const Vec &v) const
 Return a vector whose i-th element is the list of the indices in 'v' that belong to the i-th bin.
virtual int nBins () const
 Return the number of bins computed by this binner.

Static Public Member Functions

static string _classname_ ()
 Declares name and deepCopy methods.
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

int n_bins
real samples_per_bin

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Private Types

typedef Binner inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 51 of file SoftHistogramBinner.h.


Member Typedef Documentation

Reimplemented from PLearn::Binner.

Definition at line 56 of file SoftHistogramBinner.h.


Constructor & Destructor Documentation

PLearn::SoftHistogramBinner::SoftHistogramBinner ( )

Default constructor.

Definition at line 52 of file SoftHistogramBinner.cc.

{
    // ...
    // ### You may or may not want to call build_() to finish building the object
    // build_();
}

Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

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

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

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

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

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

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

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

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

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

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

void PLearn::SoftHistogramBinner::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::Binner.

Definition at line 91 of file SoftHistogramBinner.cc.

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

This does the actual building.

Reimplemented from PLearn::Binner.

Definition at line 100 of file SoftHistogramBinner.cc.

References PLearn::is_equal(), and PLERROR.

{
    // ### This method should do the real building of the object,
    // ### according to set 'options', in *any* situation. 
    // ### Typical situations include:
    // ###  - Initial building of an object from a few user-specified options
    // ###  - Building of a "reloaded" object: i.e. from the complete set of all serialised options.
    // ###  - Updating or "re-building" of an object after a few "tuning" options have been modified.
    // ### You should assume that the parent class' build_() has already been called.
  
    // Check validity of the 'samples_per_bin' option.
    if (!is_equal(samples_per_bin, -1)                 &&
        !(samples_per_bin >= 0 && samples_per_bin < 1) &&
        !(samples_per_bin >= 1 && fabs(samples_per_bin - int(samples_per_bin)) < 1e-8))
        PLERROR("In SoftHistogramBinner::build_ - Invalid value for 'samples_per_bin'");
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

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

Declares this class' options.

Reimplemented from PLearn::Binner.

Definition at line 76 of file SoftHistogramBinner.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), n_bins, and samples_per_bin.

{
    declareOption(ol, "samples_per_bin", &SoftHistogramBinner::samples_per_bin, OptionBase::buildoption,
                  "The number of samples in each bin (if >= 1), or as a fraction (if < 1).");

    declareOption(ol, "n_bins", &SoftHistogramBinner::n_bins, OptionBase::buildoption,
                  "The number of bins computed.");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::Binner.

Definition at line 110 of file SoftHistogramBinner.h.

:

SoftHistogramBinner * PLearn::SoftHistogramBinner::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

TVec< TVec< int > > PLearn::SoftHistogramBinner::getBins ( const Vec v) const [virtual]

Return a vector whose i-th element is the list of the indices in 'v' that belong to the i-th bin.

Reimplemented from PLearn::Binner.

Definition at line 120 of file SoftHistogramBinner.cc.

References PLearn::TVec< T >::append(), i, PLearn::is_equal(), PLearn::left(), PLearn::TVec< T >::length(), PLearn::min(), n, PLERROR, PLearn::right(), PLearn::sortRows(), and w.

                                                                 {
    // Find out how many samples we have in each bin.
    int n;
    if (is_equal(samples_per_bin, -1))
        n = v.length();
    else if (samples_per_bin < 1)
        n = int(samples_per_bin * v.length());
    else
        n = int(round(samples_per_bin));
    if (n == 0)
        PLERROR("In SoftHistogramBinner::getBins - You can't ask for empty bins");
    // Sort the data to make things easier.
    Mat w(v.length(), 2);
    w.column(0) << v;
    w.column(1) << TVec<int>(0, w.length() - 1, 1);
    sortRows(w);
    // Construct bins.
    TVec< TVec<int> > bins(n_bins);
    real min_w = w(0,0);
    real max_w = w(w.length() - 1, 0);
    real bin_width = (max_w - min_w) / real(n_bins);
    for (int i = 0; i < n_bins; i++) {
        real bin_left = min_w + i * bin_width;
        real bin_right = bin_left + bin_width;
        real bin_mid = (bin_left + bin_right) / 2;  // Center of the bin.
        // Find data point closest to bin_mid.
        int k = 0;
        int min;
        while (bin_mid > w(k,0)) k++;
        if (w(k,0) - bin_mid > bin_mid - w(k-1,0))
            min = k -1;
        else
            min = k;
        bins[i].append(int(w(min, 1)));
        // Expand to get n samples in the bin.
        int count = 1;
        int right = min;
        int left = min;
        int to_add;
        while (count < n) {
            if (right + 1 < w.length()) {
                // We can get more data on our right.
                if (left - 1 >= 0) {
                    // We can get more data on our left.
                    if (w(right + 1,0) - bin_mid < bin_mid - w(left - 1,0)) {
                        // Next point to add is on our right.
                        right++;
                        to_add = right;
                    } else {
                        // Next point to add is on our left.
                        left--;
                        to_add = left;
                    }
                } else {
                    // No more data on the left.
                    right++;
                    to_add = right;
                }
            } else {
                // No more data on the right.
                left--;
                to_add = left;
            }
            bins[i].append(int(w(to_add, 1)));
            count++;
        }
    }
    return bins;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

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

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

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

Reimplemented from PLearn::Binner.

Definition at line 71 of file SoftHistogramBinner.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Binner.

Definition at line 193 of file SoftHistogramBinner.cc.

References PLERROR.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields 
    // ### that you wish to be deepCopied rather than 
    // ### shallow-copied.
    // ### ex:
    // deepCopyField(trainvec, copies);

    // ### Remove this line when you have fully implemented this method.
    PLERROR("SoftHistogramBinner::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}
int PLearn::SoftHistogramBinner::nBins ( ) const [virtual]

Return the number of bins computed by this binner.

Reimplemented from PLearn::Binner.

Definition at line 210 of file SoftHistogramBinner.cc.

                                     {
    return n_bins;
}

Member Data Documentation

Reimplemented from PLearn::Binner.

Definition at line 110 of file SoftHistogramBinner.h.

Definition at line 73 of file SoftHistogramBinner.h.

Referenced by declareOptions().

Definition at line 74 of file SoftHistogramBinner.h.

Referenced by declareOptions().


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