Skip to content

Commit

Permalink
#255 tweaks to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DavAug committed Mar 21, 2022
1 parent 8a6f6af commit 837b871
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 132 deletions.
156 changes: 79 additions & 77 deletions docs/source/getting_started/code/1_simulation_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,91 +149,93 @@
# End 7.

# Start 8.
from plotly.subplots import make_subplots

# Run inference
controller = chi.SamplingController(log_posterior)
n_iterations = 5000
posterior_samples = controller.run(n_iterations)
# End 8.

# Discard warmup iterations
warmup = 3000
posterior_samples = posterior_samples.sel(draw=slice(warmup, n_iterations))
# # Visualise Markov chains
# fig = make_subplots(rows=4, cols=1, shared_xaxes=True)

# # Add MCMC chains for initial drug amount
# for idc, chain in enumerate(posterior_samples['central.drug_amount'].values):
# fig.add_trace(
# go.Scatter(
# legendgroup='Initial drug amount',
# legendgrouptitle_text='Initial drug amount',
# name='Chain %d' % idc,
# x=np.arange(warmup, n_iterations) + 1,
# y=chain,
# showlegend=False
# ),
# row=1,
# col=1
# )
# # Add MCMC chains for compartment volume
# for idc, chain in enumerate(posterior_samples['central.size'].values):
# fig.add_trace(
# go.Scatter(
# legendgroup='Compartment volume',
# legendgrouptitle_text='Compartment volume',
# name='Chain %d' % idc,
# x=np.arange(warmup, n_iterations) + 1,
# y=chain,
# showlegend=False
# ),
# row=2,
# col=1
# )
# # Add MCMC chains of elimination rate
# for idc, chain in enumerate(
# posterior_samples['myokit.elimination_rate'].values):
# fig.add_trace(
# go.Scatter(
# legendgroup='Elimination rate',
# legendgrouptitle_text='Elimination rate',
# name='Chain %d' % idc,
# x=np.arange(warmup, n_iterations) + 1,
# y=chain,
# showlegend=False
# ),
# row=3,
# col=1
# )
# # Add MCMC chains of sigma
# for idc, chain in enumerate(posterior_samples['Sigma'].values):
# fig.add_trace(
# go.Scatter(
# legendgroup='Sigma',
# legendgrouptitle_text='Sigma',
# name='Chain %d' % idc,
# x=np.arange(warmup, n_iterations) + 1,
# y=chain,
# showlegend=False
# ),
# row=4,
# col=1
# )

# fig.update_layout(
# xaxis4_title='MCMC iteration',
# yaxis_title='a_0',
# yaxis2_title='v',
# yaxis3_title='k_e',
# yaxis4_title='sigma',
# template='plotly_white'
# )
# fig.show()
# # End 8.
# fig.write_html(directory + '/images/1_simulation_4.html')

# Visualise Markov chains
fig = make_subplots(rows=4, cols=1, shared_xaxes=True)

# Add MCMC chains for initial drug amount
for idc, chain in enumerate(posterior_samples['central.drug_amount'].values):
fig.add_trace(
go.Scatter(
legendgroup='Initial drug amount',
legendgrouptitle_text='Initial drug amount',
name='Chain %d' % idc,
x=np.arange(warmup, n_iterations) + 1,
y=chain,
showlegend=False
),
row=1,
col=1
)
# Add MCMC chains for compartment volume
for idc, chain in enumerate(posterior_samples['central.size'].values):
fig.add_trace(
go.Scatter(
legendgroup='Compartment volume',
legendgrouptitle_text='Compartment volume',
name='Chain %d' % idc,
x=np.arange(warmup, n_iterations) + 1,
y=chain,
showlegend=False
),
row=2,
col=1
)
# Add MCMC chains of elimination rate
for idc, chain in enumerate(
posterior_samples['myokit.elimination_rate'].values):
fig.add_trace(
go.Scatter(
legendgroup='Elimination rate',
legendgrouptitle_text='Elimination rate',
name='Chain %d' % idc,
x=np.arange(warmup, n_iterations) + 1,
y=chain,
showlegend=False
),
row=3,
col=1
)
# Add MCMC chains of sigma
for idc, chain in enumerate(posterior_samples['Sigma'].values):
fig.add_trace(
go.Scatter(
legendgroup='Sigma',
legendgrouptitle_text='Sigma',
name='Chain %d' % idc,
x=np.arange(warmup, n_iterations) + 1,
y=chain,
showlegend=False
),
row=4,
col=1
)
# Start 9.
from plotly.subplots import make_subplots

fig.update_layout(
xaxis4_title='MCMC iteration',
yaxis_title='a_0',
yaxis2_title='v',
yaxis3_title='k_e',
yaxis4_title='sigma',
template='plotly_white'
)
fig.show()
# End 8.
fig.write_html(directory + '/images/1_simulation_4.html')
# Discard warmup iterations
warmup = 3000 # This number is not arbitrary but was carefully chosen
posterior_samples = posterior_samples.sel(draw=slice(warmup, n_iterations))

# Start 9.
# Visualise posteriors
fig = make_subplots(rows=2, cols=2, shared_yaxes=True)
fig.add_trace(
go.Histogram(
Expand Down
6 changes: 3 additions & 3 deletions docs/source/getting_started/error_model.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
***********************
Defining an error model
***********************
***************
The error model
***************

To do.
3 changes: 2 additions & 1 deletion docs/source/getting_started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ instructions please refer to the README_.
mechanistic_model
error_model
log_likelihood
log_posterior
log_posterior
mcmc_sampling
6 changes: 3 additions & 3 deletions docs/source/getting_started/log_likelihood.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*************************
Defining a log-likelihood
*************************
******************
The log-likelihood
******************

To do.
6 changes: 3 additions & 3 deletions docs/source/getting_started/log_posterior.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
************************
Defining a log-posterior
************************
*****************
The log-posterior
*****************

To do.
5 changes: 5 additions & 0 deletions docs/source/getting_started/mcmc_sampling.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
****************************************************
Inferring posterior distributions with MCMC sampling
****************************************************

To do.
6 changes: 3 additions & 3 deletions docs/source/getting_started/mechanistic_model.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
****************************
Defining a mechanistic model
****************************
*********************
The mechanistic model
*********************

To do.
Loading

0 comments on commit 837b871

Please sign in to comment.