mixture of pdf implementation

Hi there,

I'm working on a implementation of a mixture of pdfs: Mixture<T>,
which inherits from Pdf<T>.

Mixture has two important attributes:
* vector<Probability*> * weights: the vector with the pointers to the
component weights
* vector<Pdf<T>* > componentPdfs: the vector with the pointers to the
pdfs of the components.

When I want to add a component I call the function AddComponent(Pdf<T>
& pdf), which looks a little bit like this:

template<typename T>
bool Mixture<T>::AddComponent(Pdf<T>& pdf)
{
.......
_numComponents++;
(*_componentPdfs).push_back(new Pdf<T>(pdf));
......
}
}

The problem is that when you call for instance
myMixture.AddComponent(Gaussian gaussian() ), the default copy
constructor of Pdf is called.

Then afterwards, when calling for instance ProbabilityGet on one of
the components of the mixture (*componentPdfs)[i]->ProbabilityGet(),
the function ProbabilityGet of Pdf is called which is not implemented!

To solve the problem I am considering implementing a Clone function
for all Pdfs.
In Pdf itself I would add:
virtual Pdf* clone const = 0;
This forces that all the children of Pdf implement the clone function:
eg:
MCPdf* MCPdf::Clone() const
{
return new MCPdf(*this);
}
This clone function then calls the copy constructor of MCPdf (or the
default one when not implemented).

Any remarks, suggestions, other/nicer solutions?

Tinne
_______________________________________________
I hereby promise not to top-post on the
BFL mailing list
BFL [..] ...
http://lists.mech.kuleuven.be/mailman/listinfo/bfl

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm