Updated copyrights
[libdai.git] / TODO
1 - Add comments in example.cpp, add documentation.
2 - Write documentation.
3 - Improve error handling.
4 - http://www.boost.org/development/requirements.html#Design_and_Programming
5
6 OPTIMIZATION:
7 - BipartiteGraph::isConnected should be optimized using boost::graph
8 - Can the FactorGraph constructors be optimized further?
9 - Cache second-order neighborhoods (delta's) in BipGraph?
10 - Replace VarSets by small_set<size_t> if appropriate, in order to minimize the use of findVar().
11 - A DAIAlg<T> should not inherit from a FactorGraph/RegionGraph, but should store a reference to it
12
13 IDEAS:
14 - Use a PropertySet as output of a DAIAlg, instead of functions like maxDiff and Iterations().
15
16 - A FactorGraph and a RegionGraph are often equipped with
17 additional properties for nodes and edges. The code to initialize those
18 is often quite similar; maybe this can be abstracted to classes
19 like ExtFactorGraph and ExtRegionGraph (Ext stands for Extended), e.g.
20 template <typename NodeProperties, typename EdgeProperties>
21 class ExtFactorGraph : public FactorGraph {
22 public:
23 std::vector<NodeProperties> nodeProps;
24 std::vector<std::vector<EdgeProperties> > edgeProps;
25 // blabla
26 }
27 A disadvantage of this approach may be worse cachability.
28 A problem is if there are nog properties for nodes (type 1), nodes (type 2)
29 or edges. Maybe this can be solved using specializations, or using variadac
30 template arguments or something similar?
31 Idea: you could define a "class Empty {}", and add some code that checks for
32 the typeid, comparing it with Empty, and doing something special in that case
33 (e.g., not allocating memory).
34 The main disadvantage of this approach seems to be that it leads to even more
35 entanglement.
36
37 - Instead of polymorphism by inheritance,
38 use polymorphism by template parameterization. For example, the real reason
39 you introduced the complicated inheritance scheme was for functions like
40 Factor calcMarginal( const InferenceAlgorithm & obj, const VarSet & ns, bool reInit );
41 Now instead, you could use a template function:
42 template<typename InferenceAlgorithm>
43 Factor calcMarginal( const InferenceAlgorithm &obj, const VarSet &ns, bool reInit );
44 This would assume that InferenceAlgorithm supports certain methods, like
45 clone(), grm(), ......
46 Ideally, you would use concepts to define different classes of inference
47 algorithms with different capabilities, for example the ability to calculate logZ,
48 the ability to calculate marginals, the ability to calculate bounds, the ability
49 to calculate MAP states, etcetera. Then, use traits classes in order to be able to
50 query the capabilities of the model. For example, you would be able to query whether
51 the inference algorithm supports calculation of logZ.
52 Unfortunately, this is compile-time polymorphism, whereas tests/test needs runtime polymorphism.
53
54 - If you ever do a rewrite, make sure that the graphical properties are
55 not entangled with the probabilistic properties. E.g., a factor graph
56 really should be represented as a bipartite graph, with a separate array
57 of variable labels and dimensions, and a seperate array of (pointers to)
58 factor tables. In this way, each factor could be implemented differently,
59 e.g., we could have some sparse factors, some noisy-OR factors, some dense
60 factors, some arbitrary precision factors, etc. Or we could make more use
61 of templates to have a more generic factor graph. Maybe in the end,
62 HasA relations are better than IsA relations...
63 Also, the current setup is stupid: I wrote a new function that works
64 on FactorGraphs, and I had to write boiler plate code for it in graphicalmodel.h
65 and in regiongraph.h (which is stupid).
66
67 - Use Boost::uBLAS framework to deal with matrices, especially, with
68 2D sparse matrices. See http://www.boost.org/libs/numeric/ublas/doc/matrix_sparse.htm
69 and tests/errorbounds/errorbounds3
70
71 - Introduce naming scheme:
72 all Vars and VarSets should be named v_..., e.g. v_i instead of i
73 all Factors should be named f_..., e.g. f_I instead of I
74 all indices should be named _..., e.g. _k instead of k
75 all iterators should be named i_, e.g. i_i is an iterator to i
76 all const_iterators should be named ci_, e.g. ci_i is an iterator to i
77
78 - Improve weightedgraph or use Boost::Graph
79
80 - Iterations and maxDiff are only interesting for iterative inference
81 algorithms. Yet, tests/test wants to know these values in a generic
82 way. Maybe we have to think of some way (e.g. using a Properties object)
83 to return these values from run(). Then we can simply look whether a
84 InferenceAlgorithm supports these fields. What other results could
85 we return? Time. MaxDiff during initialization for LC methods.
86 Or maybe we could use some traits mechanism which we can ask whether the
87 object has _iterations and _maxdiff variables.
88
89 - Think about whether the cavity initialization belongs to init() or to run().
90
91 - Fix LCLin.
92
93 - setFactor and setFactors should only change Probs, not Factors.
94
95 - Simplify Properties framework: each Property should be a std::string.
96 Each DAIAlg should have its own _properties struct and handle conversion.
97
98 - Forwardport the Bart patch
99
100 - Another design question that needs to be answered: should a BP object own a
101 FactorGraph, or only store a reference to a FactorGraph (which can optimize
102 memory), or should it be a FactorGraph with additional variables and functions?
103 Probably, the first or second option would be the best. Since FactorGraphs are
104 assumed to be rather static, it would make sense to store *references* to
105 FactorGraphs inside AIAlgs. Or maybe some smart_ptr? It would make sense to
106 prevent unnecessary copying of FactorGraphs. Also, general marginalization
107 functions now copy a complete object. Instead, it would make more sense that
108 they construct a new object without copying the FactorGraph. Or they can be made
109 simply methods of the general InfAlg class.
110
111
112
113 DIFFICULT
114
115 - What to do in case of NANs?
116
117 - Bug: TreeEP::logZ() seems to be wrong (?).
118
119 - Kees' trick for preventing NANs in GBP updates: if quantity smaller than epsilon, replace by epsilon.
120
121
122 OPTIONAL
123
124 - Define a better fileformat for .fg files (maybe using XML)?
125
126 - Find a good multi-platform build system (GNU autotool? Boost JAM?)
127
128 - Another design question that needs to be answered: should a BP object own a
129 FactorGraph, or only store a reference to a FactorGraph (which can optimize
130 memory), or should it be a FactorGraph with additional variables and functions?
131 Probably, the first or second option would be the best. Since FactorGraphs are
132 assumed to be rather static, it would make sense to store *references* to
133 FactorGraphs inside AIAlgs. Or maybe some smart_ptr? It would make sense to
134 prevent unnecessary copying of FactorGraphs. Also, general marginalization
135 functions now copy a complete object. Instead, it would make more sense that
136 they construct a new object without copying the FactorGraph. Or they can be made
137 simply methods of the general InfAlg class.
138
139 - Forwardport the Bart/Max patch.
140
141 - Alternative implementation of undo factor changes: the only things that have to be
142 undone are setting a factor to all ones and setting a factor to a Kronecker delta. This
143 could also be implemented in the factor itself, which could maintain its state
144 (one/delta/full) and act accordingly.
145
146 - Think about the _fac2ind variable: a better implementation of this feature is
147 probably possible.
148
149 - Optimize GBP with precalculated indices.
150
151 - Optimize all indices as follows: keep a cache of all indices that have been
152 computed (use a hash). Then, instead of computing on the fly, use the precomputed
153 ones.
154
155 - Variable elimination should be implemented generically using a function
156 object that tells you which variable to delete.
157
158 - Improve general support for graphs and trees.
159
160 - Add support for sparse potentials.
161
162 - Optimize BP_SEQMAX (it should use a better data structure than a vector for the residuals).