PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // PDistribution.h 00004 // 00005 // Copyright (C) 2003 Pascal Vincent 00006 // Copyright (C) 2004-2005 University of Montreal 00007 // 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 /* ******************************************************* 00037 * $Id: PDistribution.h 8545 2008-02-20 19:56:50Z tihocan $ 00038 ******************************************************* */ 00039 00041 #ifndef PDistribution_INC 00042 #define PDistribution_INC 00043 00044 #include <plearn_learners/generic/PLearner.h> 00045 00046 namespace PLearn { 00047 using namespace std; 00048 00099 class PDistribution: public PLearner 00100 { 00101 00102 private: 00103 00104 typedef PLearner inherited; 00105 00106 protected: 00108 mutable Vec store_expect, store_result; 00109 mutable Mat store_cov; 00110 00111 protected: 00112 00114 real delta_curve; 00115 00116 mutable Vec predictor_part; 00117 mutable Vec predicted_part; 00118 00119 // ********************* 00120 // * protected options * 00121 // ********************* 00122 00126 int predictor_size; 00127 int predicted_size; 00128 00132 mutable int n_predictor; 00133 mutable int n_predicted; 00134 00135 public: 00136 00137 // ************************ 00138 // * public build options * 00139 // ************************ 00140 00141 real lower_bound, upper_bound; 00142 int n_curve_points; 00143 string outputs_def; // TODO Replace this by a TVec<string> 00144 00145 // **************** 00146 // * Constructors * 00147 // **************** 00148 00150 PDistribution(); 00151 00152 // ******************** 00153 // * PLearner methods * 00154 // ******************** 00155 00156 private: 00157 00159 void build_(); 00160 00161 protected: 00162 00164 static void declareOptions(OptionList& ol); 00165 00167 static void declareMethods(RemoteMethodMap& rmm); 00168 00169 public: 00170 00171 // ************************ 00172 // **** Object methods **** 00173 // ************************ 00174 00176 virtual void build(); 00177 00179 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00180 00181 // Declares other standard object methods 00182 PLEARN_DECLARE_OBJECT(PDistribution); 00183 00184 // ************************** 00185 // **** PLearner methods **** 00186 // ************************** 00187 00189 virtual int outputsize() const; 00190 00194 virtual void forget(); 00195 00200 virtual void train(); 00201 00203 virtual void computeOutput(const Vec& input, Vec& output) const; 00204 00207 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00208 const Vec& target, Vec& costs) const; 00209 00210 // ******************************* 00211 // **** PDistribution methods **** 00212 // ******************************* 00213 00214 protected: 00215 00222 void splitCond(const Vec& input) const; 00223 00225 // TODO Can we find a better way to perform this? 00226 virtual void unknownOutput(char def, const Vec& input, Vec& output, int& k) const; 00227 00228 public: 00229 00241 virtual bool setPredictorPredictedSizes(int the_predictor_size, 00242 int the_predicted_size, 00243 bool call_parent = true); 00244 00253 virtual void setPredictor(const Vec& predictor, bool call_parent = true) 00254 const; 00255 00257 virtual TVec<string> getTestCostNames() const; 00258 00260 virtual TVec<string> getTrainCostNames() const; 00261 00263 virtual real log_density(const Vec& y) const; 00264 00267 virtual real density(const Vec& y) const; 00268 00270 virtual real survival_fn(const Vec& y) const; 00271 00273 virtual real cdf(const Vec& y) const; 00274 00276 virtual void expectation(Vec& mu) const; 00277 00285 virtual void missingExpectation(const Vec& input, Vec& mu); 00286 00288 virtual void variance(Mat& cov) const; 00289 00296 virtual void resetGenerator(long g_seed); 00297 00300 virtual void generate(Vec& y) const; 00301 00303 Vec remote_generate(); 00304 00307 virtual void generateN(const Mat& Y) const; 00308 00313 virtual void generateJoint(Vec& xy); 00314 00319 void generateJoint(Vec& x, Vec& y); 00320 00325 virtual void generatePredictor(Vec& x); 00326 00331 virtual void generatePredicted(Vec& y); 00332 00337 virtual void generatePredictorGivenPredicted(Vec& x, const Vec& y); 00338 00340 int getNPredicted() const { return n_predicted; } 00341 00343 int getNPredictor() const { return n_predictor; } 00344 00345 00346 }; 00347 00348 // Declares a few other classes and functions related to this class 00349 DECLARE_OBJECT_PTR(PDistribution); 00350 00351 } // end of namespace PLearn 00352 00353 #endif 00354 00355 00356 /* 00357 Local Variables: 00358 mode:c++ 00359 c-basic-offset:4 00360 c-file-style:"stroustrup" 00361 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00362 indent-tabs-mode:nil 00363 fill-column:79 00364 End: 00365 */ 00366 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :