PLearn 0.1
TangentLearner.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // TangentLearner.h
00004 //
00005 // Copyright (C) 2004 Martin Monperrus & Yoshua Bengio
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: TangentLearner.h 3994 2005-08-25 13:35:03Z chapados $ 
00037  ******************************************************* */
00038 
00039 // Authors: Martin Monperrus & Yoshua Bengio
00040 
00044 #ifndef TangentLearner_INC
00045 #define TangentLearner_INC
00046 
00047 #include <plearn_learners/generic/PLearner.h>
00048 #include <plearn/var/Func.h>
00049 #include <plearn/opt/Optimizer.h>
00050 
00051 namespace PLearn {
00052 using namespace std;
00053 
00054 class TangentLearner: public PLearner
00055 {
00056 
00057 private:
00058 
00059     typedef PLearner inherited;
00060   
00061 protected:
00062     // NON-OPTION FIELDS
00063 
00064     Func cost_of_one_example;
00065     Var b, W, c, V; // explicit view of the parameters (also in parameters field).
00066     Var tangent_targets; // target for the tangent vectors for one example 
00067 
00068     // *********************
00069     // * protected options *
00070     // *********************
00071 
00072     // ### declare protected option fields (such as learnt parameters) here
00073     VarArray parameters;
00074 
00075 public:
00076 
00077     // ************************
00078     // * public build options *
00079     // ************************
00080 
00081     // ### declare public option fields (such as build options) here
00082 
00083     string training_targets; // "local_evectors", "local_neighbors"
00084     bool use_subspace_distance;
00085     bool normalize_by_neighbor_distance;
00086     bool ordered_vectors;
00087     real smart_initialization;
00088     real initialization_regularization;
00089     int n_neighbors; // number of neighbors used in local_pca or number of neighbors to predict
00090     int n_dim; // number of reduced dimensions (number of tangent vectors to compute)
00091 
00092     PP<Optimizer> optimizer; // to estimate the function that predicts local tangent vectors given the input
00093     Var embedding;
00094     Func output_f;
00095     Func tangent_predictor; // predicts local tangent vector given the input, and some parameters
00096     Func projection_error_f; // map output to projection error
00097 
00098     // manual construction of the tangent_predictor
00099     string architecture_type; // "neural_network" or "linear" or "" or "embedding_neural_nework" or "embedding_quadratic" 
00100     string output_type; // "tangent_plane", "embedding", or "tangent_plane+embedding".
00101     int n_hidden_units;
00102 
00103     int batch_size;
00104 
00105     real norm_penalization; // penalizes sum_i (||f_i||^2-1)^2
00106     real svd_threshold;
00107     real projection_error_regularization; // term to add on linear system diagonal, to solve for subspace fitting
00108     real V_slack; // 2nd argument of no_bprop(V,V_slack) used to replace outside V in slack_embedding_neural_network
00109 
00110     // ****************
00111     // * Constructors *
00112     // ****************
00113 
00115     // (Make sure the implementation in the .cc
00116     // initializes all fields to reasonable default values)
00117     TangentLearner();
00118 
00119 
00120     // ********************
00121     // * PLearner methods *
00122     // ********************
00123 
00124 private: 
00125 
00127     // (Please implement in .cc)
00128     void build_();
00129 
00130 protected: 
00131   
00133     // (Please implement in .cc)
00134     static void declareOptions(OptionList& ol);
00135 
00136 public:
00137 
00138     // ************************
00139     // **** Object methods ****
00140     // ************************
00141 
00143     virtual void build();
00144 
00146     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00147 
00148     // Declares other standard object methods.
00149     // If your class is not instantiatable (it has pure virtual methods)
00150     // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS.
00151     PLEARN_DECLARE_OBJECT(TangentLearner);
00152 
00153 
00154     // **************************
00155     // **** PLearner methods ****
00156     // **************************
00157 
00160     virtual int outputsize() const;
00161 
00164     virtual void forget();
00165     virtual void initializeParams();
00166 
00167     
00170     virtual void train();
00171 
00172 
00174     // (PLEASE IMPLEMENT IN .cc)
00175     virtual void computeOutput(const Vec& input, Vec& output) const;
00176 
00178     // (PLEASE IMPLEMENT IN .cc)
00179     virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 
00180                                          const Vec& target, Vec& costs) const;
00181                                 
00182 
00184     // (PLEASE IMPLEMENT IN .cc)
00185     virtual TVec<string> getTestCostNames() const;
00186 
00189     // (PLEASE IMPLEMENT IN .cc)
00190     virtual TVec<string> getTrainCostNames() const;
00191 
00192 
00193     // *** SUBCLASS WRITING: ***
00194     // While in general not necessary, in case of particular needs 
00195     // (efficiency concerns for ex) you may also want to overload
00196     // some of the following methods:
00197     // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const;
00198     // virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const;
00199     // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, VMat testoutputs=0, VMat testcosts=0) const;
00200     // virtual int nTestCosts() const;
00201     // virtual int nTrainCosts() const;
00202 
00203 };
00204 
00205 // Declares a few other classes and functions related to this class.
00206 DECLARE_OBJECT_PTR(TangentLearner);
00207   
00208 } // end of namespace PLearn
00209 
00210 #endif
00211 
00212 
00213 /*
00214   Local Variables:
00215   mode:c++
00216   c-basic-offset:4
00217   c-file-style:"stroustrup"
00218   c-file-offsets:((innamespace . 0)(inline-open . 0))
00219   indent-tabs-mode:nil
00220   fill-column:79
00221   End:
00222 */
00223 // 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