PLearn 0.1
MixtureDistribution.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // MixtureDistribution.h
00004 //
00005 // Copyright (C) 2008 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 // Authors: Olivier Delalleau
00036 
00040 #ifndef MixtureDistribution_INC
00041 #define MixtureDistribution_INC
00042 
00043 #include <plearn_learners/distributions/PDistribution.h>
00044 
00045 namespace PLearn {
00046 
00057 class MixtureDistribution : public PDistribution
00058 {
00059     typedef PDistribution inherited;
00060 
00061 public:
00062     //#####  Public Build Options  ############################################
00063 
00064     TVec< PP<PDistribution> > distributions;
00065     Vec weights;
00066 
00067 public:
00068     //#####  Public Member Functions  #########################################
00069 
00071     MixtureDistribution();
00072 
00073     //#####  PDistribution Member Functions  ##################################
00074 
00076     virtual real log_density(const Vec& y) const;
00077 
00079     virtual real survival_fn(const Vec& y) const;
00080 
00082     virtual real cdf(const Vec& y) const;
00083 
00085     virtual void expectation(Vec& mu) const;
00086 
00088     virtual void variance(Mat& cov) const;
00089 
00092     virtual void generate(Vec& y) const;
00093 
00094     //### Override this method if you need it (and if your distribution can
00095     //### handle it. Default version calls PLERROR.
00100     // virtual void generatePredictorGivenPredicted(Vec& x, const Vec& y);
00101 
00104     virtual void resetGenerator(long g_seed);
00105 
00107     //### See help in PDistribution.h.
00108     virtual bool setPredictorPredictedSizes(int the_predictor_size,
00109                                             int the_predicted_size,
00110                                             bool call_parent = true);
00111 
00113     //### See help in PDistribution.h.
00114     virtual void setPredictor(const Vec& predictor, bool call_parent = true)
00115                               const;
00116 
00117     // ### These methods may be overridden for efficiency purpose:
00118     /*
00119     //### Default version calls exp(log_density(y))
00121     virtual real density(const Vec& y) const;
00122 
00123     //### Default version calls setPredictorPredictedSises(0,-1) and generate
00128     virtual void generateJoint(Vec& xy);
00129 
00130     //### Default version calls generateJoint and discards y
00135     virtual void generatePredictor(Vec& x);
00136 
00137     //### Default version calls generateJoint and discards x
00142     virtual void generatePredicted(Vec& y);
00143     */
00144 
00145 
00146     //#####  PLearner Member Functions  #######################################
00147 
00148     // ### Default version of inputsize returns learner->inputsize()
00149     // ### If this is not appropriate, you should uncomment this and define
00150     // ### it properly in the .cc
00151     // virtual int inputsize() const;
00152 
00160     virtual void forget();
00161 
00165     // ### You may remove this method if your distribution does not
00166     // ### implement it.
00167     virtual void train();
00168 
00169 
00170     //#####  PLearn::Object Protocol  #########################################
00171 
00172     // Declares other standard object methods.
00173     // ### If your class is not instantiatable (it has pure virtual methods)
00174     // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS
00175     PLEARN_DECLARE_OBJECT(MixtureDistribution);
00176 
00177     // Simply calls inherited::build() then build_()
00178     virtual void build();
00179 
00181     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00182 
00183 protected:
00184     //#####  Protected Options  ###############################################
00185 
00186     // ### Declare protected option fields (such as learned parameters) here
00187     // ...
00188 
00189 protected:
00190     //#####  Protected Member Functions  ######################################
00191 
00193     static void declareOptions(OptionList& ol);
00194 
00199     void getSizes() const;
00200 
00201 private:
00202     //#####  Private Member Functions  ########################################
00203 
00205     void build_();
00206 
00207 private:
00208     //#####  Private Data Members  ############################################
00209 
00211     mutable Vec work;
00212 
00213     // The rest of the private stuff goes here
00214 };
00215 
00216 // Declares a few other classes and functions related to this class
00217 DECLARE_OBJECT_PTR(MixtureDistribution);
00218 
00219 } // end of namespace PLearn
00220 
00221 #endif
00222 
00223 
00224 /*
00225   Local Variables:
00226   mode:c++
00227   c-basic-offset:4
00228   c-file-style:"stroustrup"
00229   c-file-offsets:((innamespace . 0)(inline-open . 0))
00230   indent-tabs-mode:nil
00231   fill-column:79
00232   End:
00233 */
00234 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines