2015-03-23 18:28:29 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <exception>
|
|
|
|
|
|
|
|
#include "Net.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::cout << "Neuro running" << std::endl;
|
|
|
|
|
2015-10-18 20:05:18 +00:00
|
|
|
Net myNet({ 3, 2, 1 });
|
2015-03-23 18:28:29 +00:00
|
|
|
|
2015-10-18 20:05:18 +00:00
|
|
|
for (int i = 0; i < 100000; ++i)
|
2015-10-17 20:05:27 +00:00
|
|
|
{
|
2015-10-18 20:05:18 +00:00
|
|
|
std::vector<double> inputValues =
|
|
|
|
{
|
|
|
|
std::rand() / (double)RAND_MAX,
|
|
|
|
std::rand() / (double)RAND_MAX,
|
|
|
|
std::rand() / (double)RAND_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<double> targetValues = { inputValues[2] };
|
|
|
|
|
2015-10-17 20:05:27 +00:00
|
|
|
myNet.feedForward(inputValues);
|
2015-10-15 17:18:26 +00:00
|
|
|
|
2015-10-17 20:05:27 +00:00
|
|
|
std::vector<double> outputValues = myNet.getOutput();
|
2015-03-23 18:28:29 +00:00
|
|
|
|
2015-10-18 20:05:18 +00:00
|
|
|
double error = outputValues[0] - targetValues[0];
|
|
|
|
|
|
|
|
std::cout << "Error: ";
|
|
|
|
std::cout << std::abs(error);
|
2015-10-17 20:05:27 +00:00
|
|
|
std::cout << std::endl;
|
2015-10-15 17:18:26 +00:00
|
|
|
|
2015-10-17 20:05:27 +00:00
|
|
|
myNet.backProp(targetValues);
|
|
|
|
}
|
2015-03-23 18:28:29 +00:00
|
|
|
}
|
|
|
|
catch (std::exception &ex)
|
|
|
|
{
|
|
|
|
std::cerr << "Error: " << ex.what() << std::endl;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|