round_stochastic {pomdp}R Documentation

Round a stochastic vector or a row-stochastic matrix

Description

Rounds a vector such that the sum of 1 is preserved. Rounds a matrix such that the rows still sum up to 1.

Usage

round_stochastic(x, digits = getOption("digits"))

Arguments

x

a stochastic vector or a row-stochastic matrix.

digits

number of digits for rounding.

Details

Rounds and adjusts one entry such that the rounding error is the smallest.

Value

The rounded vector or matrix.

See Also

round

Examples

# a vector that is off by 1e-8
x <- c(0.25 + 1e-8, 0.25, 0.5)

round_stochastic(x)
round_stochastic(x, digits = 2)
round_stochastic(x, digits = 1)
round_stochastic(x, digits = 0)

[Package pomdp version 1.0.3 Index]