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 <diwa_conv.h>
48#include <math.h>
49
50#define DIWA_ACTFUNC_LOWER_BOUND -30.0f
51#define DIWA_ACTFUNC_UPPER_BOUND 30.0f
59typedef double (*diwa_activation)(double);
60
68class DiwaActivationFunc final {
69private:
70 static inline double region = 2.0f;
71 static inline double center = 0.0f;
73public:
84 static inline void initializeRadialBasis(double center, double width) {
85 DiwaActivationFunc::center = center;
86 DiwaActivationFunc::region = 2 * pow(width, 2);
87 }
88
99 static inline double radialBasis(double x) {
100 return exp(
101 -pow(x - DiwaActivationFunc::center, 2)
102 / DiwaActivationFunc::region
103 );
104 }
105
116 static inline double sigmoid(double x) {
118 return 0;
120 return 1;
121
122 return 1.0 / (1.0 + exp(-x));
123 }
124
135 static inline double gaussian(double x) {
137 return 0;
139 return 1;
140
141 return 1.0 / exp(x * x);
142 }
143};
144
145#endif
Class containing static methods for common activation functions.
Definition diwa_activations.h:68
static double radialBasis(double x)
Computes the output of the radial basis function.
Definition diwa_activations.h:99
static void initializeRadialBasis(double center, double width)
Initializes the parameters for the radial basis function.
Definition diwa_activations.h:84
static double gaussian(double x)
Gaussian activation function.
Definition diwa_activations.h:135
static double sigmoid(double x)
Sigmoid activation function.
Definition diwa_activations.h:116
#define DIWA_ACTFUNC_UPPER_BOUND
Definition diwa_activations.h:51
double(* diwa_activation)(double)
Typedef for activation function pointer.
Definition diwa_activations.h:59
#define DIWA_ACTFUNC_LOWER_BOUND
Definition diwa_activations.h:50
Utility functions for data conversion in the Diwa neural network library.