Skip to contents

Softmax cross-entropy cost (morie.fn grxent)

Usage

morie_geron_softmax_cross_entropy_cost(X, Y, theta)

Arguments

X, theta

Design and (n, K) parameters.

Y

0-based labels or a one-hot matrix.

Value

List with cost, per_instance, probabilities, accuracy.

Examples

set.seed(7)
X <- cbind(1, rnorm(20))
Y <- diag(3)[sample(1:3, 20, replace = TRUE), ]
theta <- matrix(0, 2, 3)
morie_geron_softmax_cross_entropy_cost(X, Y, theta)
#> $cost
#> [1] 1.098612
#> 
#> $per_instance
#>  [1] 1.098612 1.098612 1.098612 1.098612 1.098612 1.098612 1.098612 1.098612
#>  [9] 1.098612 1.098612 1.098612 1.098612 1.098612 1.098612 1.098612 1.098612
#> [17] 1.098612 1.098612 1.098612 1.098612
#> 
#> $probabilities
#>            [,1]      [,2]      [,3]
#>  [1,] 0.3333333 0.3333333 0.3333333
#>  [2,] 0.3333333 0.3333333 0.3333333
#>  [3,] 0.3333333 0.3333333 0.3333333
#>  [4,] 0.3333333 0.3333333 0.3333333
#>  [5,] 0.3333333 0.3333333 0.3333333
#>  [6,] 0.3333333 0.3333333 0.3333333
#>  [7,] 0.3333333 0.3333333 0.3333333
#>  [8,] 0.3333333 0.3333333 0.3333333
#>  [9,] 0.3333333 0.3333333 0.3333333
#> [10,] 0.3333333 0.3333333 0.3333333
#> [11,] 0.3333333 0.3333333 0.3333333
#> [12,] 0.3333333 0.3333333 0.3333333
#> [13,] 0.3333333 0.3333333 0.3333333
#> [14,] 0.3333333 0.3333333 0.3333333
#> [15,] 0.3333333 0.3333333 0.3333333
#> [16,] 0.3333333 0.3333333 0.3333333
#> [17,] 0.3333333 0.3333333 0.3333333
#> [18,] 0.3333333 0.3333333 0.3333333
#> [19,] 0.3333333 0.3333333 0.3333333
#> [20,] 0.3333333 0.3333333 0.3333333
#> 
#> $accuracy
#> [1] 0.45
#> 
#> $estimate
#> [1] 1.098612
#> 
#> $n
#> [1] 20
#>