blob: e91c046eebaf7cc6c4741a368be99790b8ee6122 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/////////////////////////////////////////////////////////////////////////////
//
// NNActivation.h
//
// all the activation functions of the neurons
//
// header file
//
// Copyright (c) 2005 Georg Holzmann <grh@gmx.at>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef _INCLUDE_ACTIVATION_NET__
#define _INCLUDE_ACTIVATION_NET__
#include <math.h>
namespace TheBrain
{
//------------------------------------------------------
/* implementation of the different activation functions
* and it's derivations
*/
/* Linear activation function.
* span: -inf < y < inf
* y = x
*/
#define LINEAR 0
/* Sigmoid activation function.
* span: 0 < y < 1
* y = 1/(1 + exp(-x)), y' = y*(1 - y)
*/
#define SIGMOID 1
/* Symmetric sigmoid activation function, aka. tanh.
* span: -1 < y < 1
* y = tanh(x) = 2/(1 + exp(-2*x)) - 1, d = 1-(y*y)
*/
#define TANH 2
// linear function
float act_linear(float value)
{ return value; }
// derivation of the linear function
float act_linear_derive(float value)
{ return 1; }
// sigmoid function
float act_sigmoid(float value)
{ return (1.0f/(1.0f + exp(-value))); }
// derivation of the sigmoid function
float act_sigmoid_derive(float value)
{ return (value * (1.0f - value)); }
// tanh function
float act_tanh(float value)
{ return (2.0f/(1.0f + exp(-2.0f * value)) - 1.0f); }
// derivation of the tanh function
float act_tanh_derive(float value)
{ return (1.0f - (value*value)); }
} // end of namespace
#endif // _INCLUDE_ACTIVATION_NET__
|