+ Reply to Thread
Results 1 to 1 of 1

Thread: show navigation in a graph in R using markov decision making process

  1. #1
    Points: 24, Level: 1
    Level completed: 47%, Points required for next Level: 26

    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry show navigation in a graph in R using markov decision making process




    I am trying to show navigation in R plot. The current status in time one or (t1) is set as val$currentstatus and next status in (t2) wants to be shown in the graph based on the action that the user choose from the checkbook. then I want to draw a line to show this path. The code that I wrote is as following:

    Code: 
    output$navigation<-renderPlot({
    
    
    
          #initial state of X and Y
          if(is.element("Within", vals$currentstatus))
            x <- 1
          y <- 2
          if(is.element("Out", vals$currentstatus)) {
            x <- 1
            y <- 1
          }
          action<-c(input$action1,input$action2)
          x<-1:4
          y<-1:2
          rewards<-matrix(rep(0,8),nrow=2)
          rewards[1,4]<- -1
          rewards[2,4]<- 1
          values<-rewards#initial Values
          states<-expand.grid(x=x,y=y)
          #Transition probability
          transition <- list( input$action1= c("within" = 0.8, "out" = .2), 
                              input$action2= c("within" = 0.3, "out" = .7))
          # The value of an action (e.g. move toward benchmark )
          action.values <- list(input$action1 = c("x" = 1, "y" = 0), 
                                input$action1 = c("x" = 1, "y" = 0))                   
          # act() function serves to move the agent to go to new position
          act <- function(action, state) {
            action.value <- action.values[[action]]
            new.state <- state
            #
            if(state["x"] == 4 && state["y"] == 1 || (state["x"] == 4 && state["y"] == 2))
              return(state)
            #
            new.x = state["x"] + action.value["x"]
            new.y=if(transition["within">"out"]){state["y"==2]}
            if(transition["within"<"out"]){state["y"==1]} 
    
          }
          plot(x, y, xaxt='n',yaxt='n',cex=10,pch=19,
               col=ifelse(y==1,"red","green"),ylab="status",xlab="period",
               xlim=c(0,4), ylim=c(0,3))
          axis(1,at=1:4,labels=c("t1","t2","t3","t4"))
          axis(2,at=1:2,labels=c("out bench","within bench"))

    if next position is within bench it should be green and connect to the previous state and if it is out of bench should be red and connect to previous state. Also I want to see the name of chosen action on the connection line between two states.Moreover I want to know how can I update the new position and use it for calculating next state in next period (t3) and so force.Similar to the following graph:
    Attached Images  

+ Reply to Thread

           




Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats