PLearn 0.1
|
#include <HyperSetOption.h>
Public Member Functions | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual HyperSetOption * | deepCopy (CopiesMap &copies) const |
HyperSetOption () | |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual Vec | optimize () |
Executes the command, returning the resulting costvec of its optimization (or an empty vec if it didn't do any testng). | |
virtual TVec< string > | getResultNames () const |
Returns the names of the results returned by the optimize() method. | |
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 Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
string | option_name |
string | option_value |
TVec< pair< string, string > > | options |
bool | call_build |
Private Types | |
typedef HyperCommand | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 53 of file HyperSetOption.h.
typedef HyperCommand PLearn::HyperSetOption::inherited [private] |
Reimplemented from PLearn::HyperCommand.
Definition at line 57 of file HyperSetOption.h.
PLearn::HyperSetOption::HyperSetOption | ( | ) |
Definition at line 61 of file HyperSetOption.cc.
: call_build(false) {}
string PLearn::HyperSetOption::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::HyperCommand.
Definition at line 56 of file HyperSetOption.cc.
OptionList & PLearn::HyperSetOption::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::HyperCommand.
Definition at line 56 of file HyperSetOption.cc.
RemoteMethodMap & PLearn::HyperSetOption::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::HyperCommand.
Definition at line 56 of file HyperSetOption.cc.
Reimplemented from PLearn::HyperCommand.
Definition at line 56 of file HyperSetOption.cc.
Object * PLearn::HyperSetOption::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 56 of file HyperSetOption.cc.
StaticInitializer HyperSetOption::_static_initializer_ & PLearn::HyperSetOption::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::HyperCommand.
Definition at line 56 of file HyperSetOption.cc.
void PLearn::HyperSetOption::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::HyperCommand.
Definition at line 104 of file HyperSetOption.cc.
References PLearn::HyperCommand::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::HyperSetOption::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::HyperCommand.
Definition at line 97 of file HyperSetOption.cc.
Referenced by build().
{ }
string PLearn::HyperSetOption::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file HyperSetOption.cc.
void PLearn::HyperSetOption::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::HyperCommand.
Definition at line 68 of file HyperSetOption.cc.
References PLearn::OptionBase::buildoption, call_build, PLearn::declareOption(), PLearn::HyperCommand::declareOptions(), option_name, option_value, and options.
{ // TODO Deprecated 'option_name' and 'option_value'. declareOption(ol, "option_name", &HyperSetOption::option_name, OptionBase::buildoption, "Name of a single option to set."); declareOption(ol, "option_value", &HyperSetOption::option_value, OptionBase::buildoption, "Value 'option_name' should be set to."); declareOption(ol, "options", &HyperSetOption::options, OptionBase::buildoption, "List of pairs \"optionname\":\"optionvalue\" to set."); declareOption(ol, "call_build", &HyperSetOption::call_build, OptionBase::buildoption, "If set to 1, then the learner and its sub-objects will be re-built\n" "if (and only if) one of their options has been changed, or an\n" "option of one of their sub-objects has been changed."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::HyperSetOption::declaringFile | ( | ) | [inline, static] |
HyperSetOption * PLearn::HyperSetOption::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::HyperCommand.
Definition at line 56 of file HyperSetOption.cc.
OptionList & PLearn::HyperSetOption::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file HyperSetOption.cc.
OptionMap & PLearn::HyperSetOption::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file HyperSetOption.cc.
RemoteMethodMap & PLearn::HyperSetOption::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file HyperSetOption.cc.
TVec< string > PLearn::HyperSetOption::getResultNames | ( | ) | const [virtual] |
Returns the names of the results returned by the optimize() method.
Implements PLearn::HyperCommand.
Definition at line 233 of file HyperSetOption.cc.
{
return TVec<string>();
}
void PLearn::HyperSetOption::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::HyperCommand.
Definition at line 113 of file HyperSetOption.cc.
References PLearn::deepCopyField(), PLearn::HyperCommand::makeDeepCopyFromShallowCopy(), and options.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(options, copies); }
Vec PLearn::HyperSetOption::optimize | ( | ) | [virtual] |
Executes the command, returning the resulting costvec of its optimization (or an empty vec if it didn't do any testng).
Implements PLearn::HyperCommand.
Definition at line 122 of file HyperSetOption.cc.
References call_build, PLearn::endl(), PLearn::EmbeddedLearner::getLearner(), PLearn::HyperCommand::hlearner, i, PLearn::TVec< T >::isEmpty(), PLearn::TVec< T >::length(), option_name, option_value, options, PLASSERT, PLCHECK, PLERROR, PLearn::TVec< T >::push_back(), PLearn::HyperLearner::setLearnerOptions(), PLearn::TVec< T >::size(), and PLearn::toint().
{ TVec<string> names, values; if (option_name != "") { names.push_back(option_name); values.push_back(option_value); } for (int i=0; i<options.size(); ++i) { names.push_back(options[i].first); values.push_back(options[i].second); } hlearner->setLearnerOptions(names, values); if (call_build && !names.isEmpty()) { // Call build on all objects affected by the changes. // We need to ensure this is done in the correct order. // Map each object that needs to be built to its parent. map<Object*, Object*> parent; // Map each object that needs to be built to the number of its children // that have to be built first. map<Object*, int> n_children_must_build; // Build the above maps. for (int i = 0; i < names.length(); i++) { string option = names[i]; Object* object = hlearner->getLearner(); Object* previous_object = NULL; while (true) { // Update maps if necessary. if (parent.find(object) == parent.end()) { parent[object] = previous_object; if (previous_object) n_children_must_build[previous_object]++; } if (n_children_must_build.find(object) == n_children_must_build.end()) n_children_must_build[object] = 0; // Continue to next object. size_t dot_pos = option.find('.'); if (dot_pos == string::npos) break; size_t bracket_pos = option.find(']'); bool indexed_object = (dot_pos == bracket_pos + 1); string sub_object_opt; int index = -1; if (indexed_object) { size_t left_bracket_pos = option.find('['); sub_object_opt = option.substr(0, left_bracket_pos); index = toint(option.substr(left_bracket_pos + 1, bracket_pos)); PLCHECK( index >= 0 ); } else { sub_object_opt = option.substr(0, dot_pos); } OptionList& options = object->getOptionList(); bool found = false; for (OptionList::iterator it = options.begin(); it != options.end(); ++it) { if ((*it)->optionname() == sub_object_opt) { previous_object = object; if (indexed_object) { object = (*it)->getIndexedObject(object, index); } else { object = (*it)->getAsObject(object); } found = true; break; } } if (!found) PLERROR("In HyperSetOption::optimize - Could not find " "option '%s' in an object of class '%s'", sub_object_opt.c_str(), object->classname().c_str()); option = option.substr(dot_pos + 1); } } // Build objects in the correct order. bool finished = false; size_t count_builds = 0; while (!finished) { finished = true; map<Object*, int>::iterator it = n_children_must_build.begin(); for (; it != n_children_must_build.end(); it++) { if (it->second == 0) { // This object is ready to be built. DBG_MODULE_LOG << "Building a " << it->first->classname() << endl; it->first->build(); it->second = -1; finished = false; Object* parent_obj = parent[it->first]; if (parent_obj) { PLASSERT( n_children_must_build.find(parent_obj) != n_children_must_build.end() ); n_children_must_build[parent_obj]--; } count_builds++; } } } PLASSERT( count_builds == n_children_must_build.size() ); DBG_MODULE_LOG << "All necessary builds performed" << endl; } return Vec(); }
Reimplemented from PLearn::HyperCommand.
Definition at line 61 of file HyperSetOption.h.
bool PLearn::HyperSetOption::call_build [protected] |
Definition at line 71 of file HyperSetOption.h.
Referenced by declareOptions(), and optimize().
string PLearn::HyperSetOption::option_name [protected] |
Definition at line 61 of file HyperSetOption.h.
Referenced by declareOptions(), and optimize().
string PLearn::HyperSetOption::option_value [protected] |
Definition at line 67 of file HyperSetOption.h.
Referenced by declareOptions(), and optimize().
TVec< pair<string, string> > PLearn::HyperSetOption::options [protected] |
Definition at line 69 of file HyperSetOption.h.
Referenced by declareOptions(), makeDeepCopyFromShallowCopy(), and optimize().