Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyFstat
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pep Covas Vidal
PyFstat
Commits
286b576c
Commit
286b576c
authored
8 years ago
by
Gregory Ashton
Browse files
Options
Downloads
Patches
Plain Diff
Add early stopping and clean up PSRF calculation
parent
b5ea8ff3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyfstat/mcmc_based_searches.py
+13
-10
13 additions, 10 deletions
pyfstat/mcmc_based_searches.py
with
13 additions
and
10 deletions
pyfstat/mcmc_based_searches.py
+
13
−
10
View file @
286b576c
...
@@ -229,7 +229,7 @@ class MCMCSearch(core.BaseSearchClass):
...
@@ -229,7 +229,7 @@ class MCMCSearch(core.BaseSearchClass):
self
,
convergence_period
=
10
,
convergence_length
=
10
,
self
,
convergence_period
=
10
,
convergence_length
=
10
,
convergence_burnin_fraction
=
0.25
,
convergence_threshold_number
=
10
,
convergence_burnin_fraction
=
0.25
,
convergence_threshold_number
=
10
,
convergence_threshold
=
1.2
,
convergence_prod_threshold
=
2
,
convergence_threshold
=
1.2
,
convergence_prod_threshold
=
2
,
convergence_plot_upper_lim
=
2
):
convergence_plot_upper_lim
=
2
,
convergence_early_stopping
=
True
):
"""
"""
If called, convergence testing is used during the MCMC simulation
If called, convergence testing is used during the MCMC simulation
...
@@ -258,6 +258,8 @@ class MCMCSearch(core.BaseSearchClass):
...
@@ -258,6 +258,8 @@ class MCMCSearch(core.BaseSearchClass):
the threshold to test the production values with
the threshold to test the production values with
convergence_plot_upper_lim: float
convergence_plot_upper_lim: float
the upper limit to use in the diagnostic plot
the upper limit to use in the diagnostic plot
convergence_early_stopping: bool
if true, stop the burnin early if convergence is reached
"""
"""
if
convergence_length
>
convergence_period
:
if
convergence_length
>
convergence_period
:
...
@@ -273,18 +275,18 @@ class MCMCSearch(core.BaseSearchClass):
...
@@ -273,18 +275,18 @@ class MCMCSearch(core.BaseSearchClass):
self
.
convergence_threshold
=
convergence_threshold
self
.
convergence_threshold
=
convergence_threshold
self
.
convergence_number
=
0
self
.
convergence_number
=
0
self
.
convergence_plot_upper_lim
=
convergence_plot_upper_lim
self
.
convergence_plot_upper_lim
=
convergence_plot_upper_lim
self
.
convergence_early_stopping
=
convergence_early_stopping
def
_get_convergence_statistic
(
self
,
i
,
sampler
):
def
_get_convergence_statistic
(
self
,
i
,
sampler
):
s
=
sampler
.
chain
[
0
,
:,
i
-
self
.
convergence_length
+
1
:
i
+
1
,
:]
s
=
sampler
.
chain
[
0
,
:,
i
-
self
.
convergence_length
+
1
:
i
+
1
,
:]
within_std
=
np
.
mean
(
np
.
var
(
s
,
axis
=
1
),
axis
=
0
)
N
=
float
(
self
.
convergence_length
)
M
=
float
(
self
.
nwalkers
)
W
=
np
.
mean
(
np
.
var
(
s
,
axis
=
1
),
axis
=
0
)
per_walker_mean
=
np
.
mean
(
s
,
axis
=
1
)
per_walker_mean
=
np
.
mean
(
s
,
axis
=
1
)
mean
=
np
.
mean
(
per_walker_mean
,
axis
=
0
)
mean
=
np
.
mean
(
per_walker_mean
,
axis
=
0
)
between_std
=
np
.
sqrt
(
np
.
mean
((
per_walker_mean
-
mean
)
**
2
,
axis
=
0
))
B
=
N
/
(
M
-
1.
)
*
np
.
sum
((
per_walker_mean
-
mean
)
**
2
,
axis
=
0
)
W
=
within_std
Vhat
=
(
N
-
1
)
/
N
*
W
+
(
M
+
1
)
/
(
M
*
N
)
*
B
B_over_n
=
between_std
**
2
/
self
.
convergence_period
c
=
Vhat
/
W
Vhat
=
((
self
.
convergence_period
-
1.
)
/
self
.
convergence_period
*
W
+
B_over_n
+
B_over_n
/
float
(
self
.
nwalkers
))
c
=
np
.
sqrt
(
Vhat
/
W
)
self
.
convergence_diagnostic
.
append
(
c
)
self
.
convergence_diagnostic
.
append
(
c
)
self
.
convergence_diagnosticx
.
append
(
i
-
self
.
convergence_length
/
2
)
self
.
convergence_diagnosticx
.
append
(
i
-
self
.
convergence_length
/
2
)
return
c
return
c
...
@@ -299,6 +301,7 @@ class MCMCSearch(core.BaseSearchClass):
...
@@ -299,6 +301,7 @@ class MCMCSearch(core.BaseSearchClass):
self
.
convergence_number
+=
1
self
.
convergence_number
+=
1
else
:
else
:
self
.
convergence_number
=
0
self
.
convergence_number
=
0
if
self
.
convergence_early_stopping
:
return
self
.
convergence_number
>
self
.
convergence_threshold_number
return
self
.
convergence_number
>
self
.
convergence_threshold_number
def
_prod_convergence_test
(
self
,
i
,
sampler
,
nburn
):
def
_prod_convergence_test
(
self
,
i
,
sampler
,
nburn
):
...
@@ -873,7 +876,7 @@ class MCMCSearch(core.BaseSearchClass):
...
@@ -873,7 +876,7 @@ class MCMCSearch(core.BaseSearchClass):
ax
.
plot
(
c_x
[
break_idx
:],
c_y
[
break_idx
:,
i
],
'
-b
'
)
ax
.
plot
(
c_x
[
break_idx
:],
c_y
[
break_idx
:,
i
],
'
-b
'
)
ax
.
set_ylabel
(
'
PSRF
'
)
ax
.
set_ylabel
(
'
PSRF
'
)
ax
.
ticklabel_format
(
useOffset
=
False
)
ax
.
ticklabel_format
(
useOffset
=
False
)
ax
.
set_ylim
(
1
,
self
.
convergence_plot_upper_lim
)
ax
.
set_ylim
(
0.5
,
self
.
convergence_plot_upper_lim
)
else
:
else
:
axes
[
0
].
ticklabel_format
(
useOffset
=
False
,
axis
=
'
y
'
)
axes
[
0
].
ticklabel_format
(
useOffset
=
False
,
axis
=
'
y
'
)
cs
=
chain
[:,
:,
temp
].
T
cs
=
chain
[:,
:,
temp
].
T
...
...
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