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
4a571e71
Commit
4a571e71
authored
5 years ago
by
Gregory Ashton
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "Generate initial live points in dynesty"
parent
f7ac2a19
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bilby/core/sampler/base_sampler.py
+56
-6
56 additions, 6 deletions
bilby/core/sampler/base_sampler.py
bilby/core/sampler/dynesty.py
+4
-0
4 additions, 0 deletions
bilby/core/sampler/dynesty.py
with
60 additions
and
6 deletions
bilby/core/sampler/base_sampler.py
+
56
−
6
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
"""
...
...
This diff is collapsed.
Click to expand it.
bilby/core/sampler/dynesty.py
+
4
−
0
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
,
...
...
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