Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
lscsoft
bilby
Commits
4a571e71
Commit
4a571e71
authored
May 26, 2019
by
Gregory Ashton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Generate initial live points in dynesty"
parent
f7ac2a19
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
6 deletions
+60
-6
bilby/core/sampler/base_sampler.py
bilby/core/sampler/base_sampler.py
+56
-6
bilby/core/sampler/dynesty.py
bilby/core/sampler/dynesty.py
+4
-0
No files found.
bilby/core/sampler/base_sampler.py
View file @
4a571e71
...
...
@@ -388,12 +388,62 @@ class Sampler(object):
self
.
check_draw
(
draw
)
return
draw
def
check_draw
(
self
,
draw
):
""" Checks if the draw will generate an infinite prior or likelihood """
if
np
.
isinf
(
self
.
log_likelihood
(
draw
)):
logger
.
warning
(
'Prior draw {} has inf likelihood'
.
format
(
draw
))
if
np
.
isinf
(
self
.
log_prior
(
draw
)):
logger
.
warning
(
'Prior draw {} has inf prior'
.
format
(
draw
))
def
get_initial_points_from_prior
(
self
,
npoints
=
1
):
""" Method to draw a set of live points from the prior
This iterates over draws from the prior until all the samples have a
finite prior and likelihood (relevant for constrained priors).
Parameters
----------
npoints: int
The number of values to return
Returns
-------
unit_cube, parameters, likelihood: tuple of array_like
unit_cube (nlive, ndim) is an array of the prior samples from the
unit cube, parameters (nlive, ndim) is the unit_cube array
transformed to the target space, while likelihood (nlive) are the
likelihood evaluations.
"""
unit_cube
=
[]
parameters
=
[]
likelihood
=
[]
while
len
(
unit_cube
)
<
npoints
:
unit
=
np
.
random
.
rand
(
self
.
ndim
)
theta
=
self
.
prior_transform
(
unit
)
if
self
.
check_draw
(
theta
,
warning
=
False
):
unit_cube
.
append
(
unit
)
parameters
.
append
(
theta
)
likelihood
.
append
(
self
.
log_likelihood
(
theta
))
return
np
.
array
(
unit_cube
),
np
.
array
(
parameters
),
np
.
array
(
likelihood
)
def
check_draw
(
self
,
theta
,
warning
=
True
):
""" Checks if the draw will generate an infinite prior or likelihood
Parameters
----------
theta: array_like
Parameter values at which to evaluate likelihood
Returns
-------
bool, cube (nlive,
True if the likelihood and prior are finite, false otherwise
"""
if
np
.
isinf
(
self
.
log_prior
(
theta
)):
if
warning
:
logger
.
warning
(
'Prior draw {} has inf prior'
.
format
(
theta
))
return
False
if
np
.
isinf
(
self
.
log_likelihood
(
theta
)):
if
warning
:
logger
.
warning
(
'Prior draw {} has inf likelihood'
.
format
(
theta
))
return
False
return
True
def
run_sampler
(
self
):
"""A template method to run in subclasses"""
...
...
bilby/core/sampler/dynesty.py
View file @
4a571e71
...
...
@@ -202,6 +202,10 @@ class Dynesty(NestedSampler):
def
run_sampler
(
self
):
import
dynesty
if
self
.
kwargs
[
'live_points'
]
is
None
:
self
.
kwargs
[
'live_points'
]
=
(
self
.
get_initial_points_from_prior
(
self
.
kwargs
[
'nlive'
]))
self
.
sampler
=
dynesty
.
NestedSampler
(
loglikelihood
=
self
.
log_likelihood
,
prior_transform
=
self
.
prior_transform
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment