Commit 36713460 authored by Bentriou Mahmoud's avatar Bentriou Mahmoud
Browse files

new methods trajectory_from_csv

parent 708a6c40
......@@ -29,7 +29,7 @@ export InvariantPredicateFunction, CheckConstraintsFunction, UpdateStateFunction
# Trajectory related methods
export +, -, δ, dist_lp, euclidean_distance
export get_obs_var, length_states, length_obs_var
export get_state_from_time, get_var_from_time, vectorize
export get_state_from_time, get_var_from_time, vectorize, trajectory_from_csv
export isbounded, states, times, transitions
export check_consistency, issteadystate, isaccepted
......@@ -308,3 +308,23 @@ function +(σ1::AbstractTrajectory,σ2::AbstractTrajectory) end
function -(σ1::AbstractTrajectory,σ2::AbstractTrajectory) end
δ(σ::AbstractTrajectory,idx::Int) = times(σ)[i+1] - times(σ)[i]
function trajectory_from_csv(csv_file, model::ContinuousTimeModel)
csv_mat_values, header = readdlm(csv_file, ',', header = true)
nbr_states = size(csv_mat_values, 1)
times = zeros(nbr_states)
values = Vector{Vector{Int}}(undef, length(model.g))
transitions = fill(nothing, nbr_states)
for i = eachindex(header)
model_var = header[i]
if model_var == "time"
times = csv_mat_values[:,i]
elseif model_var == "transitions"
transitions = csv_mat_values[:,i]
@assert Symbol(model_var) in model.g "Variable is not observed in the model"
values[model._map_obs_var_idx[Symbol(model_var)]] = csv_mat_values[:,i]
return Trajectory(model, values, times, transitions)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment