77.

c++ neural networks and fuzzy logic C++ Neural Networks and Fuzzy Logic
by Valluru B. Rao
M&T Books, IDG Books Worldwide, Inc.
ISBN: 1558515526   Pub Date: 06/01/95
  

Previous Table of Contents Next


C++ Code for Implementing a Kohonen Map

The C++ code for the Kohonen map draws on much of the code developed for the backpropagation simulator. The Kohonen map is a much simpler program and may not rely on as large a data set for input. The Kohonen map program uses only two files, an input file and an output file. In order to use the program, you must create an input data set and save this in a file called input.dat. The output file is called kohonen.dat and is saved in your current working directory. You will get more details shortly on the formats of these files.

The Kohonen Network

The Kohonen network has two layers, an input layer and a Kohonen output layer. (See Figure 11.4). The input layer is a size determined by the user and must match the size of each row (pattern) in the input data file.


Figure 11.4  A Kohonen network.

Modeling Lateral Inhibition and Excitation

The mexican hat function shows positive values for an immediate neighborhood around the neuron and negative values for distant neurons. A true method of modeling would incorporate mutual excitation or support for neurons that are within the neighborhood (with this excitation increasing for nearer neurons) and inhibition for distant neurons outside the neighborhood. For the sake of computational efficiency, we model lateral inhibition and excitation by looking at the maximum output for the output neurons and making that output belong to a winner neuron. Other outputs are inhibited by setting their outputs to zero. Training, or weight update, is performed on all outputs that are within a neighborhood size distance from the winner neuron. Neurons outside the neighborhood do not participate in training. The true way of modeling lateral inhibition would be too expensive since the number of lateral connections is quite large. You will find that this approximation will lead to a network with many if not all of the properties of a true modeling approach of a Kohonen network.

Classes to be Used

We use many of the classes from the backpropagation simulator. We require only two layers, the input layer and the Kohonen layer. We make a new layer class called the Kohonen layer class, and a new network class called the Kohonen_network.

Revisiting the Layer Class

The layer class needs to be slightly modified, as shown in Listing 11.1.

Listing 11.1 Modification of layer.h

 // layer.h             V.Rao, H. Rao // header file for the layer class hierarchy and // the network class #define MAX_LAYERS    5 #define MAX_VECTORS   100 class network; class Kohonen_network; class layer { protected:        int num_inputs;        int num_outputs;        float *outputs;// pointer to array of outputs        float *inputs; // pointer to array of inputs, which                                      // are outputs of some other layer        friend network;        friend Kohonen_network; // update for Kohonen model public:        virtual void calc_out()=0; }; ... 

Here the changes are indicated in italic. You notice that the Kohonen_network is made a friend to the layer class, so that the Kohonen_network can have access to the data of a layer.

A New Layer Class for a Kohonen Layer

The next step to take is to create a Kohonen_layer class and a Kohonen_network class. This is shown in Listing 11.2.

Listing 11.2 The Kohonen_layer class and Kohonen_network class in layerk.h

 // layerk.h           V.Rao, H. Rao // header file for the Kohonen layer and // the Kohonen network class Kohonen_network; class Kohonen_layer: public layer { protected:        float * weights;        int winner_index;        float win_distance;        int neighborhood_size;        friend Kohonen_network; public:         Kohonen_layer(int, int, int);         ~Kohonen_layer();         virtual void calc_out();         void randomize_weights();         void update_neigh_size(int);         void update_weights(const float);         void list_weights();         void list_outputs();         float get_win_dist(); }; class Kohonen_network { private:         layer *layer_ptr[2];         int layer_size[2];         int neighborhood_size; public:         Kohonen_network();         ~Kohonen_network();         void get_layer_info();         void set_up_network(int);         void randomize_weights();         void update_neigh_size(int);         void update_weights(const float);         void list_weights();         void list_outputs();         void get_next_vector(FILE *);         void process_next_pattern();         float get_win_dist();         int get_win_index(); }; 

The Kohonen_layer is derived from the layer class, so it has pointers inherited that point to a set of outputs and a set of inputs. Let’s look at some of the functions and member variables.


Previous Table of Contents Next

Copyright © IDG Books Worldwide, Inc.



C++ Neural Networks and Fuzzy Logic
C++ Neural Networks and Fuzzy Logic
ISBN: 1558515526
EAN: 2147483647
Year: 1995
Pages: 139

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net