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
63f29525
Commit
63f29525
authored
4 years ago
by
Bentriou Mahmoud
Browse files
Options
Downloads
Patches
Plain Diff
add of tolerance setting in abc
parent
2cc0a568
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
algorithms/abc_smc.jl
+14
-11
14 additions, 11 deletions
algorithms/abc_smc.jl
with
14 additions
and
11 deletions
algorithms/abc_smc.jl
+
14
−
11
View file @
63f29525
...
...
@@ -26,15 +26,17 @@ struct ResultAbc
l_ess
::
Vector
{
Float64
}
end
function
automaton_abc
(
pm
::
ParametricModel
;
nbr_particles
::
Int
=
100
,
alpha
::
Float64
=
0.75
,
kernel_type
=
"mvnormal"
,
function
automaton_abc
(
pm
::
ParametricModel
;
nbr_particles
::
Int
=
100
,
tolerance
::
Float64
=
0.0
,
alpha
::
Float64
=
0.75
,
kernel_type
=
"mvnormal"
,
NT
::
Float64
=
nbr_particles
/
2
,
duration_time
::
Float64
=
Inf
,
dir_results
::
Union
{
Nothing
,
String
}
=
nothing
,
bound_sim
::
Int
=
typemax
(
Int
),
sym_var_aut
::
VariableAutomaton
=
:
d
,
verbose
::
Int
=
0
)
@assert
typeof
(
pm
.
m
)
<:
SynchronizedModel
@assert
typeof
(
pm
.
m
)
<:
SynchronizedModel
"Automaton-ABC is defined for synchronized models only"
@assert
0
<
nbr_particles
@assert
0.0
<
alpha
<
1.0
@assert
kernel_type
in
[
"mvnormal"
,
"knn_mvnormal"
]
if
dir_results
!=
nothing
dir_results
=
basename
(
dir_results
)
!=
""
?
dir_results
*
"/"
:
dir_results
if
!
isdir
(
dir_results
)
mkdir
(
dir_results
)
end
file_cfg
=
open
(
dir_results
*
"config_abc.out"
,
"w"
)
write
(
file_cfg
,
"ParametricModel :
$(pm)
\n
"
)
write
(
file_cfg
,
"Number of particles :
$(nbr_particles)
\n
"
)
...
...
@@ -43,9 +45,9 @@ function automaton_abc(pm::ParametricModel; nbr_particles::Int = 100, alpha::Flo
close
(
file_cfg
)
end
if
nprocs
()
==
1
return
_abc_smc
(
pm
,
nbr_particles
,
alpha
,
kernel_type
,
NT
,
duration_time
,
bound_sim
,
dir_results
,
sym_var_aut
)
return
_abc_smc
(
pm
,
nbr_particles
,
tolerance
,
alpha
,
kernel_type
,
NT
,
duration_time
,
bound_sim
,
dir_results
,
sym_var_aut
)
end
return
_distributed_abc_smc
(
pm
,
nbr_particles
,
alpha
,
kernel_type
,
NT
,
duration_time
,
bound_sim
,
dir_results
,
sym_var_aut
)
return
_distributed_abc_smc
(
pm
,
nbr_particles
,
tolerance
,
alpha
,
kernel_type
,
NT
,
duration_time
,
bound_sim
,
dir_results
,
sym_var_aut
)
end
"""
...
...
@@ -66,7 +68,7 @@ If pm is defined on a ContinuousTimeModel, then `T1` should verify `T1 <: Trajec
"""
function
abc_smc
(
pm
::
ParametricModel
,
l_obs
::
AbstractVector
,
func_dist
::
Function
;
nbr_particles
::
Int
=
100
,
alpha
::
Float64
=
0.75
,
kernel_type
=
"mvnormal"
,
nbr_particles
::
Int
=
100
,
tolerance
::
Float64
=
0.0
,
alpha
::
Float64
=
0.75
,
kernel_type
=
"mvnormal"
,
NT
::
Float64
=
nbr_particles
/
2
,
duration_time
::
Float64
=
Inf
,
dir_results
::
Union
{
Nothing
,
String
}
=
nothing
,
bound_sim
::
Int
=
typemax
(
Int
),
sym_var_aut
::
VariableAutomaton
=
:
d
,
verbose
::
Int
=
0
)
@assert
0
<
nbr_particles
...
...
@@ -74,6 +76,7 @@ function abc_smc(pm::ParametricModel, l_obs::AbstractVector, func_dist::Function
@assert
kernel_type
in
[
"mvnormal"
,
"knn_mvnormal"
]
if
dir_results
!=
nothing
dir_results
=
basename
(
dir_results
)
!=
""
?
dir_results
*
"/"
:
dir_results
if
!
isdir
(
dir_results
)
mkdir
(
dir_results
)
end
file_cfg
=
open
(
dir_results
*
"results_abc.out"
,
"w"
)
write
(
file_cfg
,
"Configuration of ABC algorithm
\n
"
)
write
(
file_cfg
,
"ParametricModel :
$(pm)
\n
"
)
...
...
@@ -83,23 +86,23 @@ function abc_smc(pm::ParametricModel, l_obs::AbstractVector, func_dist::Function
close
(
file_cfg
)
end
if
nprocs
()
==
1
return
_abc_smc
(
pm
,
nbr_particles
,
alpha
,
kernel_type
,
NT
,
duration_time
,
bound_sim
,
dir_results
,
sym_var_aut
;
l_obs
=
l_obs
,
func_dist
=
func_dist
)
return
_abc_smc
(
pm
,
nbr_particles
,
tolerance
,
alpha
,
kernel_type
,
NT
,
duration_time
,
bound_sim
,
dir_results
,
sym_var_aut
;
l_obs
=
l_obs
,
func_dist
=
func_dist
)
end
return
_distributed_abc_smc
(
pm
,
l_obs
,
dist
,
nbr_particles
,
alpha
,
kernel_type
,
NT
,
duration_time
,
bound_sim
,
dir_results
,
sym_var_aut
;
l_obs
=
l_obs
,
func_dist
=
func_dist
)
return
_distributed_abc_smc
(
pm
,
nbr_particles
,
tolerance
,
alpha
,
kernel_type
,
NT
,
duration_time
,
bound_sim
,
dir_results
,
sym_var_aut
;
l_obs
=
l_obs
,
func_dist
=
func_dist
)
end
# To code:
# Pkg related: draw!, prior_density!
function
_abc_smc
(
pm
::
ParametricModel
,
nbr_particles
::
Int
,
alpha
::
Float64
,
function
_abc_smc
(
pm
::
ParametricModel
,
nbr_particles
::
Int
,
tolerance
::
Float64
,
alpha
::
Float64
,
kernel_type
::
String
,
NT
::
Float64
,
duration_time
::
Float64
,
bound_sim
::
Int
,
dir_results
::
Union
{
Nothing
,
String
},
sym_var_aut
::
VariableAutomaton
;
l_obs
::
Union
{
Nothing
,
AbstractVector
}
=
nothing
,
func_dist
::
Union
{
Nothing
,
Function
}
=
nothing
)
@info
"ABC PMC with
$
(nworkers()) processus and
$
(Threads.nthreads()) threads"
begin_time
=
time
()
nbr_p
=
pm
.
df
last_epsilon
=
0.0
last_epsilon
=
tolerance
# Init. Iteration 1
t
=
1
epsilon
=
Inf
...
...
@@ -192,14 +195,14 @@ function _abc_smc(pm::ParametricModel, nbr_particles::Int, alpha::Float64,
return
r
end
function
_distributed_abc_smc
(
pm
::
ParametricModel
,
nbr_particles
::
Int
,
alpha
::
Float64
,
function
_distributed_abc_smc
(
pm
::
ParametricModel
,
nbr_particles
::
Int
,
tolerance
::
Float64
,
alpha
::
Float64
,
kernel_type
::
String
,
NT
::
Float64
,
duration_time
::
Float64
,
bound_sim
::
Int
,
dir_results
::
Union
{
Nothing
,
String
},
sym_var_aut
::
VariableAutomaton
;
l_obs
::
Union
{
Nothing
,
AbstractVector
}
=
nothing
,
func_dist
::
Union
{
Nothing
,
Function
}
=
nothing
)
@info
"Distributed ABC PMC with
$
(nworkers()) processus and
$
(Threads.nthreads()) threads"
begin_time
=
time
()
nbr_p
=
pm
.
df
last_epsilon
=
0.0
last_epsilon
=
tolerance
# Init. Iteration 1
t
=
1
epsilon
=
Inf
...
...
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