mirror of
https://github.com/BlackLight/neuralpp.git
synced 2024-12-28 04:05:12 +01:00
It finally supports multiple outputs for the network
This commit is contained in:
parent
73f13abb56
commit
adfa58800f
7 changed files with 36 additions and 37 deletions
|
@ -10,22 +10,25 @@
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<NETWORK NAME="adder">
|
<NETWORK NAME="adder">
|
||||||
<TRAINING ID="1">
|
<TRAINING ID="0">
|
||||||
<INPUT ID="0">2</INPUT>
|
|
||||||
<INPUT ID="1">3</INPUT>
|
<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>
|
||||||
|
|
||||||
<TRAINING ID="1">
|
<TRAINING ID="5">
|
||||||
<INPUT ID="0">3</INPUT>
|
<INPUT ID="6">5</INPUT>
|
||||||
<INPUT ID="1">4</INPUT>
|
<INPUT ID="7">3</INPUT>
|
||||||
<OUTPUT ID="0">7</OUTPUT>
|
<OUTPUT ID="8">8</OUTPUT>
|
||||||
|
<OUTPUT ID="9">2</OUTPUT>
|
||||||
</TRAINING>
|
</TRAINING>
|
||||||
|
|
||||||
<TRAINING ID="2">
|
<TRAINING ID="10">
|
||||||
<INPUT ID="0">10</INPUT>
|
<INPUT ID="11">6</INPUT>
|
||||||
<INPUT ID="1">10</INPUT>
|
<INPUT ID="12">3</INPUT>
|
||||||
<OUTPUT ID="0">20</OUTPUT>
|
<OUTPUT ID="13">9</OUTPUT>
|
||||||
|
<OUTPUT ID="14">3</OUTPUT>
|
||||||
</TRAINING>
|
</TRAINING>
|
||||||
</NETWORK>
|
</NETWORK>
|
||||||
|
|
||||||
|
|
|
@ -12,17 +12,18 @@ using namespace std;
|
||||||
using namespace neuralpp;
|
using namespace neuralpp;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
NeuralNet net(3, 3, 1, 0.005, 1000);
|
NeuralNet net(2, 2, 2, 0.005, 1000);
|
||||||
string xml;
|
string xml;
|
||||||
double tmp;
|
double tmp;
|
||||||
|
|
||||||
// XML initialization. Then, I say XML that 2+3=5, 3+3=6, 5+4=9
|
// 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
|
// Strings' format is "input1,input2,...,inputn;output1,output2,...,outputm
|
||||||
NeuralNet::initXML(xml);
|
NeuralNet::initXML(xml);
|
||||||
xml += NeuralNet::XMLFromSet(0, "2,3,4;9");
|
xml += NeuralNet::XMLFromSet(0, "3,2;5,1");
|
||||||
xml += NeuralNet::XMLFromSet(1, "3,3,1;7");
|
xml += NeuralNet::XMLFromSet(1, "4,2;6,2");
|
||||||
xml += NeuralNet::XMLFromSet(2, "5,4,2;11");
|
xml += NeuralNet::XMLFromSet(2, "6,3;9,3");
|
||||||
NeuralNet::closeXML(xml);
|
NeuralNet::closeXML(xml);
|
||||||
|
cout << xml << endl;
|
||||||
|
|
||||||
net.train(xml, NeuralNet::str);
|
net.train(xml, NeuralNet::str);
|
||||||
vector<double> v;
|
vector<double> v;
|
||||||
|
@ -36,13 +37,9 @@ int main() {
|
||||||
cin >> tmp;
|
cin >> tmp;
|
||||||
v.push_back(tmp);
|
v.push_back(tmp);
|
||||||
|
|
||||||
cout << "Third number to add: ";
|
|
||||||
cin >> tmp;
|
|
||||||
v.push_back(tmp);
|
|
||||||
|
|
||||||
net.setInput(v);
|
net.setInput(v);
|
||||||
net.propagate();
|
net.propagate();
|
||||||
cout << "Output: " << net.getOutput() << endl;
|
cout << "Output: " << net.getOutputs()[0] << "; " << net.getOutputs()[1] << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ int main() {
|
||||||
|
|
||||||
net.setInput(v);
|
net.setInput(v);
|
||||||
net.propagate();
|
net.propagate();
|
||||||
cout << "Neural net output: " << net.getOutput() << endl;
|
cout << "Neural net output: " << net.getOutputs()[0] << "; " << net.getOutputs()[1] << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ using namespace std;
|
||||||
using namespace neuralpp;
|
using namespace neuralpp;
|
||||||
|
|
||||||
int main() {
|
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";
|
cout << "Training in progress - This may take a while...\n";
|
||||||
net.train("adder.xml", NeuralNet::file);
|
net.train("adder.xml", NeuralNet::file);
|
||||||
|
|
|
@ -289,12 +289,12 @@ namespace neuralpp {
|
||||||
/**
|
/**
|
||||||
* @return Reference to input neuron of the synapsis
|
* @return Reference to input neuron of the synapsis
|
||||||
*/
|
*/
|
||||||
Neuron* getIn();
|
Neuron* getIn() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Reference to output neuron of the synapsis
|
* @return Reference to output neuron of the synapsis
|
||||||
*/
|
*/
|
||||||
Neuron* getOut();
|
Neuron* getOut() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the weight of the synapsis
|
* @brief Set the weight of the synapsis
|
||||||
|
@ -313,19 +313,19 @@ namespace neuralpp {
|
||||||
* @brief Return the weight of the synapsis
|
* @brief Return the weight of the synapsis
|
||||||
* @return Weight of the synapsis
|
* @return Weight of the synapsis
|
||||||
*/
|
*/
|
||||||
double getWeight();
|
double getWeight() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the delta of the synapsis
|
* @brief Return the delta of the synapsis
|
||||||
* @return 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
|
* @brief Get the delta of the synapsis at the previous iteration
|
||||||
* @return The previous delta
|
* @return The previous delta
|
||||||
*/
|
*/
|
||||||
double getPrevDelta();
|
double getPrevDelta() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the inertial momentum of a synapsis. This value is inversely proportional
|
* @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
|
* @param x The number of iterations already taken
|
||||||
* @return The inertial momentum of the synapsis
|
* @return The inertial momentum of the synapsis
|
||||||
*/
|
*/
|
||||||
double momentum (int N, int x);
|
double momentum (int N, int x) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
@ -87,7 +86,7 @@ namespace neuralpp {
|
||||||
output->propagate();
|
output->propagate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeuralNet::setInput(vector <double> v) {
|
void NeuralNet::setInput(vector<double> v) {
|
||||||
input->setInput(v);
|
input->setInput(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,8 +472,8 @@ namespace neuralpp {
|
||||||
xml.OutOfElem();
|
xml.OutOfElem();
|
||||||
|
|
||||||
setInput(input);
|
setInput(input);
|
||||||
propagate();
|
|
||||||
setExpected(output);
|
setExpected(output);
|
||||||
|
propagate();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,23 +47,23 @@ namespace neuralpp {
|
||||||
actv_f = a;
|
actv_f = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
Neuron *Synapsis::getIn() {
|
Neuron *Synapsis::getIn() const {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
Neuron *Synapsis::getOut() {
|
Neuron *Synapsis::getOut() const {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Synapsis::getWeight() {
|
double Synapsis::getWeight() const {
|
||||||
return weight;
|
return weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Synapsis::getDelta() {
|
double Synapsis::getDelta() const {
|
||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Synapsis::getPrevDelta() {
|
double Synapsis::getPrevDelta() const {
|
||||||
return prev_delta;
|
return prev_delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ namespace neuralpp {
|
||||||
delta = d;
|
delta = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Synapsis::momentum(int N, int x) {
|
double Synapsis::momentum(int N, int x) const {
|
||||||
return (BETA0 * N) / (20 * x + N);
|
return (BETA0 * N) / (20 * x + N);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue