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
33b41ae4
Commit
33b41ae4
authored
Jun 06, 2023
by
Hannah Middleton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a start on the sampling script, with new likelihood
parent
0fc1a8b4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
0 deletions
+109
-0
run_sampler.py
models/galaxy_model/run_sampler.py
+109
-0
No files found.
models/galaxy_model/run_sampler.py
0 → 100644
View file @
33b41ae4
# This is based on the ptmcmcrun.py here:
# https://github.com/hannahm8/PTAInference/tree/master/code/galaxy_model
#
import
numpy
as
np
from
scipy.stats
import
gaussian_kde
as
kde
import
matplotlib.pyplot
as
plt
def
readChains
(
nFreqBins
):
'''
read in the data and return the lowest nFreqBins
chains and frequencies
'''
frequencies
=
np
.
genfromtxt
(
'../../chains/dr2new_fs/freqs.txt'
)
samples
=
np
.
genfromtxt
(
'../../chains/dr2new_fs/chains_h.txt'
)
chainsToUse
=
samples
[:,
0
:
nFreqBins
]
frequenciesToUse
=
frequencies
[
0
:
nFreqBins
]
return
frequenciesToUse
,
chainsToUse
def
makeKDEs
(
samples
,
nFreqBins
):
'''
make the KDEs to use in the likelihood
'''
KDE
=
{
i
:
kde
(
samples
[:,
i
])
for
i
in
range
(
nFrequencies
)}
return
KDE
def
in_bounds
(
par
):
return
all
(
bounds
[
i
][
0
]
<
par
[
i
]
<
bounds
[
i
][
1
]
for
i
in
range
(
len
(
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
])
return
prior_check
.
check_p
(
param
)
else
:
return
-
np
.
inf
def
log_likelihood
(
par
):
M1
=
np
.
linspace
(
9
,
12
,
25
)
q
=
np
.
linspace
(
0.25
,
1
,
10
)
z
=
np
.
linspace
(
0.
,
1.5
,
5
)
initpar
=
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
])
model
=
mr
.
mergerrate
(
M1
,
q
,
z
,
f
,
**
initpar
)
.
hmodelt
(
fbin
=
None
)[
0
]
logL
=
0.
for
i
in
range
(
nFrequencies
):
logL
+=
KDE
[
i
]
.
logpdf
(
model
)
return
logL
numberOfFrequencyBinsToUse
=
5
frequencies
,
samples
=
readChains
(
numberOfFrequencyBinsToUse
)
KDEs
=
makeKDEs
(
samples
,
numberOfFrequencyBinsToUse
)
to
do
-
add
sampler
'''
some testing...
KDE = {i: kde(samples[:,i]) for i in range(nFrequencies)}
print(KDE)
for i in range(nFrequencies):
bins = np.linspace(min(samples[:,i]), max(samples[:,i]), 100)
print('bins' , bins)
toPlot = np.linspace(min(samples[:,i]), max(samples[:,i]), 100)
print(KDE[i].logpdf(-14))
plt.plot(toPlot,KDE[i].logpdf(toPlot))
plt.hist(samples[:,i],bins=bins,density=True,histtype='step')
plt.show()
'''
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