use more Util::sizeExpected
This commit is contained in:
parent
54ae29ae02
commit
3ac854b2ff
@ -264,9 +264,8 @@ BpSolver::calcFactorToVarMsg (SpLink* link)
|
|||||||
const SpLinkSet& links = ninf(src)->getLinks();
|
const SpLinkSet& links = ninf(src)->getLinks();
|
||||||
// calculate the product of messages that were sent
|
// calculate the product of messages that were sent
|
||||||
// to factor `src', except from var `dst'
|
// to factor `src', except from var `dst'
|
||||||
unsigned msgSize = std::accumulate (src->factor().ranges().begin(),
|
unsigned reps = 1;
|
||||||
src->factor().ranges().end(), 1, std::multiplies<double>());
|
unsigned msgSize = Util::sizeExpected (src->factor().ranges());
|
||||||
unsigned reps = 1;
|
|
||||||
Params msgProduct (msgSize, LogAware::multIdenty());
|
Params msgProduct (msgSize, LogAware::multIdenty());
|
||||||
if (Globals::logDomain) {
|
if (Globals::logDomain) {
|
||||||
for (size_t i = links.size(); i-- > 0; ) {
|
for (size_t i = links.size(); i-- > 0; ) {
|
||||||
|
@ -207,9 +207,8 @@ CbpSolver::calcFactorToVarMsg (SpLink* _link)
|
|||||||
const SpLinkSet& links = ninf(src)->getLinks();
|
const SpLinkSet& links = ninf(src)->getLinks();
|
||||||
// calculate the product of messages that were sent
|
// calculate the product of messages that were sent
|
||||||
// to factor `src', except from var `dst'
|
// 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());
|
Params msgProduct (msgSize, LogAware::multIdenty());
|
||||||
if (Globals::logDomain) {
|
if (Globals::logDomain) {
|
||||||
for (size_t i = links.size(); i-- > 0; ) {
|
for (size_t i = links.size(); i-- > 0; ) {
|
||||||
|
@ -14,10 +14,9 @@ class Indexer
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Indexer (const Ranges& ranges, bool calcOffsets = true)
|
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) {
|
if (calcOffsets) {
|
||||||
calculateOffsets();
|
calculateOffsets();
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ InfAlgorithms infAlgorithm = InfAlgorithms::VE;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace BpOptions {
|
namespace BpOptions {
|
||||||
Schedule schedule = BpOptions::Schedule::SEQ_FIXED;
|
Schedule schedule = BpOptions::Schedule::SEQ_FIXED;
|
||||||
//Schedule schedule = BpOptions::Schedule::SEQ_RANDOM;
|
//Schedule schedule = BpOptions::Schedule::SEQ_RANDOM;
|
||||||
@ -71,7 +70,6 @@ stringToDouble (string str)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
factorial (unsigned num)
|
factorial (unsigned num)
|
||||||
{
|
{
|
||||||
@ -128,8 +126,8 @@ nrCombinations (unsigned n, unsigned k)
|
|||||||
size_t
|
size_t
|
||||||
sizeExpected (const Ranges& ranges)
|
sizeExpected (const Ranges& ranges)
|
||||||
{
|
{
|
||||||
return std::accumulate (
|
return std::accumulate (ranges.begin(),
|
||||||
ranges.begin(), ranges.end(), 1, multiplies<unsigned>());
|
ranges.end(), 1, multiplies<unsigned>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -392,7 +390,9 @@ getMaxNorm (const Params& v1, const Params& v2)
|
|||||||
double
|
double
|
||||||
pow (double base, unsigned iexp)
|
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
|
double
|
||||||
pow (double base, double exp)
|
pow (double base, double exp)
|
||||||
{
|
{
|
||||||
// assumes that `expoent' is never in log domain
|
// `expoent' should not be in log domain
|
||||||
return Globals::logDomain ? base * exp : std::pow (base, exp);
|
return Globals::logDomain
|
||||||
|
? base * exp
|
||||||
|
: std::pow (base, exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user