| Distribution | R Documentation |
Represents a modifiable Distribution family
default_paramsGet or set (non-recursive) default parameters of a Distribution
param_boundsGet or set (non-recursive) parameter bounds (box constraints) of a Distribution
new()Distribution$new(type, caps, params, name, default_params)
typeType of distribution. This is a string constant for the
default implementation. Distributions with non-constant type must
override the get_type() function.
capsCharacter vector of capabilities to fuel the default
implementations of has_capability() and require_capability().
Distributions with dynamic capabilities must override the
has_capability() function.
paramsInitial parameter bounds structure, backing the
param_bounds active binding (usually a list of intervals).
nameName of the Distribution class. Should be CamelCase and end
with "Distribution".
default_paramsInitial fixed parameters backing the
default_params active binding (usually a list of numeric / NULLs).
Construct a Distribution instance
Used internally by the dist_* functions.
sample()Distribution$sample(n, with_params = list())
nnumber of samples to draw.
with_paramsDistribution 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.
Sample from a Distribution
A length n vector of i.i.d. random samples from the
Distribution with the specified parameters.
dist_exponential(rate = 2.0)$sample(10)
density()Distribution$density(x, log = FALSE, with_params = list())
xVector of points to evaluate the density at.
logFlag. If TRUE, return the log-density instead.
with_paramsDistribution 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.
Density of a Distribution
A numeric vector of (log-)densities
dist_exponential()$density(c(1.0, 2.0), with_params = list(rate = 2.0))
tf_logdensity()Distribution$tf_logdensity()
Compile a TensorFlow function for log-density evaluation
A tf_function taking arguments x and args returning the
log-density of the Distribution evaluated at x with parameters args.
probability()Distribution$probability( q, lower.tail = TRUE, log.p = FALSE, with_params = list() )
qVector of points to evaluate the probability function at.
lower.tailIf TRUE, return P(X <= q). Otherwise return P(X > q).
log.pIf TRUE, probabilities are returned as log(p).
with_paramsDistribution 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.
Cumulative probability of a Distribution
A numeric vector of (log-)probabilities
dist_exponential()$probability( c(1.0, 2.0), with_params = list(rate = 2.0) )
tf_logprobability()Distribution$tf_logprobability()
Compile a TensorFlow function for log-probability evaluation
A tf_function taking arguments qmin, qmax and args
returning the log-probability of the Distribution evaluated over the
closed interval [qmin, qmax] with parameters args.
quantile()Distribution$quantile( p, lower.tail = TRUE, log.p = FALSE, with_params = list() )
pVector of probabilities.
lower.tailIf TRUE, return P(X <= q). Otherwise return P(X > q).
log.pIf TRUE, probabilities are returned as log(p).
with_paramsDistribution 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.
Quantile function of a Distribution
A numeric vector of quantiles
dist_exponential()$quantile(c(0.1, 0.5), with_params = list(rate = 2.0))
hazard()Distribution$hazard(x, log = FALSE, with_params = list())
xVector of points.
logFlag. If TRUE, return the log-hazard instead.
with_paramsDistribution 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.
Hazard function of a Distribution
A numeric vector of (log-)hazards
dist_exponential(rate = 2.0)$hazard(c(1.0, 2.0))
diff_density()Distribution$diff_density(x, log = FALSE, with_params = list())
xVector of points.
logFlag. If TRUE, return the gradient of the log-density
instead.
with_paramsDistribution 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.
Gradients of the density of a Distribution
A list structure containing the (log-)density gradients of all
free parameters of the Distribution evaluated at x.
dist_exponential()$diff_density( c(1.0, 2.0), with_params = list(rate = 2.0) )
diff_probability()Distribution$diff_probability( q, lower.tail = TRUE, log.p = FALSE, with_params = list() )
qVector of points to evaluate the probability function at.
lower.tailIf TRUE, return P(X <= q). Otherwise return P(X > q).
log.pIf TRUE, probabilities are returned as log(p).
with_paramsDistribution 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.
Gradients of the cumulative probability of a Distribution
A list structure containing the cumulative (log-)probability
gradients of all free parameters of the Distribution evaluated at q.
dist_exponential()$diff_probability( c(1.0, 2.0), with_params = list(rate = 2.0) )
is_in_support()Distribution$is_in_support(x, with_params = list())
xVector of points
with_paramsDistribution 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.
Determine if a value is in the support of a Distribution
A logical vector with the same length as x indicating whether
x is part of the support of the distribution given its parameters.
dist_exponential(rate = 1.0)$is_in_support(c(-1.0, 0.0, 1.0))
is_discrete_at()Distribution$is_discrete_at(x, with_params = list())
xVector of points
with_paramsDistribution 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.
Determine if a value has positive probability
A logical vector with the same length as x indicating whether
there is a positive probability mass at x given the Distribution
parameters.
dist_dirac(point = 0.0)$is_discrete_at(c(0.0, 1.0))
tf_is_discrete_at()Distribution$tf_is_discrete_at()
Compile a TensorFlow function for discrete support checking
A tf_function taking arguments x and args returning whether
the Distribution has a point mass at x given parameters args.
has_capability()Distribution$has_capability(caps)
capsCharacter vector of capabilities
Check if a capability is present
A logical vector the same length as caps.
dist_exponential()$has_capability("density")
get_type()Distribution$get_type()
Get the type of a Distribution. Type can be one of discrete,
continuous or mixed.
A string representing the type of the Distribution.
dist_exponential()$get_type() dist_dirac()$get_type() dist_mixture(list(dist_dirac(), dist_exponential()))$get_type() dist_mixture(list(dist_dirac(), dist_binomial()))$get_type()
get_components()Distribution$get_components()
Get the component Distributions of a transformed Distribution.
A possibly empty list of Distributions
dist_trunc(dist_exponential())$get_components() dist_dirac()$get_components() dist_mixture(list(dist_exponential(), dist_gamma()))$get_components()
is_discrete()Distribution$is_discrete()
Check if a Distribution is discrete, i.e. it has a density with respect to the counting measure.
TRUE if the Distribution is discrete, FALSE otherwise.
Note that mixed distributions are not discrete but can have point masses.
dist_exponential()$is_discrete() dist_dirac()$is_discrete()
is_continuous()Distribution$is_continuous()
Check if a Distribution is continuous, i.e. it has a density with respect to the Lebesgue measure.
TRUE if the Distribution is continuous, FALSE otherwise.
Note that mixed distributions are not continuous.
dist_exponential()$is_continuous() dist_dirac()$is_continuous()
require_capability()Distribution$require_capability( caps, fun_name = paste0(sys.call(-1)[[1]], "()") )
capsCharacter vector of Capabilities to require
fun_nameFrienly text to use for generating the error message in case of failure.
Ensure that a Distribution has all required capabilities. Will throw an error if any capability is missing.
Invisibly TRUE.
dist_exponential()$require_capability("diff_density")
get_dof()Distribution$get_dof()
Get the number of degrees of freedom of a Distribution family. Only parameters without a fixed default are considered free.
An integer representing the degrees of freedom suitable e.g. for AIC calculations.
dist_exponential()$get_dof() dist_exponential(rate = 1.0)$get_dof()
get_placeholders()Distribution$get_placeholders()
Get Placeholders of a Distribution family.
Returns a list of free parameters of the family.
Their values will be NULL.
If the Distribution has Distributions as parameters, placeholders will be computed recursively.
A named list containing any combination of (named or unnamed)
lists and NULLs.
dist_exponential()$get_placeholders() dist_mixture(list(dist_dirac(), dist_exponential()))$get_placeholders()
get_params()Distribution$get_params(with_params = list())
with_paramsOptional parameter overrides with the same structure
as dist$get_params(). Given Parameter values are expected to be length
1.
Get a full list of parameters, possibly including placeholders.
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.
dist_mixture(list(dist_dirac(), dist_exponential()))$get_params( with_params = list(probs = list(0.5, 0.5)) )
tf_make_constants()Distribution$tf_make_constants(with_params = list())
with_paramsOptional parameter overrides with the same structure
as dist$tf_make_constants(). Given Parameter values are expected to be
length 1.
Get a list of constant TensorFlow parameters
A list representing the (recursive) constant parameters of the
Distribution with values sprecified by parameters. Each constant is a
TensorFlow Tensor of dtype floatx.
tf_compile_params()Distribution$tf_compile_params(input, name_prefix = "")
inputA keras layer to bind all outputs to
name_prefixPrefix to use for layer names
Compile distribution parameters into tensorflow outputs
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()
get_param_bounds()Distribution$get_param_bounds()
Get Interval bounds on all Distribution parameters
A list representing the free (recursive) parameter structure of
the Distribution with Interval objects as values representing the
bounds of the respective free parameters.
dist_mixture( list(dist_dirac(), dist_exponential()), probs = list(0.5, 0.5) )$get_param_bounds() dist_mixture( list(dist_dirac(), dist_exponential()) )$get_param_bounds() dist_genpareto()$get_param_bounds() dist_genpareto1()$get_param_bounds()
get_param_constraints()Distribution$get_param_constraints()
Get additional (non-linear) equality constraints on Distribution parameters
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
dist_mixture( list(dist_dirac(), dist_exponential()) )$get_param_constraints()
export_functions()Distribution$export_functions( name, envir = parent.frame(), with_params = list() )
namecommon suffix of the exported functions
envirEnvironment to export the functions to
with_paramsOptional list of parameters to use as default values for the exported functions
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.
Invisibly NULL.
tmp_env <- new.env(parent = globalenv()) dist_exponential()$export_functions( name = "exp", envir = tmp_env, with_params = list(rate = 2.0) ) evalq( fitdistrplus::fitdist(rexp(100), "exp"), envir = tmp_env )
clone()The objects of this class are cloneable with this method.
Distribution$clone(deep = FALSE)
deepWhether to make a deep clone.
Other Distributions:
dist_bdegp(),
dist_beta(),
dist_binomial(),
dist_blended(),
dist_dirac(),
dist_discrete(),
dist_empirical(),
dist_erlangmix(),
dist_exponential(),
dist_gamma(),
dist_genpareto(),
dist_lognormal(),
dist_mixture(),
dist_negbinomial(),
dist_normal(),
dist_pareto(),
dist_poisson(),
dist_translate(),
dist_trunc(),
dist_uniform(),
dist_weibull()
# Example for param_bounds:
# Create an Exponential Distribution with rate constrained to (0, 2)
# instead of (0, Inf)
my_exp <- dist_exponential()
my_exp$param_bounds$rate <- interval(c(0, 2))
my_exp$get_param_bounds()
fit_dist(my_exp, rexp(100, rate = 3), start = list(rate = 1))$params$rate
## ------------------------------------------------
## Method `Distribution$sample`
## ------------------------------------------------
dist_exponential(rate = 2.0)$sample(10)
## ------------------------------------------------
## Method `Distribution$density`
## ------------------------------------------------
dist_exponential()$density(c(1.0, 2.0), with_params = list(rate = 2.0))
## ------------------------------------------------
## Method `Distribution$probability`
## ------------------------------------------------
dist_exponential()$probability(
c(1.0, 2.0),
with_params = list(rate = 2.0)
)
## ------------------------------------------------
## Method `Distribution$quantile`
## ------------------------------------------------
dist_exponential()$quantile(c(0.1, 0.5), with_params = list(rate = 2.0))
## ------------------------------------------------
## Method `Distribution$hazard`
## ------------------------------------------------
dist_exponential(rate = 2.0)$hazard(c(1.0, 2.0))
## ------------------------------------------------
## Method `Distribution$diff_density`
## ------------------------------------------------
dist_exponential()$diff_density(
c(1.0, 2.0),
with_params = list(rate = 2.0)
)
## ------------------------------------------------
## Method `Distribution$diff_probability`
## ------------------------------------------------
dist_exponential()$diff_probability(
c(1.0, 2.0),
with_params = list(rate = 2.0)
)
## ------------------------------------------------
## Method `Distribution$is_in_support`
## ------------------------------------------------
dist_exponential(rate = 1.0)$is_in_support(c(-1.0, 0.0, 1.0))
## ------------------------------------------------
## Method `Distribution$is_discrete_at`
## ------------------------------------------------
dist_dirac(point = 0.0)$is_discrete_at(c(0.0, 1.0))
## ------------------------------------------------
## Method `Distribution$has_capability`
## ------------------------------------------------
dist_exponential()$has_capability("density")
## ------------------------------------------------
## Method `Distribution$get_type`
## ------------------------------------------------
dist_exponential()$get_type()
dist_dirac()$get_type()
dist_mixture(list(dist_dirac(), dist_exponential()))$get_type()
dist_mixture(list(dist_dirac(), dist_binomial()))$get_type()
## ------------------------------------------------
## Method `Distribution$get_components`
## ------------------------------------------------
dist_trunc(dist_exponential())$get_components()
dist_dirac()$get_components()
dist_mixture(list(dist_exponential(), dist_gamma()))$get_components()
## ------------------------------------------------
## Method `Distribution$is_discrete`
## ------------------------------------------------
dist_exponential()$is_discrete()
dist_dirac()$is_discrete()
## ------------------------------------------------
## Method `Distribution$is_continuous`
## ------------------------------------------------
dist_exponential()$is_continuous()
dist_dirac()$is_continuous()
## ------------------------------------------------
## Method `Distribution$require_capability`
## ------------------------------------------------
dist_exponential()$require_capability("diff_density")
## ------------------------------------------------
## Method `Distribution$get_dof`
## ------------------------------------------------
dist_exponential()$get_dof()
dist_exponential(rate = 1.0)$get_dof()
## ------------------------------------------------
## Method `Distribution$get_placeholders`
## ------------------------------------------------
dist_exponential()$get_placeholders()
dist_mixture(list(dist_dirac(), dist_exponential()))$get_placeholders()
## ------------------------------------------------
## Method `Distribution$get_params`
## ------------------------------------------------
dist_mixture(list(dist_dirac(), dist_exponential()))$get_params(
with_params = list(probs = list(0.5, 0.5))
)
## ------------------------------------------------
## Method `Distribution$get_param_bounds`
## ------------------------------------------------
dist_mixture(
list(dist_dirac(), dist_exponential()),
probs = list(0.5, 0.5)
)$get_param_bounds()
dist_mixture(
list(dist_dirac(), dist_exponential())
)$get_param_bounds()
dist_genpareto()$get_param_bounds()
dist_genpareto1()$get_param_bounds()
## ------------------------------------------------
## Method `Distribution$get_param_constraints`
## ------------------------------------------------
dist_mixture(
list(dist_dirac(), dist_exponential())
)$get_param_constraints()
## ------------------------------------------------
## Method `Distribution$export_functions`
## ------------------------------------------------
tmp_env <- new.env(parent = globalenv())
dist_exponential()$export_functions(
name = "exp",
envir = tmp_env,
with_params = list(rate = 2.0)
)
evalq(
fitdistrplus::fitdist(rexp(100), "exp"),
envir = tmp_env
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.