-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDeterministicLabelling.jl
More file actions
84 lines (64 loc) · 2.47 KB
/
DeterministicLabelling.jl
File metadata and controls
84 lines (64 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
struct DeterministicLabelling{
T <: Integer,
AT <: AbstractArray{T}
}
A type representing the labelling of IMDP states into DFA inputs.
Formally, let ``L : S \\to 2^{AP}`` be a labelling function, where
- ``S`` is the set of IMDP states, and
- ``2^{AP}`` is the power set of atomic propositions
Then the ```DeterministicLabelling``` type is defined as vector which stores the mapping.
### Fields
- `map::AT`: mapping function where indices are (factored) IMDP states and stored values are DFA inputs.
- `num_outputs::Int32`: number of labels accounted for in mapping.
"""
struct DeterministicLabelling{T <: Integer, AT <: AbstractArray{T}} <: AbstractLabelling
map::AT
num_outputs::Int32
function DeterministicLabelling(map::AT) where {T <: Integer, AT <: AbstractArray{T}}
num_outputs = checklabelling(map)
return new{T, AT}(map, Int32(num_outputs))
end
end
function checklabelling(map::AbstractArray{<:Integer})
labels = unique(map)
if any(labels .< 1)
throw(ArgumentError("Labelled state index cannot be less than 1"))
end
# Check that labels are consecutive integers
sort!(labels)
if any(diff(labels) .!= 1)
throw(ArgumentError("Labelled state indices must be consecutive integers"))
end
return last(labels)
end
"""
mapping(dl::DeterministicLabelling)
Return the mapping array of the labelling function.
"""
mapping(dl::DeterministicLabelling) = dl.map
"""
size(dl::DeterministicLabelling)
Returns the shape of the input range of the labeling function ``L : S \\to 2^{AP}``, which can be multiple dimensions in case of factored IMDPs.
"""
Base.size(dl::DeterministicLabelling) = size(dl.map)
"""
num_labels(dl::DeterministicLabelling)
Return the number of labels (DFA inputs) in the labelling function.
"""
num_labels(dl::DeterministicLabelling) = dl.num_outputs
"""
state_values(dl::DeterministicLabelling)
Return a tuple with the number of states for each state variable of the labeling function ``L : S \\to 2^{AP}``, which can be multiple dimensions in case of factored IMDPs.
"""
state_values(dl::DeterministicLabelling) = size(dl.map)
"""
num_states(dl::DeterministicLabelling)
Return the number of states of the labeling function ``L : S \\to 2^{AP}``
"""
num_states(dl::DeterministicLabelling) = prod(state_values(dl))
"""
getindex(dl::DeterministicLabelling, s...)
Return the label for state s.
"""
Base.getindex(dl::DeterministicLabelling, s...) = dl.map[s...]