/* *************************************************************  
 
        Final Project                                 MMU 1996

        ###################################################### 
        #                                                    # 
        #               A Modular Neural Network             #    
        #                                                    # 
        #                THE SINGLE LAYER CLASS              # 
        #                                                    # 
        ###################################################### 
   
        Albrecht Schmidt                              09.08.96   
    
        FILE: CLayer.h                             Version 1.0 
  
   ************************************************************* */ 

#ifndef _CLayer_h
#define _CLayer_h

#include <stdio.h>
#include "CCell.h"
#include "CSupport.h"

class CLayer : CSupport
{
  private:
        int        no_inputs, no_outputs;
        TFunction  function;
        
        double      lambda;
        double      const_input; // The Bias value
        
	CCell * neuron[MAX_NEURONS]; // Pointer Array with the Neurons
	// enlarge the Vector to add the BIAS
	TVector CLayer::AddConst(TVector retV, TVector inputV);

  public:

  // Constructor with arguments
  CLayer::CLayer(int no_in, int no_out, TFunction fct, double lam);
  // Destructor
  CLayer::~CLayer();
  
  // function to get the number of Outputs  
  int CLayer::GetNoOutputs();
  // function to get the number of inputs
  int CLayer::GetNoInputs();
 
  // Set the labda value for the layer 
  void CLayer::SetLambda(double lam);
  // Get the labda value for the layer 
  double CLayer::GetLambda();

  // Calculate the Net Vector (weighted sum of inputs) 
  TVector CLayer::Net(TVector retV, TVector inputV);
  // Calculate the Output Vector ( f(net) )
  TVector CLayer::Out(TVector retV, TVector inputV);
  // calculates a derivative according to the used function
  double CLayer::Derive(double net);

  // Calculate the output layer delta
  TVector CLayer::DeltaOut(TVector retV, TVector inputV, TVector targetV);

  // Calculate the hidden layer delta
  TVector CLayer::DeltaHidden(TVector retV, TVector netV, TVector deltaV);

// update the weights 
void CLayer::UpdateWeights(double eta,           // learning constant
                           TVector inputV,      // input vector
                           TVector deltaV,      // delta vector
                           double alpha = DEFAULT_ALPHA);  
                                               // momentum alpha  

  // Write the Weights in a file
  void CLayer::WriteWeights(FILE* fd);
  // Read the Weights from file
  void CLayer::ReadWeights(FILE* fd);

  // Display the Weights
  void CLayer::PrintWeights();
  // Set the weights to a random value
  void CLayer::ResetWeights(double min=MIN_RND, double max=MAX_RND);
};
#endif
