/* *************************************************************

        Final Project                                 MMU 1996

        ######################################################
        #                                                    #
        #               A Modular Neural Network             #   
        #                                                    #
        #       A SINGLE LAYER OF THE MODULAR NETWORK        #   
        #                                                    #
        ######################################################

        Albrecht Schmidt                              09.08.96

        FILE: CMLayer.h                             Version 1.0

   ************************************************************* */
#ifndef _CMulLayer_h
#define _CMulLayer_h


#include <stdlib.h>
#include "neuro.h"

#define MAX_NETS 10000
#define MAX_INV_LEN 20000
#define NO_RND_MAPPING -1

enum TOutRep {small, big};
 
// the data structure to describe a network
typedef struct TNetDef
{
	int no_inputs;   // number of inputs
	int no_layers;   // number of layers (without the input layer)
	double lambda;   // lambda value for the transfer function
	TFunction fct;   // transfer function (bi_pol or uni_pol)
	int neuronL[MAX_LAYER];  // number of neurons in each layer
};

class CMulLayer : CSupport
{
   private:
	int no_inputs;  	// The number of inputs to the whole layer
	int no_inputs_user;	// The number of inputs from the user
	int no_inputs_net;	// The number of inputs per sub-net
	int no_outputs_net;	// The number of outputs per sub-net 
	int no_nets;		// The number of sub-nets
	
	TNetDef *net_definition;	// The definition of the sub-nets

        int *inputMapping;     // the mapping of the inputs onto the modules

	int rnd_seed;          // the initialization value for the
                               // random function

	double *ext_inputV;    // if the number of user inputs fits no to the 
                               // number of inputs to the modules the vector is 
                               // extented with constant values
	double *mapped_inputV; // in this array the mapping from user inputs
                               // to the modules is performed

	CBackPro *net[MAX_NETS]; // the subnetworks
 
   public:
        // the constructor with parameters
	CMulLayer::CMulLayer(int no_sub_nets, // number of subnets
			     int no_u_inputs, // number of user inputs
			     TNetDef *net_def,// definition of subnets
			     int r_seed = NO_RND_MAPPING); //random seed

        // the constructor from file
	CMulLayer::CMulLayer(char *file_start);

	// the destructor
	CMulLayer::~CMulLayer();

	// learning a vector of that the output is known 
	double CMulLayer::Learn(TVector inV,       // the input vector
                                TVector tarV,      // the target vector
                                double eta=1,      // learning constant
                                double alpha = 0); // momentum
		// returns the error-value for the input vector

	// calculate the response of the layer for an input
	TVector CMulLayer::Apply(TVector resV, // allocated result vector
                                 TVector inV); // the input vector
		// returns the response vector

	// routine to reset the weights of the Layer
	void CMulLayer::ResetWeights(double min=MIN_RND, double max=MAX_RND);
        // store the layer onto disk
	void CMulLayer::Store(char *file_start);
};

#endif

