Title: | Visualising Output from Sequential Monte Carlo and Ensemble-Based Methods |
---|---|
Description: | Functions for plotting, and animating, the output of importance samplers, sequential Monte Carlo samplers (SMC) and ensemble-based methods. The package can be used to plot and animate histograms, densities, scatter plots and time series, and to plot the genealogy of an SMC or ensemble-based algorithm. These functions all rely on algorithm output to be supplied in tidy format. A function is provided to transform algorithm output from matrix format (one Monte Carlo point per row) to the tidy format required by the plotting and animating functions. |
Authors: | Richard G Everitt [aut, cre] |
Maintainer: | Richard G Everitt <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.2.1 |
Built: | 2025-02-17 06:17:52 UTC |
Source: | https://github.com/richardgeveritt/ggsmc |
An animated density of a single variable across targets.
animate_density( output, parameter, dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, xlimits = NULL, ylimits = NULL, default_title = FALSE, duration = NULL, animate_plot = TRUE, save_filename = NULL, save_path = NULL )
animate_density( output, parameter, dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, xlimits = NULL, ylimits = NULL, default_title = FALSE, duration = NULL, animate_plot = TRUE, save_filename = NULL, save_path = NULL )
output |
Output from the SMC or EnK algorithm. |
parameter |
The parameter for which we wish to view the density. |
dimension |
(optional) The dimension of the parameter for which we wish to view the density. (default is 1) |
target |
(optiona) If specified, will fix to this target, and animate over ExternalTarget (if present in output). |
external_target |
(optional) If specified, will fix to this external_target, and animate over Target. |
use_initial_points |
(optional) If target is not specified and this argument is TRUE, will add the initial unweighted proposed points to the output to be plotted. (default is TRUE) |
use_weights |
(optional) If FALSE, will ignore particle weights in the density. If TRUE, will use the particle weights. (defaults to TRUE) |
mcmc |
(optional) If TRUE, the user is indicating that the output is from an MCMC algorithm. This will set use_initial_points=FALSE and use_weights=FALSE no matter what the user sets these arguments to. (default is FALSE) |
xlimits |
(optional) Input of the form c(start,end), which specifies the ends of the x-axis. |
ylimits |
(optional) Input of the form c(start,end), which specifies the ends of the y-axis. |
default_title |
(optional) If TRUE, will provide a default title for the figure. If FALSE, no title is used. (defaults to FALSE) |
duration |
(optional) The duration of the animation. (defaults to producing an animation that uses 10 frames per second) |
animate_plot |
(optional) If TRUE, will return an animation. If FALSE, returns a gganim object that can be further modified before animating. (defaults to FALSE) |
save_filename |
(optional) If specified, the animation will be saved to a gif with this filename. (default is not to save) |
save_path |
(optional) If specified along with save_filename, will save the gif to save_path/save_filename. (defaults to working directory) |
An animated density
An animated histogram of a single variable across targets.
animate_histogram( output, parameter, dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, bins = 30, xlimits = NULL, ylimits = NULL, default_title = FALSE, duration = NULL, animate_plot = TRUE, save_filename = NULL, save_path = NULL )
animate_histogram( output, parameter, dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, bins = 30, xlimits = NULL, ylimits = NULL, default_title = FALSE, duration = NULL, animate_plot = TRUE, save_filename = NULL, save_path = NULL )
output |
Output from the SMC or EnK algorithm. |
parameter |
The parameter we wish to histogram. |
dimension |
(optional) The dimension of the parameter we wish to histogram. (default is 1) |
target |
(optionaL) If specified, will fix to this target, and animate over ExternalTarget (if present in output). |
external_target |
(optionaL) If specified, will fix to this external_target, and animate over Target. |
use_initial_points |
(optional) If target is not specified and this argument is TRUE, will add the initial unweighted proposed points to the output to be plotted. (default is TRUE) |
use_weights |
(optional) If FALSE, will ignore particle weights in the histogram. If TRUE, will use the particle weights. (defaults to TRUE) |
mcmc |
(optional) If TRUE, the user is indicating that the output is from an MCMC algorithm. This will set use_initial_points=FALSE and use_weights=FALSE no matter what the user sets these arguments to. (default is FALSE) |
bins |
(optional) Number of bins for the histogram. (default 30) |
xlimits |
(optional) Input of the form c(start,end), which specifies the ends of the x-axis. |
ylimits |
(optional) Input of the form c(start,end), which specifies the ends of the y-axis. |
default_title |
(optional) If TRUE, will provide a default title for the figure. If FALSE, no title is used. (defaults to FALSE) |
duration |
(optional) The duration of the animation. (defaults to producing an animation that uses 10 frames per second) |
animate_plot |
(optiional) If TRUE, will return an animation. If FALSE, returns a gganim object that can be furher modified before animating. (defaults to FALSE) |
save_filename |
(optional) If specified, the animation will be saved to a gif with this filename. (default is not to save) |
save_path |
(optional) If specified along with save_filename, will save the gif to save_path/save_filename. (defaults to working directory) |
An animated histogram
Plot animated line graph showing parameter value vs dimension (revealed in the animation) from algorithm output.
animate_reveal_time_series( output, parameters, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, max_line_width = 1, alpha = 0.1, xlimits = NULL, ylimits = NULL, duration = NULL, animate_plot = TRUE, save_filename = NULL, save_path = NULL )
animate_reveal_time_series( output, parameters, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, max_line_width = 1, alpha = 0.1, xlimits = NULL, ylimits = NULL, duration = NULL, animate_plot = TRUE, save_filename = NULL, save_path = NULL )
output |
Output from the SMC or EnK algorithm. |
parameters |
The parameters we wish to be on the y-axis of the line graph. |
target |
(optional) The target to plot. (default is to use all targets) |
external_target |
(optional) The external target to plot. (default is to use all external targets, or to ignore if the column is not present) |
use_initial_points |
(optional) If target is not specified and this argument is TRUE, will add the initial unweighted proposed points to the output to be plotted. (default is TRUE) |
use_weights |
(optional) If FALSE, will ignore particle weights in the line graph. If TRUE, will use the particle weights. (defaults to TRUE) |
mcmc |
(optional) If TRUE, the user is indicating that the output is from an MCMC algorithm. This will set use_initial_points=FALSE and use_weights=FALSE no matter what the user sets these arguments to. (default is FALSE) |
max_line_width |
(optional) The maximum size of the points in the plot. (default=1) |
alpha |
(optional) The transparency of the lines in the plot. (default=0.1) |
xlimits |
(optional) Input of the form c(start,end), which specifies the ends of the x-axis. |
ylimits |
(optional) Input of the form c(start,end), which specifies the ends of the y-axis. |
duration |
(optional) The duration of the animation. (defaults to producing an animation that uses 10 frames per second) |
animate_plot |
(optiional) If TRUE, will return an animation. If FALSE, returns a gganim object that can be further modified before animating. (defaults to FALSE) |
save_filename |
(optional) If specified, the animation will be saved to a gif with this filename. (default is not to save) |
save_path |
(optional) If specified along with save_filename, will save the gif to save_path/save_filename. (defaults to working directory) |
An animated line graph, which successively adds points along the time axis.
A histogram of a single variable from a single target.
animate_scatter( output, x_parameter, x_dimension, y_parameter, y_dimension, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, max_size = 1, alpha = 0.1, xlimits = NULL, ylimits = NULL, default_title = FALSE, view_follow = FALSE, shadow_mark_proportion_of_max_size = NULL, shadow_wake_length = NULL, duration = NULL, animate_plot = TRUE, save_filename = NULL, save_path = NULL )
animate_scatter( output, x_parameter, x_dimension, y_parameter, y_dimension, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, max_size = 1, alpha = 0.1, xlimits = NULL, ylimits = NULL, default_title = FALSE, view_follow = FALSE, shadow_mark_proportion_of_max_size = NULL, shadow_wake_length = NULL, duration = NULL, animate_plot = TRUE, save_filename = NULL, save_path = NULL )
output |
Output from the SMC or EnK algorithm. |
x_parameter |
The parameter indexed by the x-axis. |
x_dimension |
(optional) The dimension of the x-parameter we wish to histogram. (default is 1) |
y_parameter |
The parameter indexed by the y-axis. |
y_dimension |
(optional) The dimension of the y-parameter we wish to histogram. (default is 1) |
target |
(optionaL) If specified, will fix to this target, and animate over ExternalTarget (if present in output). |
external_target |
(optionaL) If specified, will fix to this external_target, and animate over Target. |
use_initial_points |
(optional) If target is not specified and this argument is TRUE, will add the initial unweighted proposed points to the output to be plotted. (default is TRUE) |
use_weights |
(optional) If FALSE, will ignore particle weights in the scatter plot. If TRUE, will use the particle weights. (defaults to TRUE) |
mcmc |
(optional) If TRUE, the user is indicating that the output is from an MCMC algorithm. This will set use_initial_points=FALSE and use_weights=FALSE no matter what the user sets these arguments to. (default is FALSE) |
max_size |
(optional) The maximum size of the points in the plot. (default=1) |
alpha |
(optional) The transparency of the points in the plot. (default=0.1) |
xlimits |
(optional) Input of the form c(start,end), which specifies the ends of the x-axis. |
ylimits |
(optional) Input of the form c(start,end), which specifies the ends of the y-axis. |
default_title |
(optional) If TRUE, will provide a default title for the figure. If FALSE, no title is used. (defaults to FALSE) |
view_follow |
(optional) If TRUE, the view will follow the particles. (default FALSE) |
shadow_mark_proportion_of_max_size |
(optional) If set, the animation will leave behind shadow points, of a size (and transparency) specified by this proportion. (default to not set) |
shadow_wake_length |
(optional) If set, the animation will leave a shadow wake behind each point, of a duration given by this parameter (proportion of the entire animation length). (default to not set) |
duration |
(optional) The duration of the animation. (defaults to producing an animation that uses 10 frames per second) |
animate_plot |
(optiional) If TRUE, will return an animation. If FALSE, returns a gganim object that can be furher modified before animating. (defaults to FALSE) |
save_filename |
(optional) If specified, the animation will be saved to a gif with this filename. (default is not to save) |
save_path |
(optional) If specified along with save_filename, will save the gif to save_path/save_filename. (defaults to working directory) |
A scatter plot in a ggplot figure.
Plot animated line graph showing parameter value vs dimension across targets from algorithm output.
animate_time_series( output, parameters, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, max_line_width = 1, alpha = 0.1, xlimits = NULL, ylimits = NULL, duration = NULL, animate_plot = TRUE, save_filename = NULL, save_path = NULL )
animate_time_series( output, parameters, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, max_line_width = 1, alpha = 0.1, xlimits = NULL, ylimits = NULL, duration = NULL, animate_plot = TRUE, save_filename = NULL, save_path = NULL )
output |
Output from the SMC or EnK algorithm. |
parameters |
The parameters we wish to be on the y-axis of the line graph. |
target |
(optional) The target to plot. (default is to use all targets) |
external_target |
(optional) The external target to plot. (default is to use all external targets, or to ignore if the column is not present) |
use_initial_points |
(optional) If target is not specified and this argument is TRUE, will add the initial unweighted proposed points to the output to be plotted. (default is TRUE) |
use_weights |
(optional) If FALSE, will ignore particle weights in the line graph. If TRUE, will use the particle weights. (defaults to TRUE) |
max_line_width |
(optional) The maximum size of the points in the plot. (default=1) |
alpha |
(optional) The transparency of the lines in the plot. (default=0.1) |
xlimits |
(optional) Input of the form c(start,end), which specifies the ends of the x-axis. |
ylimits |
(optional) Input of the form c(start,end), which specifies the ends of the y-axis. |
duration |
(optional) The duration of the animation. (defaults to producing an animation that uses 10 frames per second) |
animate_plot |
(optiional) If TRUE, will return an animation. If FALSE, returns a gganim object that can be furher modified before animating. (defaults to FALSE) |
save_filename |
(optional) If specified, the animation will be saved to a gif with this filename. (default is not to save) |
save_path |
(optional) If specified along with save_filename, will save the gif to save_path/save_filename. (defaults to working directory) |
An animated line graph, showing how the lines evolve through the sequence of targets.
Data generated from a constant velocity (or continuous white noise acceleration, CWNA) model for 20 time steps.
cwna_data
cwna_data
20 observations of 4 variables.
10000 simulations from a stochastic Lotka-Volterra model, assigned weights according to a Gaussian approximate Bayesian computation kernel with tolerance equal to 50.
lv_output
lv_output
320000 observations of 15 variables.
Convert IS, SMC or EnK output stored as a matrix to tidy format.
matrix2tidy(output, parameter, target = 1, log_weights = NULL)
matrix2tidy(output, parameter, target = 1, log_weights = NULL)
output |
Matrix output (one point per row) from an IS algorithm, or one target from a SMC or EnK algorithm. |
parameter |
The name to assign the parameter in the tidy output. |
target |
(optional) The target index to use in the tidy output (default 1). |
log_weights |
(optional) The log_weights to use in the tidy output (default all equal). |
The output in tidy format.
The output of an SMC sampler where the initial distribution is a Gaussian and the final target is a mixture of Gaussians. 25 particles were used, with an adaptive method to determine the sequence of targets, and a Metropolis-Hastings move to move the particles at each step.
mixture_25_particles
mixture_25_particles
175 observations of 13 variables.
A density of a single variable.
plot_density( output, parameter, dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, xlimits = NULL, ylimits = NULL, default_title = FALSE )
plot_density( output, parameter, dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, xlimits = NULL, ylimits = NULL, default_title = FALSE )
output |
Output from the SMC or EnK algorithm. |
parameter |
The parameter for which we wish to view the density. |
dimension |
(optional) The dimension of the parameter for which we wish to view the density. (default is 1) |
target |
(optional) The index of the target for which we wish to view the density. (default to all targets) |
external_target |
(optional) The index of the external target to plot. (default is to use all external targets, or to ignore if the column is not present) |
use_initial_points |
(optional) If target is not specified and this argument is TRUE, will add the initial unweighted proposed points to the output to be plotted. (default is TRUE) |
use_weights |
(optional) If FALSE, will ignore particle weights in the density. If TRUE, will use the particle weights. (defaults to TRUE) |
mcmc |
(optional) If TRUE, the user is indicating that the output is from an MCMC algorithm. This will set use_initial_points=FALSE and use_weights=FALSE no matter what the user sets these arguments to. (default is FALSE) |
xlimits |
(optional) Input of the form c(start,end), which specifies the ends of the x-axis. |
ylimits |
(optional) Input of the form c(start,end), which specifies the ends of the y-axis. |
default_title |
(optional) If TRUE, will provide a default title for the figure. If FALSE, no title is used. (defaults to FALSE) |
A density in a ggplot figure.
Plot an SMC or EnK genealogy from algorithm output.
plot_genealogy( output, parameter, dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, alpha_points = 0.1, alpha_lines = 0.1, axis_limits = NULL, vertical = TRUE, arrows = TRUE, default_title = FALSE )
plot_genealogy( output, parameter, dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, alpha_points = 0.1, alpha_lines = 0.1, axis_limits = NULL, vertical = TRUE, arrows = TRUE, default_title = FALSE )
output |
Output from the SMC or EnK algorithm. |
parameter |
The parameter we wish to see the evolution of. |
dimension |
(optional) The dimension of the parameter we wish to see the evolution of. (default is 1) |
target |
(optional) The target to plot. (default is to use all targets) |
external_target |
(optional) The external target to plot. (default is to use all external targets, or to ignore if the column is not present) |
use_initial_points |
(optional) If target is not specified and this argument is TRUE, will add the initial unweighted proposed points to the output to be plotted. (default is TRUE) |
use_weights |
(optional) If FALSE, will ignore particle weights in the line graph. If TRUE, will use the particle weights. (defaults to TRUE) |
alpha_points |
(optional) The transparency of the points in the plot. (default=0.1) |
alpha_lines |
(optional) The transparency of the lines in the plot. (default=0.1) |
axis_limits |
(optional) Input of the form c(start,end), which specifies the ends of the parameter axis. |
vertical |
(optional) If TRUE (default), plots a genealogy vertically. If FALSE, plots horizontally. |
arrows |
(optional) If TRUE (default), includes arrowheads. If FALSE, arrowheads are omitted. |
default_title |
(optional) If TRUE, will provide a default title for the figure. If FALSE, no title is used. (defaults to FALSE) |
A particle genealogy in a ggplot figure.
A histogram of a single variable.
plot_histogram( output, parameter, dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, bins = 30, xlimits = NULL, ylimits = NULL, default_title = FALSE )
plot_histogram( output, parameter, dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, bins = 30, xlimits = NULL, ylimits = NULL, default_title = FALSE )
output |
Output from the SMC or EnK algorithm. |
parameter |
The parameter we wish to histogram. |
dimension |
(optional) The dimension of the parameter we wish to histogram. (default is 1) |
target |
(optional) The index of the target we wish to histogram. (default to all targets) |
external_target |
(optional) The index of the external target to plot. (default is to use all external targets, or to ignore if the column is not present) |
use_initial_points |
(optional) If target is not specified and this argument is TRUE, will add the initial unweighted proposed points to the output to be plotted. (default is TRUE) |
use_weights |
(optional) If FALSE, will ignore particle weights in the histogram. If TRUE, will use the particle weights. (defaults to TRUE) |
mcmc |
(optional) If TRUE, the user is indicating that the output is from an MCMC algorithm. This will set use_initial_points=FALSE and use_weights=FALSE no matter what the user sets these arguments to. (default is FALSE) |
bins |
(optional) Number of bins for the histogram. (default 30) |
xlimits |
(optional) Input of the form c(start,end), which specifies the ends of the x-axis. |
ylimits |
(optional) Input of the form c(start,end), which specifies the ends of the y-axis. |
default_title |
(optional) If TRUE, will provide a default title for the figure. If FALSE, no title is used. (defaults to FALSE) |
A histogram in a ggplot figure.
A histogram of a single variable from a single target
plot_scatter( output, x_parameter, x_dimension = 1, y_parameter, y_dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, max_size = 1, alpha = 0.1, xlimits = NULL, ylimits = NULL, default_title = FALSE )
plot_scatter( output, x_parameter, x_dimension = 1, y_parameter, y_dimension = 1, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, max_size = 1, alpha = 0.1, xlimits = NULL, ylimits = NULL, default_title = FALSE )
output |
Output from the SMC or EnK algorithm. |
x_parameter |
The parameter indexed by the x-axis. |
x_dimension |
(optional) The dimension of the x-parameter we wish to histogram. (default is 1) |
y_parameter |
The parameter indexed by the y-axis. |
y_dimension |
(optional) The dimension of the y-parameter we wish to histogram. (default is 1) |
target |
(optional) The index of the target we wish to plot. (default is to use all targets) |
external_target |
(optional) The index of the external target to plot. (default is to use all external targets, or to ignore if the column is not present) |
use_initial_points |
(optional) If target is not specified and this argument is TRUE, will add the initial unweighted proposed points to the output to be plotted. (default is TRUE) |
use_weights |
(optional) If FALSE, will ignore particle weights in the scatter plot. If TRUE, will use the particle weights. (defaults to TRUE) |
mcmc |
(optional) If TRUE, the user is indicating that the output is from an MCMC algorithm. This will set use_initial_points=FALSE and use_weights=FALSE no matter what the user sets these arguments to. (default is FALSE) |
max_size |
(optional) The maximum size of the points in the plot. (default=1) |
alpha |
(optional) The transparency of the points in the plot. (default=0.1) |
xlimits |
(optional) Input of the form c(start,end), which specifies the ends of the x-axis. |
ylimits |
(optional) Input of the form c(start,end), which specifies the ends of the y-axis. |
default_title |
(optional) If TRUE, will provide a default title for the figure. If FALSE, no title is used. (defaults to FALSE) |
A scatter plot in a ggplot figure.
Plot line graph showing parameter value vs dimension from algorithm output.
plot_time_series( output, parameters, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, max_line_width = 1, alpha = 0.1, xlimits = NULL, ylimits = NULL )
plot_time_series( output, parameters, target = NULL, external_target = NULL, use_initial_points = TRUE, use_weights = TRUE, mcmc = FALSE, max_line_width = 1, alpha = 0.1, xlimits = NULL, ylimits = NULL )
output |
Output from the SMC or EnK algorithm. |
parameters |
The parameters we wish to be on the y-axis of the line graph. |
target |
(optional) The target to plot. (default is to use all targets) |
external_target |
(optional) The external target to plot. (default is to use all external targets, or to ignore if the column is not present) |
use_initial_points |
(optional) If target is not specified and this argument is TRUE, will add the initial unweighted proposed points to the output to be plotted. (default is TRUE) |
use_weights |
(optional) If FALSE, will ignore particle weights in the line graph. If TRUE, will use the particle weights. (defaults to TRUE) |
mcmc |
(optional) If TRUE, the user is indicating that the output is from an MCMC algorithm. This will set use_initial_points=FALSE and use_weights=FALSE no matter what the user sets these arguments to. (default is FALSE) |
max_line_width |
(optional) The maximum size of the points in the plot. (default=1) |
alpha |
(optional) The transparency of the lines in the plot. (default=0.1) |
xlimits |
(optional) Input of the form c(start,end), which specifies the ends of the x-axis. |
ylimits |
(optional) Input of the form c(start,end), which specifies the ends of the y-axis. |
A line graph in a ggplot figure.
cwna_data
. The output consists of 100 particles over 20 time steps.The output of a bootstrap particle filter on the cwna_data
. The output consists of 100 particles over 20 time steps.
sir_cwna_model
sir_cwna_model
4000 observations of 13 variables.