2009-02-18 00:19:29 +01:00
|
|
|
/**
|
|
|
|
* This source creates a new neural network able to sum two integer numbers,
|
|
|
|
* creating the XML containing the training input set on the fly.
|
|
|
|
*
|
|
|
|
* by BlackLight, 2009
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2009-08-07 15:55:59 +02:00
|
|
|
#include <neural++.hpp>
|
2009-08-16 11:09:42 +02:00
|
|
|
|
|
|
|
using namespace std;
|
2009-02-18 00:19:29 +01:00
|
|
|
using namespace neuralpp;
|
|
|
|
|
|
|
|
int main() {
|
2009-08-16 18:02:24 +02:00
|
|
|
NeuralNet net(2, 2, 2, 0.005, 100);
|
2009-02-18 00:19:29 +01:00
|
|
|
string xml;
|
2009-08-08 18:05:02 +02:00
|
|
|
double tmp;
|
2009-08-16 18:02:24 +02:00
|
|
|
int id = 0;
|
2009-02-18 00:19:29 +01:00
|
|
|
|
|
|
|
// XML initialization. Then, I say XML that 2+3=5, 3+3=6, 5+4=9
|
|
|
|
// Strings' format is "input1,input2,...,inputn;output1,output2,...,outputm
|
|
|
|
NeuralNet::initXML(xml);
|
2009-08-16 18:02:24 +02:00
|
|
|
xml += NeuralNet::XMLFromSet(id, "3,2;5,1");
|
|
|
|
xml += NeuralNet::XMLFromSet(id, "4,2;6,2");
|
|
|
|
xml += NeuralNet::XMLFromSet(id, "6,3;9,3");
|
2009-02-18 00:19:29 +01:00
|
|
|
NeuralNet::closeXML(xml);
|
2009-08-16 16:02:21 +02:00
|
|
|
cout << xml << endl;
|
2009-02-18 00:19:29 +01:00
|
|
|
|
2009-08-08 18:05:02 +02:00
|
|
|
net.train(xml, NeuralNet::str);
|
|
|
|
vector<double> v;
|
2009-02-18 00:19:29 +01:00
|
|
|
cout << "Network status: trained\n\n";
|
|
|
|
|
|
|
|
cout << "First number to add: ";
|
|
|
|
cin >> tmp;
|
|
|
|
v.push_back(tmp);
|
|
|
|
|
|
|
|
cout << "Second number to add: ";
|
|
|
|
cin >> tmp;
|
|
|
|
v.push_back(tmp);
|
|
|
|
|
2009-08-08 18:05:02 +02:00
|
|
|
net.setInput(v);
|
|
|
|
net.propagate();
|
2009-08-16 16:02:21 +02:00
|
|
|
cout << "Output: " << net.getOutputs()[0] << "; " << net.getOutputs()[1] << endl;
|
2009-02-18 00:19:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|