type: Type of distribution. This is a string constant for the default implementation. Distributions with non-constant type must override the get_type() function.
caps: Character vector of capabilities to fuel the default implementations of has_capability() and require_capability(). Distributions with dynamic capabilities must override the has_capability() function.
params: Initial parameter bounds structure, backing the param_bounds active binding (usually a list of intervals).
name: Name of the Distribution class. Should be CamelCase and end with "Distribution".
default_params: Initial fixed parameters backing the default_params active binding (usually a list of numeric / NULLs).
Details
Construct a Distribution instance
Used internally by the dist_* functions.
Method sample()
Usage
Distribution$sample(n, with_params = list())
Arguments
n: number of samples to draw.
with_params: Distribution parameters to use. Each parameter value can also be a numeric vector of length n. In that case the i-th sample will use the i-th parameters.
Details
Sample from a Distribution
Returns
A length n vector of i.i.d. random samples from the Distribution with the specified parameters.
log: Flag. If TRUE, return the log-density instead.
with_params: Distribution parameters to use. Each parameter value can also be a numeric vector of length length(x). In that case, the i-th density point will use the i-th parameters.
log.p: If TRUE, probabilities are returned as log(p).
with_params: Distribution parameters to use. Each parameter value can also be a numeric vector of length length(q). In that case, the i-th probability point will use the i-th parameters.
log.p: If TRUE, probabilities are returned as log(p).
with_params: Distribution parameters to use. Each parameter value can also be a numeric vector of length length(p). In that case, the i-th quantile will use the i-th parameters.
log: Flag. If TRUE, return the log-hazard instead.
with_params: Distribution parameters to use. Each parameter value can also be a numeric vector of length length(x). In that case, the i-th hazard point will use the i-th parameters.
log: Flag. If TRUE, return the gradient of the log-density instead.
with_params: Distribution parameters to use. Each parameter value can also be a numeric vector of length length(x). In that case, the i-th density point will use the i-th parameters.
Details
Gradients of the density of a Distribution
Returns
A list structure containing the (log-)density gradients of all free parameters of the Distribution evaluated at x.
log.p: If TRUE, probabilities are returned as log(p).
with_params: Distribution parameters to use. Each parameter value can also be a numeric vector of length length(q). In that case, the i-th probability point will use the i-th parameters.
Details
Gradients of the cumulative probability of a Distribution
Returns
A list structure containing the cumulative (log-)probability gradients of all free parameters of the Distribution evaluated at q.
with_params: Distribution parameters to use. Each parameter value can also be a numeric vector of length length(x). In that case, the i-th point will use the i-th parameters.
Details
Determine if a value is in the support of a Distribution
Returns
A logical vector with the same length as x indicating whether x is part of the support of the distribution given its parameters.
with_params: Distribution parameters to use. Each parameter value can also be a numeric vector of length length(x). In that case, the i-th point will use the i-th parameters.
Details
Determine if a value has positive probability
Returns
A logical vector with the same length as x indicating whether there is a positive probability mass at x given the Distribution parameters.
with_params: Optional parameter overrides with the same structure as dist$get_params(). Given Parameter values are expected to be length 1.
Details
Get a full list of parameters, possibly including placeholders.
Returns
A list representing the (recursive) parameter structure of the Distribution with values for specified parameters and NULL for free parameters that are missing both in the Distributions parameters and in with_params.
with_params: Optional parameter overrides with the same structure as dist$tf_make_constants(). Given Parameter values are expected to be length 1.
Details
Get a list of constant TensorFlow parameters
Returns
A list representing the (recursive) constant parameters of the Distribution with values sprecified by parameters. Each constant is a TensorFlow Tensor of dtype floatx.
Compile distribution parameters into tensorflow outputs
Returns
A list with two elements
outputs a flat list of keras output layers, one for each parameter.
output_inflater a function taking keras output layers and transforming them into a list structure suitable for passing to the loss function returned by tf_compile_model()
Method get_param_bounds()
Usage
Distribution$get_param_bounds()
Details
Get Interval bounds on all Distribution parameters
Returns
A list representing the free (recursive) parameter structure of the Distribution with Interval objects as values representing the bounds of the respective free parameters.
Get additional (non-linear) equality constraints on Distribution parameters
Returns
NULL if the box constraints specified by dist$get_param_bounds() are sufficient, or a function taking full Distribution parameters and returning either a numeric vector (which must be 0 for valid parameter combinations) or a list with elements
constraints: The numeric vector of constraints
jacobian: The Jacobi matrix of the constraints with respect to the parameters
with_params: Optional list of parameters to use as default values for the exported functions
Details
Export sampling, density, probability and quantile functions to plain R functions
Creates new functions in envir named {r,d,p,q}<name> which implement dist$sample, dist$density, dist$probability and dist$quantile as plain functions with default arguments specified by with_params or the fixed parameters.
The resulting functions will have signatures taking all parameters as separate arguments.