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
60c1215c
Commit
60c1215c
authored
Mar 27, 2020
by
Christopher Suter
Browse files
Fix binomial probs errors
parent
56562073
Changes
1
Hide whitespace changes
Inline
Side-by-side
covid/impl/chainbinom_simulate.py
View file @
60c1215c
...
...
@@ -20,7 +20,7 @@ def chain_binomial_propagate(h, time_step):
# Calculate Markov transition probability matrix
markov_transition
=
tf
.
linalg
.
expm
(
rate_matrix
*
time_step
)
num_states
=
markov_transition
.
shape
[
-
1
]
prev_prob
=
tf
.
zeros_like
(
markov_transition
[...,
:,
0
])
prev_prob
s
=
tf
.
zeros_like
(
markov_transition
[...,
:,
0
])
counts
=
tf
.
zeros
(
markov_transition
.
shape
[:
-
1
].
as_list
()
+
[
0
],
dtype
=
markov_transition
.
dtype
)
total_count
=
state
...
...
@@ -29,13 +29,15 @@ def chain_binomial_propagate(h, time_step):
# as a ~10 states it should probably be fine, just increasing the size
# of the graph a bit.
for
i
in
range
(
num_states
-
1
):
probs
=
markov_transition
[...,
:,
i
]
binom
=
tfd
.
Binomial
(
total_count
=
total_count
,
probs
=
markov_transition
[...,
:,
i
]
/
(
1.
-
prev_prob
)
)
probs
=
tf
.
clip_by_value
(
probs
/
(
1.
-
prev_prob
s
),
0.
,
1.
)
sample
=
binom
.
sample
()
counts
=
tf
.
concat
([
counts
,
sample
[...,
tf
.
newaxis
]],
axis
=-
1
)
total_count
-=
sample
prev_prob
=
binom
.
probs
prev_probs
+=
probs
counts
=
tf
.
concat
([
counts
,
total_count
[...,
tf
.
newaxis
]],
axis
=-
1
)
new_state
=
tf
.
reduce_sum
(
counts
,
axis
=-
2
)
return
new_state
...
...
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