This repository has been archived on 2024-04-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
elektron/vendor/github.com/montanaflynn/stats/sigmoid.go
Pradyumna Kaushik bac60e872a Unit testing for def/ module.
Added unit tests to test code in def/ module.
2019-10-12 06:48:45 +00:00

18 lines
455 B
Go

package stats
import "math"
// Sigmoid returns the input values in the range of -1 to 1
// along the sigmoid or s-shaped curve, commonly used in
// machine learning while training neural networks as an
// activation function.
func Sigmoid(input Float64Data) ([]float64, error) {
if input.Len() == 0 {
return Float64Data{}, EmptyInput
}
s := make([]float64, len(input))
for i, v := range input {
s[i] = 1 / (1 + math.Exp(-v))
}
return s, nil
}