Skip to content

Commit

Permalink
binary log loss correction
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikeh committed Jan 29, 2018
1 parent c474100 commit 45fd2f4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions loss.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ func (l CrossEntropy) Df(estimate, ideal, activation float64) float64 {
type BinaryCrossEntropy struct{}

func (l BinaryCrossEntropy) F(estimate, ideal [][]float64) float64 {
epsilon := 1e-16
var sum float64
for i := range estimate {
ce := 0.0
for j := range estimate[i] {
ce += ideal[i][j]*math.Log(estimate[i][j]) + (1-ideal[i][j])*math.Log(1-estimate[i][j])
ce += ideal[i][j] * (math.Log(estimate[i][j]+epsilon) - (1-ideal[i][j])*math.Log(1-estimate[i][j]+epsilon))
}
sum -= ce
}
return sum / float64(len(estimate))
return sum
}

func (l BinaryCrossEntropy) Df(estimate, ideal, activation float64) float64 {
Expand Down

0 comments on commit 45fd2f4

Please sign in to comment.