12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package gradients
- import (
- neuralnetwork "git.semlanik.org/semlanik/NeuralNetwork/neuralnetwork"
- mat "gonum.org/v1/gonum/mat"
- )
- type backPropGradient struct {
- alpha float64
- }
- func NewBackPropInitializer(nu float64) neuralnetwork.GradientDescentInitializer {
- return func(nn *neuralnetwork.NeuralNetwork, layer, gradientType int) interface{} {
- return newBackPropGradient(nu / float64(nn.Sizes[0]))
- }
- }
- func newBackPropGradient(a float64) (g *backPropGradient) {
- g = &backPropGradient{alpha: a}
- return
- }
- func (g *backPropGradient) ApplyDelta(m mat.Matrix, gradient mat.Matrix) (result *mat.Dense) {
-
-
-
- scaled := &mat.Dense{}
- result = &mat.Dense{}
-
- scaled.Scale(g.alpha, gradient)
-
- result.Sub(m, scaled)
- return result
- }
|