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 each row sum up to 1. One entry is adjusted after rounding such that the rounding error is the smallest.
Usage
round_stochastic(x, digits = 7)
Arguments
x |
a stochastic vector or a row-stochastic matrix. |
digits |
number of digits for rounding. |
Value
The rounded vector or matrix.
See Also
Examples
# regular rounding would not sum up to 1
x <- c(0.333, 0.334, 0.333)
round_stochastic(x)
round_stochastic(x, digits = 2)
round_stochastic(x, digits = 1)
round_stochastic(x, digits = 0)
# round a stochastic matrix
m <- matrix(runif(15), ncol = 3)
m <- sweep(m, 1, rowSums(m), "/")
m
round_stochastic(m, digits = 2)
round_stochastic(m, digits = 1)
round_stochastic(m, digits = 0)
[Package pomdp version 1.2.3 Index]