aboutsummaryrefslogtreecommitdiff
path: root/src/mlp.c
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2012-09-14 15:49:18 -0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2012-09-14 15:49:18 -0400
commit027ff070f0bf322eb6f940001e7c78f10a8ee0f4 (patch)
treed7c7dede665f018290e38b888b3c616428612ee6 /src/mlp.c
parent97a48473acee2d3c2ec2f5a619dad6078874af23 (diff)
downloadlibopus-027ff070f0bf322eb6f940001e7c78f10a8ee0f4.tar.gz
Shrinks tansig table, makes data static const
Diffstat (limited to 'src/mlp.c')
-rw-r--r--src/mlp.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/mlp.c b/src/mlp.c
index 200f1cb3..dd3690db 100644
--- a/src/mlp.c
+++ b/src/mlp.c
@@ -64,16 +64,22 @@ static inline double tansig_approx(double x)
{
int i;
double y, dy;
- if (x>=10)
- return 1;
- if (x<=-10)
- return -1;
+ double sign=1;
+ if (x>=8)
+ return 1;
+ if (x<=-8)
+ return -1;
+ if (x<0)
+ {
+ x=-x;
+ sign=-1;
+ }
i = lrint(25*x);
x -= .04*i;
- y = tansig_table[250+i];
+ y = tansig_table[i];
dy = 1-y*y;
y = y + x*dy*(1 - y*x);
- return y;
+ return sign*y;
}
#endif