Libann

Libann: Creating a Feature Vector


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Creating a Feature Vector

Before you can do anything useful with a neural network, you need to have some feature vectors defined. Feature vectors must be of the class ExtInput or (more usually) a class which is derived from it. The ExtInput class is defined in `ann/ann.h' and if you have a look through that file you will see that it is (eventually) derived from the Standard Template Library class std::vector<float>. The following code fragment shows a na@"{i}ve way to create a feature vector.
 
#include <ann/ann.h>

// Create a feature vector of length 4
ann::ExtInput featureVector(4);

featureVector[0]=0.907;
featureVector[1]=1.092;
featureVector[2]=54.0;
featureVector[3]=-3.409;

In real life examples however, your feature vector comprises elements of some physical quantity, such as pixel values of an image, a word frequency table from a passage of text, or some physical quantities. So you will probably want to define your own class to be used in place of ann::ExtInput. The beauty of the C++ inheritance mechanism is that this can be done very easily:
 
#include <ann/ann.h>

// A class to represent physical properties of human individuals

class VitalStatistics : public ann::ExtInput {
public:
  // Construct a VitalStatistics object
  VitalStatistics(float height, float weight) : ann::ExtInput(2) {
    (*this)[0] = height;
    (*this)[1] = weight;
  }
}

Now you can instantiate a VitalStatistics object and use it anywhere you could have used a ann::ExtInput:

 
int
main(int argc, char **argv)
{

  try {

    // Make a VitalStatistics 
    VitalStatistics vs1(1.59,67,45);

    // and another
    VitalStatistics vs2(1.82,95,03);

    // rest of the program goes here

    } catch ( ...
	       
    .
    .
    .

}

These examples show the principle of how it works. In practice, you would be creating hundreds of instances, and would therefore probably read the data from a file or other external source.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by John Darrington on May, 15 2003 using texi2html

[Home] [Frequently Asked Questions] [News] [Development] [Links] [Using and Installing] [Download] [Licence]