This answer is a modification of my answer given in the discussion Creating Identification/Classification trees.
With this solution I am trying to achieve the simplification by using the impurity function applied to the data (the truth table in this case).
Make the truth table from the linked Wikipedia article (Binary Decision Diagram):
truthTable = {{0, 0, 0, 1}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 1, 1,
1}, {1, 0, 0, 0}, {1, 0, 1, 0}, {1, 1, 0, 1}, {1, 1, 1, 1}};
truthTable = Map[ToString, truthTable, {-1}];
colNames = {"x1", "x2", "x3", "f"};
TableForm[truthTable, TableHeadings -> {None, colNames}]
Import the package:
Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/AVCDecisionTreeForest.m"]
Build a decision tree:
dtree = BuildDecisionTree[truthTable, "ImpurityFunction" -> "Gini"]
(* {{0.125, "0", 2, Symbol,
8}, {{0.125, "0", 1, Symbol,
4}, {{0.5, "0", 3, Symbol,
2}, {{{1, "1"}}}, {{{1, "0"}}}}, {{{2, "0"}}}}, {{0.125, "0", 1, Symbol,
4}, {{0.5, "0", 3, Symbol, 2}, {{{1, "0"}}}, {{{1, "1"}}}}, {{{2, "1"}}}}} *)
The impurity function "Gini" is used by default. Another possible value is "Entropy". Note that to make the decision tree I converted the 0-1 values in the truth table into strings.
Visualize the tree:
trules = dtree // DecisionTreeToRules;
trules = trules /. ({m_, v_, cInd_Integer, s_, n_, id_} :> {m, v, colNames[[cInd]], s, n, id});
LayeredGraphPlot[trules, VertexLabeling -> True]
The last commands produce the plot:
The second row of a leaf shows the corresponding number of records and label.
The tree rules can be manipulated to produce a graph closer to the one in the Wikipedia article, if that is desired.
See these blog posts for application examples, parameters explanations, and tweaking discussions:
Decision trees posts at MathematicaForPrediction at WordPress.
BooleanConvert
with"BDT"
(Boolean decision tree) and"IF"
(If and constants) forms. $\endgroup$BooleanConvert
can make a Boolean Decision Tree, but not the Binary Decision Diagram the OP asks for. The latter is an optimized form of the BDT. $\endgroup$InputForm[BooleanFunction[30]]
, which givesBooleanFunction["BDD" -> {-3, 0, 2, -2, 1, 1, 3, 2, 1, -1}]
. The question is how to decode this list. $\endgroup$