-
Notifications
You must be signed in to change notification settings - Fork 0
/
loss_test.go
42 lines (38 loc) · 910 Bytes
/
loss_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package deep
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_Loss(t *testing.T) {
tests := []struct {
loss LossType
input, target [][]float64
res float64
}{
{
loss: LossMeanSquared,
input: [][]float64{{0.5, 1.0, 1.5}},
target: [][]float64{{0.0, 2.0, 2.0}},
res: 0.5,
},
{
loss: LossCrossEntropy,
input: [][]float64{{0.5, 1.0, 1.5}},
target: [][]float64{{0.0, 1.0, 1.0}},
res: -0.4,
},
{
loss: LossBinaryCrossEntropy,
input: [][]float64{{0.5}},
target: [][]float64{{0.5}},
res: 0.69,
},
}
for _, test := range tests {
loss := GetLoss(test.loss)
estimate := loss.F(test.input, test.target)
assert.InEpsilon(t, test.res, estimate, 1e-1, fmt.Sprintf("%s estimate: %.2f expected: %.2f", test.loss.String(), estimate, test.res))
assert.NotEqual(t, "N/A", test.loss.String())
}
}