Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

normalize

Normalize a matrix/vector to sum to one (probability simplex)


Description

normalize projects a vector or matrix onto the probability simplex.

If all entries (per row or column) get thresholded to 0 (since they are all negative to start with), then it sets the position of the maximum of x to 1 and leaves all other entries at 0.

Usage

normalize(x, byrow = TRUE, tol = 1e-06)

Arguments

x

a numeric matrix(like object).

byrow

logical; if TRUE rows are normalized; otherwise columns.

tol

a tolerance level to set values < tol to 0 (after an initial normalization). Default: tol=1e-6

Value

If x is a vector it returns the thresholded vector (see threshold) and normalized by its sum. If x is a matrix it works by column of by row (argument byrow).

See Also

Examples

print(normalize(c(1, 4, 2, 2, 10)))
print(normalize(c(-1, -2, -1)))
AA <- matrix(rnorm(12), ncol = 3)
print(normalize(AA, byrow = TRUE))
print(normalize(AA, byrow = FALSE))

LICORS

Light Cone Reconstruction of States - Predictive State Estimation From Spatio-Temporal Data

v0.2.0
GPL-2
Authors
Georg M. Goerg <gmg@stat.cmu.edu>
Initial release
2013-11-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.