Tuesday, February 25, 2020

Decision tree visualisation

Le code promis pour avoir l'arbre du TP5:


#En plus : Plot the decision tree
plotDecisTree <- function(decisTree){
GetNodeLabel <- function(node) switch(node$type,
                                      terminal = paste0( '$ ', format(node$payoff, scientific = FALSE, big.mark = ",")),
                                      paste0('ER\n', '$ ', format(node$payoff, scientific = FALSE, big.mark = ",")))

GetEdgeLabel <- function(node) {
  if (!node$isRoot && node$parent$type == 'chance') {
    label = paste0(node$name, " (", node$p, ")")
  } else {
    label = node$name
  }
  return (label)
}

GetNodeShape <- function(node) switch(node$type, decision = "box",
                                      chance = "circle", terminal = "house")


SetEdgeStyle(decisTree, fontname = 'helvetica', label = GetEdgeLabel)
SetNodeStyle(decisTree, fontname = 'helvetica', label = GetNodeLabel, shape = GetNodeShape)
SetGraphStyle(decisTree, rankdir = "LR")
plot(decisTree)
}

plotDecisTree(decisTree)


#sulp ne

Saturday, February 22, 2020

Test N°1

TEST SysAiD


pour les L3 (ISIL)

Mardi 25 fevrier 2020 à 12:50.

Amphi 7

Thursday, February 13, 2020

TP 5 material

Arbre d'analyse de décision

1. Fichier YAML
name: newProdTree
type: decision
capt: root_D
AnnulTest:
  type: terminal
  capt: annulTest_T
  payoff: 0.0
TestProd:
  type: chance
  capt: testProd_C
  testFail:
    type: terminal
    capt: testFail_T
    p: 0.7
    payoff: -100000
  testSucc:
    type: decision
    capt: testSucc_D
    p: 0.3
    SmallPlant:
        type: chance
        capt: smallPlant_C
        noCompet:
          type: terminal
          capt: smallNoCompet_T
          p: 0.6
          payoff: 310000 
        compet:
          type: terminal
          capt: smallCompet_T
          p: 0.4
          payoff: -110000
    LargePlant:
        type: chance
        capt: largePlant_C
        noCompet:
          type: terminal
          capt: largeNoCompet_T
          p: 0.6
          payoff: 700000
        compet:
          type: terminal
          capt: largeCompet_T
          p: 0.4
          payoff: -140000


2. Script R
fileName <- 'exCoursNewProd.yaml'
cat(readChar(fileName, file.info(fileName)$size))#on s'assure q ttVaB1
library(data.tree)
library(yaml)
l <- yaml.load_file(fileName)
decisTree <- as.Node(l)
#arbre avant resolution
print(decisTree, "type", "payoff", "p")

#resolution
payoff <- function(node){
  if (node$type == 'chance'){
    node$payoff <- sum(sapply(node$children, function(child) child$payoff * child$p))}
  else if (node$type == 'decision'){
    vChildrenPayoff <-sapply(node$children, function(child) child$payoff)

    node$payoff <- max(vChildrenPayoff)}
}

decisTree$Do(payoff, traversal = "post-order", filterFun = isNotLeaf)

#resultat
print("Decision à entreprendre:")
affichPathDecis <- function(node)  if(node$payoff==node$parent$payoff)
                                      cat(node$name,' --> ')
decisTree$Do(affichPathDecis, filterFun = isNotRoot, traversal = "pre-order")
cat('EMV -->',decisTree$payoff,'\n')


Bibliographie/Further reading