Description Usage Format Examples
An object of class HydeNetwork
establishing a graphical model for a game
of Black Jack.
1 |
A HydeNetwork
object constructed using the code shown in
the example. The network has seven random nodes, three ten deterministic
nodes, three decision nodes, and one utility node. This is (almost) the same
network used in 'vignette("DecisionNetworks", package="HydeNet")'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | ## Not run:
BlackJack <-
HydeNetwork(~ initialAces | card1*card2
+ initialPoints | card1*card2
+ highUpcard | dealerUpcard
+ hit1 | initialPoints*highUpcard
+ acesAfterCard3 | initialAces*card3
+ pointsAfterCard3 | card1*card2*card3*acesAfterCard3
+ hit2 | pointsAfterCard3*highUpcard
+ acesAfterCard4 | acesAfterCard3*card4
+ pointsAfterCard4 | card1*card2*card3*card4*acesAfterCard4
+ hit3 | pointsAfterCard4*highUpcard
+ acesAfterCard5 | acesAfterCard4*card5
+ pointsAfterCard5 | card1*card2*card3*card4*card5*acesAfterCard5
+ playerFinalPoints | initialPoints*hit1*pointsAfterCard3
*hit2*pointsAfterCard4*hit3*pointsAfterCard5
+ dealerFinalPoints | dealerUpcard
+ payoff | playerFinalPoints*dealerFinalPoints)
cardProbs <- c(rep(1/13,8), 4/13, 1/13) # probs. for 2, 3, ..., 9, (10-K), A
BlackJack <- setNode(BlackJack, card1, nodeType="dcat",
pi=vectorProbs(p=cardProbs, card1))
BlackJack <- setNode(BlackJack, card2, nodeType="dcat",
pi=vectorProbs(p=cardProbs, card2))
BlackJack <- setNode(BlackJack, card3, nodeType="dcat",
pi=vectorProbs(p=cardProbs, card3))
BlackJack <- setNode(BlackJack, card4, nodeType="dcat",
pi=vectorProbs(p=cardProbs, card4))
BlackJack <- setNode(BlackJack, card5, nodeType="dcat",
pi=vectorProbs(p=cardProbs, card5))
BlackJack <- setNode(BlackJack, dealerUpcard, nodeType="dcat",
pi=vectorProbs(p=cardProbs, dealerUpcard))
#Note: node dealerFinalPoints will be defined below, following some discussion
# about its conditional probability distribution.
#####################################
# Deterministic Nodes
#####################################
BlackJack <- setNode(BlackJack, highUpcard,
"determ", define=fromFormula(),
nodeFormula = highUpcard ~ ifelse(dealerUpcard > 8, 1, 0))
BlackJack <- setNode(BlackJack, initialAces,
"determ", define=fromFormula(),
nodeFormula = initialAces ~ ifelse(card1==10,1,0) +
ifelse(card2==10,1,0))
BlackJack <- setNode(BlackJack, acesAfterCard3,
"determ", define=fromFormula(),
nodeFormula = acesAfterCard3 ~ initialAces + ifelse(card3==10,1,0))
BlackJack <- setNode(BlackJack, acesAfterCard4,
"determ", define=fromFormula(),
nodeFormula = acesAfterCard4 ~ acesAfterCard3 + ifelse(card4==10,1,0))
BlackJack <- setNode(BlackJack, acesAfterCard5,
"determ", define=fromFormula(),
nodeFormula = acesAfterCard5 ~ acesAfterCard4 + ifelse(card5==10,1,0))
BlackJack <- setNode(BlackJack, initialPoints,
"determ", define=fromFormula(),
nodeFormula = initialPoints ~ card1+card2+2)
BlackJack <- setNode(BlackJack, pointsAfterCard3, "determ", define=fromFormula(),
nodeFormula = pointsAfterCard3 ~
ifelse(acesAfterCard3 == 3,
13,
ifelse(acesAfterCard3 == 2,
card1 + card2 + card3 + 3 - 10,
ifelse(acesAfterCard3 == 1,
ifelse(card1 + card2 + card3 + 3 > 22,
card1 + card2 + card3 + 3 - 10,
card1 + card2 + card3 + 3),
card1 + card2 + card3 + 3
)
)
)
)
BlackJack <- setNode(BlackJack, pointsAfterCard4, "determ", define=fromFormula(),
nodeFormula = pointsAfterCard4 ~
ifelse(acesAfterCard4 == 4,
14,
ifelse(acesAfterCard4 == 3,
ifelse(card1 + card2 + card3 + card4 + 4 > 38,
card1 + card2 + card3 + card4 + 4 - 30,
card1 + card2 + card3 + card4 + 4 - 20
),
ifelse(acesAfterCard4 > 0,
ifelse(card1 + card2 + card3 + card4 + 4 > 22,
card1 + card2 + card3 + card4 + 4 - 10,
card1 + card2 + card3 + card4 + 4
),
card1 + card2 + card3 + card4 + 4
)
)
)
)
BlackJack <-
setNode(BlackJack, pointsAfterCard5, "determ", define=fromFormula(),
nodeFormula = pointsAfterCard5 ~
ifelse(acesAfterCard5 == 5,
15,
ifelse(acesAfterCard5 == 4,
ifelse(card1 + card2 + card3 + card4 + card5 + 5 > 51,
card1 + card2 + card3 + card4 + card5 + 5 - 40,
card1 + card2 + card3 + card4 + card5 + 5 - 30
),
ifelse(acesAfterCard5 == 3,
ifelse(card1 + card2 + card3 + card4 + card5 + 5 > 51,
card1 + card2 + card3 + card4 + card5 + 5 - 30,
card1 + card2 + card3 + card4 + card5 + 5 - 20
),
ifelse(acesAfterCard5 == 2,
ifelse(card1 + card2 + card3 + card4 + card5 + 5 > 31,
card1 + card2 + card3 + card4 + card5 + 5 - 20,
card1 + card2 + card3 + card4 + card5 + 5 - 10
),
ifelse(acesAfterCard5 > 0,
ifelse(card1 + card2 + card3 + card4 + card5 + 5 > 22,
card1 + card2 + card3 + card4 + card5 + 5 - 10,
card1 + card2 + card3 + card4 + card5 + 5
),
card1 + card2 + card3 + card4 + card5 + 5
)
)
)
)
)
)
BlackJack <- setNode(BlackJack, playerFinalPoints, "determ", define=fromFormula(),
nodeFormula = playerFinalPoints ~
ifelse(hit1 == 0,
initialPoints,
ifelse(hit2 == 0,
pointsAfterCard3,
ifelse(hit3 == 0, pointsAfterCard4, pointsAfterCard5)
)
)
)
BlackJack <- setDecisionNodes(BlackJack, hit1, hit2, hit3)
BlackJack <- setUtilityNodes(BlackJack, payoff)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.