func entropyOverColumns(matrix [][]float64) float64 { returnValue, total := 0.0, 0.0 var sumForColumn float64 for j := range matrix[0] { sumForColumn = 0 for i := range matrix { sumForColumn += matrix[i][j] } returnValue = returnValue - lnFunc(sumForColumn) total += sumForColumn } if utils.Eq(total, 0) { return 0 } return (returnValue + lnFunc(total)) / (total * math.Log(2)) }
func entropyConditionedOnRows(matrix [][]float64) float64 { returnValue, total := 0.0, 0.0 var sumForRow float64 for i := range matrix { sumForRow = 0 for j := range matrix[0] { returnValue = returnValue + lnFunc(matrix[i][j]) sumForRow += matrix[i][j] } returnValue = returnValue - lnFunc(sumForRow) total += sumForRow } if utils.Eq(total, 0) { return 0 } return -returnValue / (total * math.Log(2)) }