PLearn 0.1
|
#include <RegressionTreeQueue.h>
Public Member Functions | |
RegressionTreeQueue () | |
RegressionTreeQueue (int verbosity, int maximum_number_of_nodes) | |
virtual | ~RegressionTreeQueue () |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual RegressionTreeQueue * | deepCopy (CopiesMap &copies) const |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be. | |
virtual void | build () |
Post-constructor. | |
void | addHeap (PP< RegressionTreeNode > new_node) |
PP< RegressionTreeNode > | popHeap () |
PP< RegressionTreeNode > | upHeap (PP< RegressionTreeNode > new_node, int node_ind) |
PP< RegressionTreeNode > | downHeap (PP< RegressionTreeNode > new_node, int node_ind) |
int | isEmpty () |
int | compareNode (PP< RegressionTreeNode > node1, PP< RegressionTreeNode > node2) |
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 PPath & | declaringFile () |
static void | declareOptions (OptionList &ol) |
Declare options (data fields) for the class. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Private Types | |
typedef Object | inherited |
Private Member Functions | |
void | build_ () |
Object-specific post-constructor. | |
void | verbose (string msg, int level) |
Private Attributes | |
int | verbosity |
int | maximum_number_of_nodes |
int | next_available_node |
TVec< PP< RegressionTreeNode > > | nodes |
Definition at line 51 of file RegressionTreeQueue.h.
typedef Object PLearn::RegressionTreeQueue::inherited [private] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.h.
PLearn::RegressionTreeQueue::RegressionTreeQueue | ( | ) |
Definition at line 55 of file RegressionTreeQueue.cc.
References build().
: verbosity(0), maximum_number_of_nodes(400), next_available_node(0) { build(); }
Definition at line 62 of file RegressionTreeQueue.cc.
References build().
: verbosity(verbosity_), maximum_number_of_nodes(maximum_number_of_nodes_), next_available_node(0) { build(); }
PLearn::RegressionTreeQueue::~RegressionTreeQueue | ( | ) | [virtual] |
Definition at line 70 of file RegressionTreeQueue.cc.
{ }
string PLearn::RegressionTreeQueue::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
OptionList & PLearn::RegressionTreeQueue::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
RemoteMethodMap & PLearn::RegressionTreeQueue::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
Object * PLearn::RegressionTreeQueue::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
StaticInitializer RegressionTreeQueue::_static_initializer_ & PLearn::RegressionTreeQueue::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
void PLearn::RegressionTreeQueue::addHeap | ( | PP< RegressionTreeNode > | new_node | ) |
Definition at line 108 of file RegressionTreeQueue.cc.
References maximum_number_of_nodes, next_available_node, nodes, PLERROR, PLearn::tostring(), and upHeap().
{ if (new_node->getErrorImprovment() < 0.0) { return; } if (next_available_node >= maximum_number_of_nodes){ string s = "RegressionTreeQueue: maximum number of entries exceeded (" +tostring(maximum_number_of_nodes)+")"; PLERROR(s.c_str()); } nodes[next_available_node] = upHeap(new_node, next_available_node); next_available_node += 1; }
void PLearn::RegressionTreeQueue::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::Object.
Definition at line 97 of file RegressionTreeQueue.cc.
References PLearn::Object::build(), and build_().
Referenced by RegressionTreeQueue().
{ inherited::build(); build_(); }
void PLearn::RegressionTreeQueue::build_ | ( | ) | [private] |
Object-specific post-constructor.
This method should be redefined in subclasses and do the actual building of the object according to previously set option fields. Constructors can just set option fields, and then call build_. This method is NOT virtual, and will typically be called only from three places: a constructor, the public virtual build()
method, and possibly the public virtual read method (which calls its parent's read). build_()
can assume that its parent's build_()
has already been called.
Reimplemented from PLearn::Object.
Definition at line 103 of file RegressionTreeQueue.cc.
References maximum_number_of_nodes, nodes, and PLearn::TVec< T >::resize().
Referenced by build().
{ nodes.resize(maximum_number_of_nodes); }
string PLearn::RegressionTreeQueue::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
int PLearn::RegressionTreeQueue::compareNode | ( | PP< RegressionTreeNode > | node1, |
PP< RegressionTreeNode > | node2 | ||
) |
Definition at line 177 of file RegressionTreeQueue.cc.
Referenced by downHeap(), and upHeap().
{ if (node1->getErrorImprovment() > node2->getErrorImprovment()) return -1; if (node1->getErrorImprovment() < node2->getErrorImprovment()) return +1; if (node1->getSplitBalance() < node2->getSplitBalance()) return -1; return +1; }
void PLearn::RegressionTreeQueue::declareOptions | ( | OptionList & | ol | ) | [static] |
Declare options (data fields) for the class.
Redefine this in subclasses: call declareOption
(...) for each option, and then call inherited::declareOptions(options)
. Please call the inherited
method AT THE END to get the options listed in a consistent order (from most recently defined to least recently defined).
static void MyDerivedClass::declareOptions(OptionList& ol) { declareOption(ol, "inputsize", &MyObject::inputsize_, OptionBase::buildoption, "The size of the input; it must be provided"); declareOption(ol, "weights", &MyObject::weights, OptionBase::learntoption, "The learned model weights"); inherited::declareOptions(ol); }
ol | List of options that is progressively being constructed for the current class. |
Reimplemented from PLearn::Object.
Definition at line 74 of file RegressionTreeQueue.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Object::declareOptions(), PLearn::OptionBase::learntoption, maximum_number_of_nodes, next_available_node, nodes, and verbosity.
{ declareOption(ol, "verbosity", &RegressionTreeQueue::verbosity, OptionBase::buildoption, "The desired level of verbosity\n"); declareOption(ol, "maximum_number_of_nodes", &RegressionTreeQueue::maximum_number_of_nodes, OptionBase::buildoption, "The maximum number of entries in the heap\n"); declareOption(ol, "next_available_node", &RegressionTreeQueue::next_available_node, OptionBase::learntoption, "The next available entry in the heap to add a node\n"); declareOption(ol, "nodes", &RegressionTreeQueue::nodes, OptionBase::learntoption, "The table of nodes kept with the best possible one to split on top\n"); inherited::declareOptions(ol); }
static const PPath& PLearn::RegressionTreeQueue::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Object.
Definition at line 77 of file RegressionTreeQueue.h.
: void build_();
RegressionTreeQueue * PLearn::RegressionTreeQueue::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
PP< RegressionTreeNode > PLearn::RegressionTreeQueue::downHeap | ( | PP< RegressionTreeNode > | new_node, |
int | node_ind | ||
) |
Definition at line 147 of file RegressionTreeQueue.cc.
References compareNode(), next_available_node, and nodes.
Referenced by popHeap().
{ int left_child_node; int right_child_node; int smallest_child_node; PP<RegressionTreeNode> saved_node; left_child_node = 2 * node_ind + 1; if (left_child_node >= next_available_node) return new_node; right_child_node = 2 * node_ind + 2; smallest_child_node = left_child_node; if (right_child_node < next_available_node) { if (compareNode(nodes[left_child_node], nodes[right_child_node]) > 0) { smallest_child_node = right_child_node; } } if (compareNode(new_node, nodes[smallest_child_node]) > 0) { saved_node = nodes[smallest_child_node]; nodes[smallest_child_node] = downHeap(new_node, smallest_child_node); return saved_node; } return new_node; }
OptionList & PLearn::RegressionTreeQueue::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
OptionMap & PLearn::RegressionTreeQueue::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
RemoteMethodMap & PLearn::RegressionTreeQueue::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file RegressionTreeQueue.cc.
int PLearn::RegressionTreeQueue::isEmpty | ( | ) |
Definition at line 172 of file RegressionTreeQueue.cc.
References next_available_node.
{ return next_available_node; }
void PLearn::RegressionTreeQueue::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.
This needs to be overridden by every class that adds "complex" data members to the class, such as Vec
, Mat
, PP<Something>
, etc. Typical implementation:
void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies) { inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(complex_data_member1, copies); deepCopyField(complex_data_member2, copies); ... }
copies | A map used by the deep-copy mechanism to keep track of already-copied objects. |
Reimplemented from PLearn::Object.
Definition at line 88 of file RegressionTreeQueue.cc.
References PLearn::deepCopyField(), PLearn::Object::makeDeepCopyFromShallowCopy(), maximum_number_of_nodes, next_available_node, nodes, and verbosity.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(verbosity, copies); deepCopyField(maximum_number_of_nodes, copies); deepCopyField(next_available_node, copies); deepCopyField(nodes, copies); }
PP< RegressionTreeNode > PLearn::RegressionTreeQueue::popHeap | ( | ) |
Definition at line 123 of file RegressionTreeQueue.cc.
References downHeap(), next_available_node, and nodes.
{ PP<RegressionTreeNode> return_value; return_value = nodes[0]; next_available_node -= 1; nodes[0] = downHeap(nodes[next_available_node], 0); return return_value; }
PP< RegressionTreeNode > PLearn::RegressionTreeQueue::upHeap | ( | PP< RegressionTreeNode > | new_node, |
int | node_ind | ||
) |
Definition at line 132 of file RegressionTreeQueue.cc.
References compareNode(), and nodes.
Referenced by addHeap().
{ int parent_node; PP<RegressionTreeNode> saved_node; if (node_ind == 0) return new_node; parent_node = (node_ind - 1) / 2; if (compareNode(new_node, nodes[parent_node]) < 0) { saved_node = nodes[parent_node]; nodes[parent_node] = upHeap(new_node, parent_node); return saved_node; } return new_node; }
void PLearn::RegressionTreeQueue::verbose | ( | string | msg, |
int | level | ||
) | [private] |
Definition at line 185 of file RegressionTreeQueue.cc.
References PLearn::endl(), and verbosity.
Reimplemented from PLearn::Object.
Definition at line 77 of file RegressionTreeQueue.h.
Definition at line 62 of file RegressionTreeQueue.h.
Referenced by addHeap(), build_(), declareOptions(), and makeDeepCopyFromShallowCopy().
Definition at line 68 of file RegressionTreeQueue.h.
Referenced by addHeap(), declareOptions(), downHeap(), isEmpty(), makeDeepCopyFromShallowCopy(), and popHeap().
TVec< PP<RegressionTreeNode> > PLearn::RegressionTreeQueue::nodes [private] |
Definition at line 69 of file RegressionTreeQueue.h.
Referenced by addHeap(), build_(), declareOptions(), downHeap(), makeDeepCopyFromShallowCopy(), popHeap(), and upHeap().
int PLearn::RegressionTreeQueue::verbosity [private] |
Definition at line 61 of file RegressionTreeQueue.h.
Referenced by declareOptions(), makeDeepCopyFromShallowCopy(), and verbose().