-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerceptron.h
73 lines (55 loc) · 1.56 KB
/
Perceptron.h
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
#pragma once
#include <iostream>
#include <vector>
#include <Math.h>
namespace NeNet
{
enum Type
{
INPUT = 0,
HIDDEN = 1,
OUTPUT = 2
};
class Edge;
class Perceptron
{
private:
const u_int _layer;
const u_int _index;
Type _type;
std::vector<std::weak_ptr<Edge>> _predecessors;
std::vector<std::weak_ptr<Edge>> _successors;
public:
std::function<double(double)> _activationFun;
std::function<double(double)> _activationFunDer; // derivative of activation function
std::function<double(double, double)> _errorFun;
std::function<double(double, double)> _errorFunDer;
double _delta;
double _weightedSum;
double _output;
public:
Perceptron(Type type, u_int layer, u_int index);
/* GETTERS */
double getDelta() { return _delta; }
double getOutput() { return _output; }
double getType() { return _type; }
void addPredecessor(std::shared_ptr<Edge> predecessor) {
_predecessors.push_back(predecessor);
}
void addSuccessor(std::shared_ptr<Edge> successor) {
_successors.push_back(successor);
}
/**
* Used in forward propagation.
* Method aggregates weighted outputs from all predecessors,
* feeds them to the activation functions and places the output on the output edges.
*/
void processInputs();
/**
* Used in backward propagation.
* Method calculates the delta of the multilayer perceptron
* stores it in member variable.
*/
void calculateDelta(double sampleOutput);
};
}