PLearn 0.1
TestMethod.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // PLearn (A C++ Machine Learning Library)
00004 // Copyright (C) 2002 Pascal Vincent, Frederic Morin
00005 
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 // 
00009 //  1. Redistributions of source code must retain the above copyright
00010 //     notice, this list of conditions and the following disclaimer.
00011 // 
00012 //  2. Redistributions in binary form must reproduce the above copyright
00013 //     notice, this list of conditions and the following disclaimer in the
00014 //     documentation and/or other materials provided with the distribution.
00015 // 
00016 //  3. The name of the authors may not be used to endorse or promote
00017 //     products derived from this software without specific prior written
00018 //     permission.
00019 // 
00020 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00021 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00022 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00023 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00025 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 // 
00031 // This file is part of the PLearn library. For more information on the PLearn
00032 // library, go to the PLearn Web site at www.plearn.org
00033 
00034 
00035  
00036 
00037 /* *******************************************************      
00038  * $Id: TestMethod.cc 3994 2005-08-25 13:35:03Z chapados $
00039  * AUTHORS: Pascal Vincent & Frederic Morin
00040  * This file is part of the PLearn library.
00041  ******************************************************* */
00042 
00043 #include "TestMethod.h"
00044 
00045 namespace PLearn {
00046 
00047 // ###### TestMethod ##########################################################
00048 
00049 PLEARN_IMPLEMENT_OBJECT(TestMethod, "ONE LINE DESCR", "NO HELP");
00050 
00051 
00052 /*
00053   Vec TestMethod::test(PP<Learner> learner, const VMat &dataset)
00054   {
00055   int nsp = splitter->nsplits(); 
00056   int nst = statnames.length();
00057   Vec results(nst);
00058 
00059   // First parse the desired statnames
00060 
00061   TVec<string> extstat(nst);
00062   TVec<string> intstat(nst);
00063   TVec<int> costindex(nst);
00064   TVec<int> setnum(nst);
00065 
00066   for(int i=0; i<nst; i++)
00067   {          
00068   string costname;
00069   parse_statname(statnames[i], extstat[i], intstat[i], setnum[i], costname);
00070   if(setnum==0) // train cost
00071   costindex[i] = learner->getTrainCostIndex(costname);
00072   else // test cost
00073   costindex[i] = learner->getTestCostIndex(costname);
00074   }
00075 
00076   // The global stats collector
00077   VecStatsCollector globalstats;
00078 
00079   // Now train/test and collect stats
00080   TVec<VecStatsCollector> stats;
00081 
00082   for(int k=0; k<nsp; k++)
00083   {
00084   Array<VMat> split = splitter->getSplit(k);
00085   stats.resize(split.size());
00086 
00087   if(forget_learner)
00088   learner->forget();
00089       
00090   // train
00091   VecStatsCollector& st = stats[0];
00092   learner->setTrainingSet(split[0]);
00093   st.forget();
00094   learner->newtrain(st);
00095   st.finalize();
00096 
00097   // tests
00098   for(int m=1; m<split.size(); m++)
00099   {
00100   VMat testset = split[m];
00101   VecStatsCollector& st = stats[m];
00102   st.forget();
00103   learner->newtest(testset,st);
00104   st.finalize();
00105   }
00106 
00107   for(int i=0; i<nst; i++)
00108   results[i] = stats[setnum[i]].getStats(costindex[i]).getStat(intstat[i]);
00109 
00110   globalstats.update(results);
00111   }
00112 
00113   globalstats.finalize();
00114 
00115   for(int i=0; i<nst; i++)
00116   results[i] = globalstats.getStats(i).getStat(extstat[i]);
00117 
00118   return results;
00119   }
00120 */
00121 
00122 void TestMethod::build_()
00123 {
00124 }
00125 
00126 void TestMethod::build()
00127 {
00128     inherited::build();
00129     build_();
00130 }
00131 
00132 void
00133 TestMethod::declareOptions(OptionList &ol)
00134 {
00135     declareOption(ol, "splitter", &TestMethod::splitter, OptionBase::buildoption,
00136                   "Splitter object defining the test method");
00137     declareOption(ol, "statnames", &TestMethod::statnames, OptionBase::buildoption,
00138                   "A vector of strings containing train/test statistics definitions of the train/test stats whose values should be returned by the test method.\n"
00139                   "Ex: E[E[train.class_error]]");
00140     declareOption(ol, "forget_learner", &TestMethod::forget_learner, OptionBase::buildoption,
00141                   "Should we call forget on the learner prior to every train?");
00142     inherited::declareOptions(ol);
00143 }
00144 
00145 
00146 
00147 }; // end of namespace PLearn
00148 
00149 
00150 /*
00151   Local Variables:
00152   mode:c++
00153   c-basic-offset:4
00154   c-file-style:"stroustrup"
00155   c-file-offsets:((innamespace . 0)(inline-open . 0))
00156   indent-tabs-mode:nil
00157   fill-column:79
00158   End:
00159 */
00160 // 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