observations.jl 1.52 KB
Newer Older
1
2
3
4
5
6

abstract type AbstractTrajectory end
ContinuousObservations = AbstractVector{AbstractTrajectory}

struct Trajectory <: AbstractTrajectory
    m::ContinuousTimeModel
7
8
9
    values::Matrix{Int}
    times::Vector{Float64}
    transitions::Vector{Union{String,Nothing}}
10
11
12
13
end

function +(σ1::AbstractTrajectory,σ2::AbstractTrajectory) end
function -(σ1::AbstractTrajectory,σ2::AbstractTrajectory) end
14
function δ(σ1::AbstractTrajectory,t::Float64) end
15

16
17
18
# Properties of the trajectory
get_states_number(σ::AbstractTrajectory) = length(σ.times)
get_obs_variables(σ::AbstractTrajectory) = (σ.m).g
Bentriou Mahmoud's avatar
Bentriou Mahmoud committed
19

20
21
22
23
24
25
# Access to trajectory values
get_var_values(σ::AbstractTrajectory, var::String) = 
@view σ.values[:,(σ.m)._map_obs_var_idx[var]] 
get_state(σ::AbstractTrajectory, idx::Int) = @view σ.values[idx,:]
get_value(σ::AbstractTrajectory, var::String, idx::Int) = 
σ.values[idx,(σ.m)._map_obs_var_idx[var]] 
26

27
28
29
# Get var values ["I"]
function getindex(σ::AbstractTrajectory, var::String)
    if var  == "times"
30
        return σ.times
31
    elseif var == "transitions"
32
33
        return σ.transitions
    else
34
35
36
37
38
39
40
41
42
43
44
45
46
47
        return get_var_values(σ, var)
    end
end
# Get i-th state [i]
getindex(σ::AbstractTrajectory, idx::Int) = get_state(σ, i)
# Get i-th value of var ["I", idx]
function getindex(σ::AbstractTrajectory, var_idx::Tuple{String,Int})
    var, idx = var_idx[1], var_idx[2]
    if var  == "times"
        return σ.times[idx]
    elseif var == "transitions"
        return σ.transitions[idx]
    else
        return get_value(σ, var, idx)
48
49
    end
end
50