-/* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
- Radboud University Nijmegen, The Netherlands /
- Max Planck Institute for Biological Cybernetics, Germany
-
- This file is part of libDAI.
-
- libDAI is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- libDAI is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with libDAI; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+/* This file is part of libDAI - http://www.libdai.org/
+ *
+ * libDAI is licensed under the terms of the GNU General Public License version
+ * 2, or (at your option) any later version. libDAI is distributed without any
+ * warranty. See the file COPYING for more details.
+ *
+ * Copyright (C) 2006-2009 Joris Mooij [joris dot mooij at libdai dot org]
+ * Copyright (C) 2006-2007 Radboud University Nijmegen, The Netherlands
+ */
/// \file
std::vector<Factor> _beliefs;
/// Maximum difference encountered so far
- double _maxdiff;
+ Real _maxdiff;
/// Number of iterations needed
size_t _iters;
/// Parameters of this inference algorithm
struct Properties {
/// Enumeration of possible ways to initialize the cavities
- DAI_ENUM(CavityType,FULL,PAIR,PAIR2,UNIFORM)
+ DAI_ENUM(CavityType,FULL,PAIR,PAIR2,UNIFORM);
/// Enumeration of different update schedules
- DAI_ENUM(UpdateType,SEQFIX,SEQRND,NONE)
+ DAI_ENUM(UpdateType,SEQFIX,SEQRND,NONE);
/// Verbosity
size_t verbose;
size_t maxiter;
/// Tolerance
- double tol;
+ Real tol;
/// Complete or partial reinit of cavity graphs?
bool reinit;
/// Damping constant
- double damping;
+ Real damping;
/// How to initialize the cavities
CavityType cavity;
/// Default constructor
LC() : DAIAlgFG(), _pancakes(), _cavitydists(), _phis(), _beliefs(), _maxdiff(), _iters(), props() {}
- /// Copy constructor
- LC( const LC &x ) : DAIAlgFG(x), _pancakes(x._pancakes), _cavitydists(x._cavitydists), _phis(x._phis), _beliefs(x._beliefs), _maxdiff(x._maxdiff), _iters(x._iters), props(x.props) {}
-
- /// Assignment operator
- LC& operator=( const LC &x ) {
- if( this != &x ) {
- DAIAlgFG::operator=( x );
- _pancakes = x._pancakes;
- _cavitydists = x._cavitydists;
- _phis = x._phis;
- _beliefs = x._beliefs;
- _maxdiff = x._maxdiff;
- _iters = x._iters;
- props = x.props;
- }
- return *this;
- }
-
/// Construct from FactorGraph fg and PropertySet opts
LC( const FactorGraph &fg, const PropertySet &opts );
/// @name General InfAlg interface
//@{
virtual LC* clone() const { return new LC(*this); }
- virtual LC* create() const { return new LC(); }
virtual std::string identify() const;
virtual Factor belief( const Var &n ) const { return( _beliefs[findVar(n)] ); }
virtual Factor belief( const VarSet &/*ns*/ ) const { DAI_THROW(NOT_IMPLEMENTED); return Factor(); }
virtual Real logZ() const { DAI_THROW(NOT_IMPLEMENTED); return 0.0; }
virtual void init();
virtual void init( const VarSet &/*ns*/ ) { init(); }
- virtual double run();
- virtual double maxDiff() const { return _maxdiff; }
+ virtual Real run();
+ virtual Real maxDiff() const { return _maxdiff; }
virtual size_t Iterations() const { return _iters; }
//@}
+ Factor beliefV( size_t i ) const { return _beliefs[i]; }
/// @name Additional interface specific for LC
- //@{
- double CalcCavityDist( size_t i, const std::string &name, const PropertySet &opts );
- double InitCavityDists( const std::string &name, const PropertySet &opts );
+ //@{
+ Real CalcCavityDist( size_t i, const std::string &name, const PropertySet &opts );
+ Real InitCavityDists( const std::string &name, const PropertySet &opts );
long SetCavityDists( std::vector<Factor> &Q );
Factor NewPancake (size_t i, size_t _I, bool & hasNaNs);