commit a3307fb7ab76fb5c9425432d8bc2df4f2578b942
parent 426f547dae88c561fd26dd095d00229769c7566f
Author: David Freifeld <freifeld.david@gmail.com>
Date: Fri, 26 Jun 2020 17:37:19 -0700
Incorporating MR update + 3 new activations
Diffstat:
4 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/bpnn.cpp b/bpnn.cpp
@@ -69,6 +69,18 @@ void Network::add_layer(int nodes, char* name)
layers[length-1].activation = lecun_tanh;
layers[length-1].activation_deriv = lecun_tanh_deriv;
}
+ else if (strcmp(name, "inverse_logit") == 0) {
+ layers[length-1].activation = inverse_logit;
+ layers[length-1].activation_deriv = inverse_logit_deriv;
+ }
+ else if (strcmp(name, "cloglog") == 0) {
+ layers[length-1].activation = cloglog;
+ layers[length-1].activation_deriv = cloglog_deriv;
+ }
+ else if (strcmp(name, "softplus") == 0) {
+ layers[length-1].activation = softplus;
+ layers[length-1].activation_deriv = softplus_deriv;
+ }
else if (strcmp(name, "relu") == 0) {
layers[length-1].activation = rectifier(linear);
layers[length-1].activation_deriv = rectifier(linear_deriv);
diff --git a/bpnn.hpp b/bpnn.hpp
@@ -3,9 +3,7 @@
#include "/Users/davidfreifeld/Downloads/eigen-3.3.7/Eigen/Dense"
-extern "C" {
- #include "../mapreduce/mapreduce.h"
-}
+#include "../mapreduce/mapreduce.hpp"
#include <vector>
#include <array>
diff --git a/utils.cpp b/utils.cpp
@@ -20,9 +20,18 @@ double linear_deriv(double x) {return 1;}
double lecun_tanh(double x) {return 1.7159 * tanh((2.0/3) * x);}
double lecun_tanh_deriv(double x) {return 1.14393 * pow(1.0/cosh(2.0/3 * x),2);}
-double tanh(double x) {return tanh(x);} // For sake of symmetry.
+double tanh(double x) {return tanh(x);}
double tanh_deriv(double x) {return pow(1.0/cosh(x),2);}
+double inverse_logit(double x) {return (exp(x)/(exp(x)+1));}
+double inverse_logit_deriv(double x) {return (exp(x)/pow(exp(x)+1, 2));}
+
+double softplus(double x) {return log(1+exp(x));}
+double softplus_deriv(double x) {return exp(x)/(exp(x)+1);}
+
+double cloglog(double x) {return 1-exp(-exp(x));}
+double cloglog_deriv(double x) {return exp(x-exp(x));}
+
double step(double x)
{
if (x > 0) return 1;
diff --git a/utils.hpp b/utils.hpp
@@ -13,6 +13,12 @@ double bipolar(double x);
double bipolar_deriv(double x);
double lecun_tanh(double x);
double lecun_tanh_deriv(double x);
+double cloglog(double x);
+double cloglog_deriv(double x);
+double softplus(double x);
+double softplus_deriv(double x);
+double inverse_logit(double x);
+double inverse_logit_deriv(double x);
std::function<double(double)> rectifier(double (*activation)(double));
uintmax_t wc(char const *fname);