mc_reject

Header file for the Monte Carlo Rejection Sampler

Functions

void parallel_sample(int threadid, mcr_job job)

internal routine to draw N samples

Should not be called by the user

Just made this separate from the class for now for convenience

Parameters:

job – mcr job — see mc_reject.h

class mcr_sampler
#include <mc_reject.h>

Public Functions

mcr_sampler(void (*probability)(double *prob, void *parameters, int d, int threadid), void (*draw_parameters)(void *prop_parameters, int d, int threadid, gsl_rng *r), int dimension, double *param_ranges_max, double *param_ranges_min)

Class constructor for Monte Carlo Rejection Sampler.

Assumes no parallel threading

`probability’ is the function that should return the probability of a given sample

`draw_parameters’ &#8212; NULL, if default should be used. Otherwise, this should propose another parameter set

param_ranges_max/min are only used if the default draw_parameter is used, otherwise can be NULL

Parameters:
  • dimension – Dimension

  • param_ranges_max – Max allowed parameters &#8212; Shape [dimension]

  • param_ranges_min – Min allowed parameters &#8212; Shape [dimension]

mcr_sampler(void (*probability)(double *prob, void *parameters, int d, int threadid), void (*draw_parameters)(void *prop_parameters, int d, int threadid, gsl_rng *r), int dimension, double *param_ranges_max, double *param_ranges_min, int thread_num, bool thread_safe)

Class constructor for Monte Carlo Rejection Sampler.

Allows parallel threading

`probability’ is the function that should return the probability of a given sample

`draw_parameters’ &#8212; NULL, if default should be used. Otherwise, this should propose another parameter set

param_ranges_max/min are only used if the default draw_parameter is used, otherwise can be NULL

Parameters:
  • dimension – Dimension

  • param_ranges_max – Max allowed parameters &#8212; Shape [dimension]

  • param_ranges_min – Min allowed parameters &#8212; Shape [dimension]

  • thread_num – Thread number to use

  • thread_safe – Bool thread safe &#8212; true if parallel threading should be used

~mcr_sampler()

Destructor function for mcr_sampler.

Deallocates the gsl_rng memory

void sample_distribution(int N_samples, void **output)

Main driver &#8212; Samples from distribution that has been associated with a sampler object.

Parameters:

output – [out] Output array shape [N_samples][dimension] Caste to void **

void sample(void *output, int threadid)

Internal routine to return one accepted sample.

Should not be used directly by user &#8212; couldn’t make private though

Parameters:
  • output – [out] Output, accepted parameter set

  • threadid – Thread id &#8212; not currently used, but included for future proofing

Public Members

bool thread_safe
int thread_num
int dimension
int parallel_job_num
double *param_ranges_max
double *param_ranges_min
std::function<void(double*, void*, int, int)> pfn
std::function<void(void*, int, int, gsl_rng*)> draw_param
double **samples

Private Functions

void draw_param_standard(void *prop_params, int d, int threadid, gsl_rng *r)

Standard option to draw samples randomly.

Assumes the parameter vector is of type double *

Uses the ranges provided by the user to randomly draw samples uniformly

Parameters:
  • prop_params – [out] Proposed Param

  • d – Dimension of parameter space

  • threadid – Thread ID for parallel execution

  • r – GSL random number seed

void init(void (*probability)(double *prob, void *parameters, int d, int threadid), void (*draw_parameters)(void *prop_parameters, int d, int threadid, gsl_rng *r), int dimension, double *param_ranges_max, double *param_ranges_min, int thread_num, bool thread_safe)

Private Members

const gsl_rng_type *T
gsl_rng **rvec
struct mcr_job
#include <mc_reject.h>

Public Members

mcr_sampler *sampler
int starting_index = 0
int job_length = 0
void **output