Skip to contents

The distribution of f(X) on the same step. Each point's mass moves to f(x); a value between two points is split between them so its mean is kept. The mean is therefore always exact, and the whole distribution is exact when every value lands on a point.

Usage

map_grid(x, f)

Arguments

x

A grid_distribution.

f

A function of one loss returning a finite, non-negative number; called once per point with mass.

Value

A list with grid (a grid_distribution) and on_points (whether every value landed on a grid point).

Examples

x <- grid_distribution(1, c(0.2, 0.3, 0.3, 0.2))
r <- map_grid(x, function(v) min(max(v - 1, 0), 1))
r$grid@probs
#> [1] 0.5 0.5
r$on_points
#> [1] TRUE