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
e297f287
Commit
e297f287
authored
4 years ago
by
Bentriou Mahmoud
Browse files
Options
Downloads
Patches
Plain Diff
rewriting parts of core/lha
parent
190833bb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lha.jl
+30
-17
30 additions, 17 deletions
core/lha.jl
tests/automata/euclidean_distance.jl
+1
-1
1 addition, 1 deletion
tests/automata/euclidean_distance.jl
with
31 additions
and
18 deletions
core/lha.jl
+
30
−
17
View file @
e297f287
...
@@ -155,7 +155,7 @@ function next_state!(Snplus1::StateLHA, A::LHA,
...
@@ -155,7 +155,7 @@ function next_state!(Snplus1::StateLHA, A::LHA,
Sn
::
StateLHA
,
xn
::
Vector
{
Int
},
p
::
Vector
{
Float64
};
verbose
::
Bool
=
false
)
Sn
::
StateLHA
,
xn
::
Vector
{
Int
},
p
::
Vector
{
Float64
};
verbose
::
Bool
=
false
)
# En fait d'apres observation de Cosmos, après qu'on ait lu la transition on devrait stop.
# En fait d'apres observation de Cosmos, après qu'on ait lu la transition on devrait stop.
edge_candidates
=
Vector
{
Edge
}(
undef
,
2
)
edge_candidates
=
Vector
{
Edge
}(
undef
,
2
)
first_round
::
Bool
=
true
#
first_round::Bool = true
detected_event
::
Bool
=
false
detected_event
::
Bool
=
false
turns
=
0
turns
=
0
...
@@ -167,7 +167,8 @@ function next_state!(Snplus1::StateLHA, A::LHA,
...
@@ -167,7 +167,8 @@ function next_state!(Snplus1::StateLHA, A::LHA,
end
end
# In terms of values not reference, Snplus1 == Sn
# In terms of values not reference, Snplus1 == Sn
# First, we check the asynchronous transitions
# First, we check the asynchronous transitions
while
first_round
||
length
(
edge_candidates
)
>
0
#while first_round || length(edge_candidates) > 0
while
true
turns
+=
1
turns
+=
1
#edge_candidates = empty!(edge_candidates)
#edge_candidates = empty!(edge_candidates)
current_loc
=
getfield
(
Snplus1
,
:
loc
)
current_loc
=
getfield
(
Snplus1
,
:
loc
)
...
@@ -179,10 +180,13 @@ function next_state!(Snplus1::StateLHA, A::LHA,
...
@@ -179,10 +180,13 @@ function next_state!(Snplus1::StateLHA, A::LHA,
ind_edge
,
detected_event
=
_get_edge_index
(
edge_candidates
,
nbr_candidates
,
detected_event
,
nothing
)
ind_edge
,
detected_event
=
_get_edge_index
(
edge_candidates
,
nbr_candidates
,
detected_event
,
nothing
)
# Update the state with the chosen one (if it exists)
# Update the state with the chosen one (if it exists)
# Should be xn here
# Should be xn here
#first_round = false
if
ind_edge
>
0
if
ind_edge
>
0
getfield
(
edge_candidates
[
ind_edge
],
:
update_state!
)(
Snplus1
,
xn
,
p
)
getfield
(
edge_candidates
[
ind_edge
],
:
update_state!
)(
Snplus1
,
xn
,
p
)
else
if
verbose
println
(
"No edge fired"
)
end
break
end
end
first_round
=
false
if
verbose
if
verbose
@show
turns
@show
turns
@show
edge_candidates
@show
edge_candidates
...
@@ -190,9 +194,6 @@ function next_state!(Snplus1::StateLHA, A::LHA,
...
@@ -190,9 +194,6 @@ function next_state!(Snplus1::StateLHA, A::LHA,
println
(
"After update"
)
println
(
"After update"
)
@show
Snplus1
@show
Snplus1
end
end
if
(
ind_edge
==
0
)
break
end
# For debug
# For debug
#=
#=
if turns > 100
if turns > 100
...
@@ -227,8 +228,9 @@ function next_state!(Snplus1::StateLHA, A::LHA,
...
@@ -227,8 +228,9 @@ function next_state!(Snplus1::StateLHA, A::LHA,
@show
Snplus1
@show
Snplus1
end
end
# Now firing an edge according to the event
# Now firing an edge according to the event
first_round
=
true
#first_round = true
while
first_round
||
length
(
edge_candidates
)
>
0
#while first_round || length(edge_candidates) > 0
while
true
turns
+=
1
turns
+=
1
current_loc
=
getfield
(
Snplus1
,
:
loc
)
current_loc
=
getfield
(
Snplus1
,
:
loc
)
edges_from_current_loc
=
getfield
(
A
,
:
map_edges
)[
current_loc
]
edges_from_current_loc
=
getfield
(
A
,
:
map_edges
)[
current_loc
]
...
@@ -237,23 +239,34 @@ function next_state!(Snplus1::StateLHA, A::LHA,
...
@@ -237,23 +239,34 @@ function next_state!(Snplus1::StateLHA, A::LHA,
# Search the one we must chose
# Search the one we must chose
ind_edge
,
detected_event
=
_get_edge_index
(
edge_candidates
,
nbr_candidates
,
detected_event
,
tr_nplus1
)
ind_edge
,
detected_event
=
_get_edge_index
(
edge_candidates
,
nbr_candidates
,
detected_event
,
tr_nplus1
)
# Update the state with the chosen one (if it exists)
# Update the state with the chosen one (if it exists)
if
verbose
#first_round = false
@show
turns
@show
edge_candidates
@show
ind_edge
,
detected_event
,
nbr_candidates
end
if
ind_edge
>
0
if
ind_edge
>
0
getfield
(
edge_candidates
[
ind_edge
],
:
update_state!
)(
Snplus1
,
xnplus1
,
p
)
getfield
(
edge_candidates
[
ind_edge
],
:
update_state!
)(
Snplus1
,
xnplus1
,
p
)
end
end
first_round
=
false
if
ind_edge
==
0
||
detected_event
if
verbose
if
detected_event
println
(
"Synchronized with
$(tr_nplus1)
"
)
@show
turns
@show
edge_candidates
@show
ind_edge
,
detected_event
,
nbr_candidates
println
(
"After update"
)
@show
detected_event
@show
Snplus1
else
println
(
"No edge fired"
)
end
end
break
end
if
verbose
if
verbose
@show
turns
@show
edge_candidates
@show
ind_edge
,
detected_event
,
nbr_candidates
println
(
"After update"
)
println
(
"After update"
)
@show
detected_event
@show
detected_event
@show
Snplus1
@show
Snplus1
end
end
if
(
ind_edge
==
0
||
detected_event
)
break
end
# For debug
# For debug
#=
#=
if turns > 100
if turns > 100
...
...
This diff is collapsed.
Click to expand it.
tests/automata/euclidean_distance.jl
+
1
−
1
View file @
e297f287
...
@@ -13,7 +13,7 @@ observe_all!(ER)
...
@@ -13,7 +13,7 @@ observe_all!(ER)
test_all
=
true
test_all
=
true
# SIR model
# SIR model
nbr_sim
=
2
0
nbr_sim
=
1
0
for
i
=
1
:
nbr_sim
for
i
=
1
:
nbr_sim
set_param!
(
SIR
,
[
:
ki
,
:
kr
],
[
rand
(
Uniform
(
5E-5
,
3E-3
)),
rand
(
Uniform
(
5E-3
,
0.2
))])
set_param!
(
SIR
,
[
:
ki
,
:
kr
],
[
rand
(
Uniform
(
5E-5
,
3E-3
)),
rand
(
Uniform
(
5E-3
,
0.2
))])
let
tml_obs
,
y_obs
,
sync_SIR
,
σ
,
test
,
test2
let
tml_obs
,
y_obs
,
sync_SIR
,
σ
,
test
,
test2
...
...
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