R/samples_from_log_distribution.R

Defines functions samples_from_log_distribution

samples_from_log_distribution <- function(log_sampling_weights,
                                          values_to_be_sampled,
                                          num_samples) {

  # allocate a vector to hold indices of values we actually want to sample.
  indices <- rep(0,num_samples)

  # populate indices with log space sampler
  for(i in 1:num_samples) {
    indices[i] <- log_space_multinomial_sampler(log_sampling_weights,
                                             runif(1))
  }

  sampled_values <- values_to_be_sampled[indices]

  return(sampled_values)
}
matthewjdenny/GERGM documentation built on May 15, 2018, 4:22 p.m.