Learn R Programming

pauwels2014 (version 1.0)

log_normalize: Normalize in log space

Description

Binding to a C implementation of addition and normalization in log space.

Usage

log_normalize(vals, maxi = max(vals), ID = which.max(vals)[1])

Arguments

vals
Log-values to be normalize
maxi
The maximum value of vals
ID
One entry of vals which has the highest value.

Value

A list with three slots. First one is a numerical vector with values normalized so that they sum to 1. The second is the same normalized vector in log space. The last one is the log of the normalization constant. See example.

Examples

Run this code
log_x <- rnorm(10)

temp <- log_normalize(log_x)

exp(temp[[2]]) - temp[[1]]

sum(exp(temp[[2]]))

log_x - temp[[3]] - temp[[2]]

Run the code above in your browser using DataLab