It finally supports multiple outputs for the network

This commit is contained in:
blacklight 2009-08-16 16:02:21 +02:00
parent 73f13abb56
commit adfa58800f
7 changed files with 36 additions and 37 deletions

View file

@ -10,22 +10,25 @@
-->
<NETWORK NAME="adder">
<TRAINING ID="1">
<INPUT ID="0">2</INPUT>
<TRAINING ID="0">
<INPUT ID="1">3</INPUT>
<OUTPUT ID="0">5</OUTPUT>
<INPUT ID="2">2</INPUT>
<OUTPUT ID="3">5</OUTPUT>
<OUTPUT ID="4">1</OUTPUT>
</TRAINING>
<TRAINING ID="1">
<INPUT ID="0">3</INPUT>
<INPUT ID="1">4</INPUT>
<OUTPUT ID="0">7</OUTPUT>
<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="2">
<INPUT ID="0">10</INPUT>
<INPUT ID="1">10</INPUT>
<OUTPUT ID="0">20</OUTPUT>
<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>

View file

@ -12,17 +12,18 @@ using namespace std;
using namespace neuralpp;
int main() {
NeuralNet net(3, 3, 1, 0.005, 1000);
NeuralNet net(2, 2, 2, 0.005, 1000);
string xml;
double tmp;
// 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, "2,3,4;9");
xml += NeuralNet::XMLFromSet(1, "3,3,1;7");
xml += NeuralNet::XMLFromSet(2, "5,4,2;11");
xml += NeuralNet::XMLFromSet(0, "3,2;5,1");
xml += NeuralNet::XMLFromSet(1, "4,2;6,2");
xml += NeuralNet::XMLFromSet(2, "6,3;9,3");
NeuralNet::closeXML(xml);
cout << xml << endl;
net.train(xml, NeuralNet::str);
vector<double> v;
@ -36,13 +37,9 @@ int main() {
cin >> tmp;
v.push_back(tmp);
cout << "Third number to add: ";
cin >> tmp;
v.push_back(tmp);
net.setInput(v);
net.propagate();
cout << "Output: " << net.getOutput() << endl;
cout << "Output: " << net.getOutputs()[0] << "; " << net.getOutputs()[1] << endl;
return 0;
}

View file

@ -38,7 +38,7 @@ int main() {
net.setInput(v);
net.propagate();
cout << "Neural net output: " << net.getOutput() << endl;
cout << "Neural net output: " << net.getOutputs()[0] << "; " << net.getOutputs()[1] << endl;
return 0;
}

View file

@ -13,7 +13,7 @@ using namespace std;
using namespace neuralpp;
int main() {
NeuralNet net(2, 2, 1, 0.005, 1000);
NeuralNet net(2, 2, 2, 0.005, 1000);
cout << "Training in progress - This may take a while...\n";
net.train("adder.xml", NeuralNet::file);

View file

@ -289,12 +289,12 @@ namespace neuralpp {
/**
* @return Reference to input neuron of the synapsis
*/
Neuron* getIn();
Neuron* getIn() const;
/**
* @return Reference to output neuron of the synapsis
*/
Neuron* getOut();
Neuron* getOut() const;
/**
* @brief Set the weight of the synapsis
@ -313,19 +313,19 @@ namespace neuralpp {
* @brief Return the weight of the synapsis
* @return Weight of the synapsis
*/
double getWeight();
double getWeight() const;
/**
* @brief Return the delta of the synapsis
* @return Delta of the synapsis
*/
double getDelta();
double getDelta() const;
/**
* @brief Get the delta of the synapsis at the previous iteration
* @return The previous delta
*/
double getPrevDelta();
double getPrevDelta() const;
/**
* @brief Get the inertial momentum of a synapsis. This value is inversely proportional
@ -337,7 +337,7 @@ namespace neuralpp {
* @param x The number of iterations already taken
* @return The inertial momentum of the synapsis
*/
double momentum (int N, int x);
double momentum (int N, int x) const;
};
/**

View file

@ -11,7 +11,6 @@
* this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************************************/
#include <iostream>
#include <fstream>
#include <sstream>
@ -87,7 +86,7 @@ namespace neuralpp {
output->propagate();
}
void NeuralNet::setInput(vector <double> v) {
void NeuralNet::setInput(vector<double> v) {
input->setInput(v);
}
@ -473,8 +472,8 @@ namespace neuralpp {
xml.OutOfElem();
setInput(input);
propagate();
setExpected(output);
propagate();
update();
}
}

View file

@ -47,23 +47,23 @@ namespace neuralpp {
actv_f = a;
}
Neuron *Synapsis::getIn() {
Neuron *Synapsis::getIn() const {
return in;
}
Neuron *Synapsis::getOut() {
Neuron *Synapsis::getOut() const {
return out;
}
double Synapsis::getWeight() {
double Synapsis::getWeight() const {
return weight;
}
double Synapsis::getDelta() {
double Synapsis::getDelta() const {
return delta;
}
double Synapsis::getPrevDelta() {
double Synapsis::getPrevDelta() const {
return prev_delta;
}
@ -82,7 +82,7 @@ namespace neuralpp {
delta = d;
}
double Synapsis::momentum(int N, int x) {
double Synapsis::momentum(int N, int x) const {
return (BETA0 * N) / (20 * x + N);
}
}