Mixture.h
Go to the documentation of this file.
1 /************************************************************************
2  * Copyright (C) 2012 Eindhoven University of Technology (TU/e). *
3  * All rights reserved. *
4  ************************************************************************
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above *
10  * copyright notice, this list of conditions and the following *
11  * disclaimer. *
12  * *
13  * 2. Redistributions in binary form must reproduce the above *
14  * copyright notice, this list of conditions and the following *
15  * disclaimer in the documentation and/or other materials *
16  * provided with the distribution. *
17  * *
18  * THIS SOFTWARE IS PROVIDED BY TU/e "AS IS" AND ANY EXPRESS OR *
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
21  * ARE DISCLAIMED. IN NO EVENT SHALL TU/e OR CONTRIBUTORS BE LIABLE *
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
28  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
29  * DAMAGE. *
30  * *
31  * The views and conclusions contained in the software and *
32  * documentation are those of the authors and should not be *
33  * interpreted as representing official policies, either expressed or *
34  * implied, of TU/e. *
35  ************************************************************************/
36 
37 #ifndef PROBLIB_MIXTUREPDF_H_
38 #define PROBLIB_MIXTUREPDF_H_
39 
40 #include "PDF.h"
41 #include "problib/pdfs/Gaussian.h"
42 #include "problib/pdfs/Uniform.h"
43 
44 namespace pbl {
45 
54 class Mixture: public PDF {
55 
56 public:
57 
61  Mixture();
62 
63  /*
64  Mixture(const PDF& pdf, double w = 1);
65  */
66 
70  Mixture(const Mixture& orig);
71 
75  virtual ~Mixture();
76 
82  Mixture& operator=(const Mixture& other);
83 
89  Mixture* clone() const;
90 
91  double getLikelihood(const PDF& pdf) const;
92 
96  void clear();
97 
102  int components() const;
103 
107  double getMaxDensity() const;
108 
114  void addComponent(const PDF& pdf, double w);
115 
121  const PDF& getComponent(int i) const;
122 
128  double getWeight(int i) const;
129 
133  void normalizeWeights();
134 
140  std::string toString(const std::string& indent = "") const;
141 
142 protected:
143 
144  struct MixtureStruct {
145 
147 
148  std::vector<PDF*> components_;
149 
150  std::vector<double> weights_;
151 
153 
154  int n_ptrs_;
155 
156  MixtureStruct() : num_components_(0) , weights_total_(0), n_ptrs_(1) { }
157 
158  MixtureStruct(const MixtureStruct& orig) : num_components_(orig.num_components_), weights_(orig.weights_),
159  weights_total_(orig.weights_total_), n_ptrs_(1) {
160 
161  for (std::vector<PDF*>::const_iterator it_pdf = orig.components_.begin(); it_pdf != orig.components_.end(); ++it_pdf) {
162  components_.push_back((*it_pdf)->clone());
163  }
164  }
165 
167  for (std::vector<PDF*>::const_iterator it_pdf = components_.begin(); it_pdf != components_.end(); ++it_pdf) {
168  delete *it_pdf;
169  }
170  }
171  };
172 
174 
175  void cloneStruct();
176 
177 };
178 
179 }
180 
181 #endif /* MIXTUREPDF_H_ */
Mixture * clone() const
Creates a clone of the object. The clone method is cheap since it only copies a pointer. A deep clone will only be created if the original object is modified.
Definition: Mixture.cpp:76
This class represents the weighted sum of a finite set of probability density functions.
Definition: Mixture.h:54
std::vector< double > weights_
Definition: Mixture.h:150
void cloneStruct()
Definition: Mixture.cpp:80
void normalizeWeights()
Normalizes the weights of all components.
Definition: Mixture.cpp:149
int components() const
Returns the number of components.
Definition: Mixture.cpp:116
void clear()
Removes all components.
Definition: Mixture.cpp:101
MixtureStruct * ptr_
Definition: Mixture.h:173
Mixture & operator=(const Mixture &other)
Assignment operator. The operation is cheap since it only copies a pointer. A deep clone will only be...
Definition: Mixture.cpp:60
double getMaxDensity() const
NOT IMPLEMENTED FOR MIXTURE.
Definition: Mixture.cpp:111
void addComponent(const PDF &pdf, double w)
Adds a component pdf with given weight.
Definition: Mixture.cpp:120
const PDF & getComponent(int i) const
Returns a reference to the i&#39;th component.
Definition: Mixture.cpp:139
const_iterator(const field< oT > &in_M, const bool at_end=false)
double getLikelihood(const PDF &pdf) const
Definition: Mixture.cpp:87
MixtureStruct(const MixtureStruct &orig)
Definition: Mixture.h:158
virtual ~Mixture()
Destructor.
Definition: Mixture.cpp:50
std::vector< PDF * > components_
Definition: Mixture.h:148
Definition: PDF.h:47
Mixture()
Constructs a mixture pdf with no initial components.
Definition: Mixture.cpp:41
double getWeight(int i) const
Returns the weight of the i&#39;th component.
Definition: Mixture.cpp:144
std::string toString(const std::string &indent="") const
Represents the Mixture as a string for easier console output.
Definition: Mixture.cpp:162


problib
Author(s): Sjoerd van den Dries, Jos Elfring
autogenerated on Fri Apr 16 2021 02:32:19