From e99043d4ac7412554fc0d3ed95e79fe6fbb62ddc Mon Sep 17 00:00:00 2001 From: Mikatech Date: Thu, 4 Aug 2022 23:25:04 +0200 Subject: [PATCH] feat(neural): add tanh func & derivate in neural funcs pkg --- neural/funcs.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/neural/funcs.go b/neural/funcs.go index 48bf3db8..cbf5b8c6 100644 --- a/neural/funcs.go +++ b/neural/funcs.go @@ -12,6 +12,14 @@ var Sigmoid NeuralFunction = NeuralFunction{ func(v float64) float64 { return v * (1 - v) }, } +// TanhForward function does tanh(t) = \frac{1 - e^{-2t}}{1 + e^{-2t}} +// +// See https://en.wikipedia.org/wiki/Hyperbolic_functions +var Tanh NeuralFunction = NeuralFunction{ + func(v float64) float64 { return math.Tanh(v) }, + func(v float64) float64 { return 1 - (v * v) }, +} + // LinearFunction doesn't modify the value var Linear NeuralFunction = NeuralFunction{ func(v float64) float64 { return v },