Shiny 在R中的图形中显示导航
我试图在R图中显示导航。时间1或t1中的当前状态设置为val$currentstatus,t2中的下一个状态希望根据用户从支票簿中选择的操作显示在图形中。然后我想画一条线来表示这条路径。我写的代码如下Shiny 在R中的图形中显示导航,shiny,decision-tree,shiny-server,markov,Shiny,Decision Tree,Shiny Server,Markov,我试图在R图中显示导航。时间1或t1中的当前状态设置为val$currentstatus,t2中的下一个状态希望根据用户从支票簿中选择的操作显示在图形中。然后我想画一条线来表示这条路径。我写的代码如下 output$navigation<-renderPlot({ #initial state of X and Y if(is.element("Within", vals$currentstatus)) x <-
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"))
如果下一个位置在工作台内,则应为绿色,并连接到上一个状态;如果下一个位置在工作台外,则应为红色,并连接到上一个状态。此外,我还想在两个状态之间的连接线上看到所选操作的名称。此外,我想知道如何更新新位置,并使用它来计算下一个时段t3的下一个状态,因此强制。类似于下图:
也许可以看看graphviz软件包?非常感谢,我会看一下并告诉你结果。当然,你可以创建一些模拟数据来创建图表吗?是的,但我只停留在一个部分,我想更新每个状态下的转移概率矩阵。我在想,如果我使用经验分布来更新每个状态的概率矩阵,它将是有用的,但我不确定。我尝试使用此方法进行更新。如果你对这个问题有任何想法,请给我一些建议。我不知道如何在没有运行示例代码的情况下实现这一点。不幸的是,也许可以发布一个小的运行示例?如果要更新循环的打印输出,可以稍后再试