- changed #ifndefs to GNU style
- added extra warning checks (-W -Wextra) and fixed resulting warnings
- dai::TProb:
- o removed copy constructor and assignment operators (redundant)
- o implementation of some methods via STL algorithms
- o added methods takeExp, takeLog, takeLog0 for transformation in-place
- o explicit constructor (prevents implicit conversion from size_t to TProb)
- o added operator+,+=,-,-=, with argument T (for calculations in log-scale)
+ o removed copy constructor and assignment operators (redundant)
+ o implementation of some methods via STL algorithms
+ o added methods takeExp, takeLog, takeLog0 for transformation in-place
+ o explicit constructor (prevents implicit conversion from size_t to TProb)
+ o added operator+,+=,-,-=, with argument T (for calculations in log-scale)
- Added "logdomain" property to BP, a boolean that controls whether
calculations are done in the log-domain or in the linear domain;
doing calculations in the log-domain may help if the numerical range
normtype is now Prob::NORMPROB by default.
* Small optimization in Diffs
* Interface changes:
- - VarSet::
- stateSpace() -> VarSet::states()
+ - VarSet::stateSpace() -> VarSet::states()
- FactorGraph::
- delta(const Var &) -> delta(size_t)
- Delta(const Var &) -> Delta(size_t)
- makeCavity(const Var &) -> makeCavity(size_t)
- removed MakeFactorCavity(size_t)
- removed ExactMarginal(const VarSet &)
- removed ExactlogZ()
- moved isConnected() to BipartiteGraph
- vars() -> vars
- factors() -> factors
+ delta(const Var &) -> delta(size_t)
+ Delta(const Var &) -> Delta(size_t)
+ makeCavity(const Var &) -> makeCavity(size_t)
+ vars() -> vars
+ factors() -> factors
+ removed MakeFactorCavity(size_t)
+ removed ExactMarginal(const VarSet &)
+ removed ExactlogZ()
+ moved isConnected() to BipartiteGraph
- RegionGraph::
- nr_ORs() -> nrORs()
- nr_IRs() -> nrIRs()
- ORs() -> ORs
- IRs() -> IRs
+ nr_ORs() -> nrORs()
+ nr_IRs() -> nrIRs()
+ ORs() -> ORs
+ IRs() -> IRs
- *::Regenerate() -> *::create()
- Renamed Index -> IndexFor
+ - Diffs:
+ max() -> maxDiff()
+ max_size() -> maxSize()
+ - Prob::max() -> Prob::maxVal()
+ - Factor::max() -> Factor::maxVal()
+ - toc() in util.h now returns seconds as a double
+* Added possibility to build for Windows in Makefile
libDAI-0.2.1 (2008-05-26)
WITH_TREEEP = true
WITH_JTREE = true
WITH_MR = true
+# Build with debug info?
DEBUG = true
-NEW_MATLAB = true
+# Build matlab interface?
WITH_MATLAB =
+# New/old matlab version?
+NEW_MATLAB = true
+# Windows or linux (default)?
+WINDOWS =
# Directories
INC = include/dai
-# Doxyfile 1.4.2
+# Doxyfile 1.5.5
# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project
# Project related configuration options
#---------------------------------------------------------------------------
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# http://www.gnu.org/software/libiconv for the list of possible encodings.
+
+DOXYFILE_ENCODING = UTF-8
+
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
# by quotes) that should identify the project.
# documentation generated by doxygen is written. Doxygen will use this
# information to generate all constant output in the proper language.
# The default language is English, other supported languages are:
-# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish,
-# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese,
-# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian,
-# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish,
-# Swedish, and Ukrainian.
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek,
+# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages),
+# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish,
+# Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish,
+# and Ukrainian.
OUTPUT_LANGUAGE = English
-# This tag can be used to specify the encoding used in the generated output.
-# The encoding is not always determined by the language that is chosen,
-# but also whether or not the output is meant for Windows or non-Windows users.
-# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES
-# forces the Windows encoding (this is the default for the Windows binary),
-# whereas setting the tag to NO uses a Unix-style encoding (the default for
-# all platforms other than Windows).
-
-USE_WINDOWS_ENCODING = NO
-
# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
# include brief member descriptions after the members that are listed in
# the file and class documentation (similar to JavaDoc).
# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
# will interpret the first line (until the first dot) of a JavaDoc-style
# comment as the brief description. If set to NO, the JavaDoc
-# comments will behave just like the Qt-style comments (thus requiring an
-# explicit @brief command for a brief description.
+# comments will behave just like regular Qt-style comments
+# (thus requiring an explicit @brief command for a brief description.)
JAVADOC_AUTOBRIEF = NO
+# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
+# interpret the first line (until the first dot) of a Qt-style
+# comment as the brief description. If set to NO, the comments
+# will behave just like regular Qt-style comments (thus requiring
+# an explicit \brief command for a brief description.)
+
+QT_AUTOBRIEF = NO
+
# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
# treat a multi-line C++ special comment block (i.e. a block of //! or ///
# comments) as a brief description. This used to be the default behaviour.
INHERIT_DOCS = YES
-# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
-# tag is set to YES, then doxygen will reuse the documentation of the first
-# member in the group (if any) for the other members of the group. By default
-# all members of a group must be documented explicitly.
-
-DISTRIBUTE_GROUP_DOC = NO
-
# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
# a new page for each member. If set to NO, the documentation of a member will
# be part of the file/class/namespace that contains it.
OPTIMIZE_OUTPUT_FOR_C = NO
-# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources
-# only. Doxygen will then generate output that is more tailored for Java.
-# For instance, namespaces will be presented as packages, qualified scopes
-# will look different, etc.
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for
+# Java. For instance, namespaces will be presented as packages, qualified
+# scopes will look different, etc.
OPTIMIZE_OUTPUT_JAVA = NO
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources only. Doxygen will then generate output that is more tailored for
+# Fortran.
+
+OPTIMIZE_FOR_FORTRAN = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for
+# VHDL.
+
+OPTIMIZE_OUTPUT_VHDL = NO
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+
+CPP_CLI_SUPPORT = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only.
+# Doxygen will parse them like normal C++ but will assume all classes use public
+# instead of private inheritance when no explicit protection keyword is present.
+
+SIP_SUPPORT = NO
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC = NO
+
# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
# the same type (for instance a group of public functions) to be put as a
# subgroup of that type (e.g. under the Public Functions section). Set it to
SUBGROUPING = YES
+# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum
+# is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically
+# be useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+
+TYPEDEF_HIDES_STRUCT = NO
+
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_LOCAL_METHODS = NO
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base
+# name of the file that contains the anonymous namespace. By default
+# anonymous namespace are hidden.
+
+EXTRACT_ANON_NSPACES = NO
+
# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
# undocumented members of documented classes, files or namespaces.
# If set to NO (the default) these members will be included in the
SORT_BRIEF_DOCS = NO
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the
+# hierarchy of group names into alphabetical order. If set to NO (the default)
+# the group names will appear in their defined order.
+
+SORT_GROUP_NAMES = NO
+
# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
# sorted by fully-qualified names, including namespaces. If set to
# NO (the default), the class list will be sorted only by class name,
# If the sources in your project are distributed over multiple directories
# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
-# in the documentation.
+# in the documentation. The default is NO.
SHOW_DIRECTORIES = YES
# The FILE_VERSION_FILTER tag can be used to specify a program or script that
-# doxygen should invoke to get the current version for each file (typically from the
-# version control system). Doxygen will invoke the program by executing (via
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
# popen()) the command <command> <input-file>, where <command> is the value of
# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
-# provided by doxygen. Whatever the progam writes to standard output
+# provided by doxygen. Whatever the program writes to standard output
# is used as the file version. See the manual for examples.
FILE_VERSION_FILTER =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = src include/dai
+INPUT = src \
+ include/dai
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
+# also the default input encoding. Doxygen uses libiconv (or the iconv built
+# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for
+# the list of possible encodings.
+
+INPUT_ENCODING = UTF-8
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
# and *.h) to filter out the source-files in the directories. If left
# blank the following patterns are tested:
# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
-# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm
+# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90
FILE_PATTERNS =
# If the value of the INPUT tag contains directories, you can use the
# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
-# certain files from those directories.
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
+# for example use the pattern */test/*
EXCLUDE_PATTERNS =
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+
+EXCLUDE_SYMBOLS =
+
# The EXAMPLE_PATH tag can be used to specify one or more files or
# directories that contain example code fragments that are included (see
# the \include command).
REFERENCES_RELATION = YES
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
+# link to the source code. Otherwise they will link to the documentstion.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
+# will need version 4.8.6 or higher.
+
+USE_HTAGS = NO
+
# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
# will generate a verbatim copy of the header file for each class for
# which an include is specified. Set to NO to disable this.
# If the GENERATE_HTMLHELP tag is set to YES, additional index files
# will be generated that can be used as input for tools like the
-# Microsoft HTML help workshop to generate a compressed HTML help file (.chm)
+# Microsoft HTML help workshop to generate a compiled HTML help file (.chm)
# of the generated HTML documentation.
GENERATE_HTMLHELP = NO
+# If the GENERATE_DOCSET tag is set to YES, additional index files
+# will be generated that can be used as input for Apple's Xcode 3
+# integrated development environment, introduced with OSX 10.5 (Leopard).
+# To create a documentation set, doxygen will generate a Makefile in the
+# HTML output directory. Running make will produce the docset in that
+# directory and running "make install" will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find
+# it at startup.
+
+GENERATE_DOCSET = NO
+
+# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the
+# feed. A documentation feed provides an umbrella under which multiple
+# documentation sets from a single provider (such as a company or product suite)
+# can be grouped.
+
+DOCSET_FEEDNAME = "Doxygen generated docs"
+
+# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that
+# should uniquely identify the documentation set bundle. This should be a
+# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen
+# will append .docset to the name.
+
+DOCSET_BUNDLE_ID = org.doxygen.Project
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded. For this to work a browser that supports
+# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox
+# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari).
+
+HTML_DYNAMIC_SECTIONS = NO
+
# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
# be used to specify the file name of the resulting .chm file. You
# can add a path in front of the file if the result should not be
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
# then the macro expansion is limited to the macros specified with the
-# PREDEFINED and EXPAND_AS_PREDEFINED tags.
+# PREDEFINED and EXPAND_AS_DEFINED tags.
EXPAND_ONLY_PREDEF = NO
CLASS_DIAGRAMS = YES
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see
+# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH =
+
# If set to YES, the inheritance and collaboration graphs will hide
# inheritance and usage relations if the target is undocumented
# or is not a class.
INCLUDED_BY_GRAPH = YES
-# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will
-# generate a call dependency graph for every global function or class method.
-# Note that enabling this option will significantly increase the time of a run.
-# So in most cases it will be better to enable call graphs for selected
-# functions only using the \callgraph command.
+# If the CALL_GRAPH and HAVE_DOT options are set to YES then
+# doxygen will generate a call dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable call graphs
+# for selected functions only using the \callgraph command.
CALL_GRAPH = NO
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
+# doxygen will generate a caller dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable caller
+# graphs for selected functions only using the \callergraph command.
+
+CALLER_GRAPH = NO
+
# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
# will graphical hierarchy of all classes instead of a textual one.
DOTFILE_DIRS =
-# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width
-# (in pixels) of the graphs generated by dot. If a graph becomes larger than
-# this value, doxygen will try to truncate the graph, so that it fits within
-# the specified constraint. Beware that most browsers cannot cope with very
-# large images.
-
-MAX_DOT_GRAPH_WIDTH = 1024
-
-# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height
-# (in pixels) of the graphs generated by dot. If a graph becomes larger than
-# this value, doxygen will try to truncate the graph, so that it fits within
-# the specified constraint. Beware that most browsers cannot cope with very
-# large images.
+# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen if the
+# number of direct children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note
+# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
-MAX_DOT_GRAPH_HEIGHT = 1024
+DOT_GRAPH_MAX_NODES = 50
# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
# graphs generated by dot. A depth value of 3 means that only nodes reachable
# from the root by following a path via at most 3 edges will be shown. Nodes
# that lay further from the root node will be omitted. Note that setting this
# option to 1 or 2 may greatly reduce the computation time needed for large
-# code bases. Also note that a graph may be further truncated if the graph's
-# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH
-# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default),
-# the graph is not depth-constrained.
+# code bases. Also note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
MAX_DOT_GRAPH_DEPTH = 0
# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
-# background. This is disabled by default, which results in a white background.
-# Warning: Depending on the platform used, enabling this option may lead to
-# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
-# read).
+# background. This is enabled by default, which results in a transparent
+# background. Warning: Depending on the platform used, enabling this option
+# may lead to badly anti-aliased labels on the edges of a graph (i.e. they
+# become hard to read).
DOT_TRANSPARENT = NO
/// Return union of all members
VarSet vars() const {
VarSet result;
- for( iterator x = begin(); x != end(); x++ )
+ for( const_iterator x = begin(); x != end(); x++ )
result |= *x;
return result;
}
/// Returns union of clusters that contain n, minus n
VarSet Delta( const Var& n ) const {
VarSet result;
- for( iterator x = begin(); x != end(); x++ )
+ for( const_iterator x = begin(); x != end(); x++ )
if( (*x && n) )
result |= *x;
return result;
_pos = begin();
_maxpos = begin();
};
- double max() {
+ double maxDiff() {
if( size() < _maxsize )
return _def;
else
}
}
}
- size_t max_size() { return _maxsize; }
+ size_t maxSize() { return _maxsize; }
};
bool hasNegatives() const { return _p.hasNegatives(); }
T totalSum() const { return _p.totalSum(); }
T maxAbs() const { return _p.maxAbs(); }
- T max() const { return _p.max(); }
+ T maxVal() const { return _p.maxVal(); }
Complex entropy() const { return _p.entropy(); }
T strength( const Var &i, const Var &j ) const;
bs = i.states();
else
as = j.states();
- T f1 = slice( ij, alpha1 * as + beta1 * bs ).p().divide( slice( ij, alpha2 * as + beta1 * bs ).p() ).max();
- T f2 = slice( ij, alpha2 * as + beta2 * bs ).p().divide( slice( ij, alpha1 * as + beta2 * bs ).p() ).max();
+ T f1 = slice( ij, alpha1 * as + beta1 * bs ).p().divide( slice( ij, alpha2 * as + beta1 * bs ).p() ).maxVal();
+ T f2 = slice( ij, alpha2 * as + beta2 * bs ).p().divide( slice( ij, alpha1 * as + beta2 * bs ).p() ).maxVal();
T f = f1 * f2;
if( f > max )
max = f;
}
/// Returns maximum value
- T max() const {
+ T maxVal() const {
T Z = *std::max_element( _p.begin(), _p.end() );
return Z;
}
typedef std::pair<PropertyKey, PropertyValue> Property;
-/// Sends a Properties object to an output stream
+/// Sends a Property object to an output stream
std::ostream& operator<< (std::ostream & os, const Property & p);
#define __defined_libdai_util_h
-#include <sys/times.h>
+#include <vector>
+#include <set>
+#include <map>
+#include <iostream>
#include <cstdio>
#include <boost/foreach.hpp>
+#ifdef WINDOWS
+ #include <float.h> // for _isnan (?)
+ #include <boost/math/special_functions/atanh.hpp> // for atanh
+ #include <boost/math/special_functions/log1p.hpp> // for log1p
+// #include <xmath.h>
+#endif
+
#define foreach BOOST_FOREACH
namespace dai {
-clock_t toc();
-void rnd_seed( int seed );
+#ifdef WINDOWS
+ bool isnan( double x ) inline { return _isnan( x ); }
+ using boost::math:atanh;
+ using boost::math::log1p;
+#endif
+
+
+double toc();
+void rnd_seed( size_t seed );
double rnd_uniform();
double rnd_stdnormal();
+int rnd_int( int min, int max );
+
+
+// Output a std::vector
+template<class T>
+std::ostream& operator << (std::ostream& os, const std::vector<T> & x) {
+ os << "(";
+ for( typename std::vector<T>::const_iterator it = x.begin(); it != x.end(); it++ )
+ os << (it != x.begin() ? ", " : "") << *it;
+ os << ")";
+ return os;
+}
+
+
+// Output a std::set
+template<class T>
+std::ostream& operator << (std::ostream& os, const std::set<T> & x) {
+ os << "{";
+ for( typename std::set<T>::const_iterator it = x.begin(); it != x.end(); it++ )
+ os << (it != x.begin() ? ", " : "") << *it;
+ os << "}";
+ return os;
+}
+
+
+/// Output a std::map
+template<class T1, class T2>
+std::ostream& operator << (std::ostream& os, const std::map<T1,T2> & x) {
+ os << "{";
+ for( typename std::map<T1,T2>::const_iterator it = x.begin(); it != x.end(); it++ )
+ os << (it != x.begin() ? ", " : "") << it->first << "->" << it->second;
+ os << "}";
+ return os;
+}
+
+
+/// Output a std::pair
+template<class T1, class T2>
+std::ostream& operator << (std::ostream& os, const std::pair<T1,T2> & x) {
+ os << "(" << x.first << ", " << x.second << ")";
+ return os;
+}
} // end of namespace dai
}
}
if( logDomain ) {
- prod -= prod.max();
+ prod -= prod.maxVal();
prod.takeExp();
}
if( Verbose() >= 3)
cout << endl;
- clock_t tic = toc();
+ double tic = toc();
Diffs diffs(nrVars(), 1.0);
typedef pair<size_t,size_t> Edge;
// do several passes over the network until maximum number of iterations has
// been reached or until the maximum belief difference is smaller than tolerance
- for( iter=0; iter < MaxIter() && diffs.max() > Tol(); ++iter ) {
+ for( iter=0; iter < MaxIter() && diffs.maxDiff() > Tol(); ++iter ) {
if( Updates() == UpdateType::SEQMAX ) {
// Residuals-BP by Koller et al.
for( size_t t = 0; t < nredges; ++t ) {
}
if( Verbose() >= 3 )
- cout << "BP::run: maxdiff " << diffs.max() << " after " << iter+1 << " passes" << endl;
+ cout << "BP::run: maxdiff " << diffs.maxDiff() << " after " << iter+1 << " passes" << endl;
}
- updateMaxDiff( diffs.max() );
+ updateMaxDiff( diffs.maxDiff() );
if( Verbose() >= 1 ) {
- if( diffs.max() > Tol() ) {
+ if( diffs.maxDiff() > Tol() ) {
if( Verbose() == 1 )
cout << endl;
- cout << "BP::run: WARNING: not converged within " << MaxIter() << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.max() << endl;
+ cout << "BP::run: WARNING: not converged within " << MaxIter() << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.maxDiff() << endl;
} else {
if( Verbose() >= 3 )
cout << "BP::run: ";
}
}
- return diffs.max();
+ return diffs.maxDiff();
}
else
prod *= newMessage( i, I.iter );
if( logDomain ) {
- prod -= prod.max();
+ prod -= prod.maxVal();
prod.takeExp();
}
}
if( logDomain ) {
- prod -= prod.max();
+ prod -= prod.maxVal();
prod.takeExp();
}
using namespace std;
-ClusterGraph ClusterGraph::VarElim( const vector<Var> & ElimSeq ) const {
+ClusterGraph ClusterGraph::VarElim( const std::vector<Var> & ElimSeq ) const {
const long verbose = 0;
// Make a copy
while( !_vars.empty() ) {
if( verbose >= 1 )
cout << "Var Eliminiation cost" << endl;
- VarSet::iterator lowest = _vars.end();
+ VarSet::const_iterator lowest = _vars.end();
size_t lowest_cost = -1UL;
for( VarSet::const_iterator n = _vars.begin(); n != _vars.end(); n++ ) {
size_t cost = _Cl.eliminationCost( *n );
using namespace std;
-FactorGraph::FactorGraph( const vector<Factor> &P ) : G(), _undoProbs(), _normtype(Prob::NORMPROB) {
+FactorGraph::FactorGraph( const std::vector<Factor> &P ) : G(), _undoProbs(), _normtype(Prob::NORMPROB) {
// add factors, obtain variables
set<Var> _vars;
factors.reserve( P.size() );
}
-void HAK::findLoopClusters( const FactorGraph & fg, set<VarSet> &allcl, VarSet newcl, const Var & root, size_t length, VarSet vars ) {
+void HAK::findLoopClusters( const FactorGraph & fg, std::set<VarSet> &allcl, VarSet newcl, const Var & root, size_t length, VarSet vars ) {
for( VarSet::const_iterator in = vars.begin(); in != vars.end(); in++ ) {
VarSet ind = fg.delta( fg.findVar( *in ) );
if( (newcl.size()) >= 2 && (ind >> root) ) {
if( Verbose() >= 3)
cout << endl;
- clock_t tic = toc();
+ double tic = toc();
// Check whether counting numbers won't lead to problems
for( size_t beta = 0; beta < nrIRs(); beta++ )
size_t iter = 0;
// do several passes over the network until maximum number of iterations has
// been reached or until the maximum belief difference is smaller than tolerance
- for( iter = 0; iter < MaxIter() && diffs.max() > Tol(); iter++ ) {
+ for( iter = 0; iter < MaxIter() && diffs.maxDiff() > Tol(); iter++ ) {
for( size_t beta = 0; beta < nrIRs(); beta++ ) {
foreach( const Neighbor &alpha, nbIR(beta) ) {
size_t _beta = alpha.dual;
}
if( Verbose() >= 3 )
- cout << "HAK::doGBP: maxdiff " << diffs.max() << " after " << iter+1 << " passes" << endl;
+ cout << "HAK::doGBP: maxdiff " << diffs.maxDiff() << " after " << iter+1 << " passes" << endl;
}
- updateMaxDiff( diffs.max() );
+ updateMaxDiff( diffs.maxDiff() );
if( Verbose() >= 1 ) {
- if( diffs.max() > Tol() ) {
+ if( diffs.maxDiff() > Tol() ) {
if( Verbose() == 1 )
cout << endl;
- cout << "HAK::doGBP: WARNING: not converged within " << MaxIter() << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.max() << endl;
+ cout << "HAK::doGBP: WARNING: not converged within " << MaxIter() << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.maxDiff() << endl;
} else {
if( Verbose() >= 2 )
cout << "HAK::doGBP: ";
}
}
- return diffs.max();
+ return diffs.maxDiff();
}
if( Verbose() >= 3)
cout << endl;
- clock_t tic = toc();
+ double tic = toc();
// Save original outer regions
vector<FRegion> org_ORs = ORs;
Verbose( outer_verbose ? outer_verbose - 1 : 0 );
size_t outer_iter = 0;
- for( outer_iter = 0; outer_iter < outer_maxiter && diffs.max() > outer_tol; outer_iter++ ) {
+ for( outer_iter = 0; outer_iter < outer_maxiter && diffs.maxDiff() > outer_tol; outer_iter++ ) {
// Calculate new outer regions
for( size_t alpha = 0; alpha < nrORs(); alpha++ ) {
OR(alpha) = org_ORs[alpha];
}
if( Verbose() >= 3 )
- cout << "HAK::doDoubleLoop: maxdiff " << diffs.max() << " after " << outer_iter+1 << " passes" << endl;
+ cout << "HAK::doDoubleLoop: maxdiff " << diffs.maxDiff() << " after " << outer_iter+1 << " passes" << endl;
}
// restore _maxiter, _verbose and _maxdiff
Verbose( outer_verbose );
MaxDiff( org_maxdiff );
- updateMaxDiff( diffs.max() );
+ updateMaxDiff( diffs.maxDiff() );
// Restore original outer regions
ORs = org_ORs;
IR(beta).c() = org_IR_cs[beta];
if( Verbose() >= 1 ) {
- if( diffs.max() > Tol() ) {
+ if( diffs.maxDiff() > Tol() ) {
if( Verbose() == 1 )
cout << endl;
- cout << "HAK::doDoubleLoop: WARNING: not converged within " << outer_maxiter << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.max() << endl;
+ cout << "HAK::doDoubleLoop: WARNING: not converged within " << outer_maxiter << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.maxDiff() << endl;
} else {
if( Verbose() >= 3 )
cout << "HAK::doDoubleLoop: ";
}
}
- return diffs.max();
+ return diffs.maxDiff();
}
}
-void JTree::GenerateJT( const vector<VarSet> &Cliques ) {
+void JTree::GenerateJT( const std::vector<VarSet> &Cliques ) {
// Construct a weighted graph (each edge is weighted with the cardinality
// of the intersection of the nodes, where the nodes are the elements of
// Cliques).
}
-double LC::CalcCavityDist (size_t i, const string &name, const Properties &opts) {
+double LC::CalcCavityDist (size_t i, const std::string &name, const Properties &opts) {
Factor Bi;
double maxdiff = 0;
}
-double LC::InitCavityDists (const string &name, const Properties &opts) {
- clock_t tic = toc();
+double LC::InitCavityDists (const std::string &name, const Properties &opts) {
+ double tic = toc();
if( Verbose() >= 1 ) {
cout << "LC::InitCavityDists: ";
}
-long LC::SetCavityDists (vector<Factor> &Q) {
+long LC::SetCavityDists( std::vector<Factor> &Q ) {
if( Verbose() >= 1 )
cout << "LC::SetCavityDists: Setting initial cavity distributions" << endl;
if( Q.size() != nrVars() )
if( Verbose() >= 2 )
cout << endl;
- clock_t tic = toc();
+ double tic = toc();
Diffs diffs(nrVars(), 1.0);
updateMaxDiff( InitCavityDists(GetPropertyAs<string>("cavainame"), GetPropertyAs<Properties>("cavaiopts")) );
// do several passes over the network until maximum number of iterations has
// been reached or until the maximum belief difference is smaller than tolerance
- for( iter=0; iter < MaxIter() && diffs.max() > Tol(); iter++ ) {
+ for( iter=0; iter < MaxIter() && diffs.maxDiff() > Tol(); iter++ ) {
// Sequential updates
if( Updates() == UpdateType::SEQRND )
random_shuffle( update_seq.begin(), update_seq.end() );
}
if( Verbose() >= 3 )
- cout << "LC::run: maxdiff " << diffs.max() << " after " << iter+1 << " passes" << endl;
+ cout << "LC::run: maxdiff " << diffs.maxDiff() << " after " << iter+1 << " passes" << endl;
}
- updateMaxDiff( diffs.max() );
+ updateMaxDiff( diffs.maxDiff() );
if( Verbose() >= 1 ) {
- if( diffs.max() > Tol() ) {
+ if( diffs.maxDiff() > Tol() ) {
if( Verbose() == 1 )
cout << endl;
- cout << "LC::run: WARNING: not converged within " << MaxIter() << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.max() << endl;
+ cout << "LC::run: WARNING: not converged within " << MaxIter() << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.maxDiff() << endl;
} else {
if( Verbose() >= 2 )
cout << "LC::run: ";
}
}
- return diffs.max();
+ return diffs.maxDiff();
}
double MF::run() {
- clock_t tic = toc();
+ double tic = toc();
if( Verbose() >= 1 )
cout << "Starting " << identify() << "...";
Diffs diffs(pass_size * 3, 1.0);
size_t t=0;
- for( t=0; t < (MaxIter()*pass_size) && diffs.max() > Tol(); t++ ) {
+ for( t=0; t < (MaxIter()*pass_size) && diffs.maxDiff() > Tol(); t++ ) {
// choose random Var i
size_t i = (size_t) (nrVars() * rnd_uniform());
_beliefs[i] = jan;
}
- updateMaxDiff( diffs.max() );
+ updateMaxDiff( diffs.maxDiff() );
if( Verbose() >= 1 ) {
- if( diffs.max() > Tol() ) {
+ if( diffs.maxDiff() > Tol() ) {
if( Verbose() == 1 )
cout << endl;
- cout << "MF::run: WARNING: not converged within " << MaxIter() << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.max() << endl;
+ cout << "MF::run: WARNING: not converged within " << MaxIter() << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.maxDiff() << endl;
} else {
if( Verbose() >= 2 )
cout << "MF::run: ";
}
}
- return diffs.max();
+ return diffs.maxDiff();
}
if( Verbose() >= 1 )
cout << "Starting " << identify() << "...";
- clock_t tic = toc();
+ double tic = toc();
// Diffs diffs(nrVars(), 1.0);
M.resize(N);
for( Properties::const_iterator p = ps.begin(); p != ps.end(); p++ ) {
if( p != ps.begin() )
os << ",";
- os << *p;
+ os << (Property)*p;
}
os << "]";
return os;
using namespace std;
-RegionGraph::RegionGraph( const FactorGraph &fg, const vector<Region> &ors, const vector<Region> &irs, const vector<pair<size_t,size_t> > &edges) : FactorGraph(fg), G(), ORs(), IRs(irs), fac2OR() {
+RegionGraph::RegionGraph( const FactorGraph &fg, const std::vector<Region> &ors, const std::vector<Region> &irs, const std::vector<std::pair<size_t,size_t> > &edges) : FactorGraph(fg), G(), ORs(), IRs(irs), fac2OR() {
// Copy outer regions (giving them counting number 1.0)
ORs.reserve( ors.size() );
for( vector<Region>::const_iterator alpha = ors.begin(); alpha != ors.end(); alpha++ )
// CVM style
-RegionGraph::RegionGraph( const FactorGraph &fg, const vector<VarSet> &cl ) : FactorGraph(fg), G(), ORs(), IRs(), fac2OR() {
+RegionGraph::RegionGraph( const FactorGraph &fg, const std::vector<VarSet> &cl ) : FactorGraph(fg), G(), ORs(), IRs(), fac2OR() {
// Retain only maximal clusters
ClusterGraph cg( cl );
cg.eraseNonMaximal();
}
-TreeEPSubTree::TreeEPSubTree( const DEdgeVec &subRTree, const DEdgeVec &jt_RTree, const vector<Factor> &jt_Qa, const vector<Factor> &jt_Qb, const Factor *I ) : _Qa(), _Qb(), _RTree(), _a(), _b(), _I(I), _ns(), _nsrem(), _logZ(0.0) {
+TreeEPSubTree::TreeEPSubTree( const DEdgeVec &subRTree, const DEdgeVec &jt_RTree, const std::vector<Factor> &jt_Qa, const std::vector<Factor> &jt_Qb, const Factor *I ) : _Qa(), _Qb(), _RTree(), _a(), _b(), _I(I), _ns(), _nsrem(), _logZ(0.0) {
_ns = _I->vars();
// Make _Qa, _Qb, _a and _b corresponding to the subtree
}
-void TreeEPSubTree::InvertAndMultiply( const vector<Factor> &Qa, const vector<Factor> &Qb ) {
+void TreeEPSubTree::InvertAndMultiply( const std::vector<Factor> &Qa, const std::vector<Factor> &Qb ) {
for( size_t alpha = 0; alpha < _Qa.size(); alpha++ )
_Qa[alpha] = Qa[_a[alpha]].divided_by( _Qa[alpha] );
}
-void TreeEPSubTree::HUGIN_with_I( vector<Factor> &Qa, vector<Factor> &Qb ) {
+void TreeEPSubTree::HUGIN_with_I( std::vector<Factor> &Qa, std::vector<Factor> &Qb ) {
// Backup _Qa and _Qb
vector<Factor> _Qa_old(_Qa);
vector<Factor> _Qb_old(_Qb);
}
-double TreeEPSubTree::logZ( const vector<Factor> &Qa, const vector<Factor> &Qb ) const {
+double TreeEPSubTree::logZ( const std::vector<Factor> &Qa, const std::vector<Factor> &Qb ) const {
double sum = 0.0;
for( size_t alpha = 0; alpha < _Qa.size(); alpha++ )
sum += (Qa[_a[alpha]] * _Qa[alpha].log0()).totalSum();
if( Verbose() >= 3)
cout << endl;
- clock_t tic = toc();
+ double tic = toc();
Diffs diffs(nrVars(), 1.0);
vector<Factor> old_beliefs;
// do several passes over the network until maximum number of iterations has
// been reached or until the maximum belief difference is smaller than tolerance
- for( iter=0; iter < MaxIter() && diffs.max() > Tol(); iter++ ) {
+ for( iter=0; iter < MaxIter() && diffs.maxDiff() > Tol(); iter++ ) {
for( size_t I = 0; I < nrFactors(); I++ )
if( offtree(I) ) {
_Q[I].InvertAndMultiply( _Qa, _Qb );
}
if( Verbose() >= 3 )
- cout << "TreeEP::run: maxdiff " << diffs.max() << " after " << iter+1 << " passes" << endl;
+ cout << "TreeEP::run: maxdiff " << diffs.maxDiff() << " after " << iter+1 << " passes" << endl;
}
- updateMaxDiff( diffs.max() );
+ updateMaxDiff( diffs.maxDiff() );
if( Verbose() >= 1 ) {
- if( diffs.max() > Tol() ) {
+ if( diffs.maxDiff() > Tol() ) {
if( Verbose() == 1 )
cout << endl;
- cout << "TreeEP::run: WARNING: not converged within " << MaxIter() << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.max() << endl;
+ cout << "TreeEP::run: WARNING: not converged within " << MaxIter() << " passes (" << toc() - tic << " clocks)...final maxdiff:" << diffs.maxDiff() << endl;
} else {
if( Verbose() >= 3 )
cout << "TreeEP::run: ";
}
}
- return diffs.max();
+ return diffs.maxDiff();
}
#include <boost/random/normal_distribution.hpp>
#include <boost/random/variate_generator.hpp>
+#ifdef WINDOWS
+ #include <windows.h>
+#else
+ // Assume POSIX compliant system. We need the following for querying the CPU time for this process
+ #include <sys/times.h>
+ #include <sys/param.h>
+#endif
+
namespace dai {
-clock_t toc() {
+// Returns user+system time in seconds
+double toc() {
+#ifdef WINDOWS
+ SYSTEMTIME tbuf;
+ GetSystemTime(&tbuf);
+ return( (double)(tbuf.wSecond + (double)tbuf.wMilliseconds / 1000.0) );
+#else
tms tbuf;
times(&tbuf);
- return( tbuf.tms_utime );
+ return( (double)(tbuf.tms_utime + tbuf.tms_stime) / HZ );
+#endif
}
// Try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand
typedef boost::minstd_rand _rnd_gen_type;
-_rnd_gen_type _rnd_gen(42);
+_rnd_gen_type _rnd_gen(42U);
-// Define a uniform random number distribution which produces "double"
+// Define a uniform random number distribution which produces
// values between 0 and 1 (0 inclusive, 1 exclusive).
boost::uniform_real<> _uni_dist(0,1);
boost::variate_generator<_rnd_gen_type&, boost::uniform_real<> > _uni_rnd(_rnd_gen, _uni_dist);
boost::variate_generator<_rnd_gen_type&, boost::normal_distribution<> > _normal_rnd(_rnd_gen, _normal_dist);
-void rnd_seed( int seed ) {
+void rnd_seed( size_t seed ) {
_rnd_gen.seed(seed);
}
return _normal_rnd();
}
+// Returns integer in interval [min, max]
+int rnd_int( int min, int max ) {
+ return (int)floor(_uni_rnd() * (max + 1 - min) + min);
+}
+
} // end of namespace dai
vector<Factor> q;
double logZ;
double maxdiff;
- clock_t time;
+ double time;
TestAI( const FactorGraph &fg, const string &_name, const Properties &opts ) : obj(NULL), name(_name), err(), q(), logZ(0.0), maxdiff(0.0), time(0) {
- clock_t tic = toc();
+ double tic = toc();
obj = newInfAlg( name, fg, opts );
time += toc() - tic;
/*
}
void doAI() {
- clock_t tic = toc();
+ double tic = toc();
// if( name == "EXACT" ) {
// // calculation has already been done
// }
cout.width( 40 );
cout << left << "# METHOD" << " ";
cout.width( 10 );
- cout << right << "CLOCKS" << " ";
+ cout << right << "SECONDS" << " ";
cout.width( 10 );
cout << "MAX ERROR" << " ";
cout.width( 10 );