12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package neuralnetworkbase
- import (
- math "math"
- rand "math/rand"
- "time"
- mat "gonum.org/v1/gonum/mat"
- )
- func generateRandomDense(rows, columns int) *mat.Dense {
- rand.Seed(time.Now().UnixNano())
- data := make([]float64, rows*columns)
- for i := range data {
- data[i] = rand.NormFloat64()
- }
- return mat.NewDense(rows, columns, data)
- }
- func applySigmoid(_, _ int, x float64) float64 {
- return sigmoid(x)
- }
- func applySigmoidPrime(_, _ int, x float64) float64 {
- return sigmoidPrime(x)
- }
- func sigmoid(x float64) float64 {
- return 1.0 / (1.0 + math.Exp(-x))
- }
- func sigmoidPrime(x float64) float64 {
- return sigmoid(x) * (1 - sigmoid(x))
- }
- func makeBackGradien(in mat.Matrix, actual mat.Matrix, alpha float64) *mat.Dense {
- scaled := &mat.Dense{}
- result := &mat.Dense{}
- scaled.Scale(alpha, in)
- result.Sub(actual, scaled)
- return result
- }
|