# safeSoftMax: Safe softmax function for computing weights In sdetorus: Statistical Tools for Toroidal Diffusions

## Description

Computes the weights w_i = \frac{e^{p_i}}{∑_{j=1}^k e^{p_j}} from p_i, i=1,…,k in a safe way to avoid overflows and to truncate automatically to zero low values of w_i.

## Usage

 1 safeSoftMax(logs, expTrc = 30) 

## Arguments

 logs matrix of logarithms where each row contains a set of p_1,…,p_k to compute the weights from. expTrc truncation for exponential: exp(x) with x <= -expTrc is set to zero. Defaults to 30.

## Details

The logs argument must be always a matrix.

## Value

A matrix of the size as logs containing the weights for each row.

## Examples

 1 2 3 4 5 6 7 # A matrix safeSoftMax(rbind(1:10, 20:11)) rbind(exp(1:10) / sum(exp(1:10)), exp(20:11) / sum(exp(20:11))) # A row-matrix safeSoftMax(rbind(-100:100), expTrc = 30) exp(-100:100) / sum(exp(-100:100)) 

sdetorus documentation built on Aug. 19, 2021, 9:06 a.m.