diff --git a/edo/src/edoBinomial.h b/edo/src/edoBinomial.h index ab8b9b8f3..9a0edf96a 100644 --- a/edo/src/edoBinomial.h +++ b/edo/src/edoBinomial.h @@ -29,10 +29,11 @@ Authors: #include -#include +#include "edoDistrib.h" /** @defgroup Binomial Binomial - * A binomial distribution that model marginal probabilities across variables. + * A binomial distribution that model marginal probabilities across boolean + * variables. * * @ingroup Distributions */ diff --git a/edo/src/edoEstimatorBinomial.h b/edo/src/edoEstimatorBinomial.h index 8e0650514..3b6aa9298 100644 --- a/edo/src/edoEstimatorBinomial.h +++ b/edo/src/edoEstimatorBinomial.h @@ -36,19 +36,18 @@ Authors: * @ingroup Binomial */ template< class EOT, class D = edoBinomial > -class edoEstimatorBinomial : public edoEstimator< edoBinomial< EOT > > +class edoEstimatorBinomial : public edoEstimator { public: /** This generic implementation makes no assumption about the underlying - * atom type of the EOT. It can be any type that may be interpreted as - * true or false. + * atom type of the EOT. It can be any type that may be casted in a + * double as 1 or 0. * - * For instance, you can use a vector, and any variable greater - * than one will increase the associated probability. + * For instance, you can use a vector, but it must contains 1 or 0. * - * 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 operator()( eoPop& pop ) + D operator()( eoPop& pop ) { unsigned int popsize = pop.size(); assert(popsize > 0); @@ -56,14 +55,11 @@ class edoEstimatorBinomial : public edoEstimator< edoBinomial< EOT > > unsigned int dimsize = pop[0].size(); assert(dimsize > 0); - edoBinomial probas(dimsize, 0.0); + D probas(dimsize, 0.0); for (unsigned int i = 0; i < popsize; ++i) { for (unsigned int d = 0; d < dimsize; ++d) { - // if this variable is true (whatever that means, x=1, x=true, etc.) - // if( pop[i][d] ) { - // probas[d] += 1/popsize; // we hope the compiler optimization pre-computes 1/p - // } + assert( pop[i][d] == 0 || pop[i][d] == 1 ); probas[d] += static_cast(pop[i][d]) / popsize; } } diff --git a/edo/src/edoSamplerBinomial.h b/edo/src/edoSamplerBinomial.h index 1425b7a74..ec424a21f 100644 --- a/edo/src/edoSamplerBinomial.h +++ b/edo/src/edoSamplerBinomial.h @@ -43,7 +43,7 @@ class edoSamplerBinomial : public edoSampler public: edoSamplerBinomial() : edoSampler() {} - EOT sample( edoBinomial& distrib ) + EOT sample( D& distrib ) { unsigned int size = distrib.size(); assert(size > 0);