Unit testing for def/ module.
Added unit tests to test code in def/ module.
This commit is contained in:
parent
e24b8a08c9
commit
bac60e872a
396 changed files with 83991 additions and 13209 deletions
25
vendor/github.com/montanaflynn/stats/softmax.go
generated
vendored
Normal file
25
vendor/github.com/montanaflynn/stats/softmax.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
package stats
|
||||
|
||||
import "math"
|
||||
|
||||
// SoftMax returns the input values in the range of 0 to 1
|
||||
// with sum of all the probabilities being equal to one. It
|
||||
// is commonly used in machine learning neural networks.
|
||||
func SoftMax(input Float64Data) ([]float64, error) {
|
||||
if input.Len() == 0 {
|
||||
return Float64Data{}, EmptyInput
|
||||
}
|
||||
|
||||
s := 0.0
|
||||
c, _ := Max(input)
|
||||
for _, e := range input {
|
||||
s += math.Exp(e - c)
|
||||
}
|
||||
|
||||
sm := make([]float64, len(input))
|
||||
for i, v := range input {
|
||||
sm[i] = math.Exp(v-c) / s
|
||||
}
|
||||
|
||||
return sm, nil
|
||||
}
|
Reference in a new issue