-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath.hpp
More file actions
41 lines (30 loc) · 1.1 KB
/
Math.hpp
File metadata and controls
41 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Created by lorenzo on 22/05/21.
//
#ifndef NEURALNETC___MATH_HPP
#define NEURALNETC___MATH_HPP
#include <cmath>
#include <type_traits>
template<typename T>
concept ArithmeticValue = std::is_arithmetic_v<T>;
template<typename T>
[[nodiscard]] constexpr auto activation_function(T value) requires ArithmeticValue<T> {
return 1/(1 + std::exp(-(value)));
}
template<typename... ArithmeticValue>
[[nodiscard]] constexpr auto sum(ArithmeticValue... values) {
return (values + ...);
}
template<typename T>
[[nodiscard]] constexpr auto loss_function(const T target, const T output) requires ArithmeticValue<T> {
return std::pow(target - output, 2);
}
template<typename T>
[[nodiscard]] constexpr auto derivative_loss_function(T target, T neuron_output, T input, T exponent) requires ArithmeticValue<T> {
auto inverse_activation_function = [=]() constexpr noexcept -> T {
return (1 + std::exp(-(exponent)));
};
return 2 * (target - neuron_output) * (-1) * std::pow(inverse_activation_function(), -2) *
std::exp(-(exponent)) * input;
}
#endif //NEURALNETC___MATH_HPP