mirror of
https://github.com/BlackLight/neuralpp.git
synced 2025-07-11 01:18:08 +02:00
Hey it's becoming damn cool...
This commit is contained in:
parent
adfa58800f
commit
5cb0faef82
10 changed files with 116 additions and 88 deletions
|
@ -8,3 +8,4 @@ clean:
|
|||
rm doAdd
|
||||
rm adderFromScratch
|
||||
rm adder.net
|
||||
rm adder.xml
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!DOCTYPE NETWORK SYSTEM "http://blacklight.gotdns.org/prog/neuralpp/trainer.dtd">
|
||||
|
||||
<!--
|
||||
Sample XML containing a training set that teach your network to do simple sums
|
||||
between integer numbers
|
||||
|
||||
BlackLight, 2009
|
||||
~ LibNeural++ project ~
|
||||
-->
|
||||
|
||||
<NETWORK NAME="adder">
|
||||
<TRAINING ID="0">
|
||||
<INPUT ID="1">3</INPUT>
|
||||
<INPUT ID="2">2</INPUT>
|
||||
<OUTPUT ID="3">5</OUTPUT>
|
||||
<OUTPUT ID="4">1</OUTPUT>
|
||||
</TRAINING>
|
||||
|
||||
<TRAINING ID="5">
|
||||
<INPUT ID="6">5</INPUT>
|
||||
<INPUT ID="7">3</INPUT>
|
||||
<OUTPUT ID="8">8</OUTPUT>
|
||||
<OUTPUT ID="9">2</OUTPUT>
|
||||
</TRAINING>
|
||||
|
||||
<TRAINING ID="10">
|
||||
<INPUT ID="11">6</INPUT>
|
||||
<INPUT ID="12">3</INPUT>
|
||||
<OUTPUT ID="13">9</OUTPUT>
|
||||
<OUTPUT ID="14">3</OUTPUT>
|
||||
</TRAINING>
|
||||
</NETWORK>
|
||||
|
|
@ -12,16 +12,17 @@ using namespace std;
|
|||
using namespace neuralpp;
|
||||
|
||||
int main() {
|
||||
NeuralNet net(2, 2, 2, 0.005, 1000);
|
||||
NeuralNet net(2, 2, 2, 0.005, 100);
|
||||
string xml;
|
||||
double tmp;
|
||||
int id = 0;
|
||||
|
||||
// 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);
|
||||
xml += NeuralNet::XMLFromSet(0, "3,2;5,1");
|
||||
xml += NeuralNet::XMLFromSet(1, "4,2;6,2");
|
||||
xml += NeuralNet::XMLFromSet(2, "6,3;9,3");
|
||||
xml += NeuralNet::XMLFromSet(id, "3,2;5,1");
|
||||
xml += NeuralNet::XMLFromSet(id, "4,2;6,2");
|
||||
xml += NeuralNet::XMLFromSet(id, "6,3;9,3");
|
||||
NeuralNet::closeXML(xml);
|
||||
cout << xml << endl;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ int main() {
|
|||
|
||||
net.setInput(v);
|
||||
net.propagate();
|
||||
cout << "Neural net output: " << net.getOutputs()[0] << "; " << net.getOutputs()[1] << endl;
|
||||
cout << "Neural net output: " << net.getOutput() << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -7,19 +7,46 @@
|
|||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <ctime>
|
||||
#include <neural++.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace neuralpp;
|
||||
|
||||
int main() {
|
||||
NeuralNet net(2, 2, 2, 0.005, 1000);
|
||||
double f (double x) {
|
||||
return (1.0/(1.0 + pow(M_E,x)));
|
||||
}
|
||||
|
||||
int main() {
|
||||
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";
|
||||
|
||||
t1 = time(NULL);
|
||||
cout << "Training in progress - This may take a while...\n";
|
||||
net.train("adder.xml", NeuralNet::file);
|
||||
t2 = time(NULL);
|
||||
|
||||
net.save("adder.net");
|
||||
cout << "Network trained. You can use adder.net file now to load this network\n";
|
||||
cout << "Network trained in " << (t2-t1) << " seconds. You can use adder.net file now to load this network\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue