From: Joris Mooij Date: Tue, 9 Oct 2012 09:34:23 +0000 (+0200) Subject: Fixed GLC::CalcFactorBelief (now uses geometric averaging) and GLC::belief X-Git-Tag: v0.3.2~13 X-Git-Url: http://git.tuebingen.mpg.de/?p=libdai.git;a=commitdiff_plain;h=60493466d85c5d01e21dd33d7ce4f3797a2506ff Fixed GLC::CalcFactorBelief (now uses geometric averaging) and GLC::belief --- diff --git a/src/glc.cpp b/src/glc.cpp index 977a563..9d9ff15 100644 --- a/src/glc.cpp +++ b/src/glc.cpp @@ -276,9 +276,15 @@ void GLC::CalcBelief( size_t i, bool isFinal ) { void GLC::CalcFactorBelief( size_t I ) { VarSet ns = factor(I).vars(); + Factor tmp( ns, 1.0 ); + size_t counter = 0; for( size_t R = 0; R < nrCWs(); R++ ) - if( ns << inds2vars( INRs(R).elements() ) ) - _factorBeliefs[ns] = CW(R).belief(ns); + if( ns << inds2vars( INRs(R).elements() ) ) { + tmp *= CW(R).belief(ns); + counter++; + } + if( counter > 0 ) + _factorBeliefs[ns] = tmp ^ (1.0 / counter); } @@ -291,6 +297,9 @@ Factor GLC::belief( const VarSet &ns ) const { map::const_iterator it = _factorBeliefs.find(ns); if( it != _factorBeliefs.end() ) return it->second; + for( map::const_iterator it = _factorBeliefs.begin(); it != _factorBeliefs.end(); it++ ) + if( ns << it->second.vars() ) + return it->second.marginal( ns ); } DAI_THROW(BELIEF_NOT_AVAILABLE); return Factor(); diff --git a/tests/testfast.out b/tests/testfast.out index 51b1500..115486b 100644 --- a/tests/testfast.out +++ b/tests/testfast.out @@ -1547,7 +1547,7 @@ GLC_FULLCAV_LOOP4 5.304e-03 1.690e-03 N/A N/A # ({x13}, (9.035e-01, 9.653e-02)) # ({x14}, (2.412e-01, 7.588e-01)) # ({x15}, (6.913e-01, 3.087e-01)) -GLC+_UNICAV_LOOP4 5.578e-06 1.980e-06 3.980e-05 5.551e-06 N/A 1.000e-09 +GLC+_UNICAV_LOOP4 5.578e-06 1.980e-06 3.523e-05 6.616e-06 N/A 1.000e-09 # ({x0}, (3.500e-01, 6.500e-01)) # ({x1}, (6.447e-01, 3.553e-01)) # ({x2}, (4.997e-01, 5.003e-01)) @@ -1564,7 +1564,7 @@ GLC+_UNICAV_LOOP4 5.578e-06 1.980e-06 3.980e-05 5.551e-06 # ({x13}, (9.038e-01, 9.616e-02)) # ({x14}, (2.408e-01, 7.592e-01)) # ({x15}, (6.910e-01, 3.090e-01)) -GLC+_FULLCAV_LOOP4 1.512e-07 2.111e-08 3.977e-07 3.838e-08 N/A 1.000e-09 +GLC+_FULLCAV_LOOP4 1.512e-07 2.111e-08 4.137e-07 5.395e-08 N/A 1.000e-09 # ({x0}, (3.500e-01, 6.500e-01)) # ({x1}, (6.447e-01, 3.553e-01)) # ({x2}, (4.997e-01, 5.003e-01)) @@ -1581,7 +1581,7 @@ GLC+_FULLCAV_LOOP4 1.512e-07 2.111e-08 3.977e-07 3.838e-08 # ({x13}, (9.038e-01, 9.617e-02)) # ({x14}, (2.408e-01, 7.592e-01)) # ({x15}, (6.910e-01, 3.090e-01)) -GLC+_UNICAV_LOOP5 5.578e-06 1.980e-06 3.980e-05 5.551e-06 N/A 1.000e-09 +GLC+_UNICAV_LOOP5 5.578e-06 1.980e-06 3.523e-05 6.616e-06 N/A 1.000e-09 # ({x0}, (3.500e-01, 6.500e-01)) # ({x1}, (6.447e-01, 3.553e-01)) # ({x2}, (4.997e-01, 5.003e-01)) @@ -1598,7 +1598,7 @@ GLC+_UNICAV_LOOP5 5.578e-06 1.980e-06 3.980e-05 5.551e-06 # ({x13}, (9.038e-01, 9.616e-02)) # ({x14}, (2.408e-01, 7.592e-01)) # ({x15}, (6.910e-01, 3.090e-01)) -GLC+_FULLCAV_LOOP5 1.513e-07 2.113e-08 3.977e-07 3.838e-08 N/A 1.000e-09 +GLC+_FULLCAV_LOOP5 1.513e-07 2.113e-08 4.137e-07 5.394e-08 N/A 1.000e-09 # ({x0}, (3.500e-01, 6.500e-01)) # ({x1}, (6.447e-01, 3.553e-01)) # ({x2}, (4.997e-01, 5.003e-01))