Discuit.jl manual

See Discuit.jl examples for a brief introduction to the package's core functionality.

Types

# Discuit.DiscuitModel — Type.

DiscuitModel

Fields

A mutable struct which represents a DSSCT model (see Discuit.jl models for further details).

source

# Discuit.SimResults — Type.

SimResults

Fields

The results of a simulation.

source

# Discuit.Trajectory — Type.

Trajectory

Fields

A single realisation of the model.

source

# Discuit.Observations — Type.

Observations

Fields

Examples

# pooley dataset
pooley = Observations([20, 40, 60, 80, 100], [0 18; 0 65; 0 70; 0 66; 0 67])

Stores one column vector of observation times and one or more column vectors of observation integer values.

source

# Discuit.MCMCResults — Type.

MCMCResults

Fields

The results of an MCMC analysis including samples; mean; covariance matrix; adaptation period; and results of the Geweke test of stationarity.

source

# Discuit.GelmanResults — Type.

GelmanResults

Fields

Results of a Gelman Rubin convergence diagnostic including n MCMCResults variables; mu; and the scale reduction factor estimates (sre).

source

# Discuit.AutocorrelationResults — Type.

AutocorrelationResults

Fields

Results of a call to compute_autocorrelation.

source

Functions

This section is organised in three parts:

core functionality

# Discuit.set_random_seed — Function.

set_random_seed(seed)

Examples

set_random_seed(1234)

Does what it says on the tin but only if you give it an integer.

source

# Discuit.gillespie_sim — Function.

gillespie_sim(model, parameters, tmax = 100.0, num_obs = 5)

Parameters

Run a DGA simulation on model. Returns a SimResults containing the trajectory and observations data.

source

# Discuit.run_met_hastings_mcmc — Function.

run_met_hastings_mcmc(model, obs_data, initial_parameters, steps = 50000, adapt_period = 10000, mbp = true, ppp = 0.3)

Parameters

Run an MCMC analysis based on model and obs_data of type Observations. The number of samples obtained is equal to steps - adapt_period.

source

# Discuit.run_gelman_diagnostic — Function.

run_gelman_diagnostic(model, obs_data, initial_parameters, steps = 50000, adapt_period = 10000, mbp = true, ppp = 0.3)

Parameters

Run n (equal to the number of rows in initial_parameters) MCMC analyses and perform a Gelman-Rubin convergence diagnostic on the results. NEED TO OVERLOAD AND EXPAND.

source

# Discuit.compute_autocorrelation — Function.

compute_autocorrelation(mcmc, lags = 200)

Parameters

Compute autocorrelation R for a single Markov chain. Autocorrelation can be used to help determine how well the algorithm mixed by using compute_autocorrelation(rs.mcmc). The autocorrelation function for a single Markov chain is implemented in Discuit using the standard formula:

for any given lag l up to lags (default: 200).

source

compute_autocorrelation(mcmc, lags = 200)

Parameters

Compute autocorrelation R' for a two or more Markov chains. The formula for multiple chains is given by:

for any given lag l up to lags (default: 200).

source

model helpers

Discuit.jl includes tools for generating components which can help minimise the amount of work required to generate customised DiscuitModels, including generate_model(...) which is used to access a library of pre defined Discuit.jl models.

# Discuit.generate_generic_obs_function — Function.

generate_generic_obs_function()

Generates a simple observation function for use in a DiscuitModel. Not very realistic...

source

# Discuit.generate_weak_prior — Method.

generate_weak_prior(n)

Parameters

Examples

generate_weak_prior(1)

Generate a "weak" prior density function, where n is the number of parameters in the model.

source

# Discuit.generate_gaussian_obs_model — Function.

generate_gaussian_obs_model(n, σ = 2.0)

Parameters

test latex eqn:

Examples

p = generate_weak_prior(1)

Generate a Gaussian observation model for a model with n states. Optionally specify observation error σ.

source

# Discuit.generate_model — Function.

generate_model(model_name, initial_condition, σ = 2.0)

Parameters

model_name options

Examples

generate_model("SIS", [100,1])

Generates a DiscuitModel. Optionally specify observation error σ.

source

utilities

# Discuit.print_trajectory — Function.

print_trajectory(model, sim_results, fpath)

Parameters

Save an augmented trajectory from a variable of type SimResults (i.e. from a call to gillespie_sim, see Simulation) to the file fpath, e.g. "./out/sim.csv".

source

# Discuit.print_observations — Function.

print_observations(obs_data, fpath)

Parameters

Save a set of observations (e.g. from a SimResults obtained by a call to gillespie_sim to the file fpath, e.g. "./out/obs.csv".

source

# Discuit.get_observations — Function.

get_observations(source)

Parameters

Create and return a variable of type Observations based on a two dimensional array, DataFrame or file location.

source

# Discuit.tabulate_mcmc_results — Function.

tabulate_mcmc_results

Parameters

Display the results of an MCMC analysis.

source

# Discuit.print_mcmc_results — Function.

print_mcmc_results(mcmc, dpath)

Parameters

Save the results from a call to run_met_hastings_mcmc or run_custom_mcmc to the directory dpath, e.g. "./out/mcmc/".

source

# Discuit.tabulate_gelman_results — Function.

tabulate_gelman_results

Parameters

Display the results of a multi chain analysis run using run_gelman_diagnostic.

source

# Discuit.print_gelman_results — Function.

print_gelman_results(results::GelmanResults, dpath::String)

Parameters

Save the results from a call to run_gelman_diagnostic to the directory dpath, e.g. "./out/gelman/".

source

# Discuit.print_autocorrelation — Function.

print_autocorrelation(autocorrelation, fpath)

Parameters

Save the results from a call to compute_autocorrelation to the file fpath, e.g. "./out/ac.csv".

source

visualisation

# Discuit.plot_trajectory — Function.

plot_trajectory(x)

Parameters

Plot the trajectory of a a DGA simulation on model using UnicodePlots.jl.

source

# Discuit.plot_parameter_trace — Function.

plot_parameter_trace(mcmc, parameter)

Parameters

Trace plot of samples from an MCMC analysis for a given model parameter using UnicodePlots.jl.

source

plot_parameter_trace(mcmc, parameter)

Parameters

Trace plot of samples from n MCMC analyses for a given model parameter using UnicodePlots.jl.

source

# Discuit.plot_parameter_marginal — Function.

plot_parameter_marginal(mcmc, parameter)

Parameters

Plot the marginal distribution of samples from an MCMC analysis for a given model parameter using UnicodePlots.jl.

source

# Discuit.plot_parameter_heatmap — Function.

plot_parameter_heatmap(mcmc, x_parameter, y_parameter)

Parameters

Plot the marginal distribution of samples from an MCMC analysis for two model parameters using UnicodePlots.jl.

source

# Discuit.plot_geweke_series — Function.

plot_geweke_series(mcmc)

Parameters

Plot the Geweke series...

source

# Discuit.plot_autocorrelation — Function.

plot_autocorrelation(autocorrelation)

Parameters

Plot autocorrelation for an MCMC analysis.

source

custom MCMC

# Discuit.run_custom_mcmc — Function.

run_custom_mcmc(model, obs_data, proposal_function, x0, steps = 50000, adapt_period = 10000, prop_param = false, ppp = 0.3)

Parameters

Run a custom MCMC analysis. Similar to run_met_hastings_mcmc except that theproposal_function (of type Function) and initial state x0 (of type MarkovState) are user defined.

source

# Discuit.run_custom_mcmc_gelman_diagnostic — Function.

run_custom_mcmc_gelman_diagnostic(m_model, obs_data, proposal_function, x0, initial_parameters, steps = 50000, adapt_period = 10000, mbp = true, ppp = 0.3)

Parameters

Run n (equal to the number of rows in initial_parameters) custom MCMC analyses and perform a Gelman-Rubin convergence diagnostic on the results. NEED TO OVERLOAD AND EXPAND.

source

# Discuit.generate_custom_x0 — Function.

generate_custom_x0(model, obs_data, parameters, event_times, event_types)

Parameters

Generate an initial MarkovState for use in a custom MCMC algorithm.

source

Index

References

TBA