Learn R Programming

modello (version 0.1.1)

cross.entropy.modello_number: Cross-entropy

Description

Cross-entropy (Negaitve Multinomial log-likelihood) $$\sum_i{y_i * log(\hat y_i)}$$

Usage

# S3 method for modello_number
cross.entropy(y, yh)

# S3 method for default cross.entropy(y, yh)

cross.entropy(y, yh)

Arguments

y

predicted probability

yh

target classes (0 or 1)

Value

Returns the entropy

Examples

Run this code
# NOT RUN {
modello.init(10, 10, 10, 10)
## For modello_numbers
y = number(matrix({x=sample(c(1, 0), 5, replace=TRUE); c(x, 1-x)}, 5, 2), dx=FALSE)
yh = number(t(apply(matrix(runif(10), 5, 2), 1, function(x)x/sum(x))))
h = cross.entropy(y, yh)
print(h)
print(h$v)
modello.close()
## For numerics
y = matrix({x=sample(c(1, 0), 5, replace=TRUE); c(x, 1-x)}, 5, 2)
yh = t(apply(matrix(runif(10), 5, 2), 1, function(x)x/sum(x)))
h = cross.entropy(y, yh)
print(h)
# }

Run the code above in your browser using DataLab