PLearn 0.1
HyperCommand.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // HyperCommand.cc
00004 //
00005 // Copyright (C) 2003-2004 ApSTAT Technologies Inc.
00006 //
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 //
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 //
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 //
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 //
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 //
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 // Author: Pascal Vincent
00036 
00037 /* *******************************************************
00038  * $Id: HyperCommand.cc 9171 2008-06-26 15:27:22Z chapados $
00039  ******************************************************* */
00040 
00043 #include "HyperCommand.h"
00044 #include "HyperLearner.h"
00045 #include <plearn/io/fileutils.h> 
00046 
00047 namespace PLearn {
00048 using namespace std;
00049 
00050 HyperCommand::HyperCommand()
00051     : verbosity(0)
00052 {
00053 }
00054 
00055 PLEARN_IMPLEMENT_ABSTRACT_OBJECT(HyperCommand,
00056                                  "HyperCommand is the base class for hyper-optimization "
00057                                  "commands to be used in the strategy of a HyperLearner",
00058                                  "");
00059 
00060 void HyperCommand::setExperimentDirectory(const PPath& the_expdir)
00061 {
00062     if(the_expdir=="")
00063         expdir = "";
00064     else
00065     {
00066         if(!force_mkdir(the_expdir))
00067             PLERROR("In PLearner::setExperimentDirectory Could not create experiment directory %s",the_expdir.c_str());
00068         expdir = the_expdir.absolute();
00069     }
00070 }
00071 
00072 void HyperCommand::declareOptions(OptionList& ol)
00073 {
00074     // Now call the parent class' declareOptions
00075     inherited::declareOptions(ol);
00076 
00077     declareOption(
00078         ol, "verbosity", &HyperCommand::verbosity, OptionBase::buildoption,
00079         " The verbosity level. Default to 0.");
00080 }
00081 
00082 void HyperCommand::declareMethods(RemoteMethodMap& rmm)
00083 {
00084     // Insert a backpointer to remote methods; note that this is different from
00085     // declareOptions().
00086     rmm.inherited(inherited::_getRemoteMethodMap_());
00087 
00088     declareMethod(
00089         rmm, "forget", &HyperCommand::forget,
00090         (BodyDoc("Resets the command's internal state as if freshly constructed")));
00091 
00092     declareMethod(
00093         rmm, "optimize", &HyperCommand::optimize,
00094         (BodyDoc("Executes the command, returning the resulting costvec of its optimization\n"
00095                  "(or an empty vec if it didn't do any testng)."),
00096          RetDoc ("Cost vectors arising from optimization")));
00097 
00098     declareMethod(
00099         rmm, "getResultNames", &HyperCommand::getResultNames,
00100         (BodyDoc("Returns the names of the results returned by the optimize() method"),
00101          RetDoc ("Vector of strings containing the result names")));
00102 }
00103 
00104 void HyperCommand::build_()
00105 {
00106     // ### This method should do the real building of the object,
00107     // ### according to set 'options', in *any* situation.
00108     // ### Typical situations include:
00109     // ###  - Initial building of an object from a few user-specified options
00110     // ###  - Building of a "reloaded" object: i.e. from the complete set of all serialised options.
00111     // ###  - Updating or "re-building" of an object after a few "tuning" options have been modified.
00112     // ### You should assume that the parent class' build_() has already been called.
00113 }
00114 
00115 // ### Nothing to add here, simply calls build_
00116 void HyperCommand::build()
00117 {
00118     inherited::build();
00119     build_();
00120 }
00121 
00122 void HyperCommand::forget()
00123 {}
00124 
00125 
00126 void HyperCommand::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00127 {
00128     inherited::makeDeepCopyFromShallowCopy(copies);
00129     deepCopyField(hlearner, copies);
00130 }
00131 
00132 } // end of namespace PLearn
00133 
00134 
00135 /*
00136   Local Variables:
00137   mode:c++
00138   c-basic-offset:4
00139   c-file-style:"stroustrup"
00140   c-file-offsets:((innamespace . 0)(inline-open . 0))
00141   indent-tabs-mode:nil
00142   fill-column:79
00143   End:
00144 */
00145 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines