• No se han encontrado resultados

LEGITIMACIÓN ACTIVA

In document La acción de deslinde (página 34-37)

6. LOS SUJETOS DEL DESLINDE

6.1 LEGITIMACIÓN ACTIVA

• weights.dat You can look at this file to see the weights for the network. It shows

the layer number followed by the weights that feed into the layer. The first layer, or input layer, layer zero, does not have any weights associated with it. An example of the weights.dat file is shown as follows for a network with three layers of sizes 3, 5, and 2. Note that the row width for layer n matches the column length for layer n + 1: 1 -0.199660 -0.859660 -0.339660 -0.25966 0.520340 1 0.292860 -0.487140 0.212860 -0.967140 -0.427140 1 0.542106 -0.177894 0.322106 -0.977894 0.562106 2 -0.175350 -0.835350 2 -0.330167 -0.250167 2 0.503317 0.283317 2 -0.477158 0.222842 2 -0.928322 -0.388322

In this weights file the row width for layer 1 is 5, corresponding to the output of that (middle) layer. The input for the layer is the column length, which is 3, just as specified. For layer 2, the output size is the row width, which is 2, and the input size is the column length, 5, which is the same as the output for the middle layer. You can read the weights file to find out how things look.

• training.dat This file contains the input patterns for training. You can have as

large a file as you’d like without degrading the performance of the simulator. The simulator caches data in memory for processing. This is to improve the speed of the simulation since disk accesses are expensive in time. A data buffer, which has a maximum size specified in a #define statement in the program, is filled with data from the training.dat file whenever data is needed. The format for the training.dat file has been shown in the Training mode section.

• test.dat The test.dat file is just like the training.dat file but without expected

outputs. You use this file with a trained neural network in Test mode to see what responses you get for untrained data.

• output.dat The output.dat file contains the results of the simulation. In Test

C++ Neural Networks and Fuzzy Logic:Backpropagation

mode, the input and output vectors are shown for all pattern vectors. In the

Simulator mode, the expected output is also shown, but only the last vector in the

training set is presented, since the training set is usually quite large. Shown here is an example of an output file in Training mode:

for input vector: 0.400000 -0.400000 output vector is: 0.880095

expected output vector is: 0.900000

Previous Table of Contents Next Copyright © IDG Books Worldwide, Inc.

C++ Neural Networks and Fuzzy Logic:Backpropagation

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++ Classes and Class Hierarchy

So far, you have learned how we address most of the objectives outlined for this program. The only objective left involves the demonstration of some C++ features. In this program we use a class hierarchy with the inheritance feature. Also, we use polymorphism with dynamic binding and function overloading with static binding.

First let us look at the class hierarchy used for this program (see Figure 7.2). An abstract class is a class that is never meant to be instantiated as an object, but serves as a base class from which others can inherit functionality and interface definitions. The layer class is such a class. You will see

shortly that one of its functions is set = zero, which indicates that this class is an abstract base class. From the layer class are two branches. One is the input_layer class, and the other is the

output_layer class. The middle layer class is very much like the output layer in function and so inherits from the output_layer class.

Figure 7.2 Class hierarchy used in the backpropagation simulator.

Function overloading can be seen in the definition of the calc_error() function. It is used in the input_layer with no parameters, while it is used in the output_layer (which the input_layer inherits from) with one parameter. Using the same function name is not a problem, and this is referred to as overloading. Besides function overloading, you may also have operator overloading, which is using an operator that performs some familiar function like + for addition, for another function, say, vector addition.

When you have overloading with the same parameters and the keyword virtual, then you have the potential for dynamic binding, which means that you determine which overloaded function to execute at run time and not at compile time. Compile time binding is referred to as static binding. If you put a bunch of C++ objects in an array of pointers to the base class, and then go through a loop that indexes each pointer and executes an overloaded virtual function that pointer is pointing to, then you will be using dynamic binding. This is exactly the case in the function calc_out(), which is

C++ Neural Networks and Fuzzy Logic:Backpropagation

declared with the virtual keyword in the layer base class. Each descendant of layer can provide a version of calc_out(), which differs in functionality from the base class, and the correct function will be selected at run time based on the object’s identity. In this case calc_out(), which is a

function to calculate the outputs for each layer, is different for the input layer than for the other two types of layers.

Let’s look at some details in the header file in Listing 7.1: Listing 7.1 Header file for the backpropagation simulator

// 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 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;

public:

virtual void calc_out()=0; };

class input_layer: public layer { private: public: input_layer(int, int); ~input_layer(); file:///H:/edonkey/docs/c/(ebook-pdf)%20-%20mathem..._Neural_Networks_and_Fuzzy_Logic/ch07/137-142.html (2 of 4) [21/11/02 21:57:28]

C++ Neural Networks and Fuzzy Logic:Backpropagation

virtual void calc_out(); };

class middle_layer;

class output_layer: public layer {

protected:

float * weights;

float * output_errors; // array of errors at output

float * back_errors; // array of errors back-propagated float * expected_values; // to inputs

friend network; public:

output_layer(int, int); ~output_layer();

virtual void calc_out(); void calc_error(float &); void randomize_weights();

void update_weights(const float); void list_weights();

void write_weights(int, FILE *); void read_weights(int, FILE *); void list_errors();

void list_outputs(); };

class middle_layer: public output_layer { private: public: middle_layer(int, int); ~middle_layer(); void calc_error(); }; class network { private: file:///H:/edonkey/docs/c/(ebook-pdf)%20-%20mathem..._Neural_Networks_and_Fuzzy_Logic/ch07/137-142.html (3 of 4) [21/11/02 21:57:28]

C++ Neural Networks and Fuzzy Logic:Backpropagation layer *layer_ptr[MAX_LAYERS]; int number_of_layers; int layer_size[MAX_LAYERS]; float *buffer; fpos_t position; unsigned training; public: network(); ~network();

void set_training(const unsigned &); unsigned get_training_value();

void get_layer_info(); void set_up_network(); void randomize_weights();

void update_weights(const float); void write_weights(FILE *); void read_weights(FILE *); void list_weights(); void write_outputs(FILE *); void list_outputs(); void list_errors(); void forward_prop();

void backward_prop(float &); int fill_IObuffer(FILE *); void set_up_pattern(int); };

Previous Table of Contents Next Copyright © IDG Books Worldwide, Inc.

C++ Neural Networks and Fuzzy Logic:Backpropagation

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

In document La acción de deslinde (página 34-37)

Documento similar