Expect Value™
TECHNICAL NOTES

The Display Function

Many of the technical support calls the DPL team receives begin something like this:

DPL USER: I have my model running and it seems to work OK. It gives me the decision policy and risk profile, and they look fine. But what I really want to know is <Insert interesting fact here>.

The most common response to this question is "Policy Summary!" The DPL Policy Summary is a tool which makes it easier to understand what's going on deep down in a complicated policy tree. Instead of showing you every branch, it provides summary information about each node. For more information about Policy Summaries, see the Decision Analysis Results chapter in the DPL 6.0 Professional Getting Started Guide.

The second most common response and the subject of this article is the display function. The display function is a general purpose tool in the Advanced Version; you can use it to find out almost anything about a DPL analysis. As with most general purpose tools, it isn't always obvious where to start.

How it works

The display function is most often used in get/pays, objective functions, and node data. When DPL evaluates an expression containing a display function, it prints something to the DPL Log. For example, if Unit_Cost is the name of a value node, then

     display(Unit_Cost, "%10.2f\n")

would cause DPL to print the value of Unit_Cost to the Log. The first argument is the item to be printed; the second argument specifies the format. "%10.2f" tells DPL to print a number with two digits to the right of the decimal point and ten characters total. "\n" indicates a carriage return, so the next number printed will appear on its own line.

Display function format specifiers are the same as those used in the C programming language. But don't panic -- you will almost always use one of the formats in this article with only the numbers changed. If the format specifier is omitted, DPL will use a default. The display function returns the value of its first argument. This is handy when you are using it in a get/pay expression. Changing a pay expression from Unit_Cost to display(Unit_Cost, "%10.2f\n") doesn't change the model's results. When you don't want the value used in the expected value calculations, you can multiply it by zero, as in 0*display(...).

Using the display function to selectively print information

Suppose you want to know the values of Unit_Cost in all scenarios where you lose money. You can add a display function inside an @if statement so that it is only evaluated when Profit is less than zero. In this example, we put the display statement in a get/pay expression.

Figure 1

The output in the Log might look like:

     3.25
     3.78

Text in a format specifier that doesn't begin with % or \ is simply printed out. In the above example, we could label our output by changing the format specifier to "Unit_Cost = %10.2f\n". Then the Log would show:

     Unit_Cost = 3.25
     Unit_Cost = 3.78

Printing qualitative information

The display function can also be used to print character strings to the Log. For example, you could sign your model by adding:

     display("Bob's DPL model")

to a get/pay expression at the root of the tree (the node all the way to the left).

The output in the Log would be:

     08:12:16 Analyzing... 
     Bob's DPL model08:12:16 Complete 

You can improve on this signature by adding a new line character to the string. For example:

     display("Bob's DPL model\n")

would give us

     08:12:16 Analyzing... 
     Bob's DPL model 
     08:12:16 Complete

DPL's ability to print character strings to the Log is especially useful when combined with the state-name function. Suppose you want to know the state of Labor_Unrest in all scenarios where Unit_Cost is more than five. You could replace the get/pay expression for Profit with:

     Profit + @if(Unit_Cost>5, display(statename(Labor_Unrest),"%s\n"))

The format "%s\n" means print a string and then print a carriage return. The display function returns zero when it's displaying a string, so there is no need to multiply it by zero.

Display functions in the objective function

Even if you're not using multiple attributes, you may want to specify an objective function which contains a display function. Objective functions can't contain values which depend on the state of events, so you are limited, but the objective function is the only place you have access to the path probability.

Suppose you want to know the probabilities of all money-losing scenarios. In the objective function you refer to the first (or only) attribute as $1, so if the only get/pay in the tree is get Profit, $1 is Profit and $1<0 means we're losing money. The path probability is called $0 (in the objective function only!). The objective function below prints the probabilities of all money-losing scenarios:

Figure 2

Copyright © 2003-2007 Syncopation Software