-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDense.cpp
49 lines (44 loc) · 1.03 KB
/
Dense.cpp
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
#include "Dense.h"
/*
* Dense constructor.
* @param weights - the weight matrix of the layer.
* @param bias - the bias matrix of the layer.
* @param act_func - the activation function of the layer.
* @return a new Dense object.
*/
Dense::Dense(Matrix& weights, Matrix& bias, activation_func act_func) :
_weights(weights), _bias(bias), _act_func(act_func)
{}
/*
* getter function.
* @return the weight matrix of the layer.
*/
Matrix Dense::get_weights () const
{
return _weights;
}
/*
* getter function.
* @return the bias matrix of the layer.
*/
Matrix Dense::get_bias () const
{
return _bias;
}
/*
* getter function.
* @return the activation function of the layer.
*/
activation_func Dense::get_activation () const
{
return _act_func;
}
/*
* operator() overload.
* @param input - the input matrix to the layer.
* @return the output matrix of the layer.
*/
Matrix Dense::operator()(const Matrix &input)
{
return Matrix(_act_func(_weights * input + _bias));
}