Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MarkovProcesses.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bentriou Mahmoud
MarkovProcesses.jl
Commits
8bd094c8
Commit
8bd094c8
authored
4 years ago
by
Bentriou Mahmoud
Browse files
Options
Downloads
Patches
Plain Diff
renaming a field in synchronized trajectory + pretty prints
parent
4162776b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
core/common.jl
+1
-1
1 addition, 1 deletion
core/common.jl
core/model.jl
+9
-9
9 additions, 9 deletions
core/model.jl
core/trajectory.jl
+35
-4
35 additions, 4 deletions
core/trajectory.jl
with
45 additions
and
14 deletions
core/common.jl
+
1
−
1
View file @
8bd094c8
...
@@ -69,7 +69,7 @@ end
...
@@ -69,7 +69,7 @@ end
struct
SynchronizedTrajectory
<:
AbstractTrajectory
struct
SynchronizedTrajectory
<:
AbstractTrajectory
state_lha_end
::
StateLHA
state_lha_end
::
StateLHA
m
::
SynchronizedModel
s
m
::
SynchronizedModel
values
::
Vector
{
Vector
{
Int
}}
values
::
Vector
{
Vector
{
Int
}}
times
::
Vector
{
Float64
}
times
::
Vector
{
Float64
}
transitions
::
Vector
{
Transition
}
transitions
::
Vector
{
Transition
}
...
...
This diff is collapsed.
Click to expand it.
core/model.jl
+
9
−
9
View file @
8bd094c8
...
@@ -364,22 +364,22 @@ function distribute_prob_accept_lha(sm::SynchronizedModel, nbr_sim::Int)
...
@@ -364,22 +364,22 @@ function distribute_prob_accept_lha(sm::SynchronizedModel, nbr_sim::Int)
end
end
function
Base.show
(
io
::
IO
,
m
::
ContinuousTimeModel
)
function
Base.show
(
io
::
IO
,
m
::
ContinuousTimeModel
)
print
(
io
,
"
$
(m.name) model
\n
"
)
print
(
io
,
"
$
(m.name) model
(ContinuousTimeModel)
\n
"
)
print
(
io
,
"- variables :
\n
"
)
print
(
io
,
"- variables :
\n
"
)
for
(
var
,
idx
)
in
m
.
map_var_idx
for
(
var
,
idx
)
in
m
.
map_var_idx
print
(
io
,
"*
$
var (i
d
x =
$
idx in state space)
\n
"
)
print
(
io
,
"*
$
var (i
nde
x =
$
idx in state space)
\n
"
)
end
end
print
(
io
,
"- parameters :
\n
"
)
print
(
io
,
"- parameters :
\n
"
)
for
(
param
,
idx
)
in
m
.
map_param_idx
for
(
param
,
idx
)
in
m
.
map_param_idx
print
(
io
,
"*
$
param (i
d
x =
$
idx in parameter space)
\n
"
)
print
(
io
,
"*
$
param (i
nde
x =
$
idx in parameter space)
\n
"
)
end
end
print
(
io
,
"- transitions :
$
(m.transitions)
\n
"
)
print
(
io
,
"- transitions :
$
(
join(
m.transitions
,',')
)
\n
"
)
print
(
io
,
"- observed variables :
\n
"
)
print
(
io
,
"- observed variables :
\n
"
)
for
i
in
eachindex
(
m
.
g
)
for
i
in
eachindex
(
m
.
g
)
print
(
io
,
"*
$
(m.g[i]) (i
d
x =
$
i in observed state space)
\n
"
)
print
(
io
,
"*
$
(m.g[i]) (i
nde
x =
$
i in observed state
space, index =
$
(m._g_idx[i]) in state
space)
\n
"
)
end
end
print
(
io
,
"p =
$
(m.p)
\n
"
)
print
(
io
,
"p =
$
(m.p)
\n
"
)
print
(
io
,
"x0 =
$
(m.x0)
(in full state space)
\n
"
)
print
(
io
,
"x0 =
$
(m.x0)
\n
"
)
print
(
io
,
"t0 =
$
(m.t0)
\n
"
)
print
(
io
,
"t0 =
$
(m.t0)
\n
"
)
print
(
io
,
"time bound =
$
(m.time_bound)"
)
print
(
io
,
"time bound =
$
(m.time_bound)"
)
end
end
...
@@ -424,7 +424,7 @@ function observe_all!(am::Model)
...
@@ -424,7 +424,7 @@ function observe_all!(am::Model)
end
end
function
set_param!
(
am
::
Model
,
new_p
::
Vector
{
Float64
})
function
set_param!
(
am
::
Model
,
new_p
::
Vector
{
Float64
})
m
=
get_proba_model
(
am
)
m
=
get_proba_model
(
am
)
@assert
length
(
new_p
)
==
m
.
dim_params
@assert
length
(
new_p
)
==
m
.
dim_params
"New parameter vector hasn't the same dimension of parameter space"
m
.
p
=
new_p
m
.
p
=
new_p
end
end
function
set_param!
(
am
::
Model
,
name_p
::
String
,
p_i
::
Float64
)
function
set_param!
(
am
::
Model
,
name_p
::
String
,
p_i
::
Float64
)
...
@@ -433,14 +433,14 @@ function set_param!(am::Model, name_p::String, p_i::Float64)
...
@@ -433,14 +433,14 @@ function set_param!(am::Model, name_p::String, p_i::Float64)
end
end
function
set_param!
(
am
::
Model
,
l_name_p
::
Vector
{
String
},
p
::
Vector
{
Float64
})
function
set_param!
(
am
::
Model
,
l_name_p
::
Vector
{
String
},
p
::
Vector
{
Float64
})
m
=
get_proba_model
(
am
)
m
=
get_proba_model
(
am
)
@assert
length
(
l_name_p
)
==
length
(
p
)
@assert
length
(
l_name_p
)
==
length
(
p
)
"Parameter names vector and parameter values haven't the same dimensions"
for
i
=
eachindex
(
l_name_p
)
for
i
=
eachindex
(
l_name_p
)
set_param!
(
m
,
l_name_p
[
i
],
p
[
i
])
set_param!
(
m
,
l_name_p
[
i
],
p
[
i
])
end
end
end
end
function
set_x0!
(
am
::
Model
,
new_x0
::
Vector
{
Int
})
function
set_x0!
(
am
::
Model
,
new_x0
::
Vector
{
Int
})
m
=
get_proba_model
(
am
)
m
=
get_proba_model
(
am
)
@assert
length
(
new_x0
)
==
m
.
dim_state
@assert
length
(
new_x0
)
==
m
.
dim_state
"New x0 vector hasn't the dimension of state space"
m
.
x0
=
new_x0
m
.
x0
=
new_x0
end
end
set_time_bound!
(
am
::
Model
,
b
::
Float64
)
=
(
get_proba_model
(
am
)
.
time_bound
=
b
)
set_time_bound!
(
am
::
Model
,
b
::
Float64
)
=
(
get_proba_model
(
am
)
.
time_bound
=
b
)
...
...
This diff is collapsed.
Click to expand it.
core/trajectory.jl
+
35
−
4
View file @
8bd094c8
...
@@ -151,7 +151,7 @@ end
...
@@ -151,7 +151,7 @@ end
function
check_consistency
(
σ
::
AbstractTrajectory
)
function
check_consistency
(
σ
::
AbstractTrajectory
)
test_length_var
=
true
test_length_var
=
true
for
i
=
1
:
get_proba_model
(
σ
.
m
)
.
dim_obs_state
for
i
=
1
:
σ
.
m
.
dim_obs_state
test_length_i
=
(
length
(
σ
.
values
[
1
])
==
length
(
σ
.
values
[
i
]))
test_length_i
=
(
length
(
σ
.
values
[
1
])
==
length
(
σ
.
values
[
i
]))
test_length_var
=
test_length_var
&&
test_length_i
test_length_var
=
test_length_var
&&
test_length_i
end
end
...
@@ -159,20 +159,44 @@ function check_consistency(σ::AbstractTrajectory)
...
@@ -159,20 +159,44 @@ function check_consistency(σ::AbstractTrajectory)
(
length
(
σ
.
times
)
==
length
(
σ
.
values
[
1
]))
&&
(
length
(
σ
.
times
)
==
length
(
σ
.
values
[
1
]))
&&
test_length_var
test_length_var
end
end
@assert
length_obs_var
(
σ
)
==
get_proba_model
(
σ
.
m
)
.
dim_obs_state
@assert
length_obs_var
(
σ
)
==
σ
.
m
.
dim_obs_state
return
true
return
true
end
end
function
Base.show
(
io
::
IO
,
σ
::
Trajectory
)
print
(
io
,
"Trajectory
\n
"
)
print
(
io
,
"- Model name:
$
(σ.m.name)
\n
"
)
print
(
io
,
"- Variable trajectories:
\n
"
)
for
obs_var
in
σ
.
m
.
g
print
(
io
,
"*
$
obs_var:
$
(σ[obs_var])
\n
"
)
end
print
(
io
,
"- times =
$
(times(σ))
\n
"
)
print
(
io
,
"- transitions =
$
(transitions(σ))"
)
end
function
Base.show
(
io
::
IO
,
σ
::
SynchronizedTrajectory
)
print
(
io
,
"SynchronizedTrajectory
\n
"
)
print
(
io
,
"End LHA state:
\n
"
)
print
(
io
,
σ
.
state_lha_end
)
print
(
io
,
"
\n
"
)
print
(
io
,
"- Model name:
$
(σ.m.name)
\n
"
)
print
(
io
,
"- Variable trajectories:
\n
"
)
for
obs_var
in
σ
.
m
.
g
print
(
io
,
"*
$
obs_var:
$
(σ[obs_var])
\n
"
)
end
print
(
io
,
"- times =
$
(times(σ))
\n
"
)
print
(
io
,
"- transitions =
$
(transitions(σ))"
)
end
# Properties of the trajectory
# Properties of the trajectory
length_states
(
σ
::
AbstractTrajectory
)
=
length
(
σ
.
times
)
length_states
(
σ
::
AbstractTrajectory
)
=
length
(
σ
.
times
)
length_obs_var
(
σ
::
AbstractTrajectory
)
=
length
(
σ
.
values
)
length_obs_var
(
σ
::
AbstractTrajectory
)
=
length
(
σ
.
values
)
get_obs_var
(
σ
::
AbstractTrajectory
)
=
get_proba_model
(
σ
.
m
)
.
g
get_obs_var
(
σ
::
AbstractTrajectory
)
=
σ
.
m
.
g
isbounded
(
σ
::
AbstractTrajectory
)
=
σ
.
transitions
[
end
]
==
nothing
&&
length_states
(
σ
)
>=
2
isbounded
(
σ
::
AbstractTrajectory
)
=
σ
.
transitions
[
end
]
==
nothing
&&
length_states
(
σ
)
>=
2
isaccepted
(
σ
::
SynchronizedTrajectory
)
=
isaccepted
(
σ
.
state_lha_end
)
isaccepted
(
σ
::
SynchronizedTrajectory
)
=
isaccepted
(
σ
.
state_lha_end
)
issteadystate
(
σ
::
AbstractTrajectory
)
=
@warn
"Unimplemented"
issteadystate
(
σ
::
AbstractTrajectory
)
=
@warn
"Unimplemented"
# Access to trajectory values
# Access to trajectory values
get_var_values
(
σ
::
AbstractTrajectory
,
var
::
String
)
=
σ
.
values
[
get_proba_model
(
σ
.
m
)
.
_map_obs_var_idx
[
var
]]
get_var_values
(
σ
::
AbstractTrajectory
,
var
::
String
)
=
σ
.
values
[
σ
.
m
.
_map_obs_var_idx
[
var
]]
get_state
(
σ
::
AbstractTrajectory
,
idx
::
Int
)
=
[
σ
.
values
[
i
][
idx
]
for
i
=
1
:
length
(
σ
.
values
)]
# /!\ Creates an array
get_state
(
σ
::
AbstractTrajectory
,
idx
::
Int
)
=
[
σ
.
values
[
i
][
idx
]
for
i
=
1
:
length
(
σ
.
values
)]
# /!\ Creates an array
get_value
(
σ
::
AbstractTrajectory
,
var
::
String
,
idx
::
Int
)
=
get_var_values
(
σ
,
var
)[
idx
]
get_value
(
σ
::
AbstractTrajectory
,
var
::
String
,
idx
::
Int
)
=
get_var_values
(
σ
,
var
)[
idx
]
# Operation σ@t
# Operation σ@t
...
@@ -194,6 +218,13 @@ function get_state_from_time(σ::AbstractTrajectory, t::Float64)
...
@@ -194,6 +218,13 @@ function get_state_from_time(σ::AbstractTrajectory, t::Float64)
end
end
error
(
"Unexpected behavior"
)
error
(
"Unexpected behavior"
)
end
end
function
getproperty
(
σ
::
SynchronizedTrajectory
,
sym
::
Symbol
)
if
sym
==
:
m
return
(
σ
.
sm
)
.
m
else
return
getfield
(
σ
,
sym
)
end
end
states
(
σ
::
AbstractTrajectory
)
=
σ
.
values
states
(
σ
::
AbstractTrajectory
)
=
σ
.
values
times
(
σ
::
AbstractTrajectory
)
=
σ
.
times
times
(
σ
::
AbstractTrajectory
)
=
σ
.
times
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment