-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.h
94 lines (73 loc) · 3.37 KB
/
Node.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef NEURAL_NETWORK_NODE_H
#define NEURAL_NETWORK_NODE_H
#include <vector>
#include <cstdlib>
#include <map>
#include <memory>
class Node {
public:
/*! Tightly coupled classes acting as single unit */
friend class NeuralNet;
typedef size_t size_type;
/*!
* Constructor initializes \c v_front with the
* number of nodes in the next layer and \c v_back
* with the number of nodes in the previous layer
* @param front_conn - number of front connections.
* @param back_conn - number of back connections.
*/
Node(unsigned int front_conn, unsigned int back_conn);
/*!
* This function should only be called when attaching
* to the next layer of nodes. The calling node
* attaches to the param \c node by assigning one of
* its pointers located within \c v_front to the param
* \c node. One connection is made per function call.
* If a failed attachment occurs, a message alerting
* the user is printed to output.
* @param node - The node to attach to.
* @return - The number of connections made.
*/
typename Node::size_type attach_v_front(Node &node);
/*!
* This function should only be called when attaching
* to the previous layer of nodes. The calling node
* attaches to the param \c node by assigning one of
* its pointers located within \c v_back to the param
* \c node. One connection is made per function call.
* If a failed attachment occurs, a message alerting
* the user is printed to output.
* @param node - The node to attach to.
* @return - The number of connections made.
*/
typename Node::size_type attach_v_back(Node &node);
private:
double val; /*!< Node's data value */
double val_before_sigmoid; /*!< Node's data value before processed using sigmoid function 1 / 1 + (e^-z) */
double error; /*!< Error value used in data processing */
double real_identity; /*!< Used to identify what each output-layer node represents */
int conn; /*!< Number of connections for current node. */
std::vector<Node *> v_front; /*!< Holds connections to every next-layer node, corresponds to \c weights field */
std::vector<Node *> v_back; /*!< Holds connections to every previous-layer node */
std::vector<double> weights; /*!< Unique floating-points for each next-layer node, corresponds to \c v_front field */
std::vector<double> old_weights; /*!< Only used within NeuralNet::back_propagate()
/*!
* Assigns arbitrarily tiny weight to each of
* the calling node's attachments in \c v_front
* by generating pseudorandom floating-points
* from [0.001 - 0.0099] and pushing into node's
* \c weights vector field. Each index within
* \c weights corresponds to the node's attachments
* in \c v_front. Thus each attachment has a unique
* weight. The seed for rand() must be established
* in driver file.
* @param front_connections - num nodes in next layer
* to the calling node's weight vector.
*/
void initialize_weights(int front_connections) {
// seed must be established in main
for (int i = 0; i < front_connections; i++)
weights.push_back(((double) rand() / RAND_MAX) / 100.0);
}
};
#endif //NEURAL_NETWORK_NODE_H