-
Notifications
You must be signed in to change notification settings - Fork 1
/
denselayer.hpp
59 lines (54 loc) · 1.55 KB
/
denselayer.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
#ifndef DENSELAYER_HPP_
#define DENSELAYER_HPP_
#include <vector>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <math.h>
enum class activation_option
{
RELU,
TANH
};
enum class print_option
{
LITE,
FULL
};
/**
* @brief Class for hidden layers and output layers.
* parts of a neural network.
*
*/
class DenseLayer
{
public:
std::vector<double> output;
std::vector<double> error;
std::vector<double> bias;
std::vector<std::vector<double>> weights;
activation_option ao;
DenseLayer(void) {}
DenseLayer(const std::size_t num_nodes,
const std::size_t num_weights);
~DenseLayer();
std::size_t num_nodes(void) const;
std::size_t num_weights(void) const;
void set_activation(const activation_option ao = activation_option::TANH);
void clear(void);
void resize(const std::size_t num_nodes,
const std::size_t num_weights);
void feedforward(const std::vector<double> &input);
void backpropagate(const std::vector<double> &reference);
void backpropagate(const DenseLayer &next_layer);
void optimize(const std::vector<double> &input,
const double learning_rate);
void print(print_option po = print_option::LITE, std::ostream &ostream = std::cout);
private:
inline double get_random(void);
inline double activation(const double sum);
inline double delta_activation(const double output);
double get_rounded(const double number,
const double threshold = 0.001);
};
#endif /* DENSELAYER_HPP_ */