PLearn 0.1
EmbeddedLearner.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // EmbeddedLearner.h
00004 // 
00005 // Copyright (C) 2002 Frederic Morin
00006 // Copyright (C) 2003 Pascal Vincent
00007 // 
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions are met:
00010 // 
00011 //  1. Redistributions of source code must retain the above copyright
00012 //     notice, this list of conditions and the following disclaimer.
00013 // 
00014 //  2. Redistributions in binary form must reproduce the above copyright
00015 //     notice, this list of conditions and the following disclaimer in the
00016 //     documentation and/or other materials provided with the distribution.
00017 // 
00018 //  3. The name of the authors may not be used to endorse or promote
00019 //     products derived from this software without specific prior written
00020 //     permission.
00021 // 
00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 // 
00033 // This file is part of the PLearn library. For more information on the PLearn
00034 // library, go to the PLearn Web site at www.plearn.org
00035 
00036 /* *******************************************************      
00037  * $Id: EmbeddedLearner.h 9108 2008-06-06 20:46:44Z louradou $ 
00038  ******************************************************* */
00039 
00041 #ifndef EmbeddedLearner_INC
00042 #define EmbeddedLearner_INC
00043 
00044 #include "PLearner.h"
00045 
00046 namespace PLearn {
00047 using namespace std;
00048 
00049 // ###### EmbeddedLearner ######################################################
00050 
00051 class EmbeddedLearner: public PLearner
00052 {
00053     typedef PLearner inherited;
00054 
00055 public:
00056 
00058     PP<PLearner> learner_;
00059 
00060     inline PP<PLearner> getLearner() const
00061     { return learner_; }
00062 
00064     string expdir_append;
00065 
00066     bool forward_test;
00067     bool provide_learner_expdir;
00068 
00069     bool forward_nstages;
00070     // ****************
00071     // * Constructors *
00072     // ****************
00073 
00074     // Default constructor, make sure the implementation in the .cc
00075     // initializes all fields to reasonable default values.
00076     EmbeddedLearner(string expdir_append = "");
00077 
00078     // ******************
00079     // * Object methods *
00080     // ******************
00081 
00082 private: 
00084     void build_();
00085 
00086 protected: 
00087 
00089     static void declareOptions(OptionList& ol);
00090 
00092     static void declareMethods(RemoteMethodMap& rmm);
00093 
00095     void setInnerLearnerTrainingSet(VMat training_set, bool call_forget);
00096     
00097 public:
00098     // simply calls inherited::build() then build_() 
00099     virtual void build();
00100 
00102     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00103 
00105     PLEARN_DECLARE_OBJECT(EmbeddedLearner);
00106 
00107     // *******************
00108     // * PLearner methods *
00109     // *******************
00110 
00112     virtual void setTrainingSet(VMat training_set, bool call_forget=true);
00113 
00115     virtual void setValidationSet(VMat validset);
00116 
00118     virtual void setTrainStatsCollector(PP<VecStatsCollector> statscol);
00119 
00121     virtual void setExperimentDirectory(const PPath& the_expdir);
00122 
00124     virtual int inputsize() const;
00125   
00127     virtual int targetsize() const; 
00128   
00130     virtual int outputsize() const;
00131 
00133     virtual void forget();
00134 
00136     virtual void train();
00137 
00139     virtual void computeOutput(const Vec& input, Vec& output) const;
00140 
00142     virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 
00143                                          const Vec& target, Vec& costs) const;
00144                               
00146     virtual void computeOutputAndCosts(const Vec& input, const Vec& target,
00147                                        Vec& output, Vec& costs) const;
00148 
00150     virtual void computeOutputsAndCosts(const Mat& input, const Mat& target,
00151                                        Mat& output, Mat& costs) const;
00152 
00154     virtual
00155     bool computeConfidenceFromOutput(const Vec& input, const Vec& output,
00156                                      real probability,
00157                                      TVec< pair<real,real> >& intervals) const;
00158   
00164     virtual void test(VMat testset, PP<VecStatsCollector> test_stats, 
00165                       VMat testoutputs=0, VMat testcosts=0) const;
00166 
00167     // NOT forwarded by default
00168     // virtual void computeCostsOnly(const Vec& input, const Vec& target,
00169     //                               Vec& costs) const;
00170 
00171     // NOT forwarded by default
00172     // virtual void use(VMat testset, VMat outputs) const;
00173 
00174     // NOT forwarded by default
00175     // virtual void useOnTrain(Mat& outputs) const;  
00176   
00178     virtual TVec<string> getTestCostNames() const;
00179 
00181     virtual TVec<string> getTrainCostNames() const;
00182 
00184     virtual TVec<string> getOutputNames() const;
00185 
00187     // virtual int nTestCosts() const;
00188 
00190     // virtual int nTrainCosts() const;
00191 
00193     virtual void resetInternalState();
00194 
00196     virtual bool isStatefulLearner() const;
00197 };
00198 
00199 // Declares a few other classes and functions related to this class
00200 DECLARE_OBJECT_PTR(EmbeddedLearner);
00201   
00202 } // end of namespace PLearn
00203 
00204 #endif
00205 
00206 
00207 /*
00208   Local Variables:
00209   mode:c++
00210   c-basic-offset:4
00211   c-file-style:"stroustrup"
00212   c-file-offsets:((innamespace . 0)(inline-open . 0))
00213   indent-tabs-mode:nil
00214   fill-column:79
00215   End:
00216 */
00217 // 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