PLearn 0.1
KernelProjection.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // KernelProjection.h
00004 //
00005 // Copyright (C) 2004 Olivier Delalleau 
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: KernelProjection.h 3994 2005-08-25 13:35:03Z chapados $ 
00037  ******************************************************* */
00038 
00039 // Authors: Olivier Delalleau
00040 
00044 #ifndef KernelProjection_INC
00045 #define KernelProjection_INC
00046 
00047 #include <plearn_learners/generic/PLearner.h>
00048 #include <plearn/ker/Kernel.h>
00049 
00050 namespace PLearn {
00051 using namespace std;
00052 
00053 class KernelProjection: public PLearner
00054 {
00055 
00056 private:
00057 
00058     typedef PLearner inherited;
00059 
00061     mutable Vec k_x_xi;
00062     mutable Mat result;
00063     mutable Mat used_eigenvectors;
00064   
00065 protected:
00066 
00067     // *********************
00068     // * protected options *
00069     // *********************
00070 
00071     int n_comp_kept;
00072     int n_examples;
00073 
00074     // Fields below are not options.
00075 
00077     mutable bool first_output;
00078 
00079     mutable Vec last_input;   
00080     mutable Vec last_output;  
00081     
00082 public:
00083 
00084     // ************************
00085     // * public build options *
00086     // ************************
00087 
00088     bool compute_costs;
00089     bool free_extra_components;
00090     int ignore_n_first;
00091     Ker kernel;
00092     real min_eigenvalue;
00093     int n_comp;
00094     int n_comp_for_cost;
00095     string normalize;
00096   
00097     // ************************
00098     // * public learnt options *
00099     // ************************
00100 
00101     Vec eigenvalues;
00102     Mat eigenvectors;
00103   
00104     // ****************
00105     // * Constructors *
00106     // ****************
00107 
00109     KernelProjection();
00110 
00111     // ********************
00112     // * PLearner methods *
00113     // ********************
00114 
00115 private: 
00116 
00118     void build_();
00119 
00120 protected: 
00121   
00123     static void declareOptions(OptionList& ol);
00124 
00125 public:
00126 
00128     virtual Vec getEigenvalues() {return eigenvalues;}
00129 
00130     // ************************
00131     // **** Object methods ****
00132     // ************************
00133 
00135     virtual void build();
00136 
00138     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00139 
00140     // Declares other standard object methods.
00141     PLEARN_DECLARE_OBJECT(KernelProjection);
00142 
00143     // **************************
00144     // **** PLearner methods ****
00145     // **************************
00146 
00149     virtual int outputsize() const;
00150 
00153     virtual void forget();
00154 
00157     virtual void train();
00158 
00160     virtual void computeOutput(const Vec& input, Vec& output) const;
00161 
00163     virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 
00164                                          const Vec& target, Vec& costs) const;
00165                                 
00167     virtual TVec<string> getTestCostNames() const;
00168 
00171     virtual TVec<string> getTrainCostNames() const;
00172 
00174     virtual void setTrainingSet(VMat training_set, bool call_forget=true);
00175 
00176     // *** SUBCLASS WRITING: ***
00177     // While in general not necessary, in case of particular needs 
00178     // (efficiency concerns for ex) you may also want to overload
00179     // some of the following methods:
00180     // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const;
00181     // virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const;
00182     // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, VMat testoutputs=0, VMat testcosts=0) const;
00183     // virtual int nTestCosts() const;
00184     // virtual int nTrainCosts() const;
00185 
00186 };
00187 
00188 // Declares a few other classes and functions related to this class.
00189 DECLARE_OBJECT_PTR(KernelProjection);
00190   
00191 } // end of namespace PLearn
00192 
00193 #endif
00194 
00195 
00196 /*
00197   Local Variables:
00198   mode:c++
00199   c-basic-offset:4
00200   c-file-style:"stroustrup"
00201   c-file-offsets:((innamespace . 0)(inline-open . 0))
00202   indent-tabs-mode:nil
00203   fill-column:79
00204   End:
00205 */
00206 // 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