gridsearch_burnin_single: gridsearch_burnin_single

Usage Arguments Author(s) Examples

View source: R/functions_burninthining.R

Usage

1
gridsearch_burnin_single(partition, theta, nodes, effects, objects, num.steps, neighborhoods, sizes.allowed, sizes.simulated, parallel = F, cpus = 1)

Arguments

partition

Observed partition.

theta

Initial model parameters.

nodes

Data frame containing the nodes.

effects

Effects or sufficient statistics. A list with a vector "names" and a vector "objects".

objects

Objects used for statistics calculation. A list with a vector "name" and a vector "object".

num.steps

Number of samples wanted.

neighborhoods

List of probability vectors (probability actors swap, probability merge/division, probability single actor move).

sizes.allowed

Vector of group sizes allowed in sampling (now, it only works for vectors like size_min:size_max).

sizes.simulated

Vector of group sizes allowed in the Markov chain but not necessraily sampled (now, it only works for vectors like size_min:size_max).

parallel

To run different neighborhoods in parallel. Default = False

cpus

Default = 1

Author(s)

Marion Hoffman

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (partition, theta, nodes, effects, objects, num.steps,
    neighborhoods, sizes.allowed, sizes.simulated, parallel = F,
    cpus = 1)
{
    if (parallel) {
        n <- ceiling(length(neighborhoods)/cpus)
        subindexes <- list()
        for (c in 1:cpus) {
            start <- (c - 1) * n + 1
            end <- c * n
            if (c == cpus)
                end <- length(neighborhoods)
            subindexes[[c]] <- start:end
        }
        sfExport("partition", "theta", "nodes", "effects", "objects",
            "num.steps", "neighborhoods", "sizes.allowed", "sizes.simulated",
            "subindexes")
        res <- sfLapply(1:cpus, fun = function(k) {
            subres <- list()
            for (i in 1:length(subindexes[[k]])) {
                index <- subindexes[[k]][i]
                subneighborhood <- neighborhoods[[index]]
                subres[[i]] <- simulate_burnin_single(partition,
                  theta, nodes, effects, objects, num.steps,
                  subneighborhood, sizes.allowed, sizes.simulated)
            }
            return(subres)
        })
        allsimulations <- list()
        for (c in 1:cpus) allsimulations <- append(allsimulations,
            res[[c]])
    }
    else {
        allsimulations <- list()
        for (i in 1:length(neighborhoods)) {
            allsimulations[[i]] <- simulate_burnin_single(partition,
                theta, nodes, effects, objects, num.steps, neighborhoods[[i]],
                sizes.allowed, sizes.simulated)
        }
    }
    return(list(all.simulations = allsimulations))
  }

isci1102/ERPM documentation built on Jan. 18, 2022, 12:25 a.m.