Mixture.h
Go to the documentation of this file.
00001 /************************************************************************
00002  *  Copyright (C) 2012 Eindhoven University of Technology (TU/e).       *
00003  *  All rights reserved.                                                *
00004  ************************************************************************
00005  *  Redistribution and use in source and binary forms, with or without  *
00006  *  modification, are permitted provided that the following conditions  *
00007  *  are met:                                                            *
00008  *                                                                      *
00009  *      1.  Redistributions of source code must retain the above        *
00010  *          copyright notice, this list of conditions and the following *
00011  *          disclaimer.                                                 *
00012  *                                                                      *
00013  *      2.  Redistributions in binary form must reproduce the above     *
00014  *          copyright notice, this list of conditions and the following *
00015  *          disclaimer in the documentation and/or other materials      *
00016  *          provided with the distribution.                             *
00017  *                                                                      *
00018  *  THIS SOFTWARE IS PROVIDED BY TU/e "AS IS" AND ANY EXPRESS OR        *
00019  *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED      *
00020  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  *
00021  *  ARE DISCLAIMED. IN NO EVENT SHALL TU/e OR CONTRIBUTORS BE LIABLE    *
00022  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR        *
00023  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT   *
00024  *  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;     *
00025  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF       *
00026  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           *
00027  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE   *
00028  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH    *
00029  *  DAMAGE.                                                             *
00030  *                                                                      *
00031  *  The views and conclusions contained in the software and             *
00032  *  documentation are those of the authors and should not be            *
00033  *  interpreted as representing official policies, either expressed or  *
00034  *  implied, of TU/e.                                                   *
00035  ************************************************************************/
00036 
00037 #ifndef PROBLIB_MIXTUREPDF_H_
00038 #define PROBLIB_MIXTUREPDF_H_
00039 
00040 #include "PDF.h"
00041 #include "problib/pdfs/Gaussian.h"
00042 #include "problib/pdfs/Uniform.h"
00043 
00044 namespace pbl {
00045 
00054 class Mixture: public PDF {
00055 
00056 public:
00057 
00061         Mixture();
00062 
00063     /*
00064         Mixture(const PDF& pdf, double w = 1);
00065     */
00066 
00070         Mixture(const Mixture& orig);
00071 
00075         virtual ~Mixture();
00076 
00082         Mixture& operator=(const Mixture& other);
00083 
00089         Mixture* clone() const;
00090 
00091         double getLikelihood(const PDF& pdf) const;
00092 
00096     void clear();
00097 
00102         int components() const;
00103 
00107         double getMaxDensity() const;
00108 
00114         void addComponent(const PDF& pdf, double w);
00115 
00121         const PDF& getComponent(int i) const;
00122 
00128         double getWeight(int i) const;
00129 
00133         void normalizeWeights();
00134 
00140         std::string toString(const std::string& indent = "") const;
00141 
00142 protected:
00143 
00144         struct MixtureStruct {
00145 
00146                 int num_components_;
00147 
00148                 std::vector<PDF*> components_;
00149 
00150                 std::vector<double> weights_;
00151 
00152                 double weights_total_;
00153 
00154                 int n_ptrs_;
00155 
00156                 MixtureStruct() : num_components_(0) , weights_total_(0), n_ptrs_(1) { }
00157 
00158                 MixtureStruct(const MixtureStruct& orig) : num_components_(orig.num_components_), weights_(orig.weights_),
00159                                 weights_total_(orig.weights_total_), n_ptrs_(1) {
00160 
00161                         for (std::vector<PDF*>::const_iterator it_pdf = orig.components_.begin(); it_pdf != orig.components_.end(); ++it_pdf) {
00162                                 components_.push_back((*it_pdf)->clone());
00163                         }
00164                 }
00165 
00166                 ~MixtureStruct() {
00167                         for (std::vector<PDF*>::const_iterator it_pdf = components_.begin(); it_pdf != components_.end(); ++it_pdf) {
00168                                 delete *it_pdf;
00169                         }
00170                 }
00171         };
00172 
00173         MixtureStruct* ptr_;
00174 
00175         void cloneStruct();
00176 
00177 };
00178 
00179 }
00180 
00181 #endif /* MIXTUREPDF_H_ */


problib
Author(s): Sjoerd van den Dries
autogenerated on Tue Jan 7 2014 11:42:42