Click here to Skip to main content
11,567,325 members (44,931 online)
Click here to Skip to main content
Add your own
alternative version

Artificial Neural Networks made easy with the FANN library

, 28 Aug 2013 CPOL 125.7K 8.1K 192
Neural networks are typically associated with specialised applications, developed only by select groups of experts. This misconception has had a highly negative effect on its popularity. Hopefully, the FANN library will help fill this gap.
fann-1_2_0.zip
fann-1.2.0
debian
changelog
compat
control
copyright
docs
libfann1-dev.dirs
libfann1-dev.examples
libfann1-dev.files
libfann1-dev.install
libfann1.dirs
libfann1.files
libfann1.install
rules
doc
fann_doc_complete_1.0.pdf
Makefile
html
src
include
Makefile.in
Makefile.am
Makefile.in
COPYING
Makefile.am
win32_dll
examples
makefile
README
Makefile.in
configure
AUTHORS
COPYING
ChangeLog
INSTALL
Makefile.am
NEWS
TODO
aclocal.m4
config.guess
config.sub
configure.in
depcomp
fann.pc.in
fann.spec.in
install-sh
ltmain.sh
missing
mkinstalldirs
benchmarks
datasets
building.test
building.train
diabetes.test
diabetes.train
gene.test
gene.train
mushroom.test
mushroom.train
robot.test
robot.train
soybean.test
soybean.train
thyroid.test
thyroid.train
two-spiral.train
pumadyn-32fm.test
pumadyn-32fm.train
two-spiral.test
parity8.train
parity8.test
parity13.test
parity13.train
Makefile
README
benchmark.sh
benchmarks.pdf
gnuplot
performance.cc
quality.cc
.cvsignore
examples
Makefile
xor.data
python
README
examples
libfann.i
makefile.gnu
makefile.msvc
libfann.pyc
MSVC++
libfann.dsp
all.dsw
simple_test.dsp
simple_train.dsp
steepness_train.dsp
xor_test.dsp
xor_train.dsp
config.in
fann_win32_dll-1_2_0.zip
changelog
compat
control
copyright
docs
libfann1-dev.dirs
libfann1-dev.examples
libfann1-dev.files
libfann1-dev.install
libfann1.dirs
libfann1.files
libfann1.install
rules
fann_doc_complete_1.0.pdf
Makefile
Makefile.in
Makefile.am
Makefile.in
COPYING
Makefile.am
makefile
README
Makefile.in
configure
AUTHORS
COPYING
ChangeLog
INSTALL
Makefile.am
NEWS
TODO
aclocal.m4
config.guess
config.sub
configure.in
depcomp
fann.pc.in
fann.spec.in
install-sh
ltmain.sh
missing
mkinstalldirs
building.test
building.train
diabetes.test
diabetes.train
gene.test
gene.train
mushroom.test
mushroom.train
robot.test
robot.train
soybean.test
soybean.train
thyroid.test
thyroid.train
two-spiral.train
pumadyn-32fm.test
pumadyn-32fm.train
two-spiral.test
parity8.train
parity8.test
parity13.test
parity13.train
Makefile
README
benchmark.sh
benchmarks.pdf
gnuplot
performance.cc
quality.cc
.cvsignore
Makefile
xor.data
README
libfann.i
makefile.gnu
makefile.msvc
libfann.pyc
libfann.dsp
all.dsw
simple_test.dsp
simple_train.dsp
steepness_train.dsp
xor_test.dsp
xor_train.dsp
config.in
bin
fanndoubled.dll
fanndoubled.lib
fanndoubleMTd.dll
fanndoubleMTd.lib
fannfixedd.dll
fannfixedd.lib
fannfixedMTd.dll
fannfixedMTd.lib
fannfloatd.dll
fannfloatd.lib
fannfloatMTd.dll
fannfloatMTd.lib
fanndouble.dll
fanndouble.lib
fanndoubleMT.dll
fanndoubleMT.lib
fannfixed.dll
fannfixed.lib
fannfixedMT.dll
fannfixedMT.lib
fannfloat.dll
fannfloat.lib
fannfloatMT.dll
fannfloatMT.lib
vs_net2003.zip
VS.NET2003
/*       Two-Spirals Benchmark
	 Data Set Generator
	 
	 v1.0
	 By:  Matt White  (mwhite+@cmu.edu)
	 Based on code by Alexis Wieland of MITRE Corporation

	 Usage: a.out <density> <radius>
	   Density defaults to '1'. 
	   Radius defaults to '6.5'.
	   These are the values used in the original benchmark.
	   Changing the density changes the number of data points generated.
	   Changing the radius changes the range of numbers generated.
	 
	 Description
	 ~~~~~~~~~~~
	   This program generates two sets of points, each with 
         96 * density + 1 data points (3 revolutions of 32 times the density
	 plus one end point).  The output of this program is in the standard
	 CMU Neural Network Benchmark format.  For more information, see the 
	 accompanying database file, 'two-spirals'.
*/ 

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

#ifndef PI           /* PI is defined on some systems, if it is not, define */
#define PI 3.1416    /*  it to four decimal places.  Good enough for our    */
#endif               /*  purposes.                                          */


/*      Function Prototypes      */

void getCommandLine ( int *, double *, int, char ** );
void printHeader    ( int, double );
void printSet       ( int, double );


int main  ( int argc, char **argv )
{
  int density;        /* Density of the data set to generate */
  double maxRadius;   /* Maximum radius of the data set to generate */

  getCommandLine ( &density, &maxRadius, argc, argv );
  printHeader    ( density, maxRadius );
  printSet       ( density, maxRadius );

  return 0;
}


/*      getCommandLine -  This function reads the values from the command line
	and interprets them.  The first argument is read as the density and the
	second as the radius.  If there is no value for radius, it defaults to
	6.5 while density defaults to 1.  Extra arguments are ignored.
*/

void getCommandLine  ( int *density, double *maxRadius, int argc, char **argv )
{
  if  ( argc < 2 )
    *density = 1;
  else  
    *density = atoi( *(argv+1) );
  if  ( argc < 3 )
    *maxRadius = 6.5;
  else
    *maxRadius = atof( *(argv+2) );
}


/*      printHeader -  This function prints out the header information for the
	data set.  This includes generation time (local), density and radius.
	It also prints the $SETUP segment for the data set.
*/

void printHeader ( int density, double maxRadius )
{
  time_t genTime;

  time( &genTime );

  /*
  printf  (";Two-Spirals Benchmark\n");
  printf  (";Generated: %s", asctime( localtime( &genTime ) ));
  printf  (";Density:   %d\n", density );
  printf  (";Radius:    %.2f\n\n", maxRadius );
  printf  (";Program by: Matt White  (mwhite+@cmu.edu)\n");
  printf  (";Benchmark by: Alexis Wieland of MITRE Corporation\n");
  printf  (";  Any questions should be directed to neural-bench@cs.cmu.edu.");
  printf  ("\n\n");

  printf  ("$SETUP\n\n");
  printf  ("PROTOCOL: IO;\n");
  printf  ("OFFSET: 0;\n");
  printf  ("INPUTS: 2;\n");
  printf  ("OUTPUTS: 1;\n\n");
  printf  ("IN [1]: CONT {%.2f,-%.2f};\n", maxRadius, maxRadius );
  printf  ("IN [2]: CONT {%.2f,-%.2f};\n\n", maxRadius, maxRadius );
  printf  ("OUT [1]: BINARY;\n\n\n");

  printf  ("$TRAIN\n\n");
  */

  printf("%d 2 1\n", (density * 96 + 1) * 2);
}


/*      printSet -  Generates and prints out a data set having the specified
	density and radius.
*/

void printSet  ( int density, double maxRadius )  
{
  int points,      /* Number of interior data points to generate */
      i;           /* Indexing variable */
  double x,        /* x coordinate */
         y,        /* y coordinate */
         angle,    /* Angle to calculate */
         radius;   /* Radius at current iteration */

  points = ( 96 * density ); 
  for  ( i = 0 ; i <= points ; i++ )  {

    /* Angle is based on the iteration * PI/16, divided by point density */
    angle = ( i * PI ) / ( 16.0 * density );

    /* Radius is the maximum radius * the fraction of iterations left */
    radius = maxRadius * ( ( 104 * density ) - i ) / ( 104 * density );

    /* x and y are based upon cos and sin of the current radius */
    x = radius * cos( angle );
    y = radius * sin( angle );

    /* printf ("%8.5f, %8.5f  =>  +;\n", x, y ); */
    /* printf ("%8.5f, %8.5f  =>  -;\n", -x, -y ); */
    printf ("%8.5f %8.5f 1\n", x, y );
    printf ("%8.5f %8.5f 0\n", -x, -y );
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Software Developer's Journal
Publisher
Poland Poland
Software Developer's Journal (formerly Software 2.0) is a magazine for professional programmers and developers publishing news from the software world and practical articles presenting very interesting ready programming solutions. To read more

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150624.2 | Last Updated 28 Aug 2013
Article Copyright 2006 by Software Developer's Journal
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid