PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // DiverseComponentAnalysis.h 00004 // 00005 // Copyright (C) 2008 Pascal Vincent 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 Vincent 00036 00040 #ifndef DiverseComponentAnalysis_INC 00041 #define DiverseComponentAnalysis_INC 00042 00043 #include <plearn_learners/generic/PLearner.h> 00044 #include <plearn/var/Var.h> 00045 #include <plearn/opt/Optimizer.h> 00046 00047 namespace PLearn { 00048 00059 class DiverseComponentAnalysis : public PLearner 00060 { 00061 typedef PLearner inherited; 00062 00063 public: 00064 //##### Public Build Options ############################################ 00065 00068 00070 int ncomponents; 00071 string nonlinearity; 00072 00073 string cov_transformation_type; 00074 00075 double diag_add; 00076 double diag_premul; 00077 double offdiag_premul; 00078 00079 string diag_nonlinearity; 00080 string offdiag_nonlinearity; 00081 00082 double diag_weight; 00083 double offdiag_weight; 00084 00085 bool force_zero_mean; 00086 real epsilon; // regularization value to add to diagonal of computed covariance matrix 00087 real nu; // regularization: off-diagonal elements of input covariance will be multiplied by 1-nu 00088 real constrain_norm_type; // how to constrain the norms of rows of W: -1:constrained source; -2:explicit normalization; >0:ordinary weight decay 00089 00090 bool normalize; 00091 00092 PP<Optimizer> optimizer; 00093 00094 // ******************* 00095 // * learned options * 00096 // ******************* 00097 00099 Vec mu; 00100 00102 Var Cx; 00103 00105 Var W; 00106 00108 Var Cy; 00109 00111 Var Cyt; 00112 00114 Var L; 00115 00116 Vec inv_stddev_of_projections; 00117 00118 // For the nonlinear case 00119 Var inputdata; // whole input data matrix 00120 Var bias; 00121 Var trdata; // transformed data 00122 Var ctrdata; // centered transformed data 00123 00124 public: 00125 //##### Public Member Functions ######################################### 00126 00128 // ### Make sure the implementation in the .cc 00129 // ### initializes all fields to reasonable default values. 00130 DiverseComponentAnalysis(); 00131 00133 Mat getVarValue(string varname) const; 00134 00136 Mat getVarGradient(string varname) const; 00137 00139 TVec<string> listVarNames() const; 00140 00141 //##### PLearner Member Functions ####################################### 00142 00145 // (PLEASE IMPLEMENT IN .cc) 00146 virtual int outputsize() const; 00147 00151 // (PLEASE IMPLEMENT IN .cc) 00152 virtual void forget(); 00153 00157 // (PLEASE IMPLEMENT IN .cc) 00158 virtual void train(); 00159 00161 // (PLEASE IMPLEMENT IN .cc) 00162 virtual void computeOutput(const Vec& input, Vec& output) const; 00163 00165 // (PLEASE IMPLEMENT IN .cc) 00166 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00167 const Vec& target, Vec& costs) const; 00168 00171 // (PLEASE IMPLEMENT IN .cc) 00172 virtual TVec<std::string> getTestCostNames() const; 00173 00176 // (PLEASE IMPLEMENT IN .cc) 00177 virtual TVec<std::string> getTrainCostNames() const; 00178 00179 00180 // *** SUBCLASS WRITING: *** 00181 // While in general not necessary, in case of particular needs 00182 // (efficiency concerns for ex) you may also want to overload 00183 // some of the following methods: 00184 // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, 00185 // Vec& output, Vec& costs) const; 00186 // virtual void computeCostsOnly(const Vec& input, const Vec& target, 00187 // Vec& costs) const; 00188 // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, 00189 // VMat testoutputs=0, VMat testcosts=0) const; 00190 // virtual int nTestCosts() const; 00191 // virtual int nTrainCosts() const; 00192 // virtual void resetInternalState(); 00193 // virtual bool isStatefulLearner() const; 00194 00195 00196 //##### PLearn::Object Protocol ######################################### 00197 00198 // Declares other standard object methods. 00199 // ### If your class is not instantiatable (it has pure virtual methods) 00200 // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS 00201 PLEARN_DECLARE_OBJECT(DiverseComponentAnalysis); 00202 00203 // Simply calls inherited::build() then build_() 00204 virtual void build(); 00205 00207 // (PLEASE IMPLEMENT IN .cc) 00208 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00209 00210 protected: 00211 //##### Protected Options ############################################### 00212 00213 // ### Declare protected option fields (such as learned parameters) here 00214 // ... 00215 00216 protected: 00217 //##### Protected Member Functions ###################################### 00218 00220 // (PLEASE IMPLEMENT IN .cc) 00221 static void declareOptions(OptionList& ol); 00222 static void declareMethods(RemoteMethodMap& rmm); 00223 static Var nonlinear_transform(Var in, string nonlinearity); 00224 00225 private: 00226 //##### Private Member Functions ######################################## 00227 00229 // (PLEASE IMPLEMENT IN .cc) 00230 void build_(); 00231 00232 private: 00233 //##### Private Data Members ############################################ 00234 VarArray allvars; 00235 00236 // The rest of the private stuff goes here 00237 }; 00238 00239 // Declares a few other classes and functions related to this class 00240 DECLARE_OBJECT_PTR(DiverseComponentAnalysis); 00241 00242 } // end of namespace PLearn 00243 00244 #endif 00245 00246 00247 /* 00248 Local Variables: 00249 mode:c++ 00250 c-basic-offset:4 00251 c-file-style:"stroustrup" 00252 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00253 indent-tabs-mode:nil 00254 fill-column:79 00255 End: 00256 */ 00257 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :