PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // TestingLearner.cc 00004 // 00005 // Copyright (C) 2004 Marius Muja 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 /* ******************************************************* 00036 * $Id: TestingLearner.cc 3994 2005-08-25 13:35:03Z chapados $ 00037 ******************************************************* */ 00038 00039 // Authors: Marius Muja 00040 00044 #include "TestingLearner.h" 00045 00046 namespace PLearn { 00047 using namespace std; 00048 00049 TestingLearner::TestingLearner() 00050 { 00051 // ... 00052 00053 // ### You may or may not want to call build_() to finish building the object 00054 // build_(); 00055 } 00056 00057 PLEARN_IMPLEMENT_OBJECT(TestingLearner, 00058 "This learner can be used to perform a given experiment on different datasets.", 00059 "The experiment's costs are returned in this learner's training costs.\n" 00060 "You do not need to specify the underlying PTester's experiment directory,\n" 00061 "nor its dataset, as they will be set by this learner.\n" 00062 ); 00063 00064 void TestingLearner::declareOptions(OptionList& ol) 00065 { 00066 // ### Declare all of this object's options here 00067 // ### For the "flags" of each option, you should typically specify 00068 // ### one of OptionBase::buildoption, OptionBase::learntoption or 00069 // ### OptionBase::tuningoption. Another possible flag to be combined with 00070 // ### is OptionBase::nosave 00071 00072 00073 declareOption(ol, "tester", &TestingLearner::tester, OptionBase::buildoption, 00074 "The tester used by the TestingLearner."); 00075 00076 // Now call the parent class' declareOptions 00077 inherited::declareOptions(ol); 00078 } 00079 00080 void TestingLearner::build_() 00081 { 00082 } 00083 00084 // ### Nothing to add here, simply calls build_ 00085 void TestingLearner::build() 00086 { 00087 inherited::build(); 00088 build_(); 00089 } 00090 00091 00092 void TestingLearner::makeDeepCopyFromShallowCopy(CopiesMap& copies) 00093 { 00094 inherited::makeDeepCopyFromShallowCopy(copies); 00095 00096 // ### Call deepCopyField on all "pointer-like" fields 00097 // ### that you wish to be deepCopied rather than 00098 // ### shallow-copied. 00099 // ### ex: 00100 // deepCopyField(trainvec, copies); 00101 00102 // ### Remove this line when you have fully implemented this method. 00103 PLERROR("TestingLearner::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); 00104 } 00105 00106 00107 int TestingLearner::outputsize() const 00108 { 00109 return 0; 00110 } 00111 00112 void TestingLearner::forget() 00113 { 00114 stage = 0; 00115 } 00116 00117 void TestingLearner::train() 00118 { 00119 if (stage > 0) { 00120 PLWARNING("In TestingLearner::train - Learner has already been trained"); 00121 return; 00122 } 00123 train_stats->update(tester->perform(true)); 00124 train_stats->setFieldNames(tester->getStatNames()); 00125 stage = 1; 00126 } 00127 00128 00129 void TestingLearner::computeOutput(const Vec& input, Vec& output) const 00130 { 00131 output.resize(0); 00132 } 00133 00134 void TestingLearner::computeCostsFromOutputs(const Vec& input, const Vec& output, 00135 const Vec& target, Vec& costs) const 00136 { 00137 // Compute the costs from *already* computed output. 00138 // ... 00139 } 00140 00141 TVec<string> TestingLearner::getTestCostNames() const 00142 { 00143 static TVec<string> no_cost; 00144 return no_cost; 00145 } 00146 00147 TVec<string> TestingLearner::getTrainCostNames() const 00148 { 00149 return tester->getStatNames(); 00150 } 00151 00152 void TestingLearner::setTrainingSet(VMat training_set, bool call_forget) 00153 { 00154 inherited::setTrainingSet(training_set, call_forget); 00155 tester->dataset = training_set; 00156 } 00157 00158 void TestingLearner::setExperimentDirectory(const PPath& the_expdir) 00159 { 00160 tester->setExperimentDirectory(the_expdir); 00161 } 00162 00163 } // end of namespace PLearn 00164 00165 00166 /* 00167 Local Variables: 00168 mode:c++ 00169 c-basic-offset:4 00170 c-file-style:"stroustrup" 00171 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00172 indent-tabs-mode:nil 00173 fill-column:79 00174 End: 00175 */ 00176 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :