PLearn 0.1
RBMTrainer.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // RBMTrainer.h
00004 //
00005 // Copyright (C) 2007 Pascal Lamblin
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 // Authors: Pascal Lamblin
00036 
00040 #ifndef RBMTrainer_INC
00041 #define RBMTrainer_INC
00042 
00043 #include <plearn/base/Object.h>
00044 #include <plearn/vmat/VMat.h>
00045 #include <plearn_learners/online/RBMModule.h>
00046 
00047 namespace PLearn {
00048 
00059 class RBMTrainer : public Object
00060 {
00061     typedef Object inherited;
00062 
00063 public:
00064     //#####  Public Build Options  ############################################
00065 
00068     int n_visible;
00069     int n_hidden;
00070     string visible_type;
00071     bool update_with_h0_sample;
00072     bool sample_v1_in_chain;
00073     bool compute_log_likelihood;
00074     int n_stages;
00075     real learning_rate;
00076     int32_t seed;
00077     int n_train;
00078     int n_valid;
00079     int n_test;
00080     int batch_size;
00081     PPath data_filename;
00082     PPath save_path;
00083     PPath save_name;
00084     bool print_debug;
00085     bool use_fast_approximations;
00086 
00087 public:
00088     //#####  Public Member Functions  #########################################
00089 
00091     RBMTrainer();
00092 
00093     // Your other public member functions go here
00094     Mat NLL(const Mat& examples);
00095 
00096     Mat recError(const Mat& examples);
00097 
00098     void CD1(const Mat& examples);
00099 
00100     virtual void run();
00101 
00102 
00103     //#####  PLearn::Object Protocol  #########################################
00104 
00105     // Declares other standard object methods.
00106     PLEARN_DECLARE_OBJECT(RBMTrainer);
00107 
00108     // Simply calls inherited::build() then build_()
00109     virtual void build();
00110 
00112     // (PLEASE IMPLEMENT IN .cc)
00113     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00114 
00115 protected:
00116     //#####  Protected Options  ###############################################
00117 
00118     // ### Declare protected option fields (such as learned parameters) here
00119     VMat data;
00120     VMat train_input;
00121     VMat valid_input;
00122     VMat test_input;
00123 
00124     PP<RBMModule> rbm;
00125     PP<RBMLayer> visible;
00126     PP<RBMLayer> hidden;
00127     PP<RBMConnection> connection;
00128 
00129     TVec<string> ports;
00130     TVec<string> state_ports;
00131     int n_ports;
00132     int n_state_ports;
00133     TVec<int> state_ports_indices;
00134     int nll_index;
00135     int visible_index;
00136     int rec_err_index;
00137 
00138 protected:
00139     //#####  Protected Member Functions  ######################################
00140 
00142     static void declareOptions(OptionList& ol);
00143 
00144     static void declareMethods(RemoteMethodMap& rmm);
00145 
00146 private:
00147     //#####  Private Member Functions  ########################################
00148 
00150     void build_();
00151 
00152 private:
00153     //#####  Private Data Members  ############################################
00154 
00155     // The rest of the private stuff goes here
00156     mutable TVec<Mat*> nll_values;
00157     mutable TVec<Mat*> rec_err_values;
00158 
00159     mutable Mat h0_a;
00160     mutable Mat h0_e;
00161     mutable Mat h0_s;
00162     mutable Mat h0;
00163 
00164     mutable Mat v1_a;
00165     mutable Mat v1_e;
00166     mutable Mat v1_s;
00167     mutable Mat v1;
00168 
00169 
00170 
00171 };
00172 
00173 // Declares a few other classes and functions related to this class
00174 DECLARE_OBJECT_PTR(RBMTrainer);
00175 
00176 } // end of namespace PLearn
00177 
00178 #endif
00179 
00180 
00181 /*
00182   Local Variables:
00183   mode:c++
00184   c-basic-offset:4
00185   c-file-style:"stroustrup"
00186   c-file-offsets:((innamespace . 0)(inline-open . 0))
00187   indent-tabs-mode:nil
00188   fill-column:79
00189   End:
00190 */
00191 // 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