func (h *HiddenLayer) BackwardWithTarget(predicted, target []float64) []float64 { delta := make([]float64, h.NumHiddenUnits) for i := 0; i < h.NumHiddenUnits; i++ { delta[i] = (predicted[i] - target[i]) * nnet.DSigmoid(predicted[i]) } return delta }
func (h *HiddenLayer) Backward(predicted, accumulateDelta []float64) []float64 { delta := make([]float64, h.NumHiddenUnits) for i := 0; i < h.NumHiddenUnits; i++ { delta[i] = accumulateDelta[i] * nnet.DSigmoid(predicted[i]) } return delta }
func (net *NeuralNetwork) ComputeDelta(predicted, target []float64) ([]float64, []float64) { outputDelta := make([]float64, len(net.OutputLayer)) hiddenDelta := make([]float64, len(net.HiddenLayer)) // Output Delta for i := 0; i < len(net.OutputLayer); i++ { outputDelta[i] = (predicted[i] - target[i]) * nnet.DSigmoid(predicted[i]) } // Hidden Delta for i := 0; i < len(net.HiddenLayer); i++ { sum := 0.0 for j := range net.OutputLayer { sum += net.OutputWeight[i][j] * outputDelta[j] } hiddenDelta[i] = sum * nnet.DSigmoid(net.HiddenLayer[i]) } return outputDelta, hiddenDelta }