California Investment Network


Recent Blog


Pitching Help Desk


Testimonials

"I made several great connections through your network. In fact, I was able to over fund my project. I also listed with another network that cost 3X as much and the leads were nowhere near as solid as the investors I met through this network. I will definitely only be using this network in the future. "
Jason A.

 BLOG >> Recent

Decision Tree Subgraphs [Decision Trees
Posted on September 5, 2013 @ 04:55:00 AM by Paul Meagher

I experimented with two Graphviz features that I thought might improve the appearance of my decision trees:

  1. I wanted the connecting lines to be rectilinear rather than curvilinear. Unfortunately, I am not able to achieve this effect when I use labelled edges; rectilinear connections only works when labels are applied to nodes, when labels are applied to edges it may be more difficult to calculate line placement. Rectilinear connections might have looked better but I'll have to live with curvilinear connections because I prefer labelled edges for the decision trees I'm exploring right now.
  2. I wanted to separately highlight actions, events, and outcome sections of the decision tree. I found a way to do this for the outcome nodes but have not found a way to apply further labelling or highlighting to labelled edges.

Todays blog shows how to use the "subgraph" feature of the dot language to highlite nodes that are related in some way. I used the subgraph feature to better highlite what the payoffs were for each separate action. The possible payoffs associated with each action option are distinguished by having a different color and bounding box for each set of payoffs.

Notice that the payoffs associated with each action are separately highlited and that I also add up the payoffs for each set of payoffs and report it as the expected value (EV) for that action. Here is where I get into calculating expected values manually because the dot language is not a general purpose programming language. For that I'll be using PHP in my next blog to compute expected values and supply them to the dot file that is generated.

Here is the dot file that was used to generate a decision tree that uses subgraphs to highlite sections of it.

/**
* @author Paul Meagher
* @modified Sept 5/2013
* @purpose Decision tree for nitrogen application decision
*/ 

digraph NitrogenDecision {

  // orient graph left to right (instead of the top to bottom default)
  rankdir=LR;
 
  // don't display any directional arrows on the edges 
  edge [dir=none];
    
  // labelled nodes will appear inside a box shape
  node [shape=box];  
  
  // name your subgraphs with cluster_* identifiers
  subgraph cluster_lo {
    node [style=filled, color=orange];
    GoodSeason100Kg AveSeason100Kg PoorSeason100Kg;
    label = "EV = $6900";
    color=orange;
  }    

  subgraph cluster_med {
    node [style=filled, color=green];
    GoodSeason160Kg AveSeason160Kg PoorSeason160Kg;
    label = "EV = $7900";
    color=green;
  }    

  subgraph cluster_hi {
    node [style=filled, color=yellow];
    GoodSeason220Kg AveSeason220Kg PoorSeason220Kg;
    label = "EV = $8900";
    color=yellow;
  }    
  
  // small connector shape without labels between actions and events 
  Apply100Kg[shape=diamond,style=filled,label="",height=.1,width=.1];
  Apply160Kg[shape=diamond,style=filled,label="",height=.1,width=.1];
  Apply220Kg[shape=diamond,style=filled,label="",height=.1,width=.1];
  
  // labels for terminal nodes when applying 100 kg nitrogen
  GoodSeason100Kg[label="Payoff = 0.2 * $8000"];
  AveSeason100Kg[label="Payoff = 0.5 * $7000"];
  PoorSeason100Kg[label="Payoff = 0.3 * $6000"];  

  // labels for terminal nodes when applying 160 kg nitrogen
  GoodSeason160Kg[label="Payoff = 0.2 * $9000"];
  AveSeason160Kg[label="Payoff = 0.5 * $8000"];
  PoorSeason160Kg[label="Payoff = 0.3 * $7000"];  

  // labels for terminal nodes when applying 220 kg nitrogen
  GoodSeason220Kg[label="Payoff = 0.2 * $10000"];
  AveSeason220Kg[label="Payoff = 0.5 * $9000"];
  PoorSeason220Kg[label="Payoff = 0.3 * $8000"];  

  // define edges and edge labels for each action
  Decision -> Apply100Kg[label="Apply 100 kg N (-$40)"];
  Decision -> Apply160Kg[label="Apply 160 kg N (-$64)"];
  Decision -> Apply220Kg[label="Apply 220 kg N (-$88)"];

  // define edges and edge labels for each action + events combo
  Apply100Kg -> GoodSeason100Kg[label="Good Season ... P = 0.2"];
  Apply100Kg -> AveSeason100Kg[label="Ave. Season ... P = 0.5"];
  Apply100Kg -> PoorSeason100Kg[label="Poor Season ... P = 0.3"];
  Apply160Kg -> GoodSeason160Kg[label="Good Season ... P = 0.2"];
  Apply160Kg -> AveSeason160Kg[label="Ave. Season ... P = 0.5"];
  Apply160Kg -> PoorSeason160Kg[label="Poor Season ... P = 0.3"];
  Apply220Kg -> GoodSeason220Kg[label="Good Season ... P = 0.2"];
  Apply220Kg -> AveSeason220Kg[label="Ave. Season ... P = 0.5"];
  Apply220Kg -> PoorSeason220Kg[label="Poor Season ... P = 0.3"];
  


}

Permalink 

 Archive 
 

Categories


 Agriculture [71]
 Bayesian Inference [14]
 Books [15]
 Business Models [24]
 Causal Inference [2]
 Creativity [7]
 Decision Making [15]
 Decision Trees [8]
 Design [36]
 Eco-Green [3]
 Economics [11]
 Education [10]
 Energy [0]
 Entrepreneurship [57]
 Events [2]
 Farming [20]
 Finance [25]
 Future [15]
 Growth [18]
 Investing [24]
 Lean Startup [10]
 Leisure [5]
 Lens Model [9]
 Making [1]
 Management [9]
 Motivation [3]
 Nature [22]
 Patents & Trademarks [1]
 Permaculture [34]
 Psychology [1]
 Real Estate [2]
 Robots [1]
 Selling [11]
 Site News [13]
 Startups [12]
 Statistics [3]
 Systems Thinking [2]
 Trends [7]
 Useful Links [3]
 Valuation [1]
 Venture Capital [5]
 Video [2]
 Writing [2]