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
29817d24
Commit
29817d24
authored
6 years ago
by
Gregory Ashton
Committed by
Moritz Huebner
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Handle priors as part of the result object and several other minor fixes
parent
988c3589
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
tupak/core/prior.py
+21
-6
21 additions, 6 deletions
tupak/core/prior.py
tupak/core/result.py
+28
-8
28 additions, 8 deletions
tupak/core/result.py
tupak/core/sampler/__init__.py
+2
-3
2 additions, 3 deletions
tupak/core/sampler/__init__.py
with
52 additions
and
17 deletions
CHANGELOG.md
+
1
−
0
View file @
29817d24
...
...
@@ -25,6 +25,7 @@ Changes currently on master, but not under a tag.
-
Fix interpretation of kwargs for dynesty
-
PowerSpectralDensity structure modified
-
Fixed bug in get_open_data
-
.prior files are no longer created. The prior is stored in the result object.
### Removed
-
Removes the "--detectors" command line argument (not a general CLI requirement)
...
...
This diff is collapsed.
Click to expand it.
tupak/core/prior.py
+
21
−
6
View file @
29817d24
...
...
@@ -7,6 +7,7 @@ from scipy.special import erf, erfinv
import
scipy.stats
import
os
from
collections
import
OrderedDict
from
future.utils
import
iteritems
from
tupak.core.utils
import
logger
from
tupak.core
import
utils
...
...
@@ -26,17 +27,17 @@ class PriorSet(OrderedDict):
"""
OrderedDict
.
__init__
(
self
)
if
isinstance
(
dictionary
,
dict
):
self
.
update
(
dictionary
)
self
.
from_dictionary
(
dictionary
)
elif
type
(
dictionary
)
is
str
:
logger
.
debug
(
'
Argument
"
dictionary
"
is a string.
'
+
'
Assuming it is intended as a file name.
'
)
self
.
read_in
_file
(
dictionary
)
self
.
from
_file
(
dictionary
)
elif
type
(
filename
)
is
str
:
self
.
read_in
_file
(
filename
)
self
.
from
_file
(
filename
)
elif
dictionary
is
not
None
:
raise
ValueError
(
"
PriorSet input dictionay not understood
"
)
raise
ValueError
(
"
PriorSet input dictiona
r
y not understood
"
)
def
write_
to_file
(
self
,
outdir
,
label
):
def
to_file
(
self
,
outdir
,
label
):
"""
Write the prior distribution to file.
Parameters
...
...
@@ -55,7 +56,7 @@ class PriorSet(OrderedDict):
outfile
.
write
(
"
{} = {}
\n
"
.
format
(
key
,
self
[
key
]))
def
read_in
_file
(
self
,
filename
):
def
from
_file
(
self
,
filename
):
"""
Reads in a prior from a file specification
Parameters
...
...
@@ -75,6 +76,20 @@ class PriorSet(OrderedDict):
prior
[
key
]
=
eval
(
val
)
self
.
update
(
prior
)
def
from_dictionary
(
self
,
dictionary
):
for
key
,
val
in
iteritems
(
dictionary
):
if
isinstance
(
val
,
str
):
try
:
prior
=
eval
(
val
)
if
isinstance
(
prior
,
Prior
):
val
=
prior
except
(
NameError
,
SyntaxError
,
TypeError
):
logger
.
debug
(
"
Failed to load dictionary value {} correctlty
"
.
format
(
key
))
pass
self
[
key
]
=
val
def
convert_floats_to_delta_functions
(
self
):
"""
Convert all float parameters to delta functions
"""
for
key
in
self
:
...
...
This diff is collapsed.
Click to expand it.
tupak/core/result.py
+
28
−
8
View file @
29817d24
...
...
@@ -10,7 +10,7 @@ from collections import OrderedDict
from
tupak.core
import
utils
from
tupak.core.utils
import
logger
from
tupak.core.prior
import
DeltaFunction
from
tupak.core.prior
import
PriorSet
,
DeltaFunction
def
result_file_name
(
outdir
,
label
):
...
...
@@ -70,12 +70,19 @@ class Result(dict):
A dictionary containing values to be set in this instance
"""
# Set some defaults
self
.
outdir
=
'
.
'
self
.
label
=
'
no_name
'
dict
.
__init__
(
self
)
if
type
(
dictionary
)
is
dict
:
for
key
in
dictionary
:
val
=
self
.
_standardise_a_string
(
dictionary
[
key
])
setattr
(
self
,
key
,
val
)
if
getattr
(
self
,
'
priors
'
,
None
)
is
not
None
:
self
.
priors
=
PriorSet
(
self
.
priors
)
def
__add__
(
self
,
other
):
matches
=
[
'
sampler
'
,
'
search_parameter_keys
'
]
for
match
in
matches
:
...
...
@@ -171,8 +178,14 @@ class Result(dict):
os
.
rename
(
file_name
,
file_name
+
'
.old
'
)
logger
.
debug
(
"
Saving result to {}
"
.
format
(
file_name
))
# Convert the prior to a string representation for saving on disk
dictionary
=
dict
(
self
)
if
dictionary
.
get
(
'
priors
'
,
False
):
dictionary
[
'
priors
'
]
=
{
key
:
str
(
self
.
priors
[
key
])
for
key
in
self
.
priors
}
try
:
deepdish
.
io
.
save
(
file_name
,
dict
(
self
)
)
deepdish
.
io
.
save
(
file_name
,
dict
ionary
)
except
Exception
as
e
:
logger
.
error
(
"
\n\n
Saving the data has failed with the
"
"
following message:
\n
{}
\n\n
"
.
format
(
e
))
...
...
@@ -270,8 +283,8 @@ class Result(dict):
string
=
r
"
${{{0}}}_{{-{1}}}^{{+{2}}}$
"
return
string
.
format
(
fmt
(
median
),
fmt
(
lower
),
fmt
(
upper
))
def
plot_corner
(
self
,
parameters
=
None
,
priors
=
Non
e
,
titles
=
True
,
save
=
True
,
filename
=
None
,
dpi
=
300
,
**
kwargs
):
def
plot_corner
(
self
,
parameters
=
None
,
priors
=
Fals
e
,
titles
=
True
,
save
=
True
,
filename
=
None
,
dpi
=
300
,
**
kwargs
):
"""
Plot a corner-plot using corner
See https://corner.readthedocs.io/en/latest/ for a detailed API.
...
...
@@ -280,9 +293,10 @@ class Result(dict):
----------
parameters: list, optional
If given, a list of the parameter names to include
priors: tupak.core.prior.PriorSet
If given, add the prior probability density functions to the
one-dimensional marginal distributions
priors: {bool (False), tupak.core.prior.PriorSet}
If true, add the stored prior probability density functions to the
one-dimensional marginal distributions. If instead a PriorSet
is provided, this will be plotted.
titles: bool
If true, add 1D titles of the median and (by default 1-sigma)
error bars. To change the error bars, pass in the quantiles kwarg.
...
...
@@ -363,11 +377,17 @@ class Result(dict):
**
kwargs
[
'
title_kwargs
'
])
# Add priors to the 1D plots
if
priors
is
not
None
:
if
priors
is
True
:
priors
=
getattr
(
self
,
'
priors
'
,
False
)
if
isinstance
(
priors
,
dict
):
for
i
,
par
in
enumerate
(
parameters
):
ax
=
axes
[
i
+
i
*
len
(
parameters
)]
theta
=
np
.
linspace
(
ax
.
get_xlim
()[
0
],
ax
.
get_xlim
()[
1
],
300
)
ax
.
plot
(
theta
,
priors
[
par
].
prob
(
theta
),
color
=
'
C2
'
)
elif
priors
in
[
False
,
None
]:
pass
else
:
raise
ValueError
(
'
Input priors={} not understood
'
.
format
(
priors
))
if
save
:
if
filename
is
None
:
...
...
This diff is collapsed.
Click to expand it.
tupak/core/sampler/__init__.py
+
2
−
3
View file @
29817d24
...
...
@@ -108,9 +108,6 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir',
priors
.
fill_priors
(
likelihood
,
default_priors_file
=
default_priors_file
)
if
save
:
priors
.
write_to_file
(
outdir
,
label
)
if
isinstance
(
sampler
,
Sampler
):
pass
elif
isinstance
(
sampler
,
str
):
...
...
@@ -148,6 +145,8 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir',
if
type
(
meta_data
)
==
dict
:
result
.
update
(
meta_data
)
result
.
priors
=
priors
end_time
=
datetime
.
datetime
.
now
()
result
.
sampling_time
=
(
end_time
-
start_time
).
total_seconds
()
logger
.
info
(
'
Sampling time: {}
'
.
format
(
end_time
-
start_time
))
...
...
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