Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bilby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
lscsoft
bilby
Commits
307ab12a
There was a problem fetching the pipeline summary.
Commit
307ab12a
authored
6 years ago
by
Gregory Ashton
Browse files
Options
Downloads
Patches
Plain Diff
Adds the emcee sampler class
parent
4db79501
No related branches found
No related tags found
1 merge request
!88
Adds the emcee sampler class
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tupak/core/sampler.py
+48
-0
48 additions, 0 deletions
tupak/core/sampler.py
with
48 additions
and
0 deletions
tupak/core/sampler.py
+
48
−
0
View file @
307ab12a
...
...
@@ -752,6 +752,54 @@ class Pymultinest(Sampler):
return
self
.
result
class
Emcee
(
Sampler
):
def
_run_external_sampler
(
self
):
nwalkers
=
self
.
kwargs
.
pop
(
'
nwalkers
'
,
100
)
nsteps
=
self
.
kwargs
.
pop
(
'
nsteps
'
,
100
)
nburn
=
self
.
kwargs
.
pop
(
'
nburn
'
,
50
)
emcee
=
self
.
external_sampler
tqdm
=
utils
.
get_progress_bar
(
self
.
kwargs
.
pop
(
'
tqdm
'
,
'
tqdm
'
))
sampler
=
emcee
.
EnsembleSampler
(
nwalkers
=
nwalkers
,
dim
=
self
.
ndim
,
lnpostfn
=
self
.
lnpostfn
,
**
self
.
kwargs
)
pos0
=
[
self
.
get_random_draw_from_prior
()
for
i
in
range
(
nwalkers
)]
for
result
in
tqdm
(
sampler
.
sample
(
pos0
,
iterations
=
nsteps
),
total
=
nsteps
):
pass
self
.
result
.
sampler_output
=
np
.
nan
self
.
result
.
samples
=
sampler
.
chain
[:,
nburn
:,
:].
reshape
(
(
-
1
,
self
.
ndim
))
self
.
result
.
walkers
=
sampler
.
chain
[:,
:,
:]
self
.
result
.
log_evidence
=
np
.
nan
self
.
result
.
log_evidence_err
=
np
.
nan
self
.
plot_walkers
()
try
:
logging
.
info
(
"
Max autocorr time = {}
"
.
format
(
np
.
max
(
sampler
.
get_autocorr_time
())))
except
emcee
.
autocorr
.
AutocorrError
as
e
:
logging
.
info
(
"
Unable to calculate autocorr time: {}
"
.
format
(
e
))
return
self
.
result
def
lnpostfn
(
self
,
theta
):
return
self
.
log_likelihood
(
theta
)
+
self
.
log_prior
(
theta
)
def
plot_walkers
(
self
,
save
=
True
,
**
kwargs
):
nwalkers
,
nsteps
,
ndim
=
self
.
result
.
walkers
.
shape
idxs
=
np
.
arange
(
nsteps
)
fig
,
axes
=
plt
.
subplots
(
nrows
=
ndim
,
figsize
=
(
6
,
3
*
self
.
ndim
))
for
i
,
ax
in
enumerate
(
axes
):
ax
.
plot
(
idxs
,
self
.
result
.
walkers
[:,
:,
i
].
T
,
lw
=
0.1
,
color
=
'
k
'
)
ax
.
set_ylabel
(
self
.
result
.
parameter_labels
[
i
])
fig
.
tight_layout
()
filename
=
'
{}/{}_walkers.png
'
.
format
(
self
.
outdir
,
self
.
label
)
logging
.
debug
(
'
Saving walkers plot to {}
'
.
format
(
'
filename
'
))
fig
.
savefig
(
filename
)
class
Ptemcee
(
Sampler
):
def
_run_external_sampler
(
self
):
...
...
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