14 const int seglength = 2;
15 const double maxinit = 0.01;
16 const double maxbias = 0.01;
17 const int hiddenlayers = 1;
19 const int trainsamples = 20;
20 const int testsamples = 20;
21 const int gap = trainsamples / 10;
24 ttypeVector typeVector;
29 double currentinput, currentref;
31 string logfilename(
"learn.log");
32 ofstream logfile(logfilename.c_str());
34 typeVector.assign(4 * seglength, bipolar);
35 for (
int i = 0; i < hiddenlayers; ++i)
37 typeArray.push_back(typeVector);
39 typeVector.assign(1, identity);
40 typeArray.push_back(typeVector);
43 Network.Input.assign(seglength, 0);
49 for (
int i = 0; i < trainsamples; ++i)
51 double input1 = (0.5 - Random.
GetNumber());
52 double input2 = (0.5 - Random.
GetNumber());
53 double desired = exp(input1 + input2);
54 Network.Input.at(0) = input1;
55 Network.Input.at(1) = input2;
56 Network.Desired.front() = desired;
57 Network.AdaptWeights();
59 for (
int j = 0; j < typeArray.size(); ++j)
61 cout <<
"Layer: " << j << endl;
62 for (
int k = 0; k < typeArray.at(j).size(); ++k)
64 cout <<
"Neuron: " << k << endl;
65 cout <<
"Delta: " << Network.Layers.at(j).at(k)->Delta << endl;
66 cout <<
"Net: " << Network.Layers.at(j).at(k)->Net << endl;
67 cout <<
"Output: " << Network.Layers.at(j).at(k)->Output
72 logfile << i <<
" " << desired <<
" " << Network.Output.at(0) <<
" "
73 << desired - Network.Output.at(0) << endl;
76 for (
int i = trainsamples + gap; i < trainsamples + gap + testsamples; ++i)
78 double input1 = (0.5 - Random.
GetNumber());
79 double input2 = (0.5 - Random.
GetNumber());
80 double desired = input1 + input2;
81 Network.Input.at(0) = input1;
82 Network.Input.at(1) = input2;
84 for (
int j = 0; j < typeArray.size(); ++j)
86 cout <<
"Layer: " << j << endl;
87 for (
int k = 0; k < typeArray.at(j).size(); ++k)
89 cout <<
"Neuron: " << k << endl;
90 cout <<
"Delta: " << Network.Layers.at(j).at(k)->Delta << endl;
91 cout <<
"Net: " << Network.Layers.at(j).at(k)->Net << endl;
92 cout <<
"Output: " << Network.Layers.at(j).at(k)->Output
98 logfile << i <<
" " << desired <<
" " << Network.Output.at(0) <<
" "
99 << desired - Network.Output.at(0) << endl;
void InitWeights(const double MaxWeight, const double MaxBias)
Initialize the weights with random values with the specified maxima.
void SetLayers(ttypeArray typeArray, bool cachedoutput=false)
Configure the layers of the network according to the types in typeArray.