-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivations.hpp
62 lines (52 loc) · 1.45 KB
/
activations.hpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once
#include <memory>
#include <aliases.hpp>
/**
* \brief Activation interface class
*/
class Activation {
public:
virtual ~Activation()
{}
virtual const std::string& Name() = 0;
virtual double Value(const double value) const = 0;
virtual Matrix Value(const Matrix& value) const = 0;
virtual double Deriv(double value) const = 0;
virtual Matrix Deriv(const Matrix& value) const = 0;
};
/**
* \brief Sigmoid activation class
*/
class Sigmoid: public Activation {
public:
Sigmoid() {}
~Sigmoid() {}
const std::string& Name() { return mName; }
double Value(const double value) const;
Matrix Value(const Matrix& value) const;
double Deriv(const double value) const;
Matrix Deriv(const Matrix& value) const;
private:
static const std::string mName;
};
/**
* \brief Identity activation class
*/
class Identity: public Activation {
public:
Identity() {}
~Identity() {}
const std::string& Name() { return mName; }
double Value(const double value) const;
Matrix Value(const Matrix& value) const;
double Deriv(const double value) const;
Matrix Deriv(const Matrix& value) const;
private:
static const std::string mName;
};
/**
* \brief Activation factory
* \param[in] actName activation function name, may be "sigmoid", "identity", otherwise exception
* \return pointer to activation functor
*/
std::unique_ptr<Activation> make_activation(const std::string& actName);