PLearn 0.1
|
#include <SoftHistogramBinner.h>
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 OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SoftHistogramBinner * | deepCopy (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 PPath & | declaringFile () |
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. |
Definition at line 51 of file SoftHistogramBinner.h.
typedef Binner PLearn::SoftHistogramBinner::inherited [private] |
Reimplemented from PLearn::Binner.
Definition at line 56 of file SoftHistogramBinner.h.
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_(); }
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.
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.
{ inherited::build(); build_(); }
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'"); }
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); }
static const PPath& PLearn::SoftHistogramBinner::declaringFile | ( | ) | [inline, static] |
SoftHistogramBinner * PLearn::SoftHistogramBinner::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Binner.
Definition at line 71 of file SoftHistogramBinner.cc.
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; }
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; }
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().