2013-02-07 17:50:02 +00:00
|
|
|
#ifndef YAP_PACKAGES_CLPBN_HORUS_WEIGHTEDBP_H_
|
|
|
|
#define YAP_PACKAGES_CLPBN_HORUS_WEIGHTEDBP_H_
|
2012-05-31 21:24:15 +01:00
|
|
|
|
2013-02-07 20:09:10 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2012-06-12 16:29:57 +01:00
|
|
|
#include "BeliefProp.h"
|
2012-05-31 21:24:15 +01:00
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
|
2013-02-07 23:53:13 +00:00
|
|
|
namespace horus {
|
|
|
|
|
2012-05-31 21:24:15 +01:00
|
|
|
class WeightedLink : public BpLink
|
|
|
|
{
|
|
|
|
public:
|
2012-12-20 23:19:10 +00:00
|
|
|
WeightedLink (FacNode* fn, VarNode* vn, size_t idx, unsigned weight)
|
2012-05-31 21:24:15 +01:00
|
|
|
: BpLink (fn, vn), index_(idx), weight_(weight),
|
2013-02-08 00:15:41 +00:00
|
|
|
pwdMsg_(vn->range(), log_aware::one()) { }
|
2012-05-31 21:24:15 +01:00
|
|
|
|
|
|
|
size_t index (void) const { return index_; }
|
|
|
|
|
|
|
|
unsigned weight (void) const { return weight_; }
|
|
|
|
|
|
|
|
const Params& powMessage (void) const { return pwdMsg_; }
|
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
void updateMessage (void);
|
2012-12-17 18:39:42 +00:00
|
|
|
|
2012-05-31 21:24:15 +01:00
|
|
|
private:
|
2012-12-27 22:25:45 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN (WeightedLink);
|
|
|
|
|
2012-05-31 21:24:15 +01:00
|
|
|
size_t index_;
|
|
|
|
unsigned weight_;
|
|
|
|
Params pwdMsg_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
inline void
|
|
|
|
WeightedLink::updateMessage (void)
|
|
|
|
{
|
|
|
|
pwdMsg_ = *nextMsg_;
|
|
|
|
swap (currMsg_, nextMsg_);
|
2013-02-08 00:15:41 +00:00
|
|
|
log_aware::pow (pwdMsg_, weight_);
|
2013-02-06 00:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-12 16:29:57 +01:00
|
|
|
class WeightedBp : public BeliefProp
|
2012-05-31 21:24:15 +01:00
|
|
|
{
|
2012-12-17 18:39:42 +00:00
|
|
|
public:
|
2012-06-12 16:29:57 +01:00
|
|
|
WeightedBp (const FactorGraph& fg,
|
2013-02-07 13:37:15 +00:00
|
|
|
const std::vector<std::vector<unsigned>>& weights)
|
2012-06-12 16:29:57 +01:00
|
|
|
: BeliefProp (fg), weights_(weights) { }
|
2012-05-31 21:24:15 +01:00
|
|
|
|
2012-06-12 16:29:57 +01:00
|
|
|
~WeightedBp (void);
|
2012-12-17 18:39:42 +00:00
|
|
|
|
2012-05-31 21:24:15 +01:00
|
|
|
Params getPosterioriOf (VarId);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void createLinks (void);
|
|
|
|
|
|
|
|
void maxResidualSchedule (void);
|
|
|
|
|
|
|
|
void calcFactorToVarMsg (BpLink*);
|
|
|
|
|
|
|
|
Params getVarToFactorMsg (const BpLink*) const;
|
|
|
|
|
|
|
|
void printLinkInformation (void) const;
|
2012-12-17 18:39:42 +00:00
|
|
|
|
2013-02-07 13:37:15 +00:00
|
|
|
std::vector<std::vector<unsigned>> weights_;
|
2012-12-27 22:25:45 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN (WeightedBp);
|
2012-05-31 21:24:15 +01:00
|
|
|
};
|
|
|
|
|
2013-02-07 23:53:13 +00:00
|
|
|
} // namespace horus
|
|
|
|
|
2013-02-08 00:20:01 +00:00
|
|
|
#endif // YAP_PACKAGES_CLPBN_HORUS_WEIGHTEDBP_H_
|
2012-05-31 21:24:15 +01:00
|
|
|
|