DiscretizedFunction: Creates a function based on a regular discretization

View source: R/helpers.R

DiscretizedFunctionR Documentation

Creates a function based on a regular discretization

Description

A simple fast tool for defining a discretized function defined continuously on [a,b] and discrete values in X, with equidistant data values y in between. The resulting function is vectorized and interpolates linearily with errors or NA outside the region. It handles infinite supports, but not infinite results on the continuous region.

Usage

DiscretizedFunction(y, ...)

## S3 method for class 'numeric'
DiscretizedFunction(y, ..., support = Support(...), transferCdf = NULL)

## S3 method for class ''function''
DiscretizedFunction(
  y,
  a = 0,
  b = a,
  n = 501,
  X = c(),
  transferCdf = NULL,
  transferQf = cdf2qf(transferCdf, ...),
  ...
)

## S3 method for class 'Discretizer'
DiscretizedFunction(y, Y, ...)

## S3 method for class 'ReferenceMeasureTransformed'
DiscretizedFunction(y, f, n = 513, support = getSupport(y), ...)

## S3 method for class 'ReferenceMeasureUniform'
DiscretizedFunction(y, f, n = 513, support = getSupport(y), ...)

Arguments

y

the function to be approximated, or evaluation values, first those for X and than those equidistantly spaced xmin and xmax (in the image of transferCdf), or ReferenceMeasure on which to define the function (in this case the function is reported is given in f)

...

further arguments for Support (a,b,X)

support

the [Support] on which the function shall be defined.

transferCdf

a transfer function mapping the interval a,b to [0,1] (or another interval), in which the nots are place equidistantly and are interpolated linearily.

a

the lower limit of the domain

b

the upper limit of the domain

n

the number of discretization points on [a,b]

X

the discrete elements of the support (i.e. positions, where the function may jump.

transferQf

(qunantile function), must be the inverse of transferCdf and is used to determine the evaluation points for the function.

Y

replaces y, if y is a Discretizer

f

the function to be approximated (only if y is a ReferenceMeasure)

Value

a function interpolating linearly between the given evaluation points and working in a vectorized form.

Methods (by class)

  • DiscretizedFunction(numeric): method for precomputed values

  • DiscretizedFunction(`function`): method for functions that need to be computed first.

  • DiscretizedFunction(Discretizer): method for Discretizer

  • DiscretizedFunction(ReferenceMeasureTransformed): method for functions on Transformed Reference measures.

  • DiscretizedFunction(ReferenceMeasureUniform): method for functions on Transformed Reference measures.

Examples

x=seq(0,1,length.out=100)
f = DiscretizedFunction(sin(x),0,1)
x=seq(0,1,length.out=1000)
max(abs(f(x)-sin(x)))

DistributionalDDA documentation built on Oct. 20, 2026, 5:06 p.m.