Jensen-holm commited on
Commit
27c0b63
·
1 Parent(s): fae8f77

adding activation funcs

Browse files
Files changed (2) hide show
  1. alg/interface.go +0 -6
  2. nn/activation.go +29 -7
alg/interface.go DELETED
@@ -1,6 +0,0 @@
1
- package alg
2
-
3
- type Alg interface {
4
- New()
5
- Train()
6
- }
 
 
 
 
 
 
 
nn/activation.go CHANGED
@@ -1,19 +1,41 @@
1
  package nn
2
 
3
- var ActivationMap = map[string]func(){
 
 
4
  "sigmoid": Sigmoid,
5
  "tanh": Tanh,
6
  "relu": Relu,
7
  }
8
 
9
- func Sigmoid() {}
 
 
10
 
11
- func SigmoidPrime() {}
 
 
 
12
 
13
- func Tanh() {}
 
 
14
 
15
- func TanhPrime() {}
 
 
16
 
17
- func Relu() {}
 
 
 
 
 
18
 
19
- func ReluPrime() {}
 
 
 
 
 
 
 
1
  package nn
2
 
3
+ import "math"
4
+
5
+ var ActivationMap = map[string]func(float64) float64{
6
  "sigmoid": Sigmoid,
7
  "tanh": Tanh,
8
  "relu": Relu,
9
  }
10
 
11
+ func Sigmoid(x float64) float64 {
12
+ return 1.0 / (1.0 + math.Exp(-x))
13
+ }
14
 
15
+ func SigmoidPrime(x float64) float64 {
16
+ s := Sigmoid(x)
17
+ return s / (1.0 - s)
18
+ }
19
 
20
+ func Tanh(x float64) float64 {
21
+ return math.Tanh(x)
22
+ }
23
 
24
+ func TanhPrime(x float64) float64 {
25
+ return math.Pow((1.0 / math.Cosh(x)), 2)
26
+ }
27
 
28
+ func Relu(x float64) float64 {
29
+ if x > 0 {
30
+ return x
31
+ }
32
+ return 0
33
+ }
34
 
35
+ func ReluPrime(x float64) float64 {
36
+ // maybe want to look into edge case if x == 0
37
+ if x > 0 {
38
+ return 1
39
+ }
40
+ return 0
41
+ }