Skip to content
GitLab
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
5906375d
Commit
5906375d
authored
Apr 21, 2021
by
Chris Jewell
Browse files
Non-centred Brownian motion to fix HMC algorithm.
parent
6c6616e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
covid/model_spec.py
View file @
5906375d
...
...
@@ -132,11 +132,16 @@ def CovidUK(covariates, initial_state, initial_step, num_steps):
rate
=
tf
.
constant
(
10.0
,
dtype
=
DTYPE
),
)
def
alpha_t
(
alpha_0
):
return
BrownianMotion
(
tf
.
range
(
num_steps
,
dtype
=
DTYPE
),
x0
=
alpha_0
,
scale
=
0.005
)
def
alpha_t
():
# return BrownianMotion(
# tf.range(num_steps, dtype=DTYPE), x0=alpha_0, scale=0.005
# )
return
tfd
.
MultivariateNormalDiag
(
loc
=
tf
.
constant
(
0.0
,
dtype
=
DTYPE
),
scale_diag
=
tf
.
fill
(
[
num_steps
-
1
],
tf
.
constant
(
0.005
,
dtype
=
DTYPE
)
),
)
def
gamma0
():
return
tfd
.
Normal
(
loc
=
tf
.
constant
(
0.0
,
dtype
=
DTYPE
),
...
...
@@ -184,12 +189,13 @@ def CovidUK(covariates, initial_state, initial_step, num_steps):
weekday_t
=
tf
.
gather
(
weekday
,
weekday_idx
)
with
tf
.
name_scope
(
"Pick_alpha_t"
):
b_t
=
alpha_0
+
tf
.
cumsum
(
alpha_t
)
alpha_t_idx
=
tf
.
cast
(
t
,
tf
.
int64
)
alpha_t_
=
tf
.
where
(
alpha_t_idx
==
initial_step
,
alpha_0
,
tf
.
gather
(
alpha
_t
,
b
_t
,
tf
.
clip_by_value
(
alpha_t_idx
-
initial_step
-
1
,
clip_value_min
=
0
,
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment