Рубрики

drawing

Sequential outline of tree drawing

However, decision trees can become excessively complex. In such cases, a more compact influence diagram can be a good alternative. Influence diagrams narrow the focus to critical decisions, inputs, and objectives.


What is a Decision Tree Diagram

Need to break down a complex decision? Try using a decision tree maker. Read on to find out all about decision trees, including what they are, how they’re used, and how to make one.

Want to make a decision tree of your own? Try Lucidchart. It’s quick, easy, and completely free.

What is a decision tree?

A decision tree is a map of the possible outcomes of a series of related choices. It allows an individual or organization to weigh possible actions against one another based on their costs, probabilities, and benefits. They can can be used either to drive informal discussion or to map out an algorithm that predicts the best choice mathematically.

A decision tree typically starts with a single node, which branches into possible outcomes. Each of those outcomes leads to additional nodes, which branch off into other possibilities. This gives it a treelike shape.

There are three different types of nodes: chance nodes, decision nodes, and end nodes. A chance node, represented by a circle, shows the probabilities of certain results. A decision node, represented by a square, shows a decision to be made, and an end node shows the final outcome of a decision path.

Decision trees can also be drawn with flowchart symbols, which some people find easier to read and understand.


Decision tree symbols

Shape Name Meaning
Decision node Indicates a decision to be made
Chance node Shows multiple uncertain outcomes
Alternative branches Each branch indicates a possible outcome or action
Rejected alternative Shows a choice that was not selected
Endpoint node Indicates a final outcome

To draw a decision tree, first pick a medium. You can draw it by hand on paper or a whiteboard, or you can use special decision tree software. In either case, here are the steps to follow:

1. Start with the main decision. Draw a small box to represent this point, then draw a line from the box to the right for each possible solution or action. Label them accordingly.

2. Add chance and decision nodes to expand the tree as follows:

  • If another decision is necessary, draw another box.
  • If the outcome is uncertain, draw a circle (circles represent chance nodes).
  • If the problem is solved, leave it blank (for now).

From each decision node, draw possible solutions. From each chance node, draw lines representing possible outcomes. If you intend to analyze your options numerically, include the probability of each outcome and the cost of each action.

3. Continue to expand until every line reaches an endpoint, meaning that there are no more choices to be made or chance outcomes to consider. Then, assign a value to each possible outcome. It could be an abstract score or a financial value. Add triangles to signify endpoints.

With a complete decision tree, you’re now ready to begin analyzing the decision you face.

Diagramming is quick and easy with Lucidchart. Start a free trial today to start creating and collaborating.


Compact Tree Syntax

Before we delve into details of XSLT implementation we should describe our task. We want to create a transformation that can take a compact tree notation and turn it into an SVG graphic. Our tree syntax will be very simple. Each character will correspond to one node, and subnodes will be closed in parenthesis. For example, the following expression a(bcd(ef)) represents the tree depicted in Figure 1.

Figure 1. Rendered tree a(bcd(ef)).

Our notation is also able to express hedges. A hedge is a sequence of trees or alternatively, “tree without the root node.” Figure 2 shows rendering of a hedge a(bcd)e(fgh).

Figure 2. Rendered hedge a(bcd)e(fgh).

If the name of a node should be longer than one character, we can put the name inside curly braces. You can see the expression () rendered as a tree in Figure 3.

Figure 3. Rendered tree ().

Solution Overview

Conversion from the compact syntax into the full-fledged SVG image is not trivial, so we will do it in several steps. The first step will parse the textual representation of a tree and will create an XML structure representing the same tree. The following XML fragment is an XML representation of the tree from Figure 1.

Each node in the tree is represented by a node element. Element nesting corresponds to the hierarchy of the tree. The label of each node is captured in the label attribute.

Creating XML representation from the text string will be the hardest part of the whole task since XSLT does not offer powerful string manipulation functions. But once we get the XML representation of a tree we can process it quite easily with XSLT.

In the next step we’ll decorate the XML tree with some layout information. We’ll add depth of a node in the tree and width of the attached sub-tree to each node.

With this layout information it is quite easy to get an SVG image. We must just emit correct SVG constructs and turn the layout information to the real coordinates using several calculations. And with that the requested SVG image of the tree is created.

 

a




b
c

d



e

f

Parsing the Compact Syntax

Given the minimalist set of string functions in XPath/XSLT, parsing the compact syntax of trees is the most challenging part of our task. Fortunately it is possible to create a parser with a combination of elementary string-manipulation functions and recursive processing. The XSLT template hedge2xml implements the following simple parsing algorithm:

  1. Get the name of a node. (It’s the first letter to process or text between curly braces if the first character is ‘'.)
  2. If the next token is '(' process text between matching parenthesis by this algorithm and place it inside the element labeled with the name from the first step. Then process the rest of the text after matching ')' by this algorithm.
  3. If the next token is not '(' emit the empty element labeled with the name from the first step and process the rest of the text by this algorithm.
          . Grab it into $head and proceed. -->  '))"/> ')"/>         Unexpected ( found in ' '.
                      

I am using a custom function, my:closingParenPos, to find the position of the matching closing parenthesis. I decided to implement it as an EXSLT function because a regularly named template would be too verbose. The function scans the input string for parenthesis and counts the depth of nesting. The function ends when the closing parenthesis is found.

Colin Wynn
the authorColin Wynn

Leave a Reply