This vignette contains a number of examples on how to use
clugenr
in 2D. Examples require the following setup
code:
# Load the clugenr library
library(clugenr)
# Load functions for plotting examples
source("plot_examples_2d.R", local = knitr::knit_global())
# Keep examples reproducible in newer R versions
RNGversion("3.6.0")
The 2D examples were plotted with the plot_examples_2d()
function available here.
direction
parameterangle_disp
parameter and using a custom
angle_deltas_fn
function# Custom angle_deltas function: arbitrarily rotate some clusters by 90 degrees
angdel_90_fn <- function(nclu, astd) sample(c(0, pi / 2), nclu, replace = TRUE)
llength
parametere007 <- clugen(2, 5, 800, c(1, 0), pi / 10, c(10, 10), 0, 0, 0.5, seed = seed,
point_dist_fn = "n")
e008 <- clugen(2, 5, 800, c(1, 0), pi / 10, c(10, 10), 10, 0, 0.5, seed = seed,
point_dist_fn = "n")
e009 <- clugen(2, 5, 800, c(1, 0), pi / 10, c(10, 10), 30, 0, 0.5, seed = seed,
point_dist_fn = "n")
llength_disp
parameter and using a custom
llengths_fn
function# Custom llengths function: line lengths grow for each new cluster
llen_grow_fn <- function(nclu, llen, llenstd) {
llen * 0:(nclu - 1) + rnorm(nclu, sd = llenstd)
}
e010 <- clugen(2, 5, 800, c(1, 0), pi / 10, c(10, 10), 15, 0.0, 0.5,
seed = seed, point_dist_fn = "n")
e011 <- clugen(2, 5, 800, c(1, 0), pi / 10, c(10, 10), 15, 10.0, 0.5,
seed = seed, point_dist_fn = "n")
e012 <- clugen(2, 5, 800, c(1, 0), pi / 10, c(10, 10), 10, 0.1, 0.5,
seed = seed, llengths_fn = llen_grow_fn, point_dist_fn = "n")
cluster_sep
parametercluster_offset
parameter and using a
custom clucenters_fn
function# Custom clucenters function: places clusters in a diagonal
centers_diag <- function(nclu, csep, coff) {
matrix(1, nrow = nclu, ncol = length(csep)) * (1:nclu * max(csep)) +
rep(coff, each = nclu)
}
e016 <- clugen(2, 8, 1000, c(1, 1), pi / 4, c(10, 10), 10, 2, 2.5, seed = seed)
e017 <- clugen(2, 8, 1000, c(1, 1), pi / 4, c(10, 10), 10, 2, 2.5, seed = seed,
cluster_offset = c(20, -20))
e018 <- clugen(2, 8, 1000, c(1, 1), pi / 4, c(10, 10), 10, 2, 2.5, seed = seed,
cluster_offset = c(-50, -50), clucenters_fn = centers_diag)
proj_dist_fn = "norm"
proj_dist_fn = "unif"
e022 <- clugen(2, 4, 1000, c(1, 0), pi / 2, c(20, 20), 13, 2, 0.0, seed = seed,
proj_dist_fn = "unif")
e023 <- clugen(2, 4, 1000, c(1, 0), pi / 2, c(20, 20), 13, 2, 1.0, seed = seed,
proj_dist_fn = "unif")
e024 <- clugen(2, 4, 1000, c(1, 0), pi / 2, c(20, 20), 13, 2, 3.0, seed = seed,
proj_dist_fn = "unif")
# Custom proj_dist_fn: point projections placed using the Beta distribution
proj_beta <- function(len, n) len * rbeta(n, 0.1, 0.1) - len / 2
e025 <- clugen(2, 4, 1000, c(1, 0), pi / 2, c(20, 20), 13, 2, 0.0, seed = seed,
proj_dist_fn = proj_beta)
e026 <- clugen(2, 4, 1000, c(1, 0), pi / 2, c(20, 20), 13, 2, 1.0, seed = seed,
proj_dist_fn = proj_beta)
e027 <- clugen(2, 4, 1000, c(1, 0), pi / 2, c(20, 20), 13, 2, 3.0, seed = seed,
proj_dist_fn = proj_beta)
# Custom proj_dist_fn: point projections placed using the Beta distribution
proj_beta <- function(len, n) len * rbeta(n, 0.1, 0.1) - len / 2
point_dist_fn = "n-1"
point_dist_fn = "n"
e031 <- clugen(2, 5, 1500, c(1, 0), pi / 4, c(20, 20), 14, 2, 2.0, seed = seed,
point_dist_fn = "n")
e032 <- clugen(2, 5, 1500, c(1, 0), pi / 4, c(20, 20), 14, 2, 2.0, seed = seed,
point_dist_fn = "n", proj_dist_fn = "unif")
e033 <- clugen(2, 5, 1500, c(1, 0), pi / 4, c(20, 20), 14, 2, 2.0, seed = seed,
point_dist_fn = "n", proj_dist_fn = proj_beta)
# Custom point_dist_fn: final points placed using the Exponential distribution
clupoints_n_1_exp <- function(projs, lat_std, len, clu_dir, clu_ctr) {
dist_exp <- function(npts, lstd) lstd * rexp(npts, rate = 2 / lstd)
clupoints_n_1_template(projs, lat_std, clu_dir, dist_exp)
}
e034 <- clugen(2, 5, 1500, c(1, 0), pi / 4, c(20, 20), 14, 2, 2.0, seed = seed,
point_dist_fn = clupoints_n_1_exp)
e035 <- clugen(2, 5, 1500, c(1, 0), pi / 4, c(20, 20), 14, 2, 2.0, seed = seed,
point_dist_fn = clupoints_n_1_exp, proj_dist_fn = "unif")
e036 <- clugen(2, 5, 1500, c(1, 0), pi / 4, c(20, 20), 14, 2, 2.0, seed = seed,
point_dist_fn = clupoints_n_1_exp, proj_dist_fn = proj_beta)
# Custom clucenters_fn (all): yields fixed positions for the clusters
centers_fixed <- function(nclu, csep, coff) {
matrix(c(-csep[1], -csep[2], csep[1], -csep[2], -csep[1], csep[2], csep[1], csep[2]),
nrow = nclu, byrow = TRUE)
}
# Custom clusizes_fn (e038): cluster sizes determined via the uniform distribution,
# no correction for total points
clusizes_unif <- function(nclu, npts, ae) sample(2 * npts / nclu, nclu, replace = TRUE)
# Custom clusizes_fn (e039): clusters all have the same size, no correction for
# total points
clusizes_equal <- function(nclu, npts, ae) npts %/% nclu * rep.int(1, nclu)
e037 <- clugen(2, 4, 1500, c(1, 1), pi, c(20, 20), 0, 0, 5, seed = seed,
clucenters_fn = centers_fixed, point_dist_fn = "n")
e038 <- clugen(2, 4, 1500, c(1, 1), pi, c(20, 20), 0, 0, 5, seed = seed,
clucenters_fn = centers_fixed, clusizes_fn = clusizes_unif,
point_dist_fn = "n")
e039 <- clugen(2, 4, 1500, c(1, 1), pi, c(20, 20), 0, 0, 5, seed = seed,
clucenters_fn = centers_fixed, clusizes_fn = clusizes_equal,
point_dist_fn = "n")
e040 <- clugen(2, 4, 1000, c(-1, 1), 0, c(0, 0), 0, 0, 0.2, seed = seed,
proj_dist_fn = "unif", point_dist_fn = "n",
clusizes_fn = c(50, 200, 500, 2000), llengths_fn = c(0, 2, 4, 6),
clucenters_fn = matrix(c(-5, -5, -2.5, -2.5, 0, 0, 2.5, 2.5),
nrow = 4, byrow = TRUE))
e041 <- clugen(2, 5, 1000, matrix(c(1, 1, 1, 0, 1, 0, 0, 1, 0, 1),
nrow = 5, byrow = TRUE),
0, c(0, 0), 0, 0, 0.2, seed = seed,
proj_dist_fn = "unif", point_dist_fn = "n",
clusizes_fn = c(200, 500, 500, 500, 500),
llengths_fn = c(0, 5, 5, 5, 5),
clucenters_fn = matrix(c(0, 0, 0, 5, 0, -5, 5, 0, -5, 0),
nrow = 5, byrow = TRUE))
e042 <- clugen(2, 5, 1000, matrix(c(0, 1, 0.25, 0.75, 0.5, 0.5, 0.75, 0.25, 1, 0),
nrow = 5, byrow = TRUE),
0, c(0, 0), 5, 0, 0.2, seed = seed,
proj_dist_fn = "unif", point_dist_fn = "n",
clusizes_fn = c(500, 500, 500, 500, 500),
clucenters_fn = matrix(c(-5, 0, -3, -0.3, -1, -0.8, 1, -1.6, 3, -2.5),
nrow = 5, byrow = TRUE))