00001 // -*- C++ -*- 00002 00003 // PLS.h 00004 // 00005 // Copyright (C) 2004 Olivier Delalleau 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: PLS.h,v 1.4 2004/07/21 16:30:58 chrish42 Exp $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00043 #ifndef PLS_INC 00044 #define PLS_INC 00045 00046 #include <plearn_learners/generic/PLearner.h> 00047 00048 namespace PLearn { 00049 using namespace std; 00050 00051 class PLS: public PLearner 00052 { 00053 00054 public: 00055 00056 typedef PLearner inherited; 00057 00058 protected: 00059 00060 // ********************* 00061 // * protected options * 00062 // ********************* 00063 00064 Mat B; 00065 int m; 00066 Vec mean_input; 00067 Vec mean_target; 00068 int p; 00069 Vec stddev_input; 00070 Vec stddev_target; 00071 Mat W; 00072 00073 public: 00074 00075 // ************************ 00076 // * public build options * 00077 // ************************ 00078 00079 int k; 00080 string method; 00081 real precision; 00082 bool output_the_score; 00083 bool output_the_target; 00084 00085 // **************** 00086 // * Constructors * 00087 // **************** 00088 00089 // Default constructor, make sure the implementation in the .cc 00090 // initializes all fields to reasonable default values. 00091 PLS(); 00092 00093 00094 // ******************** 00095 // * PLearner methods * 00096 // ******************** 00097 00098 private: 00099 00101 void build_(); 00102 00103 protected: 00104 00106 static void declareOptions(OptionList& ol); 00107 00108 public: 00109 00110 // ************************ 00111 // **** Object methods **** 00112 // ************************ 00113 00115 virtual void build(); 00116 00118 virtual void makeDeepCopyFromShallowCopy(map<const void*, void*>& copies); 00119 00120 // Declares other standard object methods. 00121 // If your class is not instantiatable (it has pure virtual methods) 00122 // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS. 00123 PLEARN_DECLARE_OBJECT(PLS); 00124 00125 00126 // ************************** 00127 // **** PLearner methods **** 00128 // ************************** 00129 00132 virtual int outputsize() const; 00133 00136 virtual void forget(); 00137 00140 virtual void train(); 00141 00143 virtual void computeOutput(const Vec& input, Vec& output) const; 00144 00146 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00147 const Vec& target, Vec& costs) const; 00148 00150 virtual TVec<string> getTestCostNames() const; 00151 00154 virtual TVec<string> getTrainCostNames() const; 00155 00156 // *** SUBCLASS WRITING: *** 00157 // While in general not necessary, in case of particular needs 00158 // (efficiency concerns for ex) you may also want to overload 00159 // some of the following methods: 00160 // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const; 00161 // virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const; 00162 // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, VMat testoutputs=0, VMat testcosts=0) const; 00163 // virtual int nTestCosts() const; 00164 // virtual int nTrainCosts() const; 00165 00166 00167 //***** STATIC METHODS ***** 00168 00174 static void NIPALSEigenvector(const Mat& m, Vec& v, real precision); 00175 00176 }; 00177 00178 // Declares a few other classes and functions related to this class. 00179 DECLARE_OBJECT_PTR(PLS); 00180 00181 } // end of namespace PLearn 00182 00183 #endif