commit 6c4d6b46e089a713edd9794f768b77bc9584a33c
parent a0397e9d06b20bb81695383ceb78a5dcb49de32f
Author: David Freifeld <freifeld.david@gmail.com>
Date: Wed, 24 Jun 2020 19:19:13 -0700
Added proper activation setting function
Diffstat:
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/bpnn.cpp b/bpnn.cpp
@@ -75,6 +75,29 @@ Network::Network(char* path, int inputs, int hidden, int outputs, int neurons, i
batches = 1;
}
+void Network::set_activation(int index, char* name)
+{
+ if (strcmp(name, "sigmoid") == 0) {
+ layers[index].activation = &sigmoid;
+ layers[index].activation_deriv = &sigmoid_deriv;
+ }
+ else if (strcmp(name, "linear") == 0) {
+ layers[index].activation = &linear;
+ layers[index].activation_deriv = &linear_deriv;
+ }
+ else if (strcmp(name, "relu") == 0) {
+ layers[index].activation = &relu;
+ layers[index].activation_deriv = &relu_deriv;
+ }
+ else if (strcmp(name, "resig") == 0) {
+ layers[index].activation = &resig;
+ layers[index].activation_deriv = &resig_deriv;
+ }
+ else {
+ std::cout << "Warning! Incorrect activation specified. Ignoring...\n";
+ }
+}
+
void Network::feedforward()
{
for (int j = 0; j < layers[0].contents->rows(); j++) {
diff --git a/bpnn.hpp b/bpnn.hpp
@@ -45,7 +45,8 @@ public:
Network(char* path, int inputs, int hidden, int outputs, int neurons, int batch_sz, float rate);
void update_layer(float* vals, int datalen, int index);
-
+ void set_activation(int index, char* activation);
+
Eigen::MatrixXd init_ones(Eigen::MatrixXd matrix);
void feedforward();
void list_net();