-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcls_ann_network_recurrent.h
executable file
·148 lines (120 loc) · 2.95 KB
/
cls_ann_network_recurrent.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
#include "ann_import.h"
#define cls_ann_layer_recurrent TLayer<cls_ann_neuron_recurrent<FUNC>,FUNC>
template<typename FUNC>
class cls_ann_network_recurrent : public cls_ann_network
{
protected:
cls_ann_layer_input<FUNC> inputs;
cls_ann_layer_recurrent neurons;
unsigned time;
public:
cls_ann_network_recurrent(unsigned init_intput_count = 0,unsigned init_recurrent_count = 0)
:cls_ann_network(0,0),
inputs(const_input_neurons_label_offset),
neurons(0)
{
time = 0;
for(int cnt=0;cnt<init_intput_count;cnt++)
{
add_input(0.0);
}
for(int cnt=0;cnt<init_recurrent_count;cnt++)
{
add_neuron();
}
}
void add_input(double init_value=0)
{
cls_ann_input_neuron<FUNC> *i = new cls_ann_input_neuron<FUNC>(get_input_count());
i->set_value(init_value);
inputs.add_neuron(i);
}
void add_input(cls_ann_input_neuron<FUNC> *in)
{
inputs.add_neuron(in);
}
void add_neuron(double ab = 0.0,double ac =0.0)
{
neurons.add_neuron(new cls_ann_neuron_recurrent<FUNC>(ab,ac));
}
void add_neuron(cls_ann_neuron_recurrent<FUNC> *n)
{
neurons.add_neuron(n);
}
virtual unsigned get_input_count() const
{
return inputs.size();
}
virtual unsigned get_output_count() const
{
return neurons.size();
}
virtual void set_input(const vector<double> &input)
{
for(int cnt=0;cnt<get_input_count();cnt++)
{
((cls_ann_input_neuron<FUNC>&) inputs[cnt]).set_value(input[cnt]);
}
}
cls_ann_neuron_recurrent<FUNC> &get_neuron(unsigned index)
{
return neurons[index];
}
cls_ann_input_neuron<FUNC> & get_input_neuron(unsigned index)
{
return inputs[index];
}
virtual void reset_activations(const vector<double> & activations)
{
for(int cnt=0;cnt<get_output_count();cnt++)
{
neurons[cnt].reset(activations[cnt]);
}
}
virtual void step()
{
for(unsigned cnt=0;cnt<get_output_count();cnt++)
{
neurons[cnt].update();
}
time++;
}
virtual double get_neuron_output(unsigned neuron)
{
return neurons[neuron].get_output();
}
virtual vector<double> get_output() const
{
vector<double> answer(get_output_count());
for(unsigned cnt=0;cnt<get_output_count();cnt++)
{
answer[cnt] = neurons[cnt].get_output();
}
return answer;
}
virtual vector<double> get_output(const vector<double> &input)
{
set_input(input);
step();
return get_output();
}
cls_ann_neuron_recurrent<FUNC> &operator[] (unsigned index)
{
return get_neuron(index);
}
virtual void set_meta_data( string meta_data )
{
}
virtual string get_meta_data()
{
return "";
}
virtual void save( ofstream& fout ) const
{
throw std::exception("cls_ann_network_recurrent::save() - the method or operation is not implemented.\n");
}
virtual void load( ifstream& fin )
{
throw std::exception("cls_ann_network_recurrent::laod() - the method or operation is not implemented.\n");
}
};