mirror of
https://github.com/BlackLight/neuralpp.git
synced 2025-07-26 07:18:53 +02:00
Is it time to release 1.0 version?
This commit is contained in:
parent
89b0ad2f8a
commit
a7fa05ba40
140 changed files with 1710 additions and 829 deletions
|
@ -1,10 +1,11 @@
|
|||
all:
|
||||
g++ -Wall -o learnAdd learnAdd.cpp -lneural++
|
||||
g++ -Wall -o doAdd doAdd.cpp -lneural++
|
||||
g++ -Wall -o adderFromScratch adderFromScratch.cpp -lneural++
|
||||
g++ -Wall -o Add Add.cpp -lneural++
|
||||
g++ -Wall -o networkForSumsAndSubtractions networkForSumsAndSubtractions.cpp -lneural++
|
||||
g++ -Wall -o adderFromString adderFromString.cpp -lneural++
|
||||
|
||||
clean:
|
||||
rm learnAdd
|
||||
rm doAdd
|
||||
rm adderFromScratch
|
||||
rm networkForSumsAndSubtractions
|
||||
rm adderFromString
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
* @example examples/learnAdd.cpp Show how to train a network that performs sums between
|
||||
* two real numbers. The training XML is built from scratch, then saved to a file, then
|
||||
* the network is initialized using that XML file, trained, and the resulting trained
|
||||
* network is saved to adder.net. Then, you should take a look at doAdd.cpp to see how
|
||||
* to use that file to use the network.
|
||||
|
||||
* @example examples/doAdd.cpp Show how to use a network already trained and saved to a
|
||||
* binary file. In this case, a network trained to simply perform sums between two real
|
||||
* numbers, that should have already been created using learnAdd.
|
||||
|
||||
* @example examples/adderFromScratch.cpp Similar to learnAdd.cpp, but this time the
|
||||
* training XML is generated as a string and not saved to a file, and parsed by the
|
||||
* program itself to build the network. Then, the program asks two real numbers, and
|
||||
* performs both the sum and the difference between them, putting the sum's output on
|
||||
* the first output neuron and the difference's on the second output neuron. Anyway,
|
||||
* using more than one neuron in the output layer is strongly discouraged, as the network
|
||||
* usually won't set correctly the synaptical weights to give satisfying and accurate
|
||||
* answers for all of the operations.
|
||||
|
91
examples/adder.xml
Normal file
91
examples/adder.xml
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!DOCTYPE NETWORK SYSTEM "http://blacklight.gotdns.org/prog/neuralpp/trainer.dtd">
|
||||
<!-- Automatically generated by Neural++ library - by BlackLight -->
|
||||
|
||||
<network>
|
||||
<training id="0">
|
||||
<input id="1">2</input>
|
||||
<input id="2">3</input>
|
||||
<output id="3">5</output>
|
||||
</training>
|
||||
|
||||
<training id="4">
|
||||
<input id="5">3</input>
|
||||
<input id="6">2</input>
|
||||
<output id="7">5</output>
|
||||
</training>
|
||||
|
||||
<training id="8">
|
||||
<input id="9">6</input>
|
||||
<input id="10">2</input>
|
||||
<output id="11">8</output>
|
||||
</training>
|
||||
|
||||
<training id="12">
|
||||
<input id="13">2</input>
|
||||
<input id="14">2</input>
|
||||
<output id="15">4</output>
|
||||
</training>
|
||||
|
||||
<training id="16">
|
||||
<input id="17">1</input>
|
||||
<input id="18">2</input>
|
||||
<output id="19">3</output>
|
||||
</training>
|
||||
|
||||
<training id="20">
|
||||
<input id="21">-1</input>
|
||||
<input id="22">-2</input>
|
||||
<output id="23">-3</output>
|
||||
</training>
|
||||
|
||||
<training id="24">
|
||||
<input id="25">8</input>
|
||||
<input id="26">9</input>
|
||||
<output id="27">17</output>
|
||||
</training>
|
||||
|
||||
<training id="28">
|
||||
<input id="29">10</input>
|
||||
<input id="30">10</input>
|
||||
<output id="31">20</output>
|
||||
</training>
|
||||
|
||||
<training id="32">
|
||||
<input id="33">4</input>
|
||||
<input id="34">1</input>
|
||||
<output id="35">5</output>
|
||||
</training>
|
||||
|
||||
<training id="36">
|
||||
<input id="37">2</input>
|
||||
<input id="38">6</input>
|
||||
<output id="39">8</output>
|
||||
</training>
|
||||
|
||||
<training id="40">
|
||||
<input id="41">2</input>
|
||||
<input id="42">7</input>
|
||||
<output id="43">9</output>
|
||||
</training>
|
||||
|
||||
<training id="44">
|
||||
<input id="45">8</input>
|
||||
<input id="46">9</input>
|
||||
<output id="47">17</output>
|
||||
</training>
|
||||
|
||||
<training id="48">
|
||||
<input id="49">4</input>
|
||||
<input id="50">7</input>
|
||||
<output id="51">11</output>
|
||||
</training>
|
||||
|
||||
<training id="52">
|
||||
<input id="53">5</input>
|
||||
<input id="54">2</input>
|
||||
<output id="55">7</output>
|
||||
</training>
|
||||
|
||||
</network>
|
||||
|
|
@ -18,7 +18,7 @@ using namespace std;
|
|||
using namespace neuralpp;
|
||||
|
||||
int main() {
|
||||
NeuralNet net(2, 2, 2, 0.005, 100);
|
||||
NeuralNet net(2, 2, 1, 0.002, 1000);
|
||||
string xml;
|
||||
double tmp;
|
||||
int id = 0;
|
||||
|
@ -26,9 +26,10 @@ int main() {
|
|||
// 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(id, "3,2;5,1");
|
||||
xml += NeuralNet::XMLFromSet(id, "4,2;6,2");
|
||||
xml += NeuralNet::XMLFromSet(id, "6,3;9,3");
|
||||
xml += NeuralNet::XMLFromSet(id, "3,2;5");
|
||||
xml += NeuralNet::XMLFromSet(id, "6,3;9");
|
||||
xml += NeuralNet::XMLFromSet(id, "2,3;5");
|
||||
xml += NeuralNet::XMLFromSet(id, "4,4;8");
|
||||
NeuralNet::closeXML(xml);
|
||||
cout << xml << endl;
|
||||
|
||||
|
@ -46,7 +47,7 @@ int main() {
|
|||
|
||||
net.setInput(v);
|
||||
net.propagate();
|
||||
cout << "Output: " << net.getOutputs()[0] << "; " << net.getOutputs()[1] << endl;
|
||||
cout << "Output: " << net.getOutput() << endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -49,6 +49,8 @@ int main() {
|
|||
xml += NeuralNet::XMLFromSet(id, "2,6;8");
|
||||
xml += NeuralNet::XMLFromSet(id, "2,7;9");
|
||||
xml += NeuralNet::XMLFromSet(id, "8,9;17");
|
||||
xml += NeuralNet::XMLFromSet(id, "4,7;11");
|
||||
xml += NeuralNet::XMLFromSet(id, "5,2;7");
|
||||
NeuralNet::closeXML(xml);
|
||||
|
||||
// Save the XML string just created to a file
|
||||
|
|
16
examples/network.xml
Normal file
16
examples/network.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!DOCTYPE NETWORK SYSTEM "http://blacklight.gotdns.org/prog/neuralpp/network.dtd">
|
||||
<!-- Automatically generated by BlackLight's Neural++ module -->
|
||||
|
||||
<network name="Put here the name for this neural network" epochs="2000" learning_rate="0.002" threshold="0">
|
||||
<layer class="input" size="2"></layer>
|
||||
<layer class="hidden" size="2"></layer>
|
||||
<layer class="output" size="1"></layer>
|
||||
|
||||
<synapsis class="inhid" input="0" output="0" weight="0.681455"></synapsis>
|
||||
<synapsis class="inhid" input="1" output="0" weight="0.770994"></synapsis>
|
||||
<synapsis class="inhid" input="0" output="1" weight="0.656911"></synapsis>
|
||||
<synapsis class="inhid" input="1" output="1" weight="0.763797"></synapsis>
|
||||
<synapsis class="hidout" input="0" output="0" weight="0.751936"></synapsis>
|
||||
<synapsis class="hidout" input="1" output="0" weight="0.68129"></synapsis>
|
||||
</network>
|
48
examples/networkForSumsAndSubtractions.cpp
Normal file
48
examples/networkForSumsAndSubtractions.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* This program creates a neural network from scratch. Its purpose is to get
|
||||
* two numbers and learn to compute their sum and difference (so the network
|
||||
* provides two output values). The training set is auto-generated to an XML
|
||||
* string, and then the network is trained.
|
||||
*
|
||||
* by BlackLight, 2009
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <neural++.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace neuralpp;
|
||||
|
||||
int main() {
|
||||
NeuralNet net(2, 2, 2, 0.002, 1000);
|
||||
string xml;
|
||||
double tmp;
|
||||
int id = 0;
|
||||
|
||||
// XML initialization. Then, I say XML that 3+2=5, 3-2=1; 4+2=6, 4-2=2; 6+3=9, 6-3=3
|
||||
// Strings' format is "input1,input2,...,inputn;output1,output2,...,outputm
|
||||
NeuralNet::initXML(xml);
|
||||
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;
|
||||
|
||||
net.train(xml, NeuralNet::str);
|
||||
vector<double> v;
|
||||
cout << "Network status: trained\n\n";
|
||||
|
||||
cout << "First number: ";
|
||||
cin >> tmp;
|
||||
v.push_back(tmp);
|
||||
|
||||
cout << "Second number: ";
|
||||
cin >> tmp;
|
||||
v.push_back(tmp);
|
||||
|
||||
net.setInput(v);
|
||||
net.propagate();
|
||||
cout << "Output: " << net.getOutputs()[0] << "; " << net.getOutputs()[1] << endl;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue