-/* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
- Radboud University Nijmegen, The Netherlands
-
- This file is part of libDAI.
+/* 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
+ */
- 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
-*/
+/// \file
+/// \brief Defines class MF
+/// \todo Improve documentation
#ifndef __defined_libdai_mf_h
namespace dai {
+/// Approximate inference algorithm "Mean Field"
class MF : public DAIAlgFG {
- protected:
+ private:
std::vector<Factor> _beliefs;
+ /// Maximum difference encountered so far
+ double _maxdiff;
+ /// Number of iterations needed
+ size_t _iters;
public:
+ /// Parameters of this inference algorithm
struct Properties {
+ /// Verbosity
size_t verbose;
+
+ /// Maximum number of iterations
size_t maxiter;
+
+ /// Tolerance
double tol;
+
+ /// Damping constant
+ double damping;
} props;
- double maxdiff;
-
+
+ /// Name of this inference algorithm
+ static const char *Name;
+
public:
- // default constructor
- MF() : DAIAlgFG(), _beliefs(), props(), maxdiff(0.0) {}
- // copy constructor
- MF( const MF& x ) : DAIAlgFG(x), _beliefs(x._beliefs), props(x.props), maxdiff(x.maxdiff) {}
- MF* clone() const { return new MF(*this); }
- // construct MF object from FactorGraph
- MF( const FactorGraph & fg, const PropertySet &opts ) : DAIAlgFG(fg), _beliefs(), props(), maxdiff(0.0) {
+ /// Default constructor
+ MF() : DAIAlgFG(), _beliefs(), _maxdiff(0.0), _iters(0U), props() {}
+
+ /// Construct from FactorGraph fg and PropertySet opts
+ MF( const FactorGraph &fg, const PropertySet &opts ) : DAIAlgFG(fg), _beliefs(), _maxdiff(0.0), _iters(0U), props() {
setProperties( opts );
- create();
- }
- // assignment operator
- MF& operator=( const MF &x ) {
- if( this != &x ) {
- DAIAlgFG::operator=( x );
- _beliefs = x._beliefs;
- props = x.props;
- maxdiff = x.maxdiff;
- }
- return *this;
+ construct();
}
- static const char *Name;
- std::string identify() const;
- void create();
- void init();
- double run();
- Factor beliefV (size_t i) const;
- Factor belief (const Var &n) const;
- Factor belief (const VarSet &ns) const;
- std::vector<Factor> beliefs() const;
- Real logZ() const;
-
- void init( const VarSet &ns );
- void undoProbs( const VarSet &ns ) { FactorGraph::undoProbs(ns); init(ns); }
+
+ /// @name General InfAlg interface
+ //@{
+ virtual MF* clone() const { return new MF(*this); }
+ virtual std::string identify() const;
+ virtual Factor belief( const Var &n ) const;
+ virtual Factor belief( const VarSet &ns ) const;
+ virtual std::vector<Factor> beliefs() const;
+ virtual Real logZ() const;
+ virtual void init();
+ virtual void init( const VarSet &ns );
+ virtual double run();
+ virtual double maxDiff() const { return _maxdiff; }
+ virtual size_t Iterations() const { return _iters; }
+ //@}
+
+
+ /// @name Additional interface specific for MF
+ //@{
+ Factor beliefV( size_t i ) const;
+ //@}
+
+ private:
+ void construct();
void setProperties( const PropertySet &opts );
PropertySet getProperties() const;
- double maxDiff() const { return maxdiff; }
+ std::string printProperties() const;
};