Diwa
Lightweight implementation of Artificial Neural Network for resource-constrained environments
Loading...
Searching...
No Matches
diwa_activations.h
Go to the documentation of this file.
1/*
2 * This file is part of the Diwa library.
3 * Copyright (c) 2024 Nathanne Isip
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
44#ifndef DIWA_ACTIVATIONS_H
45#define DIWA_ACTIVATIONS_H
46
47#include <math.h>
48
49#define DIWA_ACTFUNC_LOWER_BOUND -30.0f
50#define DIWA_ACTFUNC_UPPER_BOUND 30.0f
58typedef double (*diwa_activation)(double);
59
67class DiwaActivationFunc final {
68public:
79 static inline double sigmoid(double x) {
81 return 0;
83 return 1;
84
85 return 1.0 / (1.0 + exp(-x));
86 }
87
98 static inline double gaussian(double x) {
100 return 0;
102 return 1;
103
104 return 1.0 / exp(x * x);
105 }
106};
107
108#endif
Class containing static methods for common activation functions.
Definition diwa_activations.h:67
static double gaussian(double x)
Gaussian activation function.
Definition diwa_activations.h:98
static double sigmoid(double x)
Sigmoid activation function.
Definition diwa_activations.h:79
#define DIWA_ACTFUNC_UPPER_BOUND
Definition diwa_activations.h:50
double(* diwa_activation)(double)
Typedef for activation function pointer.
Definition diwa_activations.h:58
#define DIWA_ACTFUNC_LOWER_BOUND
Definition diwa_activations.h:49