PLearn 0.1
MoleculeTemplateLearner.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // MoleculeTemplateLearner.h
00004 //
00005 // Copyright (C) 2005 Dan Popovici 
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: .pyskeleton_header 544 2003-09-01 00:05:31Z plearner $ 
00037    ******************************************************* */
00038 
00039 // Authors: Dan Popovici
00040 
00044 #ifndef MoleculeTemplateLearner_INC
00045 #define MoleculeTemplateLearner_INC
00046 
00047 #include <plearn_learners/generic/PLearner.h>
00048 #include <plearn/opt/Optimizer.h>
00049 #include "Molecule.h"
00050 #include "Template.h"
00051 
00052 
00053 namespace PLearn {
00054 
00055 class MoleculeTemplateLearner: public PLearner
00056 {
00057 
00058 private:
00059 
00060   typedef PLearner inherited;
00061   
00062 protected:
00063 
00064   // *********************
00065   // * protected options *
00066   // *********************
00067 
00068   
00069   Var input_index ; 
00070   VarArray mu, sigma ; 
00071   VarArray mu_S, sigma_S ; 
00072   VarArray sigma_square_S ; 
00073   VarArray sigma_square ; 
00074   mutable VarArray S ; 
00075   VarArray S_after_scaling ; 
00076   VarArray params ; 
00077   VarArray penalties;
00078   Var V , W , V_b , W_b, V_direct ; 
00079   Var hl ;
00080   Var y ; // the output 
00081   Var y_before_transfer ;
00082   Var training_cost;
00083   Var test_costs ;  
00084   Var target ; 
00085   Var temp_S ; 
00086   VarArray costs;
00087   VarArray temp_output ; 
00088   int n_actives ; 
00089   int n_inactives ; 
00090   Vec S_std  ; 
00091   Vec sigma_s_vec ; 
00092 
00093   Func f_output ;     
00094   Func output_target_to_costs ;
00095   Func test_costf ;
00096 
00097   vector<PMolecule> Molecules ; 
00098 //  PMolecule  molecule ; 
00099 
00100     
00101 public:
00102     
00103   // ************************
00104   // * public build options *
00105   // ************************
00106 
00107 
00108   int nhidden; 
00109   real weight_decay ; 
00110   int noutputs , batch_size ;
00111   int n_active_templates ;  // the number of templates for the actives
00112   int n_inactive_templates ; // the number of templates for the inactives 
00113   int n_templates ; // the total number of templates  
00114   real scaling_factor ; 
00115   real lrate2 ; 
00116 
00117   bool training_mode ; 
00118   bool builded ; 
00119 
00120   // Build options related to the optimization:
00121   PP<Optimizer> optimizer; // the optimizer to use (no default)
00122 
00123   TVec<MoleculeTemplate> templates ; 
00124   Vec paramsvalues ;
00125 
00126 
00127   // ****************
00128   // * Constructors *
00129   // ****************
00130 
00132   // (Make sure the implementation in the .cc
00133   // initializes all fields to reasonable default values)
00134   MoleculeTemplateLearner();
00135 
00136 
00137   // ********************
00138   // * PLearner methods *
00139   // ********************
00140 
00141 private: 
00142 
00144   // (Please implement in .cc)
00145   void build_();
00146 
00147 protected: 
00148   
00150   // (Please implement in .cc)
00151   static void declareOptions(OptionList& ol);
00152 
00153 public:
00154 
00155   // ************************
00156   // **** Object methods ****
00157   // ************************
00158 
00160   virtual void build();
00161 
00163   virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00164 
00165   // Declares other standard object methods.
00166   // If your class is not instantiatable (it has pure virtual methods)
00167   // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT.
00168   PLEARN_DECLARE_OBJECT(MoleculeTemplateLearner);
00169 
00170 
00171   // **************************
00172   // **** PLearner methods ****
00173   // **************************
00174 
00177   // (PLEASE IMPLEMENT IN .cc)
00178   virtual int outputsize() const;
00179 
00182   // (PLEASE IMPLEMENT IN .cc)
00183   virtual void forget();
00184 
00185     
00188   // (PLEASE IMPLEMENT IN .cc)
00189   virtual void train();
00190 
00191 
00193   // (PLEASE IMPLEMENT IN .cc)
00194   virtual void computeOutput(const Vec& input, Vec& output) const;
00195 
00197   // (PLEASE IMPLEMENT IN .cc)
00198   virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 
00199           const Vec& target, Vec& costs) const;
00200 
00201   virtual void computeOutputAndCosts(const Vec& input, const Vec& target,
00202           Vec& output, Vec& costs) const;
00203     
00204   void compute_S_mean_std(Vec & mean , Vec & std) ;
00205  
00207   // (PLEASE IMPLEMENT IN .cc)
00208   virtual TVec<std::string> getTestCostNames() const;
00209 
00212   // (PLEASE IMPLEMENT IN .cc)
00213   virtual TVec<std::string> getTrainCostNames() const;
00214     
00215   virtual void test(VMat testset, PP<VecStatsCollector> test_stats, 
00216                       VMat testoutputs=0, VMat testcosts=0)const ;
00217   
00218   void initializeParams() ;
00219 
00220 
00221   // *** SUBCLASS WRITING: ***
00222   // While in general not necessary, in case of particular needs 
00223   // (efficiency concerns for ex) you may also want to overload
00224   // some of the following methods:
00225   // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const;
00226   // virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const;
00227   // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, VMat testoutputs=0, VMat testcosts=0) const;
00228   // virtual int nTestCosts() const;
00229   // virtual int nTrainCosts() const;
00230   // virtual void resetInternalState();
00231   // virtual bool isStatefulLearner() const;
00232 
00233 };
00234 
00235 // Declares a few other classes and functions related to this class.
00236 DECLARE_OBJECT_PTR(MoleculeTemplateLearner);
00237   
00238 } // end of namespace PLearn
00239 
00240 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines