Skip to content

Commit

Permalink
use parallel package in hysteresis, u[date documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjdenny committed Jan 18, 2016
1 parent 25aac42 commit f90174d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
29 changes: 17 additions & 12 deletions R/hysteresis.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
#' and plots will only be plotted to the graphics device.
#' @param parallel Logical indicating whether hysteresis plots for each theta
#' parameter should be simulated in parallel. Can greatly reduce runtime, but
#' the computer must have atleast as many cores as theta parameters. Currently
#' only functional for Unix based operating systems (OSX, Linux, CentOS, etc.)
#' the computer must have atleast as many cores as theta parameters.
#' Defauts to FALSE.
#' @return A list object containing network densities for simulated networks.
#' @examples
Expand Down Expand Up @@ -140,16 +139,22 @@ hysteresis <- function(GERGM_Object,
vec <- 1:num_network_terms
cat("Simulating networks in parallel on",length(vec),
"cores. This may take a while...\n")
results <- parallel::mclapply(X = vec,
FUN = hysteresis_parallel,
mc.cores = length(vec),
GERGM_Object = GERGM_Object,
initial_density = initial_density,
possible_structural_terms = possible_structural_terms,
seed = seed,
steps = steps,
observed_density = observed_density,
range = range)
cl <- parallel::makeCluster(getOption("cl.cores", cores))

results <- parallel::clusterApplyLB(cl = cl,
X = vec,
FUN = hysteresis_parallel,
mc.cores = length(vec),
GERGM_Object = GERGM_Object,
initial_density = initial_density,
possible_structural_terms = possible_structural_terms,
seed = seed,
steps = steps,
observed_density = observed_density,
range = range)

# stop the cluster when we are done
parallel::stopCluster(cl)

for(k in 1:length(results)){
which_term <- which(GERGM_Object@stats_to_use > 0)[k]
Expand Down
3 changes: 1 addition & 2 deletions R/parallel_gergm.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#' covariate_data_list, network_data_list, cores and generate_plots) be be
#' either specified as a single value or as a vector of values equal to the
#' length of formula_list, if the user wishes to use different values for each
#' specification. Currently only functional for Unix based operating systems
#' (OSX, Linux, CentOS, etc.)
#' specification.
#'
#' @param formula_list A list of formula objects that specifies the relationship
#' between statistics and the observed network for each gergm. See the gergm()
Expand Down
3 changes: 1 addition & 2 deletions man/hysteresis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/parallel_gergm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f90174d

Please sign in to comment.