-
Notifications
You must be signed in to change notification settings - Fork 4
/
nnode.h
169 lines (117 loc) · 4.88 KB
/
nnode.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef _NNODE_H_
#define _NNODE_H_
#include <algorithm>
#include <vector>
#include "neat.h"
#include "trait.h"
#include "link.h"
namespace NEAT {
class Network;
enum nodetype {
NEURON = 0,
SENSOR = 1
};
enum nodeplace {
HIDDEN = 0,
INPUT = 1,
OUTPUT = 2,
BIAS = 3
};
enum functype {
SIGMOID = 0
};
class Link;
// -----------------------------------------------------------------------
// A NODE is either a NEURON or a SENSOR.
// - If it's a sensor, it can be loaded with a value for output
// - If it's a neuron, it has a list of its incoming input signals (List<Link> is used)
// Use an activation count to avoid flushing
class NNode {
friend class Network;
friend class Genome;
protected:
int activation_count; // keeps track of which activation the node is currently in
double last_activation; // Holds the previous step's activation for recurrency
double last_activation2; // Holds the activation BEFORE the prevous step's
// This is necessary for a special recurrent case when the innode
// of a recurrent link is one time step ahead of the outnode.
// The innode then needs to send from TWO time steps ago
Trait *nodetrait; // Points to a trait of parameters
int trait_id; // identify the trait derived by this node
NNode *dup; // Used for Genome duplication
NNode *analogue; // Used for Gene decoding
bool override; // The NNode cannot compute its own output- something is overriding it
double override_value; // Contains the activation value that will override this node's activation
// Pointer to the Sensor corresponding to this Body.
//Sensor* mySensor;
public:
bool frozen; // When frozen, cannot be mutated (meaning its trait pointer is fixed)
functype ftype; // type is either SIGMOID ..or others that can be added
nodetype type; // type is either NEURON or SENSOR
double activesum; // The incoming activity before being processed
double activation; // The total activation entering the NNode
bool active_flag; // To make sure outputs are active
// NOT USED IN NEAT - covered by "activation" above
double output; // Output of the NNode- the value in the NNode
// ************ LEARNING PARAMETERS ***********
// The following parameters are for use in
// neurons that learn through habituation,
// sensitization, or Hebbian-type processes
double params[NEAT::num_trait_params];
std::vector<Link*> incoming; // A list of pointers to incoming weighted signals from other nodes
std::vector<Link*> outgoing; // A list of pointers to links carrying this node's signal
// These members are used for graphing with GTK+/GDK
std::vector<double> rowlevels; // Depths from output where this node appears
int row; // Final row decided upon for drawing this NNode in
int ypos;
int xpos;
int node_id; // A node can be given an identification number for saving in files
nodeplace gen_node_label; // Used for genetic marking of nodes
NNode(nodetype ntype,int nodeid);
NNode(nodetype ntype,int nodeid, nodeplace placement);
// Construct a NNode off another NNode for genome purposes
NNode(NNode *n,Trait *t);
// Construct the node out of a file specification using given list of traits
NNode (const char *argline, std::vector<Trait*> &traits);
// Copy Constructor
NNode (const NNode& nnode);
~NNode();
// Just return activation for step
double get_active_out();
// Return activation from PREVIOUS time step
double get_active_out_td();
// Returns the type of the node, NEURON or SENSOR
const nodetype get_type();
// Allows alteration between NEURON and SENSOR. Returns its argument
nodetype set_type(nodetype);
// If the node is a SENSOR, returns true and loads the value
bool sensor_load(double);
// Adds a NONRECURRENT Link to a new NNode in the incoming List
void add_incoming(NNode*,double);
// Adds a Link to a new NNode in the incoming List
void add_incoming(NNode*,double,bool);
// Recursively deactivate backwards through the network
void flushback();
// Verify flushing for debugging
void flushback_check(std::vector<NNode*> &seenlist);
// Print the node to a file
void print_to_file(std::ostream &outFile);
void print_to_file(std::ofstream &outFile);
// Have NNode gain its properties from the trait
void derive_trait(Trait *curtrait);
// Returns the gene that created the node
NNode *get_analogue();
// Force an output value on the node
void override_output(double new_output);
// Tell whether node has been overridden
bool overridden();
// Set activation to the override value and turn off override
void activate_override();
// Writes back changes weight values into the genome
// (Lamarckian trasnfer of characteristics)
void Lamarck();
//Find the greatest depth starting from this neuron at depth d
int depth(int d,Network *mynet,int& count, int thresh);
};
} // namespace NEAT
#endif