more generic edo*Binomial* code
This commit is contained in:
parent
fff9f023c5
commit
fb4ffd2954
3 changed files with 12 additions and 15 deletions
|
|
@ -29,10 +29,11 @@ Authors:
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <eoFunctor.h>
|
#include "edoDistrib.h"
|
||||||
|
|
||||||
/** @defgroup Binomial Binomial
|
/** @defgroup Binomial Binomial
|
||||||
* A binomial distribution that model marginal probabilities across variables.
|
* A binomial distribution that model marginal probabilities across boolean
|
||||||
|
* variables.
|
||||||
*
|
*
|
||||||
* @ingroup Distributions
|
* @ingroup Distributions
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -36,19 +36,18 @@ Authors:
|
||||||
* @ingroup Binomial
|
* @ingroup Binomial
|
||||||
*/
|
*/
|
||||||
template< class EOT, class D = edoBinomial<EOT> >
|
template< class EOT, class D = edoBinomial<EOT> >
|
||||||
class edoEstimatorBinomial : public edoEstimator< edoBinomial< EOT > >
|
class edoEstimatorBinomial : public edoEstimator<D>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** This generic implementation makes no assumption about the underlying
|
/** This generic implementation makes no assumption about the underlying
|
||||||
* atom type of the EOT. It can be any type that may be interpreted as
|
* atom type of the EOT. It can be any type that may be casted in a
|
||||||
* true or false.
|
* double as 1 or 0.
|
||||||
*
|
*
|
||||||
* For instance, you can use a vector<int>, and any variable greater
|
* For instance, you can use a vector<int>, but it must contains 1 or 0.
|
||||||
* than one will increase the associated probability.
|
|
||||||
*
|
*
|
||||||
* FIXME: Partial template specializations without the conditional branching may be more efficient.
|
* FIXME: Partial template specializations with a conditional branching may be more generic.
|
||||||
*/
|
*/
|
||||||
edoBinomial<EOT> operator()( eoPop<EOT>& pop )
|
D operator()( eoPop<EOT>& pop )
|
||||||
{
|
{
|
||||||
unsigned int popsize = pop.size();
|
unsigned int popsize = pop.size();
|
||||||
assert(popsize > 0);
|
assert(popsize > 0);
|
||||||
|
|
@ -56,14 +55,11 @@ class edoEstimatorBinomial : public edoEstimator< edoBinomial< EOT > >
|
||||||
unsigned int dimsize = pop[0].size();
|
unsigned int dimsize = pop[0].size();
|
||||||
assert(dimsize > 0);
|
assert(dimsize > 0);
|
||||||
|
|
||||||
edoBinomial<EOT> probas(dimsize, 0.0);
|
D probas(dimsize, 0.0);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < popsize; ++i) {
|
for (unsigned int i = 0; i < popsize; ++i) {
|
||||||
for (unsigned int d = 0; d < dimsize; ++d) {
|
for (unsigned int d = 0; d < dimsize; ++d) {
|
||||||
// if this variable is true (whatever that means, x=1, x=true, etc.)
|
assert( pop[i][d] == 0 || pop[i][d] == 1 );
|
||||||
// if( pop[i][d] ) {
|
|
||||||
// probas[d] += 1/popsize; // we hope the compiler optimization pre-computes 1/p
|
|
||||||
// }
|
|
||||||
probas[d] += static_cast<double>(pop[i][d]) / popsize;
|
probas[d] += static_cast<double>(pop[i][d]) / popsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class edoSamplerBinomial : public edoSampler<D>
|
||||||
public:
|
public:
|
||||||
edoSamplerBinomial() : edoSampler<D>() {}
|
edoSamplerBinomial() : edoSampler<D>() {}
|
||||||
|
|
||||||
EOT sample( edoBinomial<EOT>& distrib )
|
EOT sample( D& distrib )
|
||||||
{
|
{
|
||||||
unsigned int size = distrib.size();
|
unsigned int size = distrib.size();
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue