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
7e6d6ee9
Commit
7e6d6ee9
authored
4 years ago
by
Bentriou Mahmoud
Browse files
Options
Downloads
Patches
Plain Diff
fix deepcopy model.jl + fix plot oscillatory trajectory + small fix period automaton
parent
a1786dc0
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
automata/period_automaton.jl
+4
-3
4 additions, 3 deletions
automata/period_automaton.jl
core/model.jl
+2
-2
2 additions, 2 deletions
core/model.jl
core/plots.jl
+15
-12
15 additions, 12 deletions
core/plots.jl
with
21 additions
and
17 deletions
automata/period_automaton.jl
+
4
−
3
View file @
7e6d6ee9
...
@@ -153,8 +153,8 @@ function create_period_automaton(m::ContinuousTimeModel, L::Float64, H::Float64,
...
@@ -153,8 +153,8 @@ function create_period_automaton(m::ContinuousTimeModel, L::Float64, H::Float64,
@everywhere
$
(
func_name
(
:
us
,
:
mid
,
:
low
,
2
))(
S
::
StateLHA
,
x
::
Vector
{
Int
},
p
::
Vector
{
Float64
})
=
@everywhere
$
(
func_name
(
:
us
,
:
mid
,
:
low
,
2
))(
S
::
StateLHA
,
x
::
Vector
{
Int
},
p
::
Vector
{
Float64
})
=
(
setfield!
(
S
,
:
loc
,
Symbol
(
"low"
));
(
setfield!
(
S
,
:
loc
,
Symbol
(
"low"
));
setindex!
(
getfield
(
S
,
:
values
),
get_value
(
S
,
$
(
get_idx_var
(
:
n
)))
+
1
,
$
(
get_idx_var
(
:
n
)));
setindex!
(
getfield
(
S
,
:
values
),
get_value
(
S
,
$
(
get_idx_var
(
:
n
)))
+
1
,
$
(
get_idx_var
(
:
n
)));
setindex!
(
getfield
(
S
,
:
values
),
0.0
,
$
(
get_idx_var
(
:
t
)));
setindex!
(
getfield
(
S
,
:
values
),
0.0
,
$
(
get_idx_var
(
:
t
op
)));
setindex!
(
getfield
(
S
,
:
values
),
0.0
,
$
(
get_idx_var
(
:
t
o
p
))))
setindex!
(
getfield
(
S
,
:
values
),
0.0
,
$
(
get_idx_var
(
:
tp
))))
@everywhere
$
(
func_name
(
:
cc
,
:
mid
,
:
low
,
3
))(
S
::
StateLHA
,
x
::
Vector
{
Int
},
p
::
Vector
{
Float64
})
=
@everywhere
$
(
func_name
(
:
cc
,
:
mid
,
:
low
,
3
))(
S
::
StateLHA
,
x
::
Vector
{
Int
},
p
::
Vector
{
Float64
})
=
(
0
<=
get_value
(
S
,
$
(
get_idx_var
(
:
n
)))
<=
1
)
&&
(
0
<=
get_value
(
S
,
$
(
get_idx_var
(
:
n
)))
<=
1
)
&&
...
@@ -181,7 +181,8 @@ function create_period_automaton(m::ContinuousTimeModel, L::Float64, H::Float64,
...
@@ -181,7 +181,8 @@ function create_period_automaton(m::ContinuousTimeModel, L::Float64, H::Float64,
setindex!
(
getfield
(
S
,
:
values
),
g_var_tp
(
get_value
(
S
,
$
(
get_idx_var
(
:
var_tp
))),
setindex!
(
getfield
(
S
,
:
values
),
g_var_tp
(
get_value
(
S
,
$
(
get_idx_var
(
:
var_tp
))),
get_value
(
S
,
$
(
get_idx_var
(
:
mean_tp
))),
get_value
(
S
,
$
(
get_idx_var
(
:
mean_tp
))),
get_value
(
S
,
$
(
get_idx_var
(
:
tp
))),
get_value
(
S
,
$
(
get_idx_var
(
:
tp
))),
get_value
(
S
,
$
(
get_idx_var
(
:
n
)))),
$
(
get_idx_var
(
:
var_tp
))))
get_value
(
S
,
$
(
get_idx_var
(
:
n
)))),
$
(
get_idx_var
(
:
var_tp
)));
setindex!
(
getfield
(
S
,
:
values
),
0.0
,
$
(
get_idx_var
(
:
tp
))))
# * mid => high
# * mid => high
@everywhere
$
(
func_name
(
:
cc
,
:
mid
,
:
high
,
1
))(
S
::
StateLHA
,
x
::
Vector
{
Int
},
p
::
Vector
{
Float64
})
=
@everywhere
$
(
func_name
(
:
cc
,
:
mid
,
:
high
,
1
))(
S
::
StateLHA
,
x
::
Vector
{
Int
},
p
::
Vector
{
Float64
})
=
...
...
This diff is collapsed.
Click to expand it.
core/model.jl
+
2
−
2
View file @
7e6d6ee9
...
@@ -160,7 +160,7 @@ function simulate(product::SynchronizedModel; p::Union{Nothing,AbstractVector{Fl
...
@@ -160,7 +160,7 @@ function simulate(product::SynchronizedModel; p::Union{Nothing,AbstractVector{Fl
vec_x
=
zeros
(
Int
,
getfield
(
m
,
:
dim_state
))
vec_x
=
zeros
(
Int
,
getfield
(
m
,
:
dim_state
))
l_t
=
Float64
[
0.0
]
l_t
=
Float64
[
0.0
]
l_tr
=
Transition
[
nothing
]
l_tr
=
Transition
[
nothing
]
Snplus1
=
copy
(
Sn
)
Snplus1
=
deep
copy
(
Sn
)
# If x0 is absorbing
# If x0 is absorbing
if
isabsorbing
||
isacceptedLHA
if
isabsorbing
||
isacceptedLHA
_resize_trajectory!
(
full_values
,
times
,
transitions
,
1
)
_resize_trajectory!
(
full_values
,
times
,
transitions
,
1
)
...
@@ -288,7 +288,7 @@ function volatile_simulate(product::SynchronizedModel;
...
@@ -288,7 +288,7 @@ function volatile_simulate(product::SynchronizedModel;
vec_x
=
zeros
(
Int
,
getfield
(
m
,
:
dim_state
))
vec_x
=
zeros
(
Int
,
getfield
(
m
,
:
dim_state
))
l_t
=
Float64
[
0.0
]
l_t
=
Float64
[
0.0
]
l_tr
=
Transition
[
nothing
]
l_tr
=
Transition
[
nothing
]
Snplus1
=
copy
(
Sn
)
Snplus1
=
deep
copy
(
Sn
)
# If x0 is absorbing
# If x0 is absorbing
if
isabsorbing
||
isacceptedLHA
if
isabsorbing
||
isacceptedLHA
if
!
isacceptedLHA
if
!
isacceptedLHA
...
...
This diff is collapsed.
Click to expand it.
core/plots.jl
+
15
−
12
View file @
7e6d6ee9
...
@@ -78,31 +78,32 @@ function plot!(A::LHA; label::String = "")
...
@@ -78,31 +78,32 @@ function plot!(A::LHA; label::String = "")
end
end
# For tests purposes
# For tests purposes
function
plot_periodic_trajectory
(
A
::
LHA
,
σ
::
SynchronizedTrajectory
,
sym_obs
::
Symbol
;
verbose
=
false
,
filename
::
String
=
""
)
function
plot_periodic_trajectory
(
A
::
LHA
,
σ
::
SynchronizedTrajectory
,
sym_obs
::
Symbol
;
verbose
=
false
,
annot_size
::
Float64
=
6.0
,
filename
::
String
=
""
)
@assert
sym_obs
in
get_obs_var
(
σ
)
"Variable is not observed in the model"
@assert
sym_obs
in
get_obs_var
(
σ
)
"Variable is not observed in the model"
@assert
A
.
name
in
[
"Period"
]
@assert
A
.
name
in
[
"Period"
]
A_new
=
LHA
(
A
,
(
σ
.
m
)
.
_map_obs_var_idx
)
p_sim
=
(
σ
.
m
)
.
p
p_sim
=
(
σ
.
m
)
.
p
l_t
=
times
(
σ
)
l_t
=
times
(
σ
)
l_tr
=
transitions
(
σ
)
l_tr
=
transitions
(
σ
)
Sn
=
init_state
(
A
_new
,
σ
[
1
],
l_t
[
1
])
Sn
=
init_state
(
A
,
σ
[
1
],
l_t
[
1
])
Snplus1
=
copy
(
Sn
)
Snplus1
=
deep
copy
(
Sn
)
nbr_states
=
length_states
(
σ
)
nbr_states
=
length_states
(
σ
)
locations_trajectory
=
Vector
{
Location
}(
undef
,
nbr_states
)
locations_trajectory
=
Vector
{
Location
}(
undef
,
nbr_states
)
locations_trajectory
[
1
]
=
Sn
.
loc
locations_trajectory
[
1
]
=
Sn
.
loc
idx_n
=
[
1
]
idx_n
=
[
1
]
values_n
=
[
Sn
[
:
n
]]
values_n
=
[
Sn
[
:
n
]]
values_tp
=
[
Sn
[
:
tp
]]
if
verbose
println
(
"Init: "
)
end
if
verbose
println
(
"Init: "
)
end
if
verbose
@show
Sn
end
if
verbose
@show
Sn
end
for
n
in
2
:
nbr_states
for
n
in
2
:
nbr_states
next_state!
(
Snplus1
,
A_new
,
σ
[
n
],
l_t
[
n
],
l_tr
[
n
],
Sn
,
σ
[
n
-
1
],
p_sim
;
verbose
=
verbose
)
next_state!
(
Snplus1
,
A
,
σ
[
n
],
l_t
[
n
],
l_tr
[
n
],
Sn
,
σ
[
n
-
1
],
p_sim
;
verbose
=
verbose
)
copyto!
(
Sn
,
Snplus1
)
if
Snplus1
[
:
n
]
!=
values_n
[
end
]
locations_trajectory
[
n
]
=
Sn
.
loc
if
Sn
[
:
n
]
!=
values_n
[
end
]
push!
(
idx_n
,
n
)
push!
(
idx_n
,
n
)
push!
(
values_n
,
Sn
[
:
n
])
push!
(
values_n
,
Snplus1
[
:
n
])
push!
(
values_tp
,
Sn
[
:
tp
])
end
end
if
Snplus1
.
loc
in
A_new
.
locations_final
copyto!
(
Sn
,
Snplus1
)
locations_trajectory
[
n
]
=
Sn
.
loc
if
Snplus1
.
loc
in
A
.
locations_final
break
break
end
end
end
end
...
@@ -118,8 +119,10 @@ function plot_periodic_trajectory(A::LHA, σ::SynchronizedTrajectory, sym_obs::S
...
@@ -118,8 +119,10 @@ function plot_periodic_trajectory(A::LHA, σ::SynchronizedTrajectory, sym_obs::S
markersize
=
1.0
,
markershape
=
:
cross
,
markersize
=
1.0
,
markershape
=
:
cross
,
label
=
label_state
,
xlabel
=
"Time"
,
ylabel
=
"Species
$
sym_obs"
)
label
=
label_state
,
xlabel
=
"Time"
,
ylabel
=
"Species
$
sym_obs"
)
end
end
annot_n
=
[(
times
(
σ
)[
idx_n
[
i
]],
σ
[
sym_obs
][
idx_n
[
i
]]
-
10
,
text
(
"n =
$
(values_n[i])"
,
6
,
:
bottom
))
for
i
=
eachindex
(
idx_n
)]
annot_n
=
[(
times
(
σ
)[
idx_n
[
i
]],
σ
[
sym_obs
][
idx_n
[
i
]]
-
10
,
text
(
"n =
$
(values_n[i])"
,
annot_size
,
:
top
))
for
i
=
eachindex
(
idx_n
)]
scatter!
(
p
,
times
(
σ
)[
idx_n
],
σ
[
sym_obs
][
idx_n
],
annotations
=
annot_n
,
annot_tp
=
[(
times
(
σ
)[
idx_n
[
i
]],
σ
[
sym_obs
][
idx_n
[
i
]]
-
10
,
text
(
"tp =
$
(round(values_tp[i], digits = 2))"
,
annot_size
,
:
bottom
))
for
i
=
eachindex
(
idx_n
)]
annots
=
vcat
(
annot_n
,
annot_tp
)
scatter!
(
p
,
times
(
σ
)[
idx_n
],
σ
[
sym_obs
][
idx_n
],
annotations
=
annots
,
markershape
=
:
utriangle
,
markersize
=
3
,
label
=
"n"
)
markershape
=
:
utriangle
,
markersize
=
3
,
label
=
"n"
)
hline!
(
p
,
[
A
.
constants
[
:
L
],
A
.
constants
[
:
H
]],
label
=
"L, H"
,
color
=
:
grey
;
linestyle
=
:
dot
)
hline!
(
p
,
[
A
.
constants
[
:
L
],
A
.
constants
[
:
H
]],
label
=
"L, H"
,
color
=
:
grey
;
linestyle
=
:
dot
)
...
...
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