neuralpp/examples/doAdd.cpp

50 lines
993 B
C++
Raw Normal View History

2009-02-18 00:19:29 +01:00
/**
* 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.
2009-02-18 00:19:29 +01:00
*
* by BlackLight, 2009
*/
#include <iostream>
#include <neural++.hpp>
2009-08-16 11:09:42 +02:00
using namespace std;
2009-02-18 00:19:29 +01:00
using namespace neuralpp;
2009-09-02 21:16:47 +02:00
#define NETFILE "network.xml"
2009-02-18 00:19:29 +01:00
int main() {
double a,b;
NeuralNet net;
2009-02-18 00:19:29 +01:00
// Load the pre-trained network from "adder.net" file
2009-02-18 00:19:29 +01:00
try {
net = NeuralNet(NETFILE);
2009-02-18 00:19:29 +01:00
}
catch (NetworkFileNotFoundException e) {
cerr << "Fatal error while opening " << NETFILE << ": " << e.what();
return 1;
}
cout << "First number to add: ";
cin >> a;
cout << "Second number to add: ";
cin >> b;
vector<double> v;
2009-02-18 00:19:29 +01:00
v.push_back(a);
v.push_back(b);
// Set the numbers just read as input values, propagate those values, and get
// the output
net.setInput(v);
net.propagate();
2009-08-16 18:02:24 +02:00
cout << "Neural net output: " << net.getOutput() << endl;
2009-02-18 00:19:29 +01:00
return 0;
}