Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bilby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Sylvia Biscoveanu
bilby
Commits
0ac57e3d
Commit
0ac57e3d
authored
6 years ago
by
Colm Talbot
Committed by
Moritz Huebner
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
update cpnest syntax
parent
4c358a29
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bilby/core/sampler/cpnest.py
+29
-13
29 additions, 13 deletions
bilby/core/sampler/cpnest.py
sampler_requirements.txt
+1
-1
1 addition, 1 deletion
sampler_requirements.txt
test/sampler_test.py
+7
-5
7 additions, 5 deletions
test/sampler_test.py
with
37 additions
and
19 deletions
bilby/core/sampler/cpnest.py
+
29
−
13
View file @
0ac57e3d
from
__future__
import
absolute_import
import
numpy
as
np
from
pandas
import
DataFrame
from
..utils
import
logger
from
..utils
import
logger
,
check_directory_exists_and_if_not_mkdir
from
.base_sampler
import
NestedSampler
...
...
@@ -15,27 +15,33 @@ class Cpnest(NestedSampler):
Keyword Arguments
-----------------
n
points
: int
n
live
: int
The number of live points, note this can also equivalently be given as
one of [n
live
, nlives, n_live_points]
one of [n
points
, nlives, n_live_points]
seed: int (1234)
Initialised random seed
N
threads: int, (1)
n
threads: int, (1)
Number of threads to use
maxmcmc: int (1000)
The maximum number of MCMC steps to take
verbose: Bool
verbose: Bool
(True)
If true, print information information about the convergence during
resume: Bool (False)
Whether or not to resume from a previous run
output: str
Where to write the CPNest, by default this is
{self.outdir}/cpnest_{self.label}/
"""
default_kwargs
=
dict
(
verbose
=
1
,
Nthreads
=
1
,
Nlive
=
500
,
maxmcmc
=
1000
,
Poolsize
=
100
,
seed
=
None
,
balance_samplers
=
True
)
default_kwargs
=
dict
(
verbose
=
1
,
nthreads
=
1
,
nlive
=
500
,
maxmcmc
=
1000
,
seed
=
None
,
poolsize
=
100
,
nhamiltonian
=
0
,
resume
=
False
,
output
=
None
)
def
_translate_kwargs
(
self
,
kwargs
):
if
'
N
live
'
not
in
kwargs
:
if
'
n
live
'
not
in
kwargs
:
for
equiv
in
self
.
npoints_equiv_kwargs
:
if
equiv
in
kwargs
:
kwargs
[
'
N
live
'
]
=
kwargs
.
pop
(
equiv
)
kwargs
[
'
n
live
'
]
=
kwargs
.
pop
(
equiv
)
if
'
seed
'
not
in
kwargs
:
logger
.
warning
(
'
No seed provided, cpnest will use 1234.
'
)
...
...
@@ -69,15 +75,25 @@ class Cpnest(NestedSampler):
bounds
=
[[
self
.
priors
[
key
].
minimum
,
self
.
priors
[
key
].
maximum
]
for
key
in
self
.
search_parameter_keys
]
model
=
Model
(
self
.
search_parameter_keys
,
bounds
)
out
=
CPNest
(
model
,
output
=
self
.
outdir
,
**
self
.
kwargs
)
out
=
CPNest
(
model
,
**
self
.
kwargs
)
out
.
run
()
if
self
.
plot
:
out
.
plot
()
# Since the output is not just samples, but log_likelihood as well,
# we turn this into a dataframe here. The index [0] here may be wrong
self
.
result
.
posterior
=
DataFrame
(
out
.
posterior_samples
[
0
])
self
.
result
.
posterior
=
DataFrame
(
out
.
posterior_samples
)
self
.
result
.
log_evidence
=
out
.
NS
.
state
.
logZ
self
.
result
.
log_evidence_err
=
np
.
nan
return
self
.
result
def
_verify_kwargs_against_default_kwargs
(
self
):
"""
Set the directory where the output will be written.
"""
if
not
self
.
kwargs
[
'
output
'
]:
self
.
kwargs
[
'
output
'
]
=
\
'
{}/cpnest_{}/
'
.
format
(
self
.
outdir
,
self
.
label
)
if
self
.
kwargs
[
'
output
'
].
endswith
(
'
/
'
)
is
False
:
self
.
kwargs
[
'
output
'
]
=
'
{}/
'
.
format
(
self
.
kwargs
[
'
output
'
])
check_directory_exists_and_if_not_mkdir
(
self
.
kwargs
[
'
output
'
])
NestedSampler
.
_verify_kwargs_against_default_kwargs
(
self
)
This diff is collapsed.
Click to expand it.
sampler_requirements.txt
+
1
−
1
View file @
0ac57e3d
cpnest
cpnest
>=0.9.4
dynesty
emcee
nestle
...
...
This diff is collapsed.
Click to expand it.
test/sampler_test.py
+
7
−
5
View file @
0ac57e3d
...
...
@@ -121,16 +121,18 @@ class TestCPNest(unittest.TestCase):
del
self
.
sampler
def
test_default_kwargs
(
self
):
expected
=
dict
(
verbose
=
1
,
Nthreads
=
1
,
Nlive
=
500
,
maxmcmc
=
1000
,
Poolsize
=
100
,
seed
=
None
,
balance_samplers
=
True
)
expected
=
dict
(
verbose
=
1
,
nthreads
=
1
,
nlive
=
500
,
maxmcmc
=
1000
,
seed
=
None
,
poolsize
=
100
,
nhamiltonian
=
0
,
resume
=
False
,
output
=
'
outdir/cpnest_label/
'
)
self
.
assertDictEqual
(
expected
,
self
.
sampler
.
kwargs
)
def
test_translate_kwargs
(
self
):
expected
=
dict
(
verbose
=
1
,
Nthreads
=
1
,
Nlive
=
250
,
maxmcmc
=
1000
,
Poolsize
=
100
,
seed
=
None
,
balance_samplers
=
True
)
expected
=
dict
(
verbose
=
1
,
nthreads
=
1
,
nlive
=
250
,
maxmcmc
=
1000
,
seed
=
None
,
poolsize
=
100
,
nhamiltonian
=
0
,
resume
=
False
,
output
=
'
outdir/cpnest_label/
'
)
for
equiv
in
bilby
.
core
.
sampler
.
base_sampler
.
NestedSampler
.
npoints_equiv_kwargs
:
new_kwargs
=
self
.
sampler
.
kwargs
.
copy
()
del
new_kwargs
[
'
N
live
'
]
del
new_kwargs
[
'
n
live
'
]
new_kwargs
[
equiv
]
=
250
self
.
sampler
.
kwargs
=
new_kwargs
self
.
assertDictEqual
(
expected
,
self
.
sampler
.
kwargs
)
...
...
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