Learn R Programming

modello (version 0.1.1)

softmax.modello_number: Number Softmax

Description

Calculates the Softmax function $$sofmax = \frac{exp(\bf x)}{\sum{exp(\bf x)}}$$

Usage

# S3 method for modello_number
softmax(x, k = 0)

# S3 method for numeric softmax(x, k = 0)

# S3 method for matrix softmax(x, k = 0)

softmax(x, k)

Arguments

x

a 'numeric' or a reference object of class 'number'

k

dimension index. Currently constained to be <= 2

Value

Returns a 'numeric' or reference object of class 'number'

Examples

Run this code
# NOT RUN {
modello.init(10, 10, 10, 10)
## For modello_number matrices
x = number(matrix(rnorm(9), 3, 3))
y1 = softmax(x)
print(y1)
print(y1$v)
y2 = softmax(x, 1)
print(y2)
print(y2$v)
y3 = softmax(x, 2)
print(y3)
print(y3$v)
modello.close()
## For numerics
x = rnorm(5)
y = softmax(x)
print(y)
## For matrices
x = matrix(rnorm(9), 3, 3)
y1 = softmax(x)
print(y1)
y2 = softmax(x, 1)
print(y2)
y3 = softmax(x, 2)
print(y3)
# }

Run the code above in your browser using DataLab