1 #ifndef FAIF_FUSION_HPP 2 #define FAIF_FUSION_HPP 12 #include <boost/bind.hpp> 26 typedef typename Belief::ValueId AttrIdd;
29 typedef typename Belief::Beliefs Beliefs;
32 typedef std::map<AttrIdd, std::vector<Probability> > Evidence;
35 static typename Evidence::value_type InitTransformFunction(
const Belief& in) {
36 std::vector<Probability> v;
37 v.push_back(in.getProbability());
38 return typename Evidence::value_type(in.getValue(), v);
44 template<
typename Belief>
47 typedef typename FusionInternal<Belief>::Evidence Evidence;
48 typedef typename FusionInternal<Belief>::Beliefs Beliefs;
49 typedef typename FusionInternal<Belief>::AttrIdd AttrIdd;
55 void operator()(
const Beliefs& probs) {
57 for(
typename Evidence::iterator i = evidence_.begin(); i != evidence_.end(); ++i ) {
58 Probability probability_ = std::numeric_limits<Probability>::quiet_NaN();
59 typename Beliefs::const_iterator found =
60 std::find_if(probs.begin(), probs.end(),
61 boost::bind(std::equal_to<AttrIdd>(), boost::bind(&Belief::getValue, _1), i->first ) );
62 if( found != probs.end() )
63 probability_ = found->getProbability();
65 i->second.push_back(probability_);
72 Probability sum = 0.0;
74 for(
typename Evidence::const_iterator i = evidence_.begin(); i != evidence_.end(); ++i ) {
75 const Probability& v = i->second.back();
84 Probability probForUnknown = (1.0 - sum)/static_cast<Probability>(count);
85 if(probForUnknown < 0)
87 for(
typename Evidence::iterator i = evidence_.begin(); i != evidence_.end(); ++i ) {
88 Probability& v = i->second.back();
99 template<
typename Belief,
typename Ev
idenceValue>
104 Belief operator()(
const Probability& prob,
const EvidenceValue& evidence) {
105 return Belief(evidence.first, prob / sum_ );
115 template<
typename Belief>
typename Belief::Beliefs
fusion(
const typename std::vector<typename Belief::Beliefs>& input) {
119 typedef typename FusionInternal<Belief>::Evidence Evidence;
120 typedef typename FusionInternal<Belief>::Beliefs Beliefs;
128 const Beliefs& front = input.front();
131 std::for_each( ++input.begin(), input.end(), add_evidence );
133 std::vector<Probability> combination;
134 for(
typename Evidence::const_iterator i = evidence.begin(); i != evidence.end(); ++i ) {
135 const std::vector<Probability>& in = i->second;
136 combination.push_back( std::accumulate(in.begin(), in.end(), 1.0, std::multiplies<Probability>() ) );
138 Probability sum = std::accumulate(combination.begin(), combination.end(), 0.0);
141 std::transform( combination.begin(), combination.end(), evidence.begin(), std::back_inserter(output), nfunctor );
148 #endif //FAIF_FUSION_HPP Belief::Beliefs fusion(const typename std::vector< typename Belief::Beliefs > &input)
connect categories using the Dempster-Shafer combination rule, e.g. bel(cat) = bel1(cat) * bel2(cat) ...
Definition: Fusion.hpp:115
Definition: Fusion.hpp:100
Definition: Fusion.hpp:45
the belief concept
Definition: Belief.hpp:22
typedef's for Dempster-Shafer combination rule (for fusion) and some internal (helping) methods ...
Definition: Fusion.hpp:23
belief is value id with probability
Definition: Belief.hpp:41