From 00d483697a6e395ef6776320cd1e52a04f4367be Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Wed, 30 Apr 2014 23:17:40 +0000
Subject: [PATCH] Small updates
---
src/activations.c | 34 +++++++++++++++++++++++++++++-----
1 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/src/activations.c b/src/activations.c
index c81d6aa..24868a3 100644
--- a/src/activations.c
+++ b/src/activations.c
@@ -34,21 +34,37 @@
return RELU;
}
+float linear_activate(float x){return x;}
+float sigmoid_activate(float x){return 1./(1. + exp(-x));}
+float relu_activate(float x){return x*(x>0);}
+float ramp_activate(float x){return x*(x>0)+.1*x;}
+float tanh_activate(float x){return (exp(2*x)-1)/(exp(2*x)+1);}
+
float activate(float x, ACTIVATION a){
switch(a){
case LINEAR:
- return x;
+ return linear_activate(x);
case SIGMOID:
- return 1./(1.+exp(-x));
+ return sigmoid_activate(x);
case RELU:
- return x*(x>0);
+ return relu_activate(x);
case RAMP:
- return x*(x>0) + .1*x;
+ return ramp_activate(x);
case TANH:
- return (exp(2*x)-1)/(exp(2*x)+1);
+ return tanh_activate(x);
}
return 0;
}
+
+void activate_array(float *x, const int n, const ACTIVATION a)
+{
+ int i;
+ for(i = 0; i < n; ++i){
+ x[i] = activate(x[i], a);
+ }
+}
+
+
float gradient(float x, ACTIVATION a){
switch(a){
case LINEAR:
@@ -65,3 +81,11 @@
return 0;
}
+void gradient_array(const float *x, const int n, const ACTIVATION a, float *delta)
+{
+ int i;
+ for(i = 0; i < n; ++i){
+ delta[i] *= gradient(x[i], a);
+ }
+}
+
--
Gitblit v1.10.0