hmpMDPWriter {MDP} | R Documentation |
Function for writing an HMDP model to a hmp file (XML). The function define subfunctions which can be used to define an HMDP model.
hmpMDPWriter(file="r.hmp", rate=0.1, rateBase=1, precision=1e-05, desc="HMP file created using hmpMDPWriter in R")
file |
The name of the file storing the model (e.g. mdp.hmp). |
rate |
The interest rate (used if consider discounting). |
rateBase |
The time where the rate is taken over, e.g. if the rate is 0.1 and rateBase is 365 days
then we have an interest rate of 10 percent over the year. |
precision |
The precision used when checking if probabilities sum to one. |
desc |
Description of the model. |
HMP files are in XML format and human readable using e.g. a text editor. HMP files are not suitable for storing large HMDP models since text files are very verbose. Moreover, approximation of the weights and probabilities may occur since the parser writing the hmp file may no output all digits. If you consider large models then use the binary file format instead.
The functions which can be used are:
setWeights(labels, duration)
: labels
is a vector of label names, duration
A number defining which label
that corresponds to duration/time, e.g. if the first entry in labels is time then duration = 1
.
The function must be called before starting building the model.process()
: endProcess()
: stage(label=NULL)
: endStage()
: state(label=NULL)
: endState()
: action(label=NULL, weights, prob, statesNext=NULL)
: weights
must be a vector of action weights,
prob
must contain triples of (scope, idx,pr).
The scope
can be 3 values: 0 - A transition to the next stage in the
father process, 1 - A transition to next stage in the current process, 2 - A
transition to a child process (stage zero in the child process). idx
in
the pair denote the index of the state at the stage considered, e.g. if scope=1
and idx=2 we consider state number 3 at next stage in the current process
(number from zero). Note scope = 3 is not supported in the hmp file format!
statesNext
is the number of states in the next stage of the process
(only needed if have a transition to the father).endAction()
: closeWriter()
: A list of functions.
Note all indexes are starting from zero (C/C++ style).
Lars Relund lars@relund.dk
# Create a small HMDP with two levels w<-hmpMDPWriter() w$setWeights(c("Duration","Net reward","Items"),duration=1) w$process() w$stage() w$state(label="M0") w$action(label="A0",weights=c(0,0,0),prob=c(2,0,1)) w$process() w$stage() w$state(label="D") w$action(label="A0",weights=c(0,0,1),prob=c(1,0,0.5,1,1,0.5)) w$endAction() w$endState() w$endStage() w$stage() w$state(label="C0") w$action(label="A0",weights=c(0,0,0),prob=c(1,0,1)) w$endAction() w$action(label="A1",weights=c(1,2,1),prob=c(1,0,0.5,1,1,0.5)) w$endAction() w$endState() w$state(label="C1") w$action(label="A0",weights=c(0,0,0),prob=c(1,0,1)) w$endAction() w$action(label="A1",weights=c(1,2,1),prob=c(1,0,0.5,1,1,0.5)) w$endAction() w$endState() w$endStage() w$stage() w$state(label="C0") w$action(label="A0",weights=c(1,4,0),prob=c(0,0,1)) w$endAction() w$endState() w$state(label="C1") w$action(label="A0",weights=c(1,4,0),prob=c(0,0,1)) w$endAction() w$endState() w$endStage() w$endProcess() w$endAction() w$action(label="A1",weights=c(0,0,0),prob=c(2,0,1)) w$process() w$stage() w$state(label="D") w$action(label="A0",weights=c(0,0,1),prob=c(1,0,1)) w$endAction() w$endState() w$endStage() w$stage() w$state(label="C0") w$action(label="A0",weights=c(0,0,0),prob=c(1,0,1)) w$endAction() w$action(label="A1",weights=c(1,2,1),prob=c(1,0,0.5,1,1,0.5)) w$endAction() w$endState() w$endStage() w$stage() w$state(label="C0") w$action(label="A0",weights=c(1,4,0),prob=c(0,0,1)) w$endAction() w$endState() w$state(label="C1") w$action(label="A0",weights=c(1,4,0),prob=c(0,0,1)) w$endAction() w$action(label="A1",weights=c(0,10,5),prob=c(0,0,0.5,0,1,0.5)) w$endAction() w$endState() w$endStage() w$endProcess() w$endAction() w$endState() w$state(label="M1") w$action(label="A0",weights=c(0,0,0),prob=c(2,0,1)) w$process() w$stage() w$state(label="D") w$action(label="A0",weights=c(0,0,1),prob=c(1,0,0.5,1,1,0.5)) w$endAction() w$endState() w$endStage() w$stage() w$state(label="C0") w$action(label="A0",weights=c(0,0,0),prob=c(1,0,1)) w$endAction() w$endState() w$state(label="C1") w$action(label="A0",weights=c(0,0,0),prob=c(1,0,1)) w$endAction() w$endState() w$endStage() w$stage() w$state(label="C0") w$action(label="A0",weights=c(1,4,0),prob=c(0,0,1)) w$endAction() w$endState() w$state(label="C1") w$action(label="A0",weights=c(1,4,0),prob=c(0,0,1)) w$endAction() w$endState() w$endStage() w$endProcess() w$endAction() w$endState() w$endStage() w$endProcess() w$closeWriter() stateIdxDf() actionIdxDf() actionWeightMat() transProbMat() a<-actionInfo() a # ordered by action id a[order(a$sId),] # ordered by state id for (i in 1:10) { print(i) }