-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reader for my own netCDF based format
- Loading branch information
Showing
5 changed files
with
141 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
module Data | ||
using IMDP, SparseArrays | ||
using NCDatasets | ||
|
||
include("bmdp-tool.jl") | ||
export read_bmdp_tool_file, write_bmdp_tool_file | ||
|
||
include("prism.jl") | ||
export read_prism_file, write_prism_file | ||
|
||
include("imdp.jl") | ||
export read_imdp_jl_file, write_imdp_jl_file | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
function read_imdp_jl_file(path) | ||
dataset = Dataset(path) | ||
|
||
n = dataset.attrib["num_states"] | ||
initial_state = dataset.attrib["initial_state"] | ||
model = dataset.attrib["model"] | ||
|
||
@assert model ∈ ["imdp", "imc"] | ||
@assert dataset.attrib["rows"] == "to" | ||
@assert dataset.attrib["cols"] ∈ ["from", "from/action"] | ||
@assert dataset.properties["format"] == "sparse_csc" | ||
|
||
lower_colptr = convert.(Int32, dataset["lower_colptr"][:]) | ||
lower_rowval = convert.(Int32, dataset["lower_rowval"][:]) | ||
lower_nzval = dataset["lower_nzval"][:] | ||
P̲ = SparseMatrixCSC(Int32(n + 1), Int32(n), lower_colptr, lower_rowval, lower_nzval) | ||
|
||
upper_colptr = convert.(Int32, dataset["upper_colptr"][:]) | ||
upper_rowval = convert.(Int32, dataset["upper_rowval"][:]) | ||
upper_nzval = dataset["upper_nzval"][:] | ||
P̅ = SparseMatrixCSC(Int32(n + 1), Int32(n), upper_colptr, upper_rowval, upper_nzval) | ||
|
||
prob = MatrixIntervalProbabilities(; lower = P̲, upper = P̅) | ||
|
||
if model == "imdp" | ||
mdp_or_mc = read_imdp_jl_mdp(dataset, prob, initial_state) | ||
elseif model == "imc" | ||
mdp_or_mc = read_imdp_jl_mc(dataset, prob, initial_state) | ||
end | ||
|
||
# IMPORTANT! Otherwise the file cannot be reopened until the OS has released the file handle. | ||
close(dataset) | ||
|
||
return mdp_or_mc | ||
end | ||
|
||
function read_imdp_jl_mdp(dataset, prob, initial_state) | ||
@assert dataset.attrib["cols"] == "from/action" | ||
|
||
stateptr = convert.(Int32, dataset["stateptr"][:]) | ||
action_vals = dataset["action_vals"][:] | ||
|
||
mdp = IntervalMarkovDecisionProcess(prob, stateptr, action_vals, Int32(initial_state)) | ||
return mdp | ||
end | ||
|
||
function read_imdp_jl_mc(dataset, prob, initial_state) | ||
@assert dataset.attrib["cols"] == "from" | ||
|
||
mc = IntervalMarkovChain(prob, Int32(initial_state)) | ||
return mc | ||
end | ||
|
||
function write_imdp_jl_file(path, mdp_or_mc) | ||
# TODO: implement | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters