#ifndef FACEREC_GDR_H
#define FACEREC_GDR_H 1

#include <iostream.h>
#include <math.h>
#include "Functions.h"
#include <time.h>
#include <stdlib.h>

typedef double (* Function)(double ,double ) ;

class Layer
{
	// Added by Rajesh
	enum { Sig = 1001 ,DSig,Lin ,DLin };
	// Added by Rajesh
	
	long No;
	double * Neuron;//[30];
	Function Func;
	Function DerF;

	void operator = (Layer L);
	Layer (const Layer & L);

	public :
		void Initialize(long N,Function F,Function D);
		double Get(long i);
		void Set(long i,double val);
		void ApplyFunc(double al);
		double Derivative(long i);
		long NoOfNeurons();

		void SetDouble(double D[]);		

		// Added by Rajesh
		// Default constructor
		Layer();
		
		// Destroy the object explicitly
		void Destroy();
		~Layer();

		// Methods to save and retrieve from a file
		friend ostream& operator << ( ostream & os , Layer & l );
		friend istream& operator >> ( istream & is , Layer & l );
		// Added by Rajesh
};

class Weight
{
	long Present;
	long Next;
	double ** Wt;//[30][30];

	public :
		void Initialize(long P,long N);
		double Get(long i,long j);
		void Add(long i,long j,double Delta);

		// Added by Rajesh
		// Default constructor
		Weight();
		
		// Destroy the object explicitly
		void Destroy();
		~Weight();

		// Methods to save and retrieve from a file
		friend ostream& operator << ( ostream & os , Weight & w );
		friend istream& operator >> ( istream & is , Weight & w );
		// Added by Rajesh
};

class Network
{
	Layer * L;
	Weight * W;
	int No;				//No of layers
	double LRate;

	public :
		void Initialize(int N);
		void Initialize(long * N,double Lrate);	
		void SetInput(Layer & I);
		void SetInput(int * I);
		void GetOutput(Layer & O);
		void Train(Layer & I,Layer & O,double Th);
		double Train(Layer & I,Layer & O,double Th,int Dummy);
		void CalcOutput();

		// Added by Rajesh
		// Default constructor
		Network();
		
		// Destroy the object explicitly
		void Destroy();
		~Network();

		// Methods to save and retrieve from a file
		friend ostream& operator << ( ostream & os , Network & n );
		friend istream& operator >> ( istream & is , Network & n );

		// Extra methods for convinience
		bool ReadFromFile(char * szFileName);
		bool WriteToFile (char * szFileName);
		// Added by Rajesh

		void DestroyAll();
};


#endif
