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
9bdf9e9d
Commit
9bdf9e9d
authored
4 years ago
by
Bentriou Mahmoud
Browse files
Options
Downloads
Patches
Plain Diff
new model: square wave oscillator
parent
c22108a3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
models/square_wave_oscillator.jl
+67
-0
67 additions, 0 deletions
models/square_wave_oscillator.jl
tests/run_unit.jl
+1
-0
1 addition, 0 deletions
tests/run_unit.jl
tests/unit/square_wave_oscillator.jl
+32
-0
32 additions, 0 deletions
tests/unit/square_wave_oscillator.jl
with
100 additions
and
0 deletions
models/square_wave_oscillator.jl
0 → 100644
+
67
−
0
View file @
9bdf9e9d
d
=
3
k
=
7
dict_var_square
=
Dict
(
:
A
=>
1
,
:
HIGH
=>
2
,
:
LOW
=>
3
)
dict_params_square
=
Dict
(
:
p1
=>
1
,
:
w1
=>
2
,
:
p2
=>
3
,
:
w2
=>
4
,
:
p3
=>
5
,
:
w3
=>
6
,
:
d
=>
7
)
l_tr_square
=
[
:
Tu
,
:
t1
,
:
t2
,
:
t3
]
p_square
=
[
1
,
0
,
0
,
0
,
0
,
0
,
5.0
]
x0_square
=
[
1
,
0
,
1
]
t0_square
=
0.0
function
square_wave_f!
(
xnplus1
::
Vector
{
Int
},
l_t
::
Vector
{
Float64
},
l_tr
::
Vector
{
Transition
},
xn
::
Vector
{
Int
},
tn
::
Float64
,
p
::
Vector
{
Float64
})
if
p
[
1
]
==
0
&&
p
[
3
]
==
0
&&
p
[
5
]
==
0
copyto!
(
xnplus1
,
xn
)
return
nothing
end
# If in state LOW
if
xn
[
3
]
==
1
xnplus1
[
1
]
=
10
xnplus1
[
2
]
=
1
xnplus1
[
3
]
=
0
l_t
[
1
]
+=
p
[
7
]
l_tr
[
1
]
=
:
Tu
# If in state HIGH
else
possible_transitions
=
(
:
t1
,
:
t2
,
:
t3
)
l_priority
=
(
p
[
1
],
p
[
3
],
p
[
5
])
l_weights
=
(
p
[
2
],
p
[
4
],
p
[
6
])
max_priority
=
maximum
(
l_priority
)
l_idx
=
zeros
(
Int
,
0
)
for
i
=
eachindex
(
l_priority
)
if
l_priority
[
i
]
>=
max_priority
push!
(
l_idx
,
i
)
end
end
if
length
(
l_idx
)
==
1
transition
=
l_idx
[
1
]
else
wsum
=
sum
(
l_weights
[
l_idx
])
b_inf
=
0.0
b_sup
=
l_weights
[
l_idx
[
1
]]
transition
=
0
u
=
rand
()
for
i
in
l_idx
if
b_inf
<
wsum
*
u
<
b_sup
transition
=
i
break
end
@inbounds
b_inf
+=
l_weights
[
i
]
@inbounds
b_sup
+=
l_weights
[
i
]
end
end
xnplus1
[
1
]
=
1
xnplus1
[
2
]
=
0
xnplus1
[
3
]
=
1
l_t
[
1
]
+=
2
^
(
transition
-
1
)
*
p
[
7
]
l_tr
[
1
]
=
possible_transitions
[
transition
]
end
end
isabsorbing_square_wave
(
p
::
Vector
{
Float64
},
xn
::
Vector
{
Int
})
=
(
p
[
1
]
==
0
&&
p
[
3
]
==
0
&&
p
[
5
]
==
0
)
g_square_wave
=
[
:
A
,
:
HIGH
,
:
LOW
]
square_wave_oscillator
=
ContinuousTimeModel
(
d
,
k
,
dict_var_square
,
dict_params_square
,
l_tr_square
,
p_square
,
x0_square
,
t0_square
,
square_wave_f!
,
isabsorbing_square_wave
;
g
=
g_square_wave
,
name
=
"square wave oscillator pkg"
,
time_bound
=
105.0
)
export
square_wave_oscillator
This diff is collapsed.
Click to expand it.
tests/run_unit.jl
+
1
−
0
View file @
9bdf9e9d
...
...
@@ -40,5 +40,6 @@ using Test
@test
include
(
"unit/simulate_sir.jl"
)
@test
include
(
"unit/simulate_sir_bounded.jl"
)
@test
include
(
"unit/simulate_er.jl"
)
@test
include
(
"unit/square_wave_oscillator.jl"
)
end
This diff is collapsed.
Click to expand it.
tests/unit/square_wave_oscillator.jl
0 → 100644
+
32
−
0
View file @
9bdf9e9d
using
MarkovProcesses
load_model
(
"square_wave_oscillator"
)
swo
=
square_wave_oscillator
swo_reg1
=
deepcopy
(
swo
)
set_param!
(
swo_reg1
,
[
:
p1
,
:
p2
,
:
p3
],
[
1.0
,
0.0
,
0.0
])
swo_reg2
=
deepcopy
(
swo
)
set_param!
(
swo_reg2
,
[
:
p1
,
:
p2
,
:
p3
],
[
0.0
,
1.0
,
0.0
])
swo_reg3
=
deepcopy
(
swo
)
set_param!
(
swo_reg3
,
[
:
p1
,
:
p2
,
:
p3
],
[
0.0
,
0.0
,
1.0
])
swo_irreg1
=
deepcopy
(
swo
)
set_param!
(
swo_irreg1
,
[
:
p1
,
:
p2
,
:
p3
],
[
1.0
,
1.0
,
0.0
])
set_param!
(
swo_irreg1
,
[
:
w1
,
:
w2
,
:
w3
],
[
1.0
,
1.0
,
0.0
])
swo_irreg2
=
deepcopy
(
swo
)
set_param!
(
swo_irreg2
,
[
:
p1
,
:
p2
,
:
p3
],
[
0.0
,
1.0
,
1.0
])
set_param!
(
swo_irreg2
,
[
:
w1
,
:
w2
,
:
w3
],
[
0.0
,
1.0
,
1.0
])
swo_irreg3
=
deepcopy
(
swo
)
set_param!
(
swo_irreg3
,
[
:
p1
,
:
p2
,
:
p3
],
[
1.0
,
0.0
,
1.0
])
set_param!
(
swo_irreg3
,
[
:
w1
,
:
w2
,
:
w3
],
[
1.0
,
0.0
,
1.0
])
swo_irreg4
=
deepcopy
(
swo
)
set_param!
(
swo_irreg4
,
[
:
p1
,
:
p2
,
:
p3
],
[
1.0
,
1.0
,
1.0
])
set_param!
(
swo_irreg4
,
[
:
w1
,
:
w2
,
:
w3
],
[
1.0
,
1.0
,
1.0
])
return
true
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