Created
January 16, 2016 18:21
-
-
Save nurettin/157a7e41ce15478ab5fe to your computer and use it in GitHub Desktop.
fast artificial neural network library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fann.h> | |
#include <fann_cpp.h> | |
void prepare_data(std::string const &name){ | |
std::ofstream file(name+ ".data", std::ios::trunc); | |
file<< "4 2 1\n" | |
<< "0 0\n0\n" | |
<< "0 1\n1\n" | |
<< "1 0\n1\n" | |
<< "1 1\n0\n"; | |
} | |
void prepare_net(std::string const &name, | |
std::initializer_list<unsigned> layers){ | |
for(int t= 0; t< 10; ++ t){ | |
FANN::neural_net net; | |
std::vector<unsigned> v(layers); | |
net.create_standard_array(v.size(), &v[0]); | |
net.train_on_file(name+ ".data", 1000, 0, .0f); | |
if(net.get_MSE()== 0){ | |
if(!net.save(name+ ".net")){ | |
throw std::runtime_error("unable to save: "+ name); | |
} | |
return; | |
} | |
} | |
throw std::runtime_error("unable to create: "+ name); | |
} | |
int main(){ | |
prepare_data("xor"); | |
for(int n= 0; n< 100; ++ n) | |
{ | |
prepare_net("xor", { 2, 2, 1 }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment