2009-02-18 00:19:29 +01:00
|
|
|
/**
|
|
|
|
* This source creates a new neural network able to sum two integer numbers,
|
|
|
|
* using the training input set saved on "adder.xml" and saving output network
|
|
|
|
* on "adder.net"
|
|
|
|
*
|
|
|
|
* by BlackLight, 2009
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2009-08-16 18:02:24 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <ctime>
|
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;
|
|
|
|
|
2009-08-16 18:02:24 +02:00
|
|
|
double f (double x) {
|
|
|
|
return (1.0/(1.0 + pow(M_E,x)));
|
|
|
|
}
|
|
|
|
|
2009-02-18 00:19:29 +01:00
|
|
|
int main() {
|
2009-08-16 18:02:24 +02:00
|
|
|
int id = 0;
|
|
|
|
string xml;
|
|
|
|
time_t t1, t2;
|
|
|
|
NeuralNet net(2, 2, 1, 0.005, 100);
|
|
|
|
|
|
|
|
NeuralNet::initXML(xml);
|
|
|
|
xml += NeuralNet::XMLFromSet(id, "2,3;5");
|
|
|
|
xml += NeuralNet::XMLFromSet(id, "3,2;5");
|
|
|
|
xml += NeuralNet::XMLFromSet(id, "6,2;8");
|
|
|
|
xml += NeuralNet::XMLFromSet(id, "2,2;4");
|
|
|
|
xml += NeuralNet::XMLFromSet(id, "1,2;3");
|
|
|
|
xml += NeuralNet::XMLFromSet(id, "-1,-2;-3");
|
|
|
|
xml += NeuralNet::XMLFromSet(id, "8,9;17");
|
|
|
|
xml += NeuralNet::XMLFromSet(id, "10,10;20");
|
|
|
|
NeuralNet::closeXML(xml);
|
|
|
|
|
|
|
|
ofstream out("adder.xml");
|
|
|
|
out << xml;
|
|
|
|
out.close();
|
|
|
|
cout << "Training file adder.xml has been written\n";
|
2009-02-18 00:19:29 +01:00
|
|
|
|
2009-08-16 18:02:24 +02:00
|
|
|
t1 = time(NULL);
|
2009-08-15 02:59:09 +02:00
|
|
|
cout << "Training in progress - This may take a while...\n";
|
2009-08-08 18:05:02 +02:00
|
|
|
net.train("adder.xml", NeuralNet::file);
|
2009-08-16 18:02:24 +02:00
|
|
|
t2 = time(NULL);
|
2009-02-18 00:19:29 +01:00
|
|
|
|
2009-08-08 18:05:02 +02:00
|
|
|
net.save("adder.net");
|
2009-08-16 18:02:24 +02:00
|
|
|
cout << "Network trained in " << (t2-t1) << " seconds. You can use adder.net file now to load this network\n";
|
2009-02-18 00:19:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|