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,v 1.2 2004/07/19 22:47:00 mariusmuja Exp $ 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, "ONE LINE DESCRIPTION", "MULTI-LINE \nHELP"); 00058 00059 void TestingLearner::declareOptions(OptionList& ol) 00060 { 00061 // ### Declare all of this object's options here 00062 // ### For the "flags" of each option, you should typically specify 00063 // ### one of OptionBase::buildoption, OptionBase::learntoption or 00064 // ### OptionBase::tuningoption. Another possible flag to be combined with 00065 // ### is OptionBase::nosave 00066 00067 00068 declareOption(ol, "tester", &TestingLearner::tester, OptionBase::buildoption, 00069 "The tester used by the TestingLearner."); 00070 00071 // Now call the parent class' declareOptions 00072 inherited::declareOptions(ol); 00073 } 00074 00075 void TestingLearner::build_() 00076 { 00077 } 00078 00079 // ### Nothing to add here, simply calls build_ 00080 void TestingLearner::build() 00081 { 00082 inherited::build(); 00083 build_(); 00084 } 00085 00086 00087 void TestingLearner::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00088 { 00089 inherited::makeDeepCopyFromShallowCopy(copies); 00090 00091 // ### Call deepCopyField on all "pointer-like" fields 00092 // ### that you wish to be deepCopied rather than 00093 // ### shallow-copied. 00094 // ### ex: 00095 // deepCopyField(trainvec, copies); 00096 00097 // ### Remove this line when you have fully implemented this method. 00098 PLERROR("TestingLearner::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); 00099 } 00100 00101 00102 int TestingLearner::outputsize() const 00103 { 00104 return tester->learner->outputsize(); 00105 } 00106 00107 void TestingLearner::forget() 00108 { 00109 stage = 0; 00110 } 00111 00112 void TestingLearner::train() 00113 { 00114 if (stage > 0) { 00115 PLWARNING("In TestingLearner::train - Learner has already been trained"); 00116 return; 00117 } 00118 train_stats->update(tester->perform(true)); 00119 train_stats->setFieldNames(tester->getStatNames()); 00120 stage = 1; 00121 } 00122 00123 00124 void TestingLearner::computeOutput(const Vec& input, Vec& output) const 00125 { 00126 // Compute the output from the input. 00127 // int nout = outputsize(); 00128 // output.resize(nout); 00129 // ... 00130 } 00131 00132 void TestingLearner::computeCostsFromOutputs(const Vec& input, const Vec& output, 00133 const Vec& target, Vec& costs) const 00134 { 00135 // Compute the costs from *already* computed output. 00136 // ... 00137 } 00138 00139 TVec<string> TestingLearner::getTestCostNames() const 00140 { 00141 TVec<string> result; 00142 00143 return result; 00144 } 00145 00146 TVec<string> TestingLearner::getTrainCostNames() const 00147 { 00148 return tester->getStatNames(); 00149 } 00150 00151 void TestingLearner::setTrainingSet(VMat training_set, bool call_forget) 00152 { 00153 inherited::setTrainingSet(training_set, call_forget); 00154 tester->dataset = training_set; 00155 } 00156 00157 00158 void TestingLearner::setExperimentDirectory(const string& the_expdir) 00159 { 00160 tester->setExperimentDirectory(the_expdir); 00161 } 00162 00163 } // end of namespace PLearn