Stepdown: Stepdown class

StepdownR Documentation

Stepdown class

Description

Stepdown class

Stepdown class

Details

This R6 class represents a step function approximation to the non-increasing function \rm{Pr}(A_u) for u \in [0,1].

The object w represents a unimodal weight function. It is expected to contain several members:

  • log_c: the logarithm of the value c, which is the mode of the weight function.

  • roots(log_a): return the roots of the equation \log w(x) - \rm{log_a} = 0.

  • eval(x, log = TRUE): evaluate the function. Return the value on the log-scale if log = TRUE.

The object g represents a base distribution. It is expected to contain two member functions:

  • pr_interval(x1, x2): Return \rm{Pr}(x1 < X < x2) under distribution g.

  • r_truncated(n, x1, x2): Take n draws from distribution g truncated to the open interval (x1, x2).

We make use of the fibonacci_heap structure in the datastructures package to avoid repeated sorted when small_rects is used as the method of knot selection. This package is not maintained on CRAN at the time this message is being written; therefore, we make use of it as a suggested package, following the guidance in https://cran.r-project.org/doc/manuals/R-exts.html#Suggested-packages. I.e., all datastructures function calls are proceeded with a namespace and the package is not listed in Imports or Depends.

Methods

Public methods


Method new()

Construct the step function

Usage
Stepdown$new(
  w,
  g,
  tol,
  N,
  method,
  priority_weight = 1/2,
  midpoint_type = "geometric"
)
Arguments
w

An object representing a weight function (see details).

g

An object representing a base distribution (see details).

tol

A small positive number used in search for u_L and u_H.

N

Number of knot points will be N+1.

method

Either equal_steps or small_rects (see details).

priority_weight

Experimental: An weight between 0 and 1. When closer to 1, more priority is given in small_rects to rectangle height. When closer to 0, more priority is given to rectangle width.

midpoint_type

Type of midpoint function to use. Currently only geometric or arithmetic are supported. geometric is preferred when the support of p(u) is focused very close to zero.


Method get_cum_probs()

Get cumulative probabilities after normalizing the step function to a discrete distribution.

Usage
Stepdown$get_cum_probs()

Method get_norm_const()

The constant used to normalize the step function to a discrete distribution.

Usage
Stepdown$get_norm_const()

Method get_log_x_vals()

The knot values on which the approximation is based, returned on the log-scale.

Usage
Stepdown$get_log_x_vals()

Method get_log_h_vals()

Values of the approximation evaluated at the points returned by get_log_x_vals, given at the log-scale.

Usage
Stepdown$get_log_h_vals()

Method get_rects()

Rectangles used to bound the approximation: x and h coordinates along with the area. Values are returned on the log-scale or the original scale according to the log argument.

Usage
Stepdown$get_rects(log = FALSE)
Arguments
log

If TRUE, return value on the log-scale.


Method get_knot_order()

Returns the order in which knot points were added to the step function. Indices correspond to the points returned by get_log_x_vals.

Usage
Stepdown$get_knot_order()

Method get_log_p()

Evaluate the function \rm{Pr}(A_u) on a given point u (to be provided on the log-scale). The result is returned on the log-scale.

Usage
Stepdown$get_log_p(log_u)
Arguments
log_u

A value of u given at the log-scale.


Method get_priority_weight()

Returns the value of priority_weight.

Usage
Stepdown$get_priority_weight()

Method add()

Update step function by adding a knot at the point u (given on the log-scale).

Usage
Stepdown$add(log_u)
Arguments
log_u

A value of u given at the log-scale.


Method q()

Quantiles of the distribution based on the step function.

Usage
Stepdown$q(p, log = FALSE)
Arguments
p

A probability to evaluate.

log

If TRUE, return value on the log-scale.


Method r()

Draw from the distribution based on the step function.

Usage
Stepdown$r(n, log = TRUE)
Arguments
n

Number of draws to generate.

log

If TRUE, return value on the log-scale.


Method d()

Density of the distribution based on the step function.

Usage
Stepdown$d(log_x, log = FALSE, normalize = TRUE)
Arguments
log_x

A vector of points to evaluate, provided on the log-scale.

log

If TRUE, return value on the log-scale.

normalize

If TRUE, normalize the result to be a density value.


Method p()

CDF of the distribution based on the step function.

Usage
Stepdown$p(log_x)
Arguments
log_x

A vector of points to evaluate, provided on the log-scale.


Method clone()

The objects of this class are cloneable with this method.

Usage
Stepdown$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

References

Simon Dirmeier, (2018). datastructures: An R package for organisation and storage of data . Journal of Open Source Software, 3(28), 910, https://doi.org/10.21105/joss.00910

Winston Chang (2020). R6: Encapsulated Classes with Reference Semantics. R package version 2.5.0. https://CRAN.R-project.org/package=R6


andrewraim/DirectSampling documentation built on June 5, 2024, 4:36 p.m.