diff --git a/examples/adderFromScratch.cpp b/examples/adderFromScratch.cpp index da133ec..c49e9b6 100644 --- a/examples/adderFromScratch.cpp +++ b/examples/adderFromScratch.cpp @@ -10,16 +10,16 @@ using namespace neuralpp; int main() { - NeuralNet net(2, 2, 1, 0.005, 10000); + NeuralNet net(3, 3, 1, 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;5"); - xml += NeuralNet::XMLFromSet(1, "3,3;6"); - xml += NeuralNet::XMLFromSet(2, "5,4;9"); + xml += NeuralNet::XMLFromSet(0, "2,3,4;9"); + xml += NeuralNet::XMLFromSet(1, "3,3,1;7"); + xml += NeuralNet::XMLFromSet(2, "5,4,2;11"); NeuralNet::closeXML(xml); net.train(xml, NeuralNet::str); @@ -34,6 +34,10 @@ 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; diff --git a/examples/learnAdd.cpp b/examples/learnAdd.cpp index 157e960..ee81ae3 100644 --- a/examples/learnAdd.cpp +++ b/examples/learnAdd.cpp @@ -11,7 +11,7 @@ using namespace neuralpp; int main() { - NeuralNet net(2, 2, 1, 0.005, 10000); + NeuralNet net(2, 2, 1, 0.005, 1000); cout << "Training in progress - This may take a while...if it gets stuck, interrupt and restart the app\n"; net.train("adder.xml", NeuralNet::file); diff --git a/include/neural++.hpp b/include/neural++.hpp index 40c4800..5889758 100644 --- a/include/neural++.hpp +++ b/include/neural++.hpp @@ -53,10 +53,6 @@ namespace neuralpp { double l_rate; double ex; - Layer* input; - Layer* hidden; - Layer* output; - /** * @brief It updates the weights of the net's synapsis through back-propagation. * In-class use only @@ -90,6 +86,10 @@ namespace neuralpp { double (*deriv)(double); public: + Layer* input; + Layer* hidden; + Layer* output; + /** * @brief Enum to choose the eventual training source for our network (XML from a file or from a string) */ diff --git a/src/neuralnet.cpp b/src/neuralnet.cpp index 5daf42b..40d988e 100644 --- a/src/neuralnet.cpp +++ b/src/neuralnet.cpp @@ -11,6 +11,7 @@ * this program. If not, see . * **************************************************************************************************/ +#include #include "neural++.hpp" #include "Markup.h" @@ -417,7 +418,7 @@ namespace neuralpp { xml.OutOfElem(); while (!valid) { - char str[BUFSIZ]; + stringstream ss(stringstream::in | stringstream::out); setInput(input); propagate(); @@ -425,11 +426,10 @@ namespace neuralpp { update(); out = getOutput(); - memset(str, 0x0, sizeof(str)); - snprintf(str, sizeof(str), "%f", - out); - if (!strstr(str, "inf")) + ss << out; + + if (ss.str().find("inf") == string::npos) valid = true; } } diff --git a/src/synapsis.cpp b/src/synapsis.cpp index dea48da..46543e6 100644 --- a/src/synapsis.cpp +++ b/src/synapsis.cpp @@ -73,7 +73,10 @@ namespace neuralpp { } void Synapsis::setWeight(double w) { - weight = w; + if (weight > 1.0) + weight = 1.0; + else + weight = w; } void Synapsis::setDelta(double d) {