Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
PTAInterpretation
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Schedules
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Hannah Middleton
PTAInterpretation
Commits
da538db7
Commit
da538db7
authored
Jun 12, 2023
by
Hannah Middleton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on sampling script
parent
19a6ab8b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
7 deletions
+57
-7
run_sampler.py
models/galaxy_model/run_sampler.py
+57
-7
No files found.
models/galaxy_model/run_sampler.py
View file @
da538db7
...
...
@@ -6,6 +6,11 @@ import numpy as np
from
scipy.stats
import
gaussian_kde
as
kde
import
matplotlib.pyplot
as
plt
import
mergerratemodel
as
mr
import
prior_check
from
PTMCMCSampler.PTMCMCSampler
import
PTSampler
as
ptmcmc
def
readChains
(
nFreqBins
):
...
...
@@ -27,7 +32,7 @@ def makeKDEs(samples,nFreqBins):
make the KDEs to use in the likelihood
'''
KDE
=
{
i
:
kde
(
samples
[:,
i
])
for
i
in
range
(
nFreq
uencie
s
)}
KDE
=
{
i
:
kde
(
samples
[:,
i
])
for
i
in
range
(
nFreq
Bin
s
)}
return
KDE
...
...
@@ -38,7 +43,24 @@ def in_bounds(par):
def
log_prior
(
par
):
if
in_bounds
(
par
):
param
=
dict
(
Phi0
=
par
[
0
],
PhiI
=
par
[
1
],
M0
=
par
[
2
],
alpha
=
par
[
3
],
alphaI
=
par
[
4
],
f0
=
par
[
5
],
beta
=
par
[
6
],
gamma
=
par
[
7
],
delta
=
par
[
8
],
t0
=
par
[
9
],
epsilon
=
par
[
10
],
zeta
=
par
[
11
],
eta
=
par
[
12
],
Ms
=
par
[
13
],
theta
=
par
[
14
],
sigma
=
par
[
15
],
e0
=
par
[
16
],
rho
=
par
[
17
])
param
=
dict
(
Phi0
=
par
[
0
],
PhiI
=
par
[
1
],
M0
=
par
[
2
],
alpha
=
par
[
3
],
alphaI
=
par
[
4
],
f0
=
par
[
5
],
beta
=
par
[
6
],
gamma
=
par
[
7
],
delta
=
par
[
8
],
t0
=
par
[
9
],
epsilon
=
par
[
10
],
zeta
=
par
[
11
],
eta
=
par
[
12
],
Ms
=
par
[
13
],
theta
=
par
[
14
],
sigma
=
par
[
15
],
e0
=
par
[
16
],
rho
=
par
[
17
])
return
prior_check
.
check_p
(
param
)
else
:
return
-
np
.
inf
...
...
@@ -49,7 +71,7 @@ def log_likelihood(par):
M1
=
np
.
linspace
(
9
,
12
,
25
)
q
=
np
.
linspace
(
0.25
,
1
,
10
)
z
=
np
.
linspace
(
0.
,
1.5
,
5
)
f
=
frequencies
initpar
=
dict
(
Phi0
=
par
[
0
],
PhiI
=
par
[
1
],
M0
=
par
[
2
],
...
...
@@ -71,20 +93,48 @@ def log_likelihood(par):
model
=
mr
.
mergerrate
(
M1
,
q
,
z
,
f
,
**
initpar
)
.
hmodelt
(
fbin
=
None
)[
0
]
logL
=
0.
for
i
in
range
(
n
Frequencies
):
logL
+=
KDE
[
i
]
.
logpdf
(
model
)
for
i
in
range
(
n
umberOfFrequencyBinsToUse
):
logL
+=
KDE
s
[
i
]
.
logpdf
(
model
[
i
]
)
return
logL
# prior bounds
bounds
=
[(
-
3.4
,
-
2.4
),
(
-
0.6
,
0.2
),
(
11
,
11.5
),
(
-
1.5
,
-
1.
),
(
-
0.2
,
0.2
),
(
0.01
,
0.05
),
(
0.
,
2.
),
(
-
0.5
,
0.5
),
(
-
0.2
,
0.2
),
(
0.1
,
10.
),
(
-
0.5
,
0.5
),
(
-
3.
,
1.
),
(
-
0.2
,
0.2
),
(
7.75
,
8.75
),
(
0.9
,
1.1
),
(
0.2
,
0.5
),
(
0.01
,
0.99
),
(
-
2.
,
2.
)]
# read in the data
numberOfFrequencyBinsToUse
=
5
frequencies
,
samples
=
readChains
(
numberOfFrequencyBinsToUse
)
# make the kdes
KDEs
=
makeKDEs
(
samples
,
numberOfFrequencyBinsToUse
)
# ptmcmc things
x0
=
np
.
array
([
-
2.8
,
-
0.2
,
11.25
,
-
1.25
,
0.
,
0.025
,
0.8
,
0.
,
0.
,
1.
,
0.
,
-
0.5
,
0.
,
8.25
,
1.
,
0.4
,
0.5
,
0.
])
ndim
=
len
(
x0
)
cov
=
np
.
diag
(
np
.
ones
(
ndim
)
*
0.01
**
2
)
N
=
1000
# 1000000
sampler
=
ptmcmc
(
ndim
,
log_likelihood
,
log_prior
,
cov
,
outDir
=
'./output'
,
resume
=
False
)
sampler
.
sample
(
x0
,
N
,
SCAMweight
=
30
,
AMweight
=
15
,
DEweight
=
50
)
to
do
-
add
sampler
...
...
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