Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Chris Jewell
covid19uk
Commits
e0bd5fe8
Unverified
Commit
e0bd5fe8
authored
Mar 24, 2020
by
Chris Jewell
Committed by
GitHub
Mar 24, 2020
Browse files
Update mcmc.py
parent
ed619eae
Changes
1
Hide whitespace changes
Inline
Side-by-side
mcmc.py
View file @
e0bd5fe8
...
...
@@ -145,32 +145,31 @@ if __name__ == '__main__':
num_covariance_estimation_iterations
=
50
num_covariance_estimation_samples
=
50
num_final_samples
=
10000
with
tf
.
device
(
"/CPU:0"
):
start
=
time
.
perf_counter
()
for
i
in
range
(
num_covariance_estimation_iterations
):
step_start
=
time
.
perf_counter
()
samples
,
results
=
sample
(
num_covariance_estimation_samples
,
initial_mcmc_state
,
scale
)
step_end
=
time
.
perf_counter
()
print
(
f
'
{
i
}
time
{
step_end
-
step_start
}
'
)
print
(
"Acceptance: "
,
results
.
numpy
().
mean
())
joint_posterior
=
tf
.
concat
([
joint_posterior
,
samples
],
axis
=
0
)
cov
=
tfp
.
stats
.
covariance
(
tf
.
math
.
log
(
joint_posterior
))
print
(
cov
.
numpy
())
scale
=
cov
*
2.38
**
2
/
joint_posterior
.
shape
[
1
]
initial_mcmc_state
=
joint_posterior
[
-
1
,
:]
start
=
time
.
perf_counter
()
for
i
in
range
(
num_covariance_estimation_iterations
):
step_start
=
time
.
perf_counter
()
samples
,
results
=
sample
(
num_
final
_samples
,
init
_state
=
joint_posterior
[
-
1
,
:],
scale
=
scale
,)
joint_posterior
=
tf
.
concat
([
joint_posterior
,
samples
],
axis
=
0
)
samples
,
results
=
sample
(
num_
covariance_estimation
_samples
,
init
ial_mcmc_state
,
scale
)
step_end
=
time
.
perf_counter
()
print
(
f
'Sampling step time
{
step_end
-
step_start
}
'
)
end
=
time
.
perf_counter
()
print
(
f
"Simulation complete in
{
end
-
start
}
seconds"
)
print
(
"Acceptance: "
,
np
.
mean
(
results
.
numpy
()))
print
(
tfp
.
stats
.
covariance
(
tf
.
math
.
log
(
joint_posterior
)))
print
(
f
'
{
i
}
time
{
step_end
-
step_start
}
'
)
print
(
"Acceptance: "
,
results
.
numpy
().
mean
())
joint_posterior
=
tf
.
concat
([
joint_posterior
,
samples
],
axis
=
0
)
cov
=
tfp
.
stats
.
covariance
(
tf
.
math
.
log
(
joint_posterior
))
print
(
cov
.
numpy
())
scale
=
cov
*
2.38
**
2
/
joint_posterior
.
shape
[
1
]
initial_mcmc_state
=
joint_posterior
[
-
1
,
:]
step_start
=
time
.
perf_counter
()
samples
,
results
=
sample
(
num_final_samples
,
init_state
=
joint_posterior
[
-
1
,
:],
scale
=
scale
,)
joint_posterior
=
tf
.
concat
([
joint_posterior
,
samples
],
axis
=
0
)
step_end
=
time
.
perf_counter
()
print
(
f
'Sampling step time
{
step_end
-
step_start
}
'
)
end
=
time
.
perf_counter
()
print
(
f
"Simulation complete in
{
end
-
start
}
seconds"
)
print
(
"Acceptance: "
,
np
.
mean
(
results
.
numpy
()))
print
(
tfp
.
stats
.
covariance
(
tf
.
math
.
log
(
joint_posterior
)))
fig
,
ax
=
plt
.
subplots
(
1
,
3
)
ax
[
0
].
plot
(
joint_posterior
[:,
0
])
...
...
Write
Preview
Supports
Markdown
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