mirror of
https://github.com/BlackLight/neuralpp.git
synced 2024-12-28 04:05:12 +01:00
Testing, testing, testing
This commit is contained in:
parent
b50b2c08ae
commit
aac905673b
5 changed files with 22 additions and 15 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
*/
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
**************************************************************************************************/
|
||||
|
||||
#include <sstream>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,9 @@ namespace neuralpp {
|
|||
}
|
||||
|
||||
void Synapsis::setWeight(double w) {
|
||||
if (weight > 1.0)
|
||||
weight = 1.0;
|
||||
else
|
||||
weight = w;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue