Skip to content

Instantly share code, notes, and snippets.

@nurettin
Created January 16, 2016 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nurettin/157a7e41ce15478ab5fe to your computer and use it in GitHub Desktop.
Save nurettin/157a7e41ce15478ab5fe to your computer and use it in GitHub Desktop.
fast artificial neural network library
#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