Discuit.jl manual

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

Types

# Discuit.DiscuitModelType.

DiscuitModel

Fields

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

source

# Discuit.SimResultsType.

SimResults

Fields

The results of a simulation.

source

# Discuit.TrajectoryType.

Trajectory

Fields

A single realisation of the model.

source

# Discuit.ObservationsType.

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.MCMCResultsType.

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.GelmanResultsType.

GelmanResults

Fields

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

source

# Discuit.AutocorrelationResultsType.

AutocorrelationResults

Fields

Results of a call to compute_autocorrelation.

source

Functions

This section is organised in three parts:

core functionality

# Discuit.set_random_seedFunction.

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_simFunction.

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_mcmcFunction.

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_diagnosticFunction.

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_autocorrelationFunction.

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_functionFunction.

generate_generic_obs_function()

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

source

# Discuit.generate_weak_priorMethod.

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_modelFunction.

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_modelFunction.

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_trajectoryFunction.

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_observationsFunction.

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_observationsFunction.

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_resultsFunction.

tabulate_mcmc_results

Parameters

Display the results of an MCMC analysis.

source

# Discuit.print_mcmc_resultsFunction.

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_resultsFunction.

tabulate_gelman_results

Parameters

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

source

# Discuit.print_gelman_resultsFunction.

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_autocorrelationFunction.

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_trajectoryFunction.

plot_trajectory(x)

Parameters

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

source

# Discuit.plot_parameter_traceFunction.

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_marginalFunction.

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_heatmapFunction.

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_seriesFunction.

plot_geweke_series(mcmc)

Parameters

Plot the Geweke series...

source

# Discuit.plot_autocorrelationFunction.

plot_autocorrelation(autocorrelation)

Parameters

Plot autocorrelation for an MCMC analysis.

source

custom MCMC

# Discuit.run_custom_mcmcFunction.

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_diagnosticFunction.

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_x0Function.

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