round_stochastic {pomdp} | R Documentation |
Rounds a vector such that the sum of 1 is preserved. Rounds a matrix such that the rows still sum up to 1.
round_stochastic(x, digits = getOption("digits"))
x |
a stochastic vector or a row-stochastic matrix. |
digits |
number of digits for rounding. |
Rounds and adjusts one entry such that the rounding error is the smallest.
The rounded vector or matrix.
# 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)