use more Util::sizeExpected

This commit is contained in:
Tiago Gomes 2012-05-28 21:27:52 +01:00
parent 54ae29ae02
commit 3ac854b2ff
4 changed files with 14 additions and 15 deletions

View File

@ -264,9 +264,8 @@ BpSolver::calcFactorToVarMsg (SpLink* link)
const SpLinkSet& links = ninf(src)->getLinks();
// calculate the product of messages that were sent
// to factor `src', except from var `dst'
unsigned msgSize = std::accumulate (src->factor().ranges().begin(),
src->factor().ranges().end(), 1, std::multiplies<double>());
unsigned reps = 1;
unsigned reps = 1;
unsigned msgSize = Util::sizeExpected (src->factor().ranges());
Params msgProduct (msgSize, LogAware::multIdenty());
if (Globals::logDomain) {
for (size_t i = links.size(); i-- > 0; ) {

View File

@ -207,9 +207,8 @@ CbpSolver::calcFactorToVarMsg (SpLink* _link)
const SpLinkSet& links = ninf(src)->getLinks();
// calculate the product of messages that were sent
// to factor `src', except from var `dst'
unsigned msgSize = std::accumulate (src->factor().ranges().begin(),
src->factor().ranges().end(), 1, std::multiplies<double>());
unsigned reps = 1;
unsigned msgSize = Util::sizeExpected (src->factor().ranges());
Params msgProduct (msgSize, LogAware::multIdenty());
if (Globals::logDomain) {
for (size_t i = links.size(); i-- > 0; ) {

View File

@ -14,10 +14,9 @@ class Indexer
{
public:
Indexer (const Ranges& ranges, bool calcOffsets = true)
: index_(0), indices_(ranges.size(), 0), ranges_(ranges)
: index_(0), indices_(ranges.size(), 0), ranges_(ranges),
size_(Util::sizeExpected (ranges))
{
size_ = std::accumulate (ranges.begin(), ranges.end(), 1,
std::multiplies<unsigned>());
if (calcOffsets) {
calculateOffsets();
}

View File

@ -18,7 +18,6 @@ InfAlgorithms infAlgorithm = InfAlgorithms::VE;
namespace BpOptions {
Schedule schedule = BpOptions::Schedule::SEQ_FIXED;
//Schedule schedule = BpOptions::Schedule::SEQ_RANDOM;
@ -71,7 +70,6 @@ stringToDouble (string str)
double
factorial (unsigned num)
{
@ -128,8 +126,8 @@ nrCombinations (unsigned n, unsigned k)
size_t
sizeExpected (const Ranges& ranges)
{
return std::accumulate (
ranges.begin(), ranges.end(), 1, multiplies<unsigned>());
return std::accumulate (ranges.begin(),
ranges.end(), 1, multiplies<unsigned>());
}
@ -392,7 +390,9 @@ getMaxNorm (const Params& v1, const Params& v2)
double
pow (double base, unsigned iexp)
{
return Globals::logDomain ? base * iexp : std::pow (base, iexp);
return Globals::logDomain
? base * iexp
: std::pow (base, iexp);
}
@ -400,8 +400,10 @@ pow (double base, unsigned iexp)
double
pow (double base, double exp)
{
// assumes that `expoent' is never in log domain
return Globals::logDomain ? base * exp : std::pow (base, exp);
// `expoent' should not be in log domain
return Globals::logDomain
? base * exp
: std::pow (base, exp);
}