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
1abfa584
Commit
1abfa584
authored
6 years ago
by
Matthew Pitkin
Browse files
Options
Downloads
Patches
Plain Diff
Move setting of PyMC3 prior into Prior class
parent
7aaab5fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!139
Add PyMC3 sampler
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tupak/core/likelihood.py
+2
-2
2 additions, 2 deletions
tupak/core/likelihood.py
tupak/core/prior.py
+24
-16
24 additions, 16 deletions
tupak/core/prior.py
with
26 additions
and
18 deletions
tupak/core/likelihood.py
+
2
−
2
View file @
1abfa584
...
...
@@ -127,10 +127,10 @@ class GaussianLikelihood(Likelihood):
model_parameters
=
dict
()
for
key
in
sampler
.
priors
:
if
key
==
'
sigma
'
and
self
.
sigma
is
None
:
self
.
sigma
=
sampler
.
priors
[
key
].
pymc3
(
sampler
)
self
.
sigma
=
sampler
.
priors
[
key
].
pymc3
_prior
(
sampler
)
else
:
if
key
in
self
.
function_keys
:
model_parameters
[
key
]
=
sampler
.
priors
[
key
].
pymc3
(
sampler
)
model_parameters
[
key
]
=
sampler
.
priors
[
key
].
pymc3
_prior
(
sampler
)
else
:
raise
ValueError
(
"
Prior key
'
{}
'
is not a function key!
"
.
format
(
key
))
...
...
This diff is collapsed.
Click to expand it.
tupak/core/prior.py
+
24
−
16
View file @
1abfa584
...
...
@@ -472,6 +472,23 @@ class Prior(object):
label
=
self
.
name
return
label
def
set_pymc3_prior
(
self
,
sampler
,
priortype
,
**
kwargs
):
from
tupak.core.sampler
import
Sampler
if
not
isinstance
(
sampler
,
Sampler
):
raise
ValueError
(
"'
sampler
'
is not a Sampler class
"
)
try
:
samplername
=
sampler
.
external_sampler
.
__name__
except
ValueError
:
raise
ValueError
(
"
Sampler
'
s
'
external_sampler
'
has not been initialised
"
)
if
samplername
!=
'
pymc3
'
:
raise
ValueError
(
"
Only use this class method for PyMC3 sampler
"
)
if
priortype
in
sampler
.
external_sampler
.
__dict__
:
return
sampler
.
external_sampler
.
__dict__
[
priortype
](
self
.
name
,
**
kwargs
)
class
DeltaFunction
(
Prior
):
...
...
@@ -524,7 +541,7 @@ class DeltaFunction(Prior):
else
:
return
0
def
pymc3
(
self
,
sampler
):
def
pymc3
_prior
(
self
,
sampler
):
# just return the value
return
self
.
peak
...
...
@@ -666,22 +683,13 @@ class Uniform(Prior):
return
scipy
.
stats
.
uniform
.
logpdf
(
val
,
loc
=
self
.
minimum
,
scale
=
self
.
maximum
-
self
.
minimum
)
def
pymc3
(
self
,
sampler
):
from
tupak.core.sampler
import
Sampler
def
pymc3_prior
(
self
,
sampler
):
priortype
=
'
Uniform
'
priorargs
=
{}
priorargs
[
'
lower
'
]
=
self
.
minimum
priorargs
[
'
upper
'
]
=
self
.
maximum
if
not
isinstance
(
sampler
,
Sampler
):
raise
ValueError
(
"'
sampler
'
is not a Sampler class
"
)
try
:
samplername
=
sampler
.
external_sampler
.
__name__
except
ValueError
:
raise
ValueError
(
"
Sampler
'
s
'
external_sampler
'
has not been initialised
"
)
if
samplername
!=
'
pymc3
'
:
raise
ValueError
(
"
Only use this class method for PyMC3 sampler
"
)
return
sampler
.
external_sampler
.
Uniform
(
self
.
name
,
lower
=
self
.
minimum
,
upper
=
self
.
maximum
)
return
self
.
set_pymc3_prior
(
sampler
,
priortype
,
**
priorargs
)
class
LogUniform
(
PowerLaw
):
...
...
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