Description Usage Arguments Details Value Note Author(s) References Examples
This repository implements Q-Learning, a model-free form of reinforcement learning in R.
1 | qlearningaction(q, currentstate, exploration=.5)
|
q
|
Input state/action matrix. |
currentstate
|
Current state of the game. Does not have to match any of the state for q. |
exploration
|
The probability of choosing a random state, rather than the one with the highest EV. Default 0.5. |
For internal use for qlearn.
An action to take, taken from the possible actions of q.
Contact at liam.bressler@yale.edu
Liam Bressler
http://labressler.github.io/analytics
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 | cardgame <- function()
{
playercards <- sample(1:8,4) #distribute the cards, we're player one
ourcard <- playercards[1] #our card
playertotals <- rep(-1,4) #including the antes
playersinpot <- vector()
for (player in 2:4) #other 3 players go first
{
if (playercards[player]>=2)
{
playertotals[player] <- (-3)
playersinpot <- append(playersinpot,player)
}
}
#the next line is where we want to choose our action
player1 <- 'Choose'
if (player1=="Call")
{
playertotals[1] <- (-3)
playersinpot <- append(playersinpot,1)
}
potsize <- -1*(sum(playertotals)) #the amount in the pot is how much the players put in
playercards[!(1:4 %in% playersinpot)] <- 0 #get rid of everyone who folded
winner <- which.max(playercards) #winner is the person with the highest card who didn't fold
playertotals[winner] <- playertotals[winner]+potsize
return(playertotals[1]) #return how much we won
}
strat <- qlearn(game="cardgame",statevars="ourcard",possibleactions=c("Call","Fold"),
playername="player1",numiter=25000) #make sure each function and variable name is a string
qlearningaction(strat,3,exploration=.75)
#Pick an action to perform when we have the 3 card, with high exploration
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.