PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // NxProfileLearner.h 00004 // 00005 // Copyright (C) 2007 Pierre-Antoine Manzagol 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: Pierre-Antoine Manzagol 00036 00040 #ifndef NxProfileLearner_INC 00041 #define NxProfileLearner_INC 00042 00043 #include <plearn_learners/generic/PLearner.h> 00044 #include <plearn_learners/generic/NatGradEstimator.h> 00045 00046 namespace PLearn { 00047 00058 class NxProfileLearner : public PLearner 00059 { 00060 typedef PLearner inherited; 00061 00062 public: 00063 //##### Public Build Options ############################################ 00064 00067 00068 int profile_dim; 00069 real slr; 00070 real dc; 00071 00072 real L1_penalty_factor; 00073 real L2_penalty_factor; 00074 00079 00082 PP<NatGradEstimator> ngest_films; 00083 00086 PP<NatGradEstimator> ngest_users; 00087 00088 //##### Public NOT Options ############################################## 00089 00090 int n_films; 00091 int n_users; 00092 00093 //map<int, int> u_map; //! userID to userProfileID 00094 // We are already using modified IDs... see about this 00095 //map<int, int> f_map; //! filmID to filmProfileID 00096 00097 // The rest of the private stuff goes here 00098 Mat f_profiles; 00099 Mat u_profiles; 00100 00101 00102 public: 00103 //##### Public Member Functions ######################################### 00104 00106 // ### Make sure the implementation in the .cc 00107 // ### initializes all fields to reasonable default values. 00108 NxProfileLearner(); 00109 00110 00111 //##### PLearner Member Functions ####################################### 00112 00115 // (PLEASE IMPLEMENT IN .cc) 00116 virtual int outputsize() const; 00117 00121 // (PLEASE IMPLEMENT IN .cc) 00122 virtual void forget(); 00123 00127 // (PLEASE IMPLEMENT IN .cc) 00128 virtual void train(); 00129 00131 // (PLEASE IMPLEMENT IN .cc) 00132 virtual void computeOutput(const Vec& input, Vec& output) const; 00133 00135 // (PLEASE IMPLEMENT IN .cc) 00136 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00137 const Vec& target, Vec& costs) const; 00138 00141 // (PLEASE IMPLEMENT IN .cc) 00142 virtual TVec<std::string> getTestCostNames() const; 00143 00146 // (PLEASE IMPLEMENT IN .cc) 00147 virtual TVec<std::string> getTrainCostNames() const; 00148 00149 00150 // *** SUBCLASS WRITING: *** 00151 // While in general not necessary, in case of particular needs 00152 // (efficiency concerns for ex) you may also want to overload 00153 // some of the following methods: 00154 // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, 00155 // Vec& output, Vec& costs) const; 00156 // virtual void computeCostsOnly(const Vec& input, const Vec& target, 00157 // Vec& costs) const; 00158 // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, 00159 // VMat testoutputs=0, VMat testcosts=0) const; 00160 // virtual int nTestCosts() const; 00161 // virtual int nTrainCosts() const; 00162 // virtual void resetInternalState(); 00163 // virtual bool isStatefulLearner() const; 00164 00165 00166 //##### PLearn::Object Protocol ######################################### 00167 00168 // Declares other standard object methods. 00169 // ### If your class is not instantiatable (it has pure virtual methods) 00170 // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS 00171 PLEARN_DECLARE_OBJECT(NxProfileLearner); 00172 00173 // Simply calls inherited::build() then build_() 00174 virtual void build(); 00175 00177 // (PLEASE IMPLEMENT IN .cc) 00178 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00179 00180 protected: 00181 //##### Protected Options ############################################### 00182 00183 // ### Declare protected option fields (such as learned parameters) here 00184 // ... 00185 00186 protected: 00187 //##### Protected Member Functions ###################################### 00188 00190 // (PLEASE IMPLEMENT IN .cc) 00191 static void declareOptions(OptionList& ol); 00192 00193 private: 00194 //##### Private Member Functions ######################################## 00195 00197 // (PLEASE IMPLEMENT IN .cc) 00198 void build_(); 00199 00200 private: 00201 //##### Private Data Members ############################################ 00202 00203 00204 }; 00205 00206 // Declares a few other classes and functions related to this class 00207 DECLARE_OBJECT_PTR(NxProfileLearner); 00208 00209 } // end of namespace PLearn 00210 00211 #endif 00212 00213 00214 /* 00215 Local Variables: 00216 mode:c++ 00217 c-basic-offset:4 00218 c-file-style:"stroustrup" 00219 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00220 indent-tabs-mode:nil 00221 fill-column:79 00222 End: 00223 */ 00224 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :