binaryMDPWriter {MDP} | R Documentation |
Function for writing an HMDP model to binary files. The function defineds subfunctions which can be used to define an HMDP model saved in a set of binary files.
binaryMDPWriter(prefix="", binNames=c("stateIdx.bin","stateIdxLbl.bin","actionIdx.bin", "actionIdxLbl.bin","actionWeight.bin","actionWeightLbl.bin","transProb.bin"))
prefix |
A character string with the prefix added to binNames . |
binNames |
A character vector of length 7 giving the names of the binary files storing the model. |
Binary files are efficent for storing large models. Compared to the HMP (XML) format the binary files use less storage space and loading the model is faster.
The functions which can be used are:
setWeights(labels, ...)
: labels
is a vector of label names, ...
are not used.
The function must be called before starting building the model.process()
: endProcess()
: stage(label=NULL)
: label
are not used in the binary format.endStage()
: state(label=NULL)
: endState()
: action(label=NULL, weights, prob, ...)
: weights
must be a vector of action weights,
prob
must contain triples of (scope,idx,pr) (see the description of actionIdx.bin below), ...
is currently not used.endAction()
: closeWriter()
: Seven binary files are created using the following format:
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<-binaryMDPWriter() w$setWeights(c("Duration","Net reward","Items")) 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