-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc.hpp
85 lines (57 loc) · 1.71 KB
/
func.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// Created by Imran on 05-Sep-18.
//
#ifndef VANILLA_NN_FUNC_HPP
#define VANILLA_NN_FUNC_HPP
#include "matrix.hpp"
#include "impl.hpp"
template <typename E>
struct Activation{
Matrix<E> (*f)(Matrix<E>);
Matrix<E> (*d)(Matrix<E>);
Activation(Matrix<E> (*f_)(Matrix<E>),
Matrix<E> (*d_)(Matrix<E>))
: f(f_), d(d_)
{
}
};
template <typename E>
struct Final_Activation{
Matrix<E> (*f)(Matrix<E>&);
Matrix<E> (*d)(Matrix<E>&);
Final_Activation(Matrix<E> (*f_)(Matrix<E>&),
Matrix<E> (*d_)(Matrix<E>&))
: f(f_), d(d_)
{
}
};
template <typename E>
struct Cost{
E (*f)(Matrix<E>&, Matrix<E>&);
Matrix<E> (*d)(Matrix<E>&, Matrix<E>&);
Cost( E (*f_)(Matrix<E>&, Matrix<E>&),
Matrix<E> (*d_)(Matrix<E>&, Matrix<E>&))
: f(f_), d(d_)
{
}
};
namespace F{
// ---------- Activation ----------
template <typename E>
Activation<E> sigmoid(impl::sigmoid, impl::d_sigmoid);
template <typename E>
Activation<E> relu(impl::relu, impl::d_relu);
template <typename E>
Activation<E> leaky_relu(impl::leaky_relu, impl::d_leaky_relu);
template <typename E>
Activation<E> tanh(impl::tanh, impl::d_tanh);
// ---------- Final Activation ----------
template <typename E>
Final_Activation<E> softmax(impl::softmax, impl::d_softmax);
// ------------ Cost ------------
template <typename E>
Cost<E> mse(impl::mse, impl::d_mse);
template <typename E>
Cost<E> cce(impl::cce, impl::d_cce);
}
#endif //VANILLA_NN_FUNC_HPP