aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjvech <jmvalenciae@unal.edu.co>2024-07-18 21:42:38 -0500
committerjvech <jmvalenciae@unal.edu.co>2024-07-18 21:42:38 -0500
commit4a5b6b12040a87dd8319a735cc48f31a2d140e3a (patch)
treed82e7f1610de7d68710cf8d015bf554624453bd8 /src
parentd6db47f94e9b72c551000326172219f4fe7a23a4 (diff)
add: linear activation added
Diffstat (limited to 'src')
-rw-r--r--src/activations.c10
-rw-r--r--src/main.c2
2 files changed, 12 insertions, 0 deletions
diff --git a/src/activations.c b/src/activations.c
index 7a2d6a7..064482d 100644
--- a/src/activations.c
+++ b/src/activations.c
@@ -28,6 +28,8 @@ double sigmoid(double x);
double dsigmoid(double x);
double softplus(double x);
double dsoftplus(double x);
+double linear(double x);
+double dlinear(double x);
struct Activation NN_LEAKY_RELU = {
.func = leaky_relu,
@@ -49,6 +51,14 @@ struct Activation NN_SIGMOID = {
.dfunc = dsigmoid
};
+struct Activation NN_LINEAR = {
+ .func = linear,
+ .dfunc = dlinear,
+};
+
+double linear(double x) {return x;}
+double dlinear(double x) {return 1.0;}
+
double sigmoid(double x) { return 1 / (1 + exp(-x)); }
double dsigmoid(double x) { return sigmoid(x) * (1 - sigmoid(x)); }
diff --git a/src/main.c b/src/main.c
index 8718a66..f3e6750 100644
--- a/src/main.c
+++ b/src/main.c
@@ -170,6 +170,7 @@ Layer * load_network(struct Configs cfg)
extern struct Activation NN_SOFTPLUS;
extern struct Activation NN_SIGMOID;
extern struct Activation NN_LEAKY_RELU;
+ extern struct Activation NN_LINEAR;
Layer *network = ecalloc(cfg.network_size, sizeof(Layer));
@@ -178,6 +179,7 @@ Layer * load_network(struct Configs cfg)
else if (!strcmp("sigmoid", cfg.activations[i])) network[i].activation = NN_SIGMOID;
else if (!strcmp("softplus", cfg.activations[i])) network[i].activation = NN_SOFTPLUS;
else if (!strcmp("leaky_relu", cfg.activations[i])) network[i].activation = NN_LEAKY_RELU;
+ else if (!strcmp("linear", cfg.activations[i])) network[i].activation = NN_LINEAR;
else die("load_network() Error: Unknown '%s' activation", cfg.activations[i]);
network[i].neurons = cfg.neurons[i];
Feel free to download, copy and edit any repo