ars: ARS class providing object with methods for communication...

Description Usage Format Value Public Methods Private Methods Public fields Active bindings Methods Examples

Description

ARS class providing object with methods for communication with R6

ARS class providing object with methods for communication with R6

Usage

1
example <- ars$new(funx=dnorm, D=c(-Inf, Inf))

Format

R6Class object.

Value

Object of R6Class with methods to generate adaptive rejection sampling

Public Methods

sample(n, init_l, init_r, squeeze)

This method samples n points from using adaptive rejection sampling. User may pick two initalizing points, init_l and init_r which represent data points to start at. Useful if -1 and 1 are far from the pdf, i.e rnorm(mean=3000, sd=1)

f(x)

This method calculates our funx observation at a given x

plot_sampdist()

This method plots our normalized envelope function

calc_sampdist()

This method calculates the sampling distribution from a uniform distribution

plot_samples()

This method plots our samples in a histogramm, with a blue line highlighting the median value

s()

This method calculates the envelope or sampling function

Private Methods

h(x)

This method calculates the log of our funx at a given point x

init_hprim()

This method intializes our hprim values

init_hval()

This method initalizes our h values

init_scdf()

This method initalizes our cdf under the upper hull

init_u()

This method initializes our upper hull values

init_y()

This method initalizes our y values

l(p)

This method is a function that returns the slope of a lowerhull line given a point p

u(p)

This method is a function that returns the slope of a upperhull line given a point p

sampl_exph()

This method samples from our exp(h values)

update(y, hy, hy_prim)

This method updates our private variables after an interation

Public fields

self$f

Desnity function we want to sample from

self$var_max

Upper bound on function we want to sample from

self$var_min

Lower bound on function we want to sample from

private$h_prims

A R6 namedVector that contains h'(x)

private$h_vals

A R6 namedVector that contains h(x)

private$s_cdfs

A R6 namedVector that contains each interval's CDF

private$u_vals

A R6 namedVector that contains u(x)

private$x

a vector of x values that are our sample values. Empty unless sample() run

private$y

a vector of y values that begins to increase once sample() is run

private$z

a vector of z values, or intersection points, that begins to increase once sample() is run

Active bindings

self$f

Desnity function we want to sample from

self$var_max

Upper bound on function we want to sample from

self$var_min

Lower bound on function we want to sample from

private$h_prims

A R6 namedVector that contains h'(x)

private$h_vals

A R6 namedVector that contains h(x)

private$s_cdfs

A R6 namedVector that contains each interval's CDF

private$u_vals

A R6 namedVector that contains u(x)

private$x

a vector of x values that are our sample values. Empty unless sample() run

private$y

a vector of y values that begins to increase once sample() is run

private$z

a vector of z values, or intersection points, that begins to increase once sample() is run

Methods

Public methods


Method new()

Usage
ars$new(funx, D = c(-Inf, Inf), ...)
Arguments
funx

a function we want to sample from

D

a vector of length 2 of numbers for bounds of function


Method calc_sampdist()

Usage
ars$calc_sampdist()

Method sample()

Usage
ars$sample(n = 1000, init_l = -1, init_r = 1, squeeze = TRUE)

Method plot_samples()

Usage
ars$plot_samples()

Method plot_sampdist()

Usage
ars$plot_sampdist()

Method plot_u_l()

Usage
ars$plot_u_l()

Method clone()

The objects of this class are cloneable with this method.

Usage
ars$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

1
2
3
ex <- ars$new(dnorm, c(-Inf,Inf),mean=3, sd=1)
samples <- ex$sample(n=1000)
ex$plot_samples()

andrea2910/ars documentation built on June 17, 2021, 3:32 a.m.