PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // PCA.h 00004 // 00005 // Copyright (C) 2003 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 /* ******************************************************* 00036 * $Id: PCA.h 5898 2006-06-18 04:10:23Z chapados $ 00037 ******************************************************* */ 00038 00040 #ifndef PCA_INC 00041 #define PCA_INC 00042 00043 #include <plearn_learners/generic/PLearner.h> 00044 00045 namespace PLearn { 00046 using namespace std; 00047 00048 class PCA: public PLearner 00049 { 00050 private: 00051 typedef PLearner inherited; 00052 00053 protected: 00054 00056 VecStatsCollector _incremental_stats; 00057 00067 int _oldest_observation; 00068 00069 00070 // The following methods correspond to the algo option choices 00071 void classical_algo ( ); 00072 void incremental_algo ( ); 00073 void em_algo ( ); 00074 void em_orth_algo ( ); 00075 00076 public: 00077 00078 // ************************ 00079 // * public build options * 00080 // ************************ 00081 00099 string algo; 00100 00110 int _horizon; 00111 00113 int ncomponents; 00114 00117 real sigmasq; 00118 00120 bool normalize; 00121 bool normalize_warning; 00122 00126 bool impute_missing; 00127 00128 00129 // ******************* 00130 // * learned options * 00131 // ******************* 00132 00134 Vec mu; 00135 00137 Vec eigenvals; 00138 00140 Mat eigenvecs; 00141 00142 // **************** 00143 // * Constructors * 00144 // **************** 00145 00147 PCA(); 00148 00149 // ****************** 00150 // * PLearner methods * 00151 // ****************** 00152 00153 private: 00154 00156 void build_(); 00157 00158 protected: 00159 00161 static void declareOptions(OptionList& ol); 00162 00163 public: 00164 00165 // ************************ 00166 // **** Object methods **** 00167 // ************************ 00168 00170 virtual void setTrainingSet(VMat training_set, bool call_forget=true); 00171 00173 virtual void build(); 00174 00176 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00177 00178 // Declares other standard object methods 00179 // If your class is not instantiatable (it has pure virtual methods) 00180 // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS 00181 PLEARN_DECLARE_OBJECT(PCA); 00182 00183 00184 // ************************** 00185 // **** PLearner methods **** 00186 // ************************** 00187 00190 virtual int outputsize() const; 00191 00194 virtual void forget(); 00195 00196 00199 virtual void train(); 00200 00201 00203 virtual void computeOutput(const Vec& input, Vec& output) const; 00204 00206 void reconstruct(const Vec& output, Vec& input) const; 00207 00210 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00211 const Vec& target, Vec& costs) const; 00212 00213 00215 virtual TVec<string> getTestCostNames() const; 00216 00217 00219 virtual TVec<string> getTrainCostNames() const; 00220 00221 00222 // *** SUBCLASS WRITING: *** 00223 // While in general not necessary, in case of particular needs 00224 // (efficiency concerns for ex) you may also want to overload 00225 // some of the following methods: 00226 // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const; 00227 // virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const; 00228 // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, VMat testoutputs=0, VMat testcosts=0) const; 00229 // virtual int nTestCosts() const; 00230 // virtual int nTrainCosts() const; 00231 }; 00232 00233 // Declares a few other classes and functions related to this class 00234 DECLARE_OBJECT_PTR(PCA); 00235 00236 } // end of namespace PLearn 00237 00238 #endif 00239 00240 00241 /* 00242 Local Variables: 00243 mode:c++ 00244 c-basic-offset:4 00245 c-file-style:"stroustrup" 00246 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00247 indent-tabs-mode:nil 00248 fill-column:79 00249 End: 00250 */ 00251 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :