mirror of
https://github.com/davidalbertonogueira/MLP.git
synced 2025-12-17 04:14:41 +03:00
WIP project still in dev.
MISC Remove bias from examples. Change in the license type. Update legal instrument.
This commit is contained in:
25
src/Layer.h
25
src/Layer.h
@@ -14,6 +14,7 @@
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cassert> // for assert()
|
||||
|
||||
class Layer {
|
||||
public:
|
||||
@@ -25,14 +26,36 @@ public:
|
||||
|
||||
Layer(int num_nodes, int num_inputs_per_node) {
|
||||
m_num_nodes = num_nodes;
|
||||
m_num_inputs_per_node = num_inputs_per_node;
|
||||
m_nodes = std::vector<Node>(num_nodes, Node(num_inputs_per_node));
|
||||
};
|
||||
|
||||
~Layer() {
|
||||
|
||||
m_nodes.clear();
|
||||
};
|
||||
|
||||
void GetOutput(const std::vector<double> &input, std::vector<double> * output) const {
|
||||
assert(input.size() == m_num_inputs_per_node);
|
||||
|
||||
output->resize(m_num_nodes);
|
||||
|
||||
for (int i = 0; i < m_num_nodes; ++i) {
|
||||
(*output)[i] = m_nodes[i].GetOutput(input);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateWeights(const std::vector<double> &x,
|
||||
double m_learning_rate,
|
||||
double error) {
|
||||
assert(x.size() == m_num_inputs_per_node);
|
||||
|
||||
for (size_t i = 0; i < m_nodes.size(); i++)
|
||||
m_nodes[i].UpdateWeights(x, m_learning_rate, error);
|
||||
};
|
||||
|
||||
protected:
|
||||
int m_num_nodes;
|
||||
int m_num_inputs_per_node;
|
||||
std::vector<Node> m_nodes;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user