mhahsler / pomdp

R package for Partially Observable Markov Decision Processes
16 stars 5 forks source link

Max number of episodes #10

Closed haniees closed 3 years ago

haniees commented 3 years ago

Hello,

Can I ask how many episodes does the package support?

I can run up to 4 episodes and I get an error when I add more episodes. This is the error:

Error in .is_timedependent(model, "transition_prob") : Inconsistent POMDP specification. Field transition_prob does not contain data for the appropriate number of episodes.

Thanks, Hanie

mhahsler commented 3 years ago

There should not be such a restriction. Please send us some code to replicate this problem.

haniees commented 3 years ago

Here is the code: I sent the excel files to this email: mhahsler@lyle.smu.edu

xl_dataPhysio <- "C:/P/PF-THA-obsfinal-Physio.xlsx" obsPhysio_1 <- read_excel(path = xl_dataPhysio, sheet = 1) obsPhysio_2 <- read_excel(path = xl_dataPhysio, sheet = 2) obsPhysio_3 <- read_excel(path = xl_dataPhysio, sheet = 3) obsPhysio_4 <- read_excel(path = xl_dataPhysio, sheet = 4) obsPhysio_5 <- read_excel(path = xl_dataPhysio, sheet = 5) obsPhysio_6 <- read_excel(path = xl_dataPhysio, sheet = 6) obsPhysio_7 <- read_excel(path = xl_dataPhysio, sheet = 7) obsPhysio_8 <- read_excel(path = xl_dataPhysio, sheet = 8) obsPhysio_9 <- read_excel(path = xl_dataPhysio, sheet = 9) obsPhysio_10 <- read_excel(path = xl_dataPhysio, sheet = 10) obsPhysio_11 <- read_excel(path = xl_dataPhysio, sheet = 11) obsPhysio_12 <- read_excel(path = xl_dataPhysio, sheet = 12) obsPhysio_13 <- read_excel(path = xl_dataPhysio, sheet = 13) obsPhysio_14 <- read_excel(path = xl_dataPhysio, sheet = 14) obsPhysio_15 <- read_excel(path = xl_dataPhysio, sheet = 15)

obs Cardio

xl_dataCardio <- "C:/P/PF-THA-obsfinal-cardioA.xlsx" obsCardio_1 <- read_excel(path = xl_dataCardio, sheet = 1) obsCardio_2 <- read_excel(path = xl_dataCardio, sheet = 2) obsCardio_3 <- read_excel(path = xl_dataCardio, sheet = 3) obsCardio_4 <- read_excel(path = xl_dataCardio, sheet = 4) obsCardio_5 <- read_excel(path = xl_dataCardio, sheet = 5) obsCardio_6 <- read_excel(path = xl_dataCardio, sheet = 6) obsCardio_7 <- read_excel(path = xl_dataCardio, sheet = 7) obsCardio_8 <- read_excel(path = xl_dataCardio, sheet = 8) obsCardio_9 <- read_excel(path = xl_dataCardio, sheet = 9) obsCardio_10 <- read_excel(path = xl_dataCardio, sheet = 10) obsCardio_11 <- read_excel(path = xl_dataCardio, sheet = 11) obsCardio_12 <- read_excel(path = xl_dataCardio, sheet = 12) obsCardio_13 <- read_excel(path = xl_dataCardio, sheet = 13) obsCardio_14 <- read_excel(path = xl_dataCardio, sheet = 14) obsCardio_15 <- read_excel(path = xl_dataCardio, sheet = 15)

obs Gait

xl_dataGait <- "C:/P/PF-THA-obsfinal-GaitA.xlsx" obsGait_1 <- read_excel(path = xl_dataGait, sheet = 1) obsGait_2 <- read_excel(path = xl_dataGait, sheet = 2) obsGait_3 <- read_excel(path = xl_dataGait, sheet = 3) obsGait_4 <- read_excel(path = xl_dataGait, sheet = 4) obsGait_5 <- read_excel(path = xl_dataGait, sheet = 5) obsGait_6 <- read_excel(path = xl_dataGait, sheet = 6) obsGait_7 <- read_excel(path = xl_dataGait, sheet = 7) obsGait_8 <- read_excel(path = xl_dataGait, sheet = 8) obsGait_9 <- read_excel(path = xl_dataGait, sheet = 9) obsGait_10 <- read_excel(path = xl_dataGait, sheet = 10) obsGait_11 <- read_excel(path = xl_dataGait, sheet = 11) obsGait_12 <- read_excel(path = xl_dataGait, sheet = 12) obsGait_13 <- read_excel(path = xl_dataGait, sheet = 13) obsGait_14 <- read_excel(path = xl_dataGait, sheet = 14) obsGait_15 <- read_excel(path = xl_dataGait, sheet = 15)

Trans Physio

xl_dataPhysioT <- "C:/P/PF-THA-Trans-Physio.xlsx" TransPhysio_0 <- read_excel(path = xl_dataPhysioT, sheet = 1) TransPhysio_1 <- read_excel(path = xl_dataPhysioT, sheet = 2) TransPhysio_2 <- read_excel(path = xl_dataPhysioT, sheet = 3) TransPhysio_3 <- read_excel(path = xl_dataPhysioT, sheet = 4) TransPhysio_4 <- read_excel(path = xl_dataPhysioT, sheet = 5) TransPhysio_5 <- read_excel(path = xl_dataPhysioT, sheet = 6) TransPhysio_6 <- read_excel(path = xl_dataPhysioT, sheet = 7) TransPhysio_7 <- read_excel(path = xl_dataPhysioT, sheet = 8) TransPhysio_8 <- read_excel(path = xl_dataPhysioT, sheet = 9) TransPhysio_9 <- read_excel(path = xl_dataPhysioT, sheet = 10) TransPhysio_10 <- read_excel(path = xl_dataPhysioT, sheet = 11) TransPhysio_11 <- read_excel(path = xl_dataPhysioT, sheet = 12) TransPhysio_12 <- read_excel(path = xl_dataPhysioT, sheet = 13) TransPhysio_13 <- read_excel(path = xl_dataPhysioT, sheet = 14) TransPhysio_14 <- read_excel(path = xl_dataPhysioT, sheet = 15)

Trans Cardio

xl_dataCardioT <- "C:/P/PF-THA-Trans - CarcioA.xlsx" TransCardio_0 <- read_excel(path = xl_dataCardioT, sheet = 1) TransCardio_1 <- read_excel(path = xl_dataCardioT, sheet = 2) TransCardio_2 <- read_excel(path = xl_dataCardioT, sheet = 3) TransCardio_3 <- read_excel(path = xl_dataCardioT, sheet = 4) TransCardio_4 <- read_excel(path = xl_dataCardioT, sheet = 5) TransCardio_5 <- read_excel(path = xl_dataCardioT, sheet = 6) TransCardio_6 <- read_excel(path = xl_dataCardioT, sheet = 7) TransCardio_7 <- read_excel(path = xl_dataCardioT, sheet = 8) TransCardio_8 <- read_excel(path = xl_dataCardioT, sheet = 9) TransCardio_9 <- read_excel(path = xl_dataCardioT, sheet = 10) TransCardio_10 <- read_excel(path = xl_dataCardioT, sheet = 11) TransCardio_11 <- read_excel(path = xl_dataCardioT, sheet = 12) TransCardio_12 <- read_excel(path = xl_dataCardioT, sheet = 13) TransCardio_13 <- read_excel(path = xl_dataCardioT, sheet = 14) TransCardio_14 <- read_excel(path = xl_dataCardioT, sheet = 15)

Trans Gait

Trans Cardio

xl_dataGaitT <- "C:/P/PF-THA-Trans - GaitA.xlsx" TransGait_0 <- read_excel(path = xl_dataGaitT, sheet = 1) TransGait_1 <- read_excel(path = xl_dataGaitT, sheet = 2) TransGait_2 <- read_excel(path = xl_dataGaitT, sheet = 3) TransGait_3 <- read_excel(path = xl_dataGaitT, sheet = 4) TransGait_4 <- read_excel(path = xl_dataGaitT, sheet = 5) TransGait_5 <- read_excel(path = xl_dataGaitT, sheet = 6) TransGait_6 <- read_excel(path = xl_dataGaitT, sheet = 7) TransGait_7 <- read_excel(path = xl_dataGaitT, sheet = 8) TransGait_8 <- read_excel(path = xl_dataGaitT, sheet = 9) TransGait_9 <- read_excel(path = xl_dataGaitT, sheet = 10) TransGait_10 <- read_excel(path = xl_dataGaitT, sheet = 11) TransGait_11 <- read_excel(path = xl_dataGaitT, sheet = 12) TransGait_12 <- read_excel(path = xl_dataGaitT, sheet = 13) TransGait_13 <- read_excel(path = xl_dataGaitT, sheet = 14) TransGait_14 <- read_excel(path = xl_dataGaitT, sheet = 15) Total <- POMDP( name = "Total", discount = 0.99, horizon = c(a = 1, b = 1, c =1, d = 1, e=1, f=1, g=1, h=1, i =1, j=1, k=1, l=1, m=1,n=1, o=1), states = c("s1", "s2", "s3", "s4", "s5","s6","s7", "s8", "s9","s10","s11","s12","s13","s14","s15","s16"), actions = c("Physio", "Gait", "cardiovascular", "nothing"), observations = c("o1", "o2", "o3", "o4"), start = "uniform", transition_prob = list( a = list( "Physio" = as.matrix(TransPhysio_0), "Gait" = as.matrix(TransGait_0), "cardiovascular" = as.matrix(TransCardio_0), "nothing" = "uniform"), b = list( "Physio" = as.matrix(TransPhysio_1), "Gait" = as.matrix(TransGait_1), "cardiovascular" = as.matrix(TransCardio_1), "nothing" = "uniform"), c = list( "Physio" = as.matrix(TransPhysio_2), "Gait" = as.matrix(TransGait_2), "cardiovascular" = as.matrix(TransCardio_2), "nothing" = "uniform"), d = list( "Physio" = as.matrix(TransPhysio_3), "Gait" = as.matrix(TransGait_3), "cardiovascular" = as.matrix(TransCardio_3), "nothing" = "uniform"), e = list( "Physio" = as.matrix(TransPhysio_4), "Gait" = as.matrix(TransGait_4), "cardiovascular" = as.matrix(TransCardio_4), "nothing" = "uniform"), f = list( "Physio" = as.matrix(TransPhysio_5), "Gait" = as.matrix(TransGait_5), "cardiovascular" = as.matrix(TransCardio_5), "nothing" = "uniform"), g = list( "Physio" = as.matrix(TransPhysio_6), "Gait" = as.matrix(TransGait_6), "cardiovascular" = as.matrix(TransCardio_6), "nothing" = "uniform"), h = list( "Physio" = as.matrix(TransPhysio_7), "Gait" = as.matrix(TransGait_7), "cardiovascular" = as.matrix(TransCardio_7), "nothing" = "uniform"), i = list( "Physio" = as.matrix(TransPhysio_8), "Gait" = as.matrix(TransGait_8), "cardiovascular" = as.matrix(TransCardio_8), "nothing" = "uniform"), j = list( "Physio" = as.matrix(TransPhysio_9), "Gait" = as.matrix(TransGait_9), "cardiovascular" = as.matrix(TransCardio_9), "nothing" = "uniform"), k = list( "Physio" = as.matrix(TransPhysio_10), "Gait" = as.matrix(TransGait_10), "cardiovascular" = as.matrix(TransCardio_10), "nothing" = "uniform"), l = list( "Physio" = as.matrix(TransPhysio_11), "Gait" = as.matrix(TransGait_11), "cardiovascular" = as.matrix(TransCardio_11), "nothing" = "uniform"), m = list( "Physio" = as.matrix(TransPhysio_12), "Gait" = as.matrix(TransGait_12), "cardiovascular" = as.matrix(TransCardio_12), "nothing" = "uniform"), n = list( "Physio" = as.matrix(TransPhysio_13), "Gait" = as.matrix(TransGait_13), "cardiovascular" = as.matrix(TransCardio_13), "nothing" = "uniform"), o = list( "Physio" = as.matrix(TransPhysio_14), "Gait" = as.matrix(TransGait_14), "cardiovascular" = as.matrix(TransCardio_14), "nothing" = "uniform")),

observation_prob = list( a = list( "Physio" = as.matrix(obsPhysio_1), "Gait" = as.matrix(obsGait_1), "cardiovascular" = as.matrix(obsCardio_1), "nothing" = "uniform"), b = list( "Physio" = as.matrix(obsPhysio_2), "Gait" = as.matrix(obsGait_2), "cardiovascular" = as.matrix(obsCardio_2), "nothing" = "uniform"), c = list( "Physio" = as.matrix(obsPhysio_3), "Gait" = as.matrix(obsGait_3), "cardiovascular" = as.matrix(obsCardio_3), "nothing" = "uniform"), d = list( "Physio" = as.matrix(obsPhysio_4), "Gait" = as.matrix(obsGait_4), "cardiovascular" = as.matrix(obsCardio_4), "nothing" = "uniform"), e = list( "Physio" = as.matrix(obsPhysio_5), "Gait" = as.matrix(obsGait_5), "cardiovascular" = as.matrix(obsCardio_5), "nothing" = "uniform"), f = list( "Physio" = as.matrix(obsPhysio_6), "Gait" = as.matrix(obsGait_6), "cardiovascular" = as.matrix(obsCardio_6), "nothing" = "uniform"), g = list( "Physio" = as.matrix(obsPhysio_7), "Gait" = as.matrix(obsGait_7), "cardiovascular" = as.matrix(obsCardio_7), "nothing" = "uniform"), h = list( "Physio" = as.matrix(obsPhysio_8), "Gait" = as.matrix(obsGait_8), "cardiovascular" = as.matrix(obsCardio_8), "nothing" = "uniform"), i = list( "Physio" = as.matrix(obsPhysio_9), "Gait" = as.matrix(obsGait_9), "cardiovascular" = as.matrix(obsCardio_9), "nothing" = "uniform"), j = list( "Physio" = as.matrix(obsPhysio_10), "Gait" = as.matrix(obsGait_10), "cardiovascular" = as.matrix(obsCardio_10), "nothing" = "uniform"), k = list( "Physio" = as.matrix(obsPhysio_11), "Gait" = as.matrix(obsGait_11), "cardiovascular" = as.matrix(obsCardio_11), "nothing" = "uniform"), l = list( "Physio" = as.matrix(obsPhysio_12), "Gait" = as.matrix(obsGait_12), "cardiovascular" = as.matrix(obsCardio_12), "nothing" = "uniform"), m = list( "Physio" = as.matrix(obsPhysio_13), "Gait" = as.matrix(obsGait_13), "cardiovascular" = as.matrix(obsCardio_13), "nothing" = "uniform"), n = list( "Physio" = as.matrix(obsPhysio_14), "Gait" = as.matrix(obsGait_14), "cardiovascular" = as.matrix(obsCardio_14), "nothing" = "uniform"), o = list( "Physio" = as.matrix(obsPhysio_15), "Gait" = as.matrix(obsGait_15), "cardiovascular" = as.matrix(obsCardio_15), "nothing" = "uniform")),

the reward helper expects: action, start.state, end.state, observation, value

reward = rbind( R("Physio", "s1", v = 22.5), R("Physio", "s2", v = 67.5), R("Physio", "s3", v = 112.5), R("Physio", "s4", v = 157.5), R("Physio", "s5", v = 202.5), R("Physio", "s6", v = 247.5), R("Physio", "s7", v = 337.5), R("Physio", "s8", v = 382.5), R("Physio", "s9", v = 427.5), R("Physio", "s10", v = 472.5), R("Physio", "s11", v = 517.5), R("Physio", "s12", v = 562.5), R("Physio", "s13", v = 607.5), R("Physio", "s14", v = 652.5), R("Physio", "s15", v = 697.5), R("Physio", "s16", v = 742.5), R("Gait", "s1", v = 22.5), R("Gait", "s2", v = 67.5), R("Gait", "s3", v = 112.5), R("Gait", "s4", v = 157.5), R("Gait", "s5", v = 202.5), R("Gait", "s6", v = 247.5), R("Gait", "s7", v = 337.5), R("Gait", "s8", v = 382.5), R("Gait", "s9", v = 427.5), R("Gait", "s10", v = 472.5), R("Gait", "s11", v = 517.5), R("Gait", "s12", v = 562.5), R("Gait", "s13", v = 607.5), R("Gait", "s14", v = 652.5), R("Gait", "s15", v = 697.5), R("Gait", "s16", v = 742.5), R("cardiovascular", "s1", v = 22.5), R("cardiovascular", "s2", v = 67.5), R("cardiovascular", "s3", v = 112.5), R("cardiovascular", "s4", v = 157.5), R("cardiovascular", "s5", v = 202.5), R("cardiovascular", "s6", v = 247.5), R("cardiovascular", "s7", v = 337.5), R("cardiovascular", "s8", v = 382.5), R("cardiovascular", "s9", v = 427.5), R("cardiovascular", "s10", v = 472.5), R("cardiovascular", "s11", v = 517.5), R("cardiovascular", "s12", v = 562.5), R("cardiovascular", "s13", v = 607.5), R("cardiovascular", "s14", v = 652.5), R("cardiovascular", "s15", v = 697.5), R("cardiovascular", "s16", v = 742.5), R("nothing", "s1", v = 12.5), R("nothing", "s2", v = 47.5), R("nothing", "s3", v = 92.5), R("nothing", "s4", v = 127.5), R("nothing", "s5", v = 182.5), R("nothing", "s6", v = 217.5), R("nothing", "s7", v = 297.5), R("nothing", "s8", v = 322.5), R("nothing", "s9", v = 377.5), R("nothing", "s10", v = 412.5), R("nothing", "s11", v = 487.5), R("nothing", "s12", v = 512.5), R("nothing", "s13", v = 587.5), R("nothing", "s14", v = 612.5), R("nothing", "s15", v = 637.5), R("nothing", "s16", v = 682.5)
), max = TRUE, ) Total sol <- solve_POMDP(model = Total, discount = 0.99, method = "enum") sol policy(sol)

haniees commented 3 years ago

There should not be such a restriction. Please send us some code to replicate this problem.

Did you have a chance to run the code I posted here?

mhahsler commented 3 years ago

The latest version on GitHub seems to run with your model.