qlearningaction: qlearningaction

Description Usage Arguments Details Value Note Author(s) References Examples

Description

This repository implements Q-Learning, a model-free form of reinforcement learning in R.

Usage

1
qlearningaction(q, currentstate, exploration=.5)

Arguments

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.

Details

For internal use for qlearn.

Value

An action to take, taken from the possible actions of q.

Note

Contact at liam.bressler@yale.edu

Author(s)

Liam Bressler

References

http://labressler.github.io/analytics

Examples

 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

QLearning documentation built on May 1, 2019, 6:50 p.m.