(C++) FANN example 1: basics

February 24, 2017 · View on GitHub

 

 

 

 

 

(C++) FANN example 1: basics

 

This example demonstrates a basic FANN program.

 

 

Operating system: Ubuntu 10.04 LTS Lucid Lynx

IDE: Qt Creator 2.0.0

Project type: GUI application

Compiler: G++ 4.4.1

Libraries used:

 

 

 

 

 

Qt project file

 


#------------------------------------------------- # # Project created by QtCreator 2010-08-12T16:17:45 # #------------------------------------------------- QT += core QT -= gui LIBS += -L/usr/local/lib -lfann TARGET = CppFannExample1 CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp

 

 

 

 

 

main.cpp

 


#include <iostream> #include <vector> #include <floatfann.h> int main() {   //Create layer sizes { 2,2,1 }   std::vector<unsigned int> layer_sizes(2,2);   layer_sizes.push_back(1); //One output neuron   //Create the neural network from it   const double learning_rate = 0.05;   fann * const n = fann_create_shortcut_array(     learning_rate,     layer_sizes.size(),     &layer_sizes[0]);   //Create the inputs   std::vector<fann_type> inputs(2);   inputs[0] = 0.0;   inputs[1] = 1.0;   //Calculate the neural net output   fann_type * const outputs = fann_run(n, &inputs[0]);   //'The' output is just the one output neuron added at top   const double output = outputs[0];   std::cout << "Output: " << output << '\n';   //Destroy the network   fann_destroy(ann); }